BuddyThread.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. ** Command & Conquer Generals(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: BuddyThread.h //////////////////////////////////////////////////////
  24. // Generals GameSpy BuddyList thread class interface
  25. // Author: Matthew D. Campbell, June 2002
  26. #pragma once
  27. #ifndef __BUDDYTHREAD_H__
  28. #define __BUDDYTHREAD_H__
  29. #include "GameSpy/GP/GP.h"
  30. #define MAX_BUDDY_CHAT_LEN 128
  31. // this class encapsulates a request for the buddy thread
  32. class BuddyRequest
  33. {
  34. public:
  35. enum
  36. {
  37. BUDDYREQUEST_LOGIN, // attempt to login
  38. BUDDYREQUEST_RELOGIN, // log in after being disconnected
  39. BUDDYREQUEST_LOGOUT, // log out if connected
  40. BUDDYREQUEST_MESSAGE,
  41. BUDDYREQUEST_LOGINNEW, // attempt to create a new nick and login
  42. //BUDDYREQUEST_DELETELOGIN,
  43. BUDDYREQUEST_ADDBUDDY, // add someone to your buddy list
  44. BUDDYREQUEST_DELBUDDY, // delete someone from your buddy list
  45. BUDDYREQUEST_OKADD, // allow someone to add you to their buddy list
  46. BUDDYREQUEST_DENYADD, // don't allow someone to add you to their buddy list
  47. BUDDYREQUEST_SETSTATUS, // Set our status
  48. BUDDYREQUEST_DELETEACCT, // Delete our account
  49. BUDDYREQUEST_MAX
  50. } buddyRequestType;
  51. union
  52. {
  53. struct
  54. {
  55. GPProfile recipient;
  56. WideChar text[MAX_BUDDY_CHAT_LEN];
  57. } message;
  58. struct
  59. {
  60. char nick[GP_NICK_LEN];
  61. char email[GP_EMAIL_LEN];
  62. char password[GP_PASSWORD_LEN];
  63. Bool hasFirewall;
  64. } login;
  65. struct
  66. {
  67. GPProfile id;
  68. WideChar text[MAX_BUDDY_CHAT_LEN];
  69. } addbuddy;
  70. struct
  71. {
  72. GPProfile id;
  73. } profile;
  74. struct
  75. {
  76. GPEnum status;
  77. char statusString[GP_STATUS_STRING_LEN];
  78. char locationString[GP_LOCATION_STRING_LEN];
  79. } status;
  80. } arg;
  81. };
  82. //-------------------------------------------------------------------------
  83. // this class encapsulates an action the buddy thread wants from the UI
  84. class BuddyResponse
  85. {
  86. public:
  87. enum
  88. {
  89. BUDDYRESPONSE_LOGIN,
  90. BUDDYRESPONSE_DISCONNECT,
  91. BUDDYRESPONSE_MESSAGE,
  92. BUDDYRESPONSE_REQUEST,
  93. BUDDYRESPONSE_STATUS,
  94. BUDDYRESPONSE_MAX
  95. } buddyResponseType;
  96. GPProfile profile;
  97. GPResult result;
  98. union
  99. {
  100. struct
  101. {
  102. UnsignedInt date;
  103. char nick[GP_NICK_LEN];
  104. WideChar text[MAX_BUDDY_CHAT_LEN];
  105. } message;
  106. struct
  107. {
  108. char nick[GP_NICK_LEN];
  109. char email[GP_EMAIL_LEN];
  110. char countrycode[GP_COUNTRYCODE_LEN];
  111. WideChar text[GP_REASON_LEN];
  112. } request;
  113. struct
  114. {
  115. //GPResult result;
  116. GPErrorCode errorCode;
  117. char errorString[MAX_BUDDY_CHAT_LEN];
  118. GPEnum fatal;
  119. } error;
  120. struct
  121. {
  122. char nick[GP_NICK_LEN];
  123. char email[GP_EMAIL_LEN];
  124. char countrycode[GP_COUNTRYCODE_LEN];
  125. char location[GP_LOCATION_STRING_LEN];
  126. GPEnum status;
  127. char statusString[GP_STATUS_STRING_LEN];
  128. } status;
  129. } arg;
  130. };
  131. //-------------------------------------------------------------------------
  132. // this is the actual message queue used to pass messages between threads
  133. class GameSpyBuddyMessageQueueInterface
  134. {
  135. public:
  136. virtual ~GameSpyBuddyMessageQueueInterface() {}
  137. virtual void startThread( void ) = 0;
  138. virtual void endThread( void ) = 0;
  139. virtual Bool isThreadRunning( void ) = 0;
  140. virtual Bool isConnected( void ) = 0;
  141. virtual Bool isConnecting( void ) = 0;
  142. virtual void addRequest( const BuddyRequest& req ) = 0;
  143. virtual Bool getRequest( BuddyRequest& req ) = 0;
  144. virtual void addResponse( const BuddyResponse& resp ) = 0;
  145. virtual Bool getResponse( BuddyResponse& resp ) = 0;
  146. virtual GPProfile getLocalProfileID( void ) = 0;
  147. static GameSpyBuddyMessageQueueInterface* createNewMessageQueue( void );
  148. };
  149. extern GameSpyBuddyMessageQueueInterface *TheGameSpyBuddyMessageQueue;
  150. #endif // __BUDDYTHREAD_H__