cnetwork.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. ** Command & Conquer Renegade(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. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Commando/cnetwork.h $*
  25. * *
  26. * $Author:: Byon_g $*
  27. * *
  28. * $Modtime:: 2/19/02 4:49p $*
  29. * *
  30. * $Revision:: 76 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSV_VER)
  36. #pragma once
  37. #endif
  38. #ifndef CNETWORK_H
  39. #define CNETWORK_H
  40. #include "always.h"
  41. #include "vector3.h"
  42. #include "w3d_file.h"
  43. #include "teammanager.h"
  44. #include "comnetrcvinst.h"
  45. #include "comnetrcv.h"
  46. #include "connect.h"
  47. #include "nethandler.h"
  48. #include "regbool.h"
  49. #define MAX_TEXTMESSAGE_LENGTH 200
  50. class cPlayer;
  51. class cTeam;
  52. class cPacket;
  53. class ScriptableGameObj;
  54. class SmartGameObj;
  55. class ChunkSaveClass;
  56. class ChunkLoadClass;
  57. class cMsgStatList;
  58. class cMsgStatListGroup;
  59. class Render2DTextClass;
  60. class VisTableClass;
  61. //-----------------------------------------------------------------------------
  62. class cNetwork
  63. {
  64. public:
  65. enum {
  66. ALL = -1, // for sending to everyone
  67. };
  68. static void Compute_Exe_Key(void);
  69. static void Onetime_Init(void);
  70. static void Onetime_Shutdown(void);
  71. static void Update();
  72. static bool Save(ChunkSaveClass & csave);
  73. static bool Load(ChunkLoadClass & cload);
  74. static float Get_Distance_Priority(Vector3 & pos1, Vector3 & pos2);
  75. static void Update_Fps(void);
  76. static int Get_Fps(void) {return Fps;}
  77. static int Get_Think_Count(void) {return ThinkCount;}
  78. static void Shell_Command(LPCSTR command);
  79. static void Server_Packet_Handler(cPacket & packet, int rhost_id);
  80. static void Client_Packet_Handler(cPacket & packet);
  81. static void Server_Broken_Connection_Handler(int rhost_id);
  82. static void Client_Broken_Connection_Handler(void);
  83. static void Accept_Handler(void);
  84. static void Refusal_Handler(REFUSAL_CODE refusal_code);
  85. static void Connection_Handler(int new_rhost_id);
  86. static REFUSAL_CODE Application_Acceptance_Handler(cPacket & packet);
  87. static void Eviction_Handler(int evicted_rhost_id);
  88. static bool I_Am_Client(void) {return PClientConnection != NULL;}
  89. static bool I_Am_Server(void) {return PServerConnection != NULL;}
  90. static bool I_Am_Only_Client(void) {return PClientConnection != NULL && PServerConnection == NULL;}
  91. static bool I_Am_Only_Server(void) {return PClientConnection == NULL && PServerConnection != NULL;}
  92. static bool I_Am_Client_Server(void) {return PClientConnection != NULL && PServerConnection != NULL;}
  93. static bool I_Am_God(void);
  94. // Sending Simple Client Packets
  95. static int Send_Object_Update(NetworkObjectClass *object, int client_id);
  96. static void Tell_Client_About_Dynamic_Objects(int recipient_client_id, Vector3 & dest_pos);
  97. static void Tell_Client_About_Delete_Notifications(int recipient_client_id);
  98. static void Tell_Server_About_Dynamic_Objects(void);
  99. static void Server_Kill_Connection(int client_id);
  100. static void Set_Receiver(CombatNetworkReceiver *receiver ) {Receiver = receiver;}
  101. static void Process_Eviction_Sc(cPacket & packet);
  102. static void Cleanup_After_Client(int client_id);
  103. static void Delete_Player_Objects(int client_id);
  104. static void Remove_Player(int player_id);
  105. static void Test_For_Team_Defaulting(cPlayer * p_player);
  106. static void Packet_Graph(Render2DTextClass * renderer, cMsgStatList * p_stat_list, int watch_type, LPCSTR label);
  107. static void Watch_Packets(Render2DTextClass * renderer);
  108. static void Bandwidth_Graph(Render2DTextClass * renderer, LPCSTR label, int count, int target_bps, float packetloss_pc,
  109. const int bar_color, bool is_send, float threshold_priority);
  110. static void Watch_Bandwidth(Render2DTextClass * renderer);
  111. static void Latency_Graph(Render2DTextClass * renderer, LPCSTR label, const float bar_length, cRemoteHost * p_rhost);
  112. static void Last_Contact_Graph(Render2DTextClass * renderer, LPCSTR label, const float bar_length, cRemoteHost * p_rhost);
  113. static void List_Size_Graph(Render2DTextClass * renderer, LPCSTR label, const float bar_length, int count);
  114. static void List_Time_Graph(Render2DTextClass * renderer, LPCSTR label, const float bar_length, int time_ms);
  115. static void List_Packet_Size_Graph(Render2DTextClass * renderer, LPCSTR label, const float bar_length, int count);
  116. static void Watch_Latency(Render2DTextClass * renderer);
  117. static void Watch_Last_Contact(Render2DTextClass * renderer);
  118. static void Watch_Size_Lists(Render2DTextClass * renderer);
  119. static void Watch_Time_Lists(Render2DTextClass * renderer);
  120. static void Watch_Packet_Size_Lists(Render2DTextClass * renderer);
  121. static void Simulation_Warnings(Render2DTextClass * renderer);
  122. static void Connection_Status_Change_Feedback(void);
  123. static void Client_Send_Packet(cPacket & packet, int mode);
  124. static void Server_Send_Packet(cPacket & packet, int mode, int recipient = ALL);
  125. static void Server_Send_Packet_To_All_Connected(cPacket & packet, int mode);
  126. static int Show_Welcome_Message(WideStringClass & name);
  127. static cPlayer * Get_My_Player_Object(void);
  128. static int Get_My_Team_Number(void);
  129. static Vector3 Get_My_Color(void);
  130. static LPCSTR Get_Client_String(int recipient);
  131. static LPCSTR Get_Client_Enumeration_String(void);
  132. static cRemoteHost * Get_Server_Rhost(int client_id);
  133. static cRemoteHost * Get_Client_Rhost(void);
  134. static float Get_Server_Rhost_Threshold_Priority(int client_id);
  135. static float Get_Client_Rhost_Threshold_Priority(void);
  136. static int Get_My_Id(void);
  137. static int Get_Exe_Key(void) { return ExeKey; }
  138. static int Get_Exe_CRC(void) { return ExeCRC; }
  139. static int Get_Strings_CRC(void) { return StringsCRC; }
  140. static void Set_Desired_Frame_Sleep_Ms(int b);
  141. static void Set_Simulated_Packet_Loss_Pc(int b);
  142. static void Set_Simulated_Packet_Duplication_Pc(int b);
  143. static void Set_Simulated_Latency_Range_Ms(int lower, int upper);
  144. static void Set_Spam_Count(int spam_count);
  145. static void Get_Simulated_Latency_Range_Ms(int & lower, int & upper);
  146. static void Set_Graphing_Y(float y) {GraphingY = y;}
  147. static void Init_Client(unsigned short my_port = 0);
  148. static void Init_Server(void);
  149. static void Cleanup_Server(void);
  150. static void Cleanup_Client(void);
  151. static void Flush(void);//TSS2001e
  152. static void SwitchTeam(int newTeam);
  153. static void Enable_Waiting_Players(void);
  154. //
  155. // Hide...
  156. //
  157. static cConnection * PServerConnection;
  158. static cConnection * PClientConnection;
  159. // Temp - going away later. ST - 10/16/2001 9:33PM
  160. static bool SensibleUpdates;
  161. private:
  162. static int Get_Data_Files_CRC(void);
  163. static void Shared_Client_And_Server_Think(void);
  164. static bool Client_Think(void);
  165. static bool Server_Think(void);
  166. static void Hibernation_Think(void);
  167. static void End_Game_Test(void);
  168. static void Intermission_Over_Processing(void);
  169. static VisTableClass * Peek_Temp_Vis_Table(void);
  170. static CombatNetworkReceiver *Receiver;
  171. static CombatNetworkReceiverInstanceClass * NetworkReceiver;
  172. static char ClientString[300]; // used by Get_Client_String
  173. static char ClientEnumerationString[300]; // used by Get_Client_Enumeration_String
  174. static bool LastServerConnectionStateBad;
  175. //
  176. // Version validation data
  177. //
  178. static int ExeKey;
  179. static int ExeCRC;
  180. static int StringsCRC;
  181. //
  182. // Server-specific data
  183. //
  184. static char MessageToSend[MAX_TEXTMESSAGE_LENGTH];
  185. static char Command[MAX_TEXTMESSAGE_LENGTH];
  186. static float GraphingY;
  187. static float BandwidthBarLength;
  188. static int BandwidthScaler;
  189. static GameCombatNetworkHandlerClass NetHandler;
  190. static int Fps;
  191. static int ThinkCount;
  192. static cMsgStatList * PClientStatList;
  193. static cMsgStatListGroup * PServerStatListGroup;
  194. static bool HaveDoneTeamChangeDialog;
  195. static bool HaveDoneMotdDialog;
  196. static VisTableClass * VisTable;
  197. };
  198. #endif