Phasor  01.00.10.059
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Server.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "../../../Common/Types.h"
5 #include "MapLoader.h"
6 
7 // declared in ../../Commands.h
9 
10 namespace halo {
11  struct s_player;
12  struct s_player_structure;
13 namespace server
14 {
15  //---------------------------------------------------------------------
16  // DEFINITIONS
17  //
18  #pragma pack(push, 1)
19 
21  {
22  BYTE ip[4];
23  WORD port;
24  WORD pad;
25  BYTE unk[0x148]; // handshake stuff etc, don't care atm.
26  };
27  static_assert(sizeof(s_connection_info) == 0x150, "incorrect s_connection_info");
28 
31  {
35  WORD playerNum; // used for rcon etc
36  WORD seven;
37  BYTE unk[0x42];
38  char key[10]; // only 7 chars long tho.. i think rest is padding
39  DWORD machineNum; // 0 - 0xFFFFFFFF increased for each connection in server's life
40 
42  {
43  return **con_info_ptr;
44  }
45 #ifdef PHASOR_CE
46  char unk1[0x20];
47  char ip[0x20];
48  char cd_key_hash[0x20];
49  char unk2[0x2c];
50 #endif
51  };
52  static_assert(sizeof(s_machine_info) == MACHINE_ENTRY_SIZE, "incorrect s_machine_info");
53 
56  {
57  wchar_t name[12];
59  BYTE machineId;
60  BYTE status; // 1 = ok, 2 = invalid hash (or auth, or w/e)
61  BYTE team;
62  BYTE playerId;
63  };
64  static_assert(sizeof(s_presence_item) == 0x20, "incorrect s_presence_item");
65 
68  {
69  void* unk_ptr;
70  WORD state; // 0 inactive, 1 game, 2 results
71  WORD unk1;
72  wchar_t server_name[0x42];
73  char map_name[0x80];
74  wchar_t gametype[0x18];
75  BYTE unk2[0x69];
76 #ifdef PHASOR_CE
77  BYTE unk_ce[0x40];
78 #endif
79  BYTE max_players;//1e6 before this
80  WORD unk3;
82  BYTE unk4;
84  BYTE unk5[14];
86  };
87 
88  struct s_command_input {
89  char password[9]; // don't forget to ensure null-termination
90  char command[65];
91  };
92  static_assert(sizeof(s_command_input) == 74, "incorrect s_command_input");
93 
96  char hash[32];
99  UNKNOWN(0x0C);
100  DWORD status; // 1 = valid, 2 = invalid
101  };
102 
104  {
105  char hash[32];
106  char challenge[32];
107  char clientKey[9]; // including null terminator
108  UNKNOWN(1); // only seen 1, halo uses it for something
109  UNKNOWN(2); //probably padding
110  wchar_t name[12]; // including null terminator
111  };
112 
113  #pragma pack(pop)
114 
116  {
119 
121  ~PhasorMachine();
122  };
123 
124  class SayStreamRaw : public COutStream
125  {
126  protected:
127  virtual bool Write(const std::wstring& str);
128 
129  public:
131 
132  virtual std::unique_ptr<COutStream> clone() const override
133  {
134  return std::unique_ptr<COutStream>(new SayStreamRaw());
135  }
136  };
137 
138  // Stream for sending server messages with **SERVER** prepended
139  class SayStream : public SayStreamRaw
140  {
141  protected:
142  virtual bool Write(const std::wstring& str);
143 
144  public:
146 
147  virtual std::unique_ptr<COutStream> clone() const override
148  {
149  return std::unique_ptr<COutStream>(new SayStream());
150  }
151  };
152 
154  extern SayStream say_stream;
155  extern SayStreamRaw say_stream_raw;
156 
157  void acceptInvalidHashes(bool state);
158  bool getInvalidHashState();
159 
163  void MessagePlayer(const s_player& player, const std::wstring& str);
164 
168  bool ConsoleMessagePlayer(const s_player& player, const std::wstring& str);
169 
172  void NotifyServerOfTeamChange(const halo::s_player& player);
173 
174  void ExecuteServerCommand(const std::string& command, s_player* execute_as);
175 
176  // Gets the player's ip
177  bool GetPlayerIP(const s_player& player, std::string* ip, WORD* port);
178  bool GetMachineIP(s_machine_info& machine, std::string* ip, WORD* port);
179 
180  // Gets the player's hash
181  bool GetPlayerHash(const s_player& player, std::string& hash);
182  bool GetMachineHash(const s_machine_info& machine, std::string& hash);
183 
184  PhasorMachine* FindMachine(const s_player& player);
185  PhasorMachine* FindMachineById(DWORD machineId);
186  PhasorMachine* FindMachineByIndex(DWORD index);
187 
191 
192  void SetExecutingPlayer(halo::s_player* player);
193 
196  s_server_info* GetServerStruct();
197 
200 
201  e_command_result sv_quit(void*,
203 
204  // --------------------------------------------------------------------
205  // Events
206  //
207 
208  void __stdcall OnMachineConnect(DWORD machineIndex);
209  void __stdcall OnMachineDisconnect(DWORD machineIndex);
210  void __stdcall OnMachineInfoFix(s_machinfo_info_partial_packet* data);
211 
212  // Called for console events (exit etc)
215  void __stdcall ConsoleHandler(DWORD fdwCtrlType);
216 
218  void __stdcall OnConsoleProcessing();
219 
222  void __stdcall OnClientUpdate(s_player_structure* m_player);
223 
227  e_command_result __stdcall ProcessCommand(char* command);
228 
229  void __stdcall ProcessCommandAttempt(s_command_input* input, int playerNum);
230 
233  void __stdcall OnNewGame(const char* map);
234 
237  void __stdcall OnGameEnd(DWORD mode);
238 
242  bool __stdcall OnMapLoad(maploader::s_mapcycle_entry* loading_map);
243 
245  void __stdcall OnHaloPrint(char* msg);
246 
250  bool __stdcall OnHaloBanCheck(char* hash, s_machine_info* machine);
251 
252  // Called once Halo has received the hash-checking response from gamespy
253  void __stdcall OnHashValidation(s_hash_validation* info, const char* status);
254 
255  // Called when the server info is about to be broadcast
256  //bool __stdcall OnVersionBroadcast(DWORD arg1, DWORD arg2);
257 
258 } }