GameSpyGP.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: GameSpyGP.cpp //////////////////////////////////////////////////////
  24. // GameSpy GP callbacks, utils, etc
  25. // Author: Matthew D. Campbell, February 2002
  26. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  27. #include "GameClient/GameText.h"
  28. #include "GameNetwork/GameSpy.h"
  29. #include "GameNetwork/GameSpyGP.h"
  30. #include "GameNetwork/GameSpyOverlay.h"
  31. GPConnection TheGPConnectionObj;
  32. GPConnection *TheGPConnection = &TheGPConnectionObj;
  33. GPProfile GameSpyLocalProfile = 0;
  34. char GameSpyProfilePassword[64];
  35. void GPRecvBuddyMessageCallback(GPConnection * pconnection, GPRecvBuddyMessageArg * arg, void * param)
  36. {
  37. DEBUG_LOG(("GPRecvBuddyMessageCallback: message from %d is %s\n", arg->profile, arg->message));
  38. //gpGetInfo(pconn, arg->profile, GP_DONT_CHECK_CACHE, GP_BLOCKING, (GPCallback)Whois, NULL);
  39. //printf("MESSAGE (%d): %s: %s\n", msgCount,whois, arg->message);
  40. }
  41. static void buddyTryReconnect( void )
  42. {
  43. TheGameSpyChat->reconnectProfile();
  44. }
  45. void GPErrorCallback(GPConnection * pconnection, GPErrorArg * arg, void * param)
  46. {
  47. DEBUG_LOG(("GPErrorCallback\n"));
  48. AsciiString errorCodeString;
  49. AsciiString resultString;
  50. #define RESULT(x) case x: resultString = #x; break;
  51. switch(arg->result)
  52. {
  53. RESULT(GP_NO_ERROR)
  54. RESULT(GP_MEMORY_ERROR)
  55. RESULT(GP_PARAMETER_ERROR)
  56. RESULT(GP_NETWORK_ERROR)
  57. RESULT(GP_SERVER_ERROR)
  58. default:
  59. resultString = "Unknown result!";
  60. }
  61. #undef RESULT
  62. #define ERRORCODE(x) case x: errorCodeString = #x; break;
  63. switch(arg->errorCode)
  64. {
  65. ERRORCODE(GP_GENERAL)
  66. ERRORCODE(GP_PARSE)
  67. ERRORCODE(GP_NOT_LOGGED_IN)
  68. ERRORCODE(GP_BAD_SESSKEY)
  69. ERRORCODE(GP_DATABASE)
  70. ERRORCODE(GP_NETWORK)
  71. ERRORCODE(GP_FORCED_DISCONNECT)
  72. ERRORCODE(GP_CONNECTION_CLOSED)
  73. ERRORCODE(GP_LOGIN)
  74. ERRORCODE(GP_LOGIN_TIMEOUT)
  75. ERRORCODE(GP_LOGIN_BAD_NICK)
  76. ERRORCODE(GP_LOGIN_BAD_EMAIL)
  77. ERRORCODE(GP_LOGIN_BAD_PASSWORD)
  78. ERRORCODE(GP_LOGIN_BAD_PROFILE)
  79. ERRORCODE(GP_LOGIN_PROFILE_DELETED)
  80. ERRORCODE(GP_LOGIN_CONNECTION_FAILED)
  81. ERRORCODE(GP_LOGIN_SERVER_AUTH_FAILED)
  82. ERRORCODE(GP_NEWUSER)
  83. ERRORCODE(GP_NEWUSER_BAD_NICK)
  84. ERRORCODE(GP_NEWUSER_BAD_PASSWORD)
  85. ERRORCODE(GP_UPDATEUI)
  86. ERRORCODE(GP_UPDATEUI_BAD_EMAIL)
  87. ERRORCODE(GP_NEWPROFILE)
  88. ERRORCODE(GP_NEWPROFILE_BAD_NICK)
  89. ERRORCODE(GP_NEWPROFILE_BAD_OLD_NICK)
  90. ERRORCODE(GP_UPDATEPRO)
  91. ERRORCODE(GP_UPDATEPRO_BAD_NICK)
  92. ERRORCODE(GP_ADDBUDDY)
  93. ERRORCODE(GP_ADDBUDDY_BAD_FROM)
  94. ERRORCODE(GP_ADDBUDDY_BAD_NEW)
  95. ERRORCODE(GP_ADDBUDDY_ALREADY_BUDDY)
  96. ERRORCODE(GP_AUTHADD)
  97. ERRORCODE(GP_AUTHADD_BAD_FROM)
  98. ERRORCODE(GP_AUTHADD_BAD_SIG)
  99. ERRORCODE(GP_STATUS)
  100. ERRORCODE(GP_BM)
  101. ERRORCODE(GP_BM_NOT_BUDDY)
  102. ERRORCODE(GP_GETPROFILE)
  103. ERRORCODE(GP_GETPROFILE_BAD_PROFILE)
  104. ERRORCODE(GP_DELBUDDY)
  105. ERRORCODE(GP_DELBUDDY_NOT_BUDDY)
  106. ERRORCODE(GP_DELPROFILE)
  107. ERRORCODE(GP_DELPROFILE_LAST_PROFILE)
  108. ERRORCODE(GP_SEARCH)
  109. ERRORCODE(GP_SEARCH_CONNECTION_FAILED)
  110. default:
  111. errorCodeString = "Unknown error code!";
  112. }
  113. #undef ERRORCODE
  114. if(arg->fatal)
  115. {
  116. DEBUG_LOG(( "-----------\n"));
  117. DEBUG_LOG(( "GP FATAL ERROR\n"));
  118. DEBUG_LOG(( "-----------\n"));
  119. // if we're still connected to the chat server, tell the user. He can always hit the buddy
  120. // button to try reconnecting. Oh yes, also hide the buddy popup.
  121. GameSpyCloseOverlay(GSOVERLAY_BUDDY);
  122. if (TheGameSpyChat->isConnected())
  123. {
  124. GSMessageBoxYesNo(TheGameText->fetch("GUI:GPErrorTitle"), TheGameText->fetch("GUI:GPDisconnected"), buddyTryReconnect, NULL);
  125. }
  126. }
  127. else
  128. {
  129. DEBUG_LOG(( "-----\n"));
  130. DEBUG_LOG(( "GP ERROR\n"));
  131. DEBUG_LOG(( "-----\n"));
  132. }
  133. DEBUG_LOG(( "RESULT: %s (%d)\n", resultString.str(), arg->result));
  134. DEBUG_LOG(( "ERROR CODE: %s (0x%X)\n", errorCodeString.str(), arg->errorCode));
  135. DEBUG_LOG(( "ERROR STRING: %s\n", arg->errorString));
  136. }
  137. void GPRecvBuddyStatusCallback(GPConnection * connection, GPRecvBuddyStatusArg * arg, void * param)
  138. {
  139. DEBUG_LOG(("GPRecvBuddyStatusCallback: info on %d is in %d\n", arg->profile, arg->index));
  140. //GameSpyUpdateBuddyOverlay();
  141. }
  142. void GPRecvBuddyRequestCallback(GPConnection * connection, GPRecvBuddyRequestArg * arg, void * param)
  143. {
  144. DEBUG_LOG(("GPRecvBuddyRequestCallback: %d wants to be our buddy because '%s'\n", arg->profile, arg->reason));
  145. }