Skip to content

Commit 8c72289

Browse files
Caball009Chapter5780
authored andcommitted
refactor(lanapi): Make LANMessage accessible in LANAPI (TheSuperHackers#2241)
1 parent 8bdd2c4 commit 8c72289

File tree

1 file changed

+133
-132
lines changed
  • Core/GameEngine/Include/GameNetwork

1 file changed

+133
-132
lines changed

Core/GameEngine/Include/GameNetwork/LANAPI.h

Lines changed: 133 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,139 @@ class LANAPIInterface : public SubsystemInterface
140140
};
141141

142142

143+
/**
144+
* LAN message class
145+
*/
146+
#pragma pack(push, 1)
147+
struct LANMessage
148+
{
149+
enum Type ///< What kind of message are we?
150+
{
151+
// Locating everybody
152+
MSG_REQUEST_LOCATIONS, ///< Hey, where is everybody?
153+
MSG_GAME_ANNOUNCE, ///< Here I am, and here's my game info!
154+
MSG_LOBBY_ANNOUNCE, ///< Hey, I'm in the lobby!
155+
156+
// Joining games
157+
MSG_REQUEST_JOIN, ///< Let me in! Let me in!
158+
MSG_JOIN_ACCEPT, ///< Okay, you can join.
159+
MSG_JOIN_DENY, ///< Go away! We don't want any!
160+
161+
// Leaving games
162+
MSG_REQUEST_GAME_LEAVE, ///< I want to leave the game
163+
MSG_REQUEST_LOBBY_LEAVE,///< I'm leaving the lobby
164+
165+
// Game options, chat, etc
166+
MSG_SET_ACCEPT, ///< I'm cool with everything as is.
167+
MSG_MAP_AVAILABILITY, ///< I do (not) have the map.
168+
MSG_CHAT, ///< Just spouting my mouth off.
169+
MSG_GAME_START, ///< Hold on; we're starting!
170+
MSG_GAME_START_TIMER, ///< The game will start in N seconds
171+
MSG_GAME_OPTIONS, ///< Here's some info about the game.
172+
MSG_INACTIVE, ///< I've alt-tabbed out. Unaccept me cause I'm a poo-flinging monkey.
173+
174+
MSG_REQUEST_GAME_INFO, ///< For direct connect, get the game info from a specific IP Address
175+
} messageType;
176+
177+
WideChar name[g_lanPlayerNameLength+1]; ///< My name, for convenience
178+
char userName[g_lanLoginNameLength+1]; ///< login name, for convenience
179+
char hostName[g_lanHostNameLength+1]; ///< machine name, for convenience
180+
181+
// No additional data is required for REQUEST_LOCATIONS, LOBBY_ANNOUNCE,
182+
// REQUEST_LOBBY_LEAVE, GAME_START.
183+
union
184+
{
185+
// StartTimer is sent with GAME_START_TIMER
186+
struct
187+
{
188+
Int seconds;
189+
} StartTimer;
190+
191+
// GameJoined is sent with REQUEST_GAME_LEAVE
192+
struct
193+
{
194+
WideChar gameName[g_lanGameNameLength+1];
195+
} GameToLeave;
196+
197+
// GameInfo if sent with GAME_ANNOUNCE
198+
struct
199+
{
200+
WideChar gameName[g_lanGameNameLength+1];
201+
Bool inProgress;
202+
char options[m_lanMaxOptionsLength+1];
203+
Bool isDirectConnect;
204+
} GameInfo;
205+
206+
// PlayerInfo is sent with REQUEST_GAME_INFO for direct connect games.
207+
struct
208+
{
209+
UnsignedInt ip;
210+
WideChar playerName[g_lanPlayerNameLength+1];
211+
} PlayerInfo;
212+
213+
// GameToJoin is sent with REQUEST_JOIN
214+
struct
215+
{
216+
UnsignedInt gameIP;
217+
UnsignedInt exeCRC;
218+
UnsignedInt iniCRC;
219+
char serial[g_maxSerialLength];
220+
} GameToJoin;
221+
222+
// GameJoined is sent with JOIN_ACCEPT
223+
struct
224+
{
225+
WideChar gameName[g_lanGameNameLength+1];
226+
UnsignedInt gameIP;
227+
UnsignedInt playerIP;
228+
Int slotPosition;
229+
} GameJoined;
230+
231+
// GameNotJoined is sent with JOIN_DENY
232+
struct
233+
{
234+
WideChar gameName[g_lanGameNameLength+1];
235+
UnsignedInt gameIP;
236+
UnsignedInt playerIP;
237+
LANAPIInterface::ReturnType reason;
238+
} GameNotJoined;
239+
240+
// Accept is sent with SET_ACCEPT
241+
struct
242+
{
243+
WideChar gameName[g_lanGameNameLength+1];
244+
Bool isAccepted;
245+
} Accept;
246+
247+
// Accept is sent with MAP_AVAILABILITY
248+
struct
249+
{
250+
WideChar gameName[g_lanGameNameLength+1];
251+
UnsignedInt mapCRC; // to make sure we're talking about the same map
252+
Bool hasMap;
253+
} MapStatus;
254+
255+
// Chat is sent with CHAT
256+
struct
257+
{
258+
WideChar gameName[g_lanGameNameLength+1];
259+
LANAPIInterface::ChatType chatType;
260+
WideChar message[g_lanMaxChatLength+1];
261+
} Chat;
262+
263+
// GameOptions is sent with GAME_OPTIONS
264+
struct
265+
{
266+
char options[m_lanMaxOptionsLength+1];
267+
} GameOptions;
268+
269+
};
270+
};
271+
#pragma pack(pop)
272+
273+
static_assert(sizeof(LANMessage) <= MAX_PACKET_SIZE, "LANMessage struct cannot be larger than the max packet size");
274+
275+
143276
/**
144277
* The LANAPI class is used to instantiate a singleton which
145278
* implements the interface to all LAN broadcast communications.
@@ -278,135 +411,3 @@ class LANAPI : public LANAPIInterface
278411
void handleInActive( LANMessage *msg, UnsignedInt senderIP );
279412

280413
};
281-
282-
283-
284-
/**
285-
* LAN message class
286-
*/
287-
#pragma pack(push, 1)
288-
struct LANMessage
289-
{
290-
enum Type ///< What kind of message are we?
291-
{
292-
// Locating everybody
293-
MSG_REQUEST_LOCATIONS, ///< Hey, where is everybody?
294-
MSG_GAME_ANNOUNCE, ///< Here I am, and here's my game info!
295-
MSG_LOBBY_ANNOUNCE, ///< Hey, I'm in the lobby!
296-
297-
// Joining games
298-
MSG_REQUEST_JOIN, ///< Let me in! Let me in!
299-
MSG_JOIN_ACCEPT, ///< Okay, you can join.
300-
MSG_JOIN_DENY, ///< Go away! We don't want any!
301-
302-
// Leaving games
303-
MSG_REQUEST_GAME_LEAVE, ///< I want to leave the game
304-
MSG_REQUEST_LOBBY_LEAVE,///< I'm leaving the lobby
305-
306-
// Game options, chat, etc
307-
MSG_SET_ACCEPT, ///< I'm cool with everything as is.
308-
MSG_MAP_AVAILABILITY, ///< I do (not) have the map.
309-
MSG_CHAT, ///< Just spouting my mouth off.
310-
MSG_GAME_START, ///< Hold on; we're starting!
311-
MSG_GAME_START_TIMER, ///< The game will start in N seconds
312-
MSG_GAME_OPTIONS, ///< Here's some info about the game.
313-
MSG_INACTIVE, ///< I've alt-tabbed out. Unaccept me cause I'm a poo-flinging monkey.
314-
315-
MSG_REQUEST_GAME_INFO, ///< For direct connect, get the game info from a specific IP Address
316-
} messageType;
317-
318-
WideChar name[g_lanPlayerNameLength+1]; ///< My name, for convenience
319-
char userName[g_lanLoginNameLength+1]; ///< login name, for convenience
320-
char hostName[g_lanHostNameLength+1]; ///< machine name, for convenience
321-
322-
// No additional data is required for REQUEST_LOCATIONS, LOBBY_ANNOUNCE,
323-
// REQUEST_LOBBY_LEAVE, GAME_START.
324-
union
325-
{
326-
// StartTimer is sent with GAME_START_TIMER
327-
struct
328-
{
329-
Int seconds;
330-
} StartTimer;
331-
332-
// GameJoined is sent with REQUEST_GAME_LEAVE
333-
struct
334-
{
335-
WideChar gameName[g_lanGameNameLength+1];
336-
} GameToLeave;
337-
338-
// GameInfo if sent with GAME_ANNOUNCE
339-
struct
340-
{
341-
WideChar gameName[g_lanGameNameLength+1];
342-
Bool inProgress;
343-
char options[m_lanMaxOptionsLength+1];
344-
Bool isDirectConnect;
345-
} GameInfo;
346-
347-
// PlayerInfo is sent with REQUEST_GAME_INFO for direct connect games.
348-
struct
349-
{
350-
UnsignedInt ip;
351-
WideChar playerName[g_lanPlayerNameLength+1];
352-
} PlayerInfo;
353-
354-
// GameToJoin is sent with REQUEST_JOIN
355-
struct
356-
{
357-
UnsignedInt gameIP;
358-
UnsignedInt exeCRC;
359-
UnsignedInt iniCRC;
360-
char serial[g_maxSerialLength];
361-
} GameToJoin;
362-
363-
// GameJoined is sent with JOIN_ACCEPT
364-
struct
365-
{
366-
WideChar gameName[g_lanGameNameLength+1];
367-
UnsignedInt gameIP;
368-
UnsignedInt playerIP;
369-
Int slotPosition;
370-
} GameJoined;
371-
372-
// GameNotJoined is sent with JOIN_DENY
373-
struct
374-
{
375-
WideChar gameName[g_lanGameNameLength+1];
376-
UnsignedInt gameIP;
377-
UnsignedInt playerIP;
378-
LANAPIInterface::ReturnType reason;
379-
} GameNotJoined;
380-
381-
// Accept is sent with SET_ACCEPT
382-
struct
383-
{
384-
WideChar gameName[g_lanGameNameLength+1];
385-
Bool isAccepted;
386-
} Accept;
387-
388-
// Accept is sent with MAP_AVAILABILITY
389-
struct
390-
{
391-
WideChar gameName[g_lanGameNameLength+1];
392-
UnsignedInt mapCRC; // to make sure we're talking about the same map
393-
Bool hasMap;
394-
} MapStatus;
395-
396-
// Chat is sent with CHAT
397-
struct
398-
{
399-
WideChar gameName[g_lanGameNameLength+1];
400-
LANAPIInterface::ChatType chatType;
401-
WideChar message[g_lanMaxChatLength+1];
402-
} Chat;
403-
404-
// GameOptions is sent with GAME_OPTIONS
405-
struct
406-
{
407-
char options[m_lanMaxOptionsLength+1];
408-
} GameOptions;
409-
410-
};
411-
};
412-
#pragma pack(pop)

0 commit comments

Comments
 (0)