Clone of UAS2 @ https://github.com/drudgedance/uas2

Status.cpp 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * This file is part of UAS2.
  3. *
  4. * UAS2 is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * UAS2 is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. * You should have received a copy of the GNU General Public License
  14. * along with UASv1; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. /**
  18. * @file Status.cpp
  19. */
  20. /*
  21. Server Updates
  22. On Server Load:
  23. svr_update.php?nStat=2&sID=&sSer=&sKey=&aIP=&bIP=&cIP=&dIP=&sPort=&sVer="Moo"&cVer=&cMax=
  24. On Server Start & every 15 minutes there-after:
  25. svr_update.php?nStat=4&sID=&sSer=&sKey=&cAvg=
  26. On Server Shutdown Schedule & every 15 minutes there-after:
  27. svr_update.php?nStat=3&sID=&sSer=&sKey=&sTTE=&mText="Moo"&cAvg=
  28. sTTTE can be omitted, if it is not, it should be the number of seconds until the server will shut down.
  29. mText can be omittes, if it is not, it can be free-style text explaining why the server is going down.
  30. On server final go down:
  31. svr_update.php?nStat=1&sID=&sSer=&sKey=&sTTE=&mText="Moo"
  32. sTTTE can be omitted, if it is not, it should be the number of seconds until the server will return.
  33. mText can be omittes, if it is not, it can be free-style text explaining why the server is down.
  34. Variables:
  35. nStat = New Status. 1=down, 2=loading, 3=countdown to down, 4=running
  36. sID = Server IS. Serial number given when server registered.
  37. sSer = Server Serial. A 30-character random alphanumeric serial string to prevent server ID 'jacking.'
  38. sKey = Session Key. 6-charactes. Generated by server on load. used to track a session (and server crashes.) Random Number
  39. aIP =\
  40. bIP = \IP address: a.b.c.d
  41. cIP = /
  42. dIP =/
  43. sPort = Login server port.
  44. sVer = String describing server version. Up to 30 characters. (could eventually be used for sorting)
  45. cVer = serial of version supported.
  46. cMax = Max number of simultaneous users based on speed of hardware server is runnign on.
  47. cAvg = Average number of connected clients in last 5 minutes
  48. sTTE = Time To next Event. Time to downing on stat 3, time to server return (estimated) on stat 1.
  49. mText = Random text string that will be shown in server details for reasons for a server going down or being down. 50 chars max
  50. */
  51. #include "UAS.h"
  52. #include "Status.h"
  53. #ifdef _DEBUG
  54. #undef THIS_FILE
  55. static char THIS_FILE[]=__FILE__;
  56. #define new DEBUG_NEW
  57. #endif
  58. /***************
  59. * constructors/destructors
  60. **************/
  61. int CStatus::m_fPrivate = 1;
  62. char CStatus::m_strHost[16] = { ' ', };
  63. int CStatus::m_sPort = 0;
  64. char CStatus::m_strHTTP[500] = { ' ', };
  65. DWORD CStatus::m_sID = 0x0L;
  66. char CStatus::m_sSer[31] = { ' ', };
  67. char CStatus::m_sKey[7] = { ' ', };
  68. char CStatus::m_cVer[31] = { ' ', };
  69. DWORD CStatus::m_dwMax = 0x0L;
  70. char CStatus::m_strOutput[500] = { ' ', };
  71. char CStatus::m_strSend[1024] = { ' ', };
  72. char CStatus::m_mText[51] = { ' ', };
  73. DWORD CStatus::m_sTTE = 0x0L;
  74. DWORD CStatus::m_cAvg = 0x0L;
  75. char CStatus::m_cVersion[10] = { ' ', };
  76. byte CStatus::m_nStat = 0x00;
  77. SOCKET CStatus::m_Socket;
  78. WSADATA CStatus::m_wsaData;
  79. SOCKET CStatus::m_SendSocket;
  80. byte CStatus::m_bServer[4] = { 0,0,0,0 };
  81. int CStatus::m_ServerPort = 0;
  82. unsigned long CStatus::m_ulLastUpdate = 0;
  83. CStatus::CStatus()
  84. {
  85. }
  86. CStatus::~CStatus()
  87. {
  88. }
  89. void CStatus::Clear()
  90. {
  91. m_fPrivate = true;
  92. sprintf(m_strHost,"127.0.0.1");
  93. m_sPort = 80;
  94. sprintf(m_strHTTP," ");
  95. m_sID = 0x0L;
  96. sprintf(m_sSer," ");
  97. sprintf(m_sKey,"000000");
  98. sprintf(m_cVer,"0000000000000");
  99. m_dwMax = 0x0L;
  100. }
  101. void CStatus::ServerLoad()
  102. {
  103. char strOne[200];
  104. sprintf(strOne,"GET %ssvr_update.php?nStat=2&sID=%d&sSer=%s&sKey=%s&aIP=%d&bIP=%d&cIP=%d&dIP=%d&sPort=%d&sVer=\"UASv1.2\"&cVer=%s&cMax=%d",m_strHTTP,m_sID,m_sSer,&m_sKey,m_bServer[0],m_bServer[1],m_bServer[2],m_bServer[3],m_ServerPort,m_cVersion,m_dwMax);
  105. SendHTTP(strOne);
  106. }
  107. void CStatus::ServerStart()
  108. {
  109. sprintf(m_strOutput,"GET %ssvr_update.php?nStat=4&sID=%d&sSer=%s&sKey=%s&cAvg=%d",m_strHTTP,m_sID,m_sSer,m_sKey,m_cAvg);
  110. SendHTTP(m_strOutput);
  111. }
  112. void CStatus::UpDate( )
  113. {
  114. sprintf(m_strOutput,"GET %ssvr_update.php?nStat=4&sID=%d&sSer=%s&sKey=%s&cAvg=%d",m_strHTTP,m_sID,m_sSer,m_sKey,m_cAvg);
  115. SendHTTP(m_strOutput);
  116. }
  117. void CStatus::ServerShutdown()
  118. {
  119. sprintf(m_strOutput,"GET %ssvr_update.php?nStat=3&sID=%d&sSer=%s&sKey=%s&sTTE=%d&mText=\"Normal_Shutdown\"&cAvg=0",m_strHTTP,m_sID,m_sSer,m_sKey,m_sTTE);
  120. SendHTTP(m_strOutput);
  121. }
  122. void CStatus::ServerOffline()
  123. {
  124. sprintf(m_strOutput,"GET %ssvr_update.php?nStat=1&sID=%d&sSer=%s&sKey=%s&sTTE=%d&mText=\"Offline\"",m_strHTTP,m_sID,m_sSer,m_sKey,m_sTTE);
  125. SendHTTP(m_strOutput);
  126. }
  127. void CStatus::SendHTTP(char* strOutput)
  128. {
  129. char strTwo[400] = { ' ', };
  130. char strSend[425] = { ' ', };
  131. SOCKADDR_IN saSockAddr;
  132. saSockAddr.sin_family = AF_INET;
  133. saSockAddr.sin_port = htons( m_sPort );
  134. saSockAddr.sin_addr.s_addr = inet_addr( m_strHost );
  135. int strLen = sizeof( strOutput );
  136. sprintf(strTwo, "\r\nHTTP/1.1\r\nAccept:image/gif,image/x-xbitmap,image/jpeg,image/pjpeg,application/vnd.ms-powerpoint,application/vnd.ms-excel,application/msword,*/*\r\nAccept-Language:en-us\r\nAccept-Encoding:gzip,deflate\r\nUser-Agent:UAS\r\nHost:%s:%d\r\nConnection:Keep-Alive\r\n", m_strHost,m_sPort);
  137. sprintf(strSend,"%s %s",strOutput,strTwo);
  138. m_SendSocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
  139. m_ulLastUpdate = timeGetTime( ); // Update Time of Last Status Transmission
  140. if( m_fPrivate == 1)
  141. {
  142. // Private Server do not send data messages
  143. }
  144. else
  145. {
  146. connect(m_SendSocket, (SOCKADDR *)&saSockAddr, sizeof( SOCKADDR ) );
  147. //
  148. send(m_SendSocket, (char *)strSend, sizeof( strSend ), NULL);
  149. //
  150. closesocket(m_SendSocket);
  151. }
  152. }