Log.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program 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. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. // log.cpp
  19. // Project: Nostril (aka Postal)
  20. //
  21. // This module with a mechanism to log network traffic created by the game
  22. //
  23. // History:
  24. // 12/05/97 AJC Started.
  25. //
  26. // 12/23/97 SPA Moved from Play.cpp to seperate file
  27. ////////////////////////////////////////////////////////////////////////////////
  28. #include "RSPiX.h"
  29. #include "game.h"
  30. #include "net.h"
  31. #include "netmsgr.h"
  32. #include "Log.h"
  33. ////////////////////////////////////////////////////////////////////////////////
  34. // OpenLogFile()
  35. // Open a file for logging
  36. // global variables used: g_GameSettings
  37. ////////////////////////////////////////////////////////////////////////////////
  38. short OpenLogFile()
  39. {
  40. short sResult = 0; // Assume success
  41. if (g_GameSettings.m_bLogNetTime)
  42. {
  43. if (!g_GameSettings.m_rfNetSyncLog.IsOpen())
  44. {
  45. #ifdef SYS_ENDIAN_BIG
  46. if (g_GameSettings.m_rfNetSyncLog.Open(g_GameSettings.m_szNetSyncLogFile,
  47. "wt+", RFile::BigEndian) != 0)
  48. #else
  49. if (g_GameSettings.m_rfNetSyncLog.Open(g_GameSettings.m_szNetSyncLogFile,
  50. "wt+", RFile::LittleEndian) != 0)
  51. #endif
  52. {
  53. sResult = 1;
  54. TRACE("Play: Cannot open network syn log file\n");
  55. }
  56. }
  57. }
  58. return sResult;
  59. }
  60. ////////////////////////////////////////////////////////////////////////////////
  61. // CloseLogFile()
  62. // Close a file for logging
  63. // global variables used: g_GameSettings
  64. ////////////////////////////////////////////////////////////////////////////////
  65. short CloseLogFile()
  66. {
  67. short sResult = 0; // Assume success
  68. if (g_GameSettings.m_bLogNetTime)
  69. {
  70. if ((g_GameSettings.m_rfNetSyncLog.Close()) != 0)
  71. {
  72. sResult = 1;
  73. TRACE("Play: Failed to close the network syn log file\n");
  74. }
  75. }
  76. return sResult;
  77. }
  78. ////////////////////////////////////////////////////////////////////////////////
  79. // WriteTimeStamp()
  80. // Write the network time log
  81. // global variables used: g_GameSettings
  82. ////////////////////////////////////////////////////////////////////////////////
  83. extern
  84. short WriteTimeStamp(char *pszCaller, // Name of calling routine
  85. char *pszCalleeName, // Name of player being sent or sending
  86. unsigned char ucMsgType, // Message type
  87. Net::SEQ seqStart, // Beginning sequent sent/received
  88. long sNum, // Number of seq's sent/received
  89. char bReceived, // a received or a sent message? TRUE if received
  90. U16 u16PackageID/*=0*/) // Uniquely identifiable package id // True if receiving, false if sending
  91. {
  92. short sResult = 0;
  93. char *szCallerMsg;
  94. char szTime[256];
  95. char szSeq[256];
  96. char szNum[256];
  97. long lTime = rspGetMilliseconds();
  98. if ((ucMsgType == NetMsg::START_REALM)&&(bReceived))
  99. {
  100. g_GameSettings.m_lStartRealmTime = lTime;
  101. _ltoa(lTime, szTime, 10);
  102. }
  103. _ltoa(lTime - g_GameSettings.m_lStartRealmTime, szTime, 10);
  104. #ifdef SYS_ENDIAN_BIG
  105. RFile::Endian endian = RFile::BigEndian;
  106. #else
  107. RFile::Endian endian = RFile::LittleEndian;
  108. #endif
  109. szCallerMsg = 0;
  110. // For convenience
  111. RFile *prfLog = &(g_GameSettings.m_rfNetSyncLog);
  112. // Log file should be open, if not, open it
  113. if (!prfLog->IsOpen())
  114. {
  115. if ((prfLog->Open(g_GameSettings.m_szNetSyncLogFile, "wt+", endian)) != 0)
  116. {
  117. TRACE("WriteTimeStamp: Failed to open network time stamp log file\n");
  118. sResult = -1;
  119. }
  120. }
  121. // Write name of player calling
  122. prfLog->Write(g_GameSettings.m_szPlayerName);
  123. // Write receiving or sending
  124. if (bReceived)
  125. prfLog->Write(" Received ");
  126. else
  127. prfLog->Write(" Sent ");
  128. // Write name of person who will be receiving or has sent the message
  129. if (pszCalleeName != NULL)
  130. prfLog->Write(pszCalleeName);
  131. else
  132. prfLog->Write("Server");
  133. prfLog->Write(" ");
  134. // Write package ID
  135. char szPackageID[256];
  136. ltoa((long)u16PackageID, szPackageID, 10);
  137. prfLog->Write(szPackageID);
  138. prfLog->Write(" ");
  139. // Write time of logging
  140. prfLog->Write(szTime);
  141. prfLog->Write(" ");
  142. // Write starting sequence sent/received
  143. itoa(seqStart, szSeq, 10);
  144. prfLog->Write(szSeq);
  145. prfLog->Write(" ");
  146. // Write number of sequences sent/received
  147. ltoa(sNum, szNum, 10);
  148. prfLog->Write(szNum);
  149. prfLog->Write(" ");
  150. // Write type of message
  151. switch (ucMsgType)
  152. {
  153. case NetMsg::NOTHING:
  154. szCallerMsg = "NOTHING";
  155. break;
  156. case NetMsg::STAT:
  157. szCallerMsg = "STAT";
  158. break;
  159. case NetMsg::ERR:
  160. szCallerMsg = "ERR";
  161. break;
  162. case NetMsg::LOGIN:
  163. szCallerMsg = "LOGIN";
  164. break;
  165. case NetMsg::LOGIN_ACCEPT:
  166. szCallerMsg = "LOGIN_ACCEPT";
  167. break;
  168. case NetMsg::LOGIN_DENY:
  169. szCallerMsg = "LOGIN_DENY";
  170. break;
  171. case NetMsg::LOGOUT:
  172. szCallerMsg = "LOGOUT";
  173. break;
  174. case NetMsg::JOIN_REQ:
  175. szCallerMsg = "JOIN_REQ";
  176. break;
  177. case NetMsg::JOIN_ACCEPT:
  178. szCallerMsg = "JOIN_ACCEPT";
  179. break;
  180. case NetMsg::JOIN_DENY:
  181. szCallerMsg = "JOIN_DENY";
  182. break;
  183. case NetMsg::JOINED:
  184. szCallerMsg = "JOINED";
  185. break;
  186. case NetMsg::CHANGE_REQ:
  187. szCallerMsg = "CHANGE_REQ";
  188. break;
  189. case NetMsg::CHANGED:
  190. szCallerMsg = "CHANGED";
  191. break;
  192. case NetMsg::DROP_REQ:
  193. szCallerMsg = "DROP_REQ";
  194. break;
  195. case NetMsg::DROPPED:
  196. szCallerMsg = "DROP_REQ";
  197. break;
  198. case NetMsg::DROP_ACK:
  199. szCallerMsg = "DROP_ACK";
  200. break;
  201. case NetMsg::INPUT_REQ:
  202. szCallerMsg = "INPUT_REQ";
  203. break;
  204. case NetMsg::INPUT_DATA:
  205. szCallerMsg = "INPUT_DATA";
  206. break;
  207. case NetMsg::INPUT_MARK:
  208. szCallerMsg = "INPUT_MARK";
  209. break;
  210. case NetMsg::CHAT_REQ:
  211. szCallerMsg = "CHAT_REQ";
  212. break;
  213. case NetMsg::CHAT:
  214. szCallerMsg = "CHAT";
  215. break;
  216. case NetMsg::SETUP_GAME:
  217. szCallerMsg = "SETUP_GAME";
  218. break;
  219. case NetMsg::START_GAME:
  220. szCallerMsg = "START_GAME";
  221. break;
  222. case NetMsg::ABORT_GAME:
  223. szCallerMsg = "ABORT_GAME";
  224. break;
  225. case NetMsg::READY_REALM:
  226. szCallerMsg = "READY_REALM";
  227. break;
  228. case NetMsg::BAD_REALM:
  229. szCallerMsg = "BAD_REALM";
  230. break;
  231. case NetMsg::START_REALM:
  232. szCallerMsg = "START_REALM";
  233. break;
  234. case NetMsg::HALT_REALM:
  235. szCallerMsg = "HALT_REALM";
  236. break;
  237. case NetMsg::NEXT_REALM:
  238. szCallerMsg = "NEXT_REALM";
  239. break;
  240. case NetMsg::PROGRESS_REALM:
  241. szCallerMsg = "PROGRESS_REALM";
  242. break;
  243. case NetMsg::PROCEED:
  244. szCallerMsg = "PROCEED";
  245. break;
  246. case NetMsg::PING:
  247. szCallerMsg = "PING";
  248. break;
  249. case NetMsg::RAND:
  250. szCallerMsg = "RAND";
  251. break;
  252. default:
  253. szCallerMsg = "INVALID";
  254. }
  255. // Write the message type
  256. prfLog->Write(szCallerMsg);
  257. prfLog->Write(" ");
  258. // Write the calling routine
  259. prfLog->Write(pszCaller);
  260. prfLog->Write("\n");
  261. sResult = prfLog->Error();
  262. return sResult;
  263. }
  264. /*** 12/5/97 AJC ***/
  265. /*** 12/7/97 AJC ***/
  266. ////////////////////////////////////////////////////////////////////////////////
  267. // WriteInputData()
  268. // Write the network input data to network sync log
  269. // global variables used: g_GameSettings
  270. ////////////////////////////////////////////////////////////////////////////////
  271. extern
  272. short WriteInputData(U32 *input)
  273. {
  274. short sResult = 0;
  275. char szInput[256];
  276. // For convenience
  277. RFile *prfLog = &(g_GameSettings.m_rfNetSyncLog);
  278. ltoa(*input, szInput, 16);
  279. prfLog->Write(szInput);
  280. prfLog->Write("\n");
  281. sResult = prfLog->Error();
  282. return sResult;
  283. }
  284. /*** 12/7/97 AJC ***/
  285. ////////////////////////////////////////////////////////////////////////////////
  286. // EOF
  287. ////////////////////////////////////////////////////////////////////////////////