Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Core/GameEngine/Include/GameNetwork/GameInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ enum
class GameSlot
{
public:
struct ProductInfo
{
enum CPP_11(: UnsignedInt)
{
COMMUNITY_PATCH = 1 << 0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this flag? It seems oddly specific. Now every product that derives from this will deliver this flag. If all this is needed for is seeing if the remote player has any non retail patch, then simply check if productTitle (or exeCRC?) is set, because the retail game will not serve this information.

bool isRetailGame() const
{
  return productTitle.empty();
}

};

UnsignedInt flags;
UnsignedInt exeCRC;
UnsignedInt iniCRC;
UnicodeString productTitle;
UnicodeString productVersion;
UnicodeString productAuthor;
UnicodeString gitShortHash;
};

GameSlot();
virtual void reset();

Expand Down Expand Up @@ -125,6 +141,9 @@ class GameSlot

void mute( Bool isMuted ) { m_isMuted = isMuted; }
Bool isMuted( void ) const { return m_isMuted; }

void setProductInfo(const ProductInfo& productInfo) { m_productInfo = productInfo; }
const ProductInfo& getProductInfo() const { return m_productInfo; }
protected:
SlotState m_state;
Bool m_isAccepted;
Expand All @@ -143,6 +162,7 @@ class GameSlot
FirewallHelperClass::FirewallBehaviorType m_NATBehavior; ///< The NAT behavior for this slot's player.
UnsignedInt m_lastFrameInGame; // only valid for human players
Bool m_disconnected; // only valid for human players
ProductInfo m_productInfo; ///< Community made product information
};

/**
Expand Down
294 changes: 162 additions & 132 deletions Core/GameEngine/Include/GameNetwork/LANAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,155 @@ class LANAPIInterface : public SubsystemInterface
};


/**
* LAN message class
*/
#pragma pack(push, 1)
struct LANMessage
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You moved this whole struct up so you can use it further down below, which is fine. Can you make a separate Pull Request moving it, so that the diff of this change is cleaner?

{
enum Type ///< What kind of message are we?
{
// Locating everybody
MSG_REQUEST_LOCATIONS, ///< Hey, where is everybody?
MSG_GAME_ANNOUNCE, ///< Here I am, and here's my game info!
MSG_LOBBY_ANNOUNCE, ///< Hey, I'm in the lobby!

// Joining games
MSG_REQUEST_JOIN, ///< Let me in! Let me in!
MSG_JOIN_ACCEPT, ///< Okay, you can join.
MSG_JOIN_DENY, ///< Go away! We don't want any!

// Leaving games
MSG_REQUEST_GAME_LEAVE, ///< I want to leave the game
MSG_REQUEST_LOBBY_LEAVE,///< I'm leaving the lobby

// Game options, chat, etc
MSG_SET_ACCEPT, ///< I'm cool with everything as is.
MSG_MAP_AVAILABILITY, ///< I do (not) have the map.
MSG_CHAT, ///< Just spouting my mouth off.
MSG_GAME_START, ///< Hold on; we're starting!
MSG_GAME_START_TIMER, ///< The game will start in N seconds
MSG_GAME_OPTIONS, ///< Here's some info about the game.
MSG_INACTIVE, ///< I've alt-tabbed out. Unaccept me cause I'm a poo-flinging monkey.

MSG_REQUEST_GAME_INFO, ///< For direct connect, get the game info from a specific IP Address

// Community Product
MSG_GAME_REQUEST_PRODUCT_INFO = 1000,
MSG_GAME_RESPONSE_PRODUCT_INFO,
MSG_LOBBY_REQUEST_PRODUCT_INFO,
MSG_LOBBY_RESPONSE_PRODUCT_INFO,
MSG_MATCH_REQUEST_PRODUCT_INFO,
MSG_MATCH_RESPONSE_PRODUCT_INFO,
} messageType;

WideChar name[g_lanPlayerNameLength+1]; ///< My name, for convenience
char userName[g_lanLoginNameLength+1]; ///< login name, for convenience
char hostName[g_lanHostNameLength+1]; ///< machine name, for convenience

// No additional data is required for REQUEST_LOCATIONS, LOBBY_ANNOUNCE,
// REQUEST_LOBBY_LEAVE, GAME_START.
union
{
// StartTimer is sent with GAME_START_TIMER
struct
{
Int seconds;
} StartTimer;

// GameJoined is sent with REQUEST_GAME_LEAVE
struct
{
WideChar gameName[g_lanGameNameLength+1];
} GameToLeave;

// GameInfo if sent with GAME_ANNOUNCE
struct
{
WideChar gameName[g_lanGameNameLength+1];
Bool inProgress;
char options[m_lanMaxOptionsLength+1];
Bool isDirectConnect;
} GameInfo;

// PlayerInfo is sent with REQUEST_GAME_INFO for direct connect games.
struct
{
UnsignedInt ip;
WideChar playerName[g_lanPlayerNameLength+1];
} PlayerInfo;

// GameToJoin is sent with REQUEST_JOIN
struct
{
UnsignedInt gameIP;
UnsignedInt exeCRC;
UnsignedInt iniCRC;
char serial[g_maxSerialLength];
} GameToJoin;

// GameJoined is sent with JOIN_ACCEPT
struct
{
WideChar gameName[g_lanGameNameLength+1];
UnsignedInt gameIP;
UnsignedInt playerIP;
Int slotPosition;
} GameJoined;

// GameNotJoined is sent with JOIN_DENY
struct
{
WideChar gameName[g_lanGameNameLength+1];
UnsignedInt gameIP;
UnsignedInt playerIP;
LANAPIInterface::ReturnType reason;
} GameNotJoined;

// Accept is sent with SET_ACCEPT
struct
{
WideChar gameName[g_lanGameNameLength+1];
Bool isAccepted;
} Accept;

// Accept is sent with MAP_AVAILABILITY
struct
{
WideChar gameName[g_lanGameNameLength+1];
UnsignedInt mapCRC; // to make sure we're talking about the same map
Bool hasMap;
} MapStatus;

// Chat is sent with CHAT
struct
{
WideChar gameName[g_lanGameNameLength+1];
LANAPIInterface::ChatType chatType;
WideChar message[g_lanMaxChatLength+1];
} Chat;

// GameOptions is sent with GAME_OPTIONS
struct
{
char options[m_lanMaxOptionsLength+1];
} GameOptions;

// ProductInfo is sent with REQUEST_PRODUCT_INFO and RESPONSE_PRODUCT_INFO
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps also explain how this is different from the original GameToJoin struct, which also contains exeCRC and iniCRC.

On that note, does ProductInfo also implicitly cover Product information for Game Rooms?

struct
{
UnsignedInt flags;
UnsignedInt exeCRC;
UnsignedInt iniCRC;
WideChar data[201];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the absolute max possible length for this? I suspect MAX_PACKET_SIZE-12 ?

} ProductInfo;
};
};
#pragma pack(pop)

static_assert(sizeof(LANMessage) <= MAX_PACKET_SIZE, "LANMessage struct cannot be larger than the max packet size");


/**
* The LANAPI class is used to instantiate a singleton which
* implements the interface to all LAN broadcast communications.
Expand Down Expand Up @@ -198,6 +347,7 @@ class LANAPI : public LANAPIInterface
// Misc utility functions
virtual LANGameInfo * LookupGame( UnicodeString gameName ); ///< return a pointer to a game we know about
virtual LANGameInfo * LookupGameByListOffset( Int offset ); ///< return a pointer to a game we know about
virtual LANGameInfo * LookupGameByHost( UnsignedInt hostIP ); ///< return a pointer to a game we know about
virtual LANPlayer * LookupPlayer( UnsignedInt playerIP ); ///< return a pointer to a player we know about
virtual Bool SetLocalIP( UnsignedInt localIP ); ///< For multiple NIC machines
virtual void SetLocalIP( AsciiString localIP ); ///< For multiple NIC machines
Expand Down Expand Up @@ -259,6 +409,11 @@ class LANAPI : public LANAPIInterface
void addGame(LANGameInfo *game);
AsciiString createSlotString( void );

static void setProductInfoFromLocalData(GameSlot *slot);
static void setProductInfoFromMessage(LANMessage *msg, GameSlot *slot);
static Bool setProductInfoStrings(const UnicodeString(&input)[4], WideChar(&output)[201]);
static Bool getProductInfoStrings(const WideChar(&input)[201], UnicodeString*(&output)[4]);

// Functions to handle incoming messages -----------------------------------
void handleRequestLocations( LANMessage *msg, UnsignedInt senderIP );
void handleGameAnnounce( LANMessage *msg, UnsignedInt senderIP );
Expand All @@ -277,136 +432,11 @@ class LANAPI : public LANAPIInterface
void handleGameOptions( LANMessage *msg, UnsignedInt senderIP );
void handleInActive( LANMessage *msg, UnsignedInt senderIP );

void sendProductInfoMessage(LANMessage::Type messageType, UnsignedInt senderIP);
void handleGameProductInfoRequest(LANMessage *msg, UnsignedInt senderIP);
void handleGameProductInfoResponse(LANMessage *msg, UnsignedInt senderIP);
void handleLobbyProductInfoRequest(LANMessage *msg, UnsignedInt senderIP);
void handleLobbyProductInfoResponse(LANMessage *msg, UnsignedInt senderIP);
void handleMatchProductInfoRequest(LANMessage *msg, UnsignedInt senderIP);
void handleMatchProductInfoResponse(LANMessage *msg, UnsignedInt senderIP);
};



/**
* LAN message class
*/
#pragma pack(push, 1)
struct LANMessage
{
enum Type ///< What kind of message are we?
{
// Locating everybody
MSG_REQUEST_LOCATIONS, ///< Hey, where is everybody?
MSG_GAME_ANNOUNCE, ///< Here I am, and here's my game info!
MSG_LOBBY_ANNOUNCE, ///< Hey, I'm in the lobby!

// Joining games
MSG_REQUEST_JOIN, ///< Let me in! Let me in!
MSG_JOIN_ACCEPT, ///< Okay, you can join.
MSG_JOIN_DENY, ///< Go away! We don't want any!

// Leaving games
MSG_REQUEST_GAME_LEAVE, ///< I want to leave the game
MSG_REQUEST_LOBBY_LEAVE,///< I'm leaving the lobby

// Game options, chat, etc
MSG_SET_ACCEPT, ///< I'm cool with everything as is.
MSG_MAP_AVAILABILITY, ///< I do (not) have the map.
MSG_CHAT, ///< Just spouting my mouth off.
MSG_GAME_START, ///< Hold on; we're starting!
MSG_GAME_START_TIMER, ///< The game will start in N seconds
MSG_GAME_OPTIONS, ///< Here's some info about the game.
MSG_INACTIVE, ///< I've alt-tabbed out. Unaccept me cause I'm a poo-flinging monkey.

MSG_REQUEST_GAME_INFO, ///< For direct connect, get the game info from a specific IP Address
} messageType;

WideChar name[g_lanPlayerNameLength+1]; ///< My name, for convenience
char userName[g_lanLoginNameLength+1]; ///< login name, for convenience
char hostName[g_lanHostNameLength+1]; ///< machine name, for convenience

// No additional data is required for REQUEST_LOCATIONS, LOBBY_ANNOUNCE,
// REQUEST_LOBBY_LEAVE, GAME_START.
union
{
// StartTimer is sent with GAME_START_TIMER
struct
{
Int seconds;
} StartTimer;

// GameJoined is sent with REQUEST_GAME_LEAVE
struct
{
WideChar gameName[g_lanGameNameLength+1];
} GameToLeave;

// GameInfo if sent with GAME_ANNOUNCE
struct
{
WideChar gameName[g_lanGameNameLength+1];
Bool inProgress;
char options[m_lanMaxOptionsLength+1];
Bool isDirectConnect;
} GameInfo;

// PlayerInfo is sent with REQUEST_GAME_INFO for direct connect games.
struct
{
UnsignedInt ip;
WideChar playerName[g_lanPlayerNameLength+1];
} PlayerInfo;

// GameToJoin is sent with REQUEST_JOIN
struct
{
UnsignedInt gameIP;
UnsignedInt exeCRC;
UnsignedInt iniCRC;
char serial[g_maxSerialLength];
} GameToJoin;

// GameJoined is sent with JOIN_ACCEPT
struct
{
WideChar gameName[g_lanGameNameLength+1];
UnsignedInt gameIP;
UnsignedInt playerIP;
Int slotPosition;
} GameJoined;

// GameNotJoined is sent with JOIN_DENY
struct
{
WideChar gameName[g_lanGameNameLength+1];
UnsignedInt gameIP;
UnsignedInt playerIP;
LANAPIInterface::ReturnType reason;
} GameNotJoined;

// Accept is sent with SET_ACCEPT
struct
{
WideChar gameName[g_lanGameNameLength+1];
Bool isAccepted;
} Accept;

// Accept is sent with MAP_AVAILABILITY
struct
{
WideChar gameName[g_lanGameNameLength+1];
UnsignedInt mapCRC; // to make sure we're talking about the same map
Bool hasMap;
} MapStatus;

// Chat is sent with CHAT
struct
{
WideChar gameName[g_lanGameNameLength+1];
LANAPIInterface::ChatType chatType;
WideChar message[g_lanMaxChatLength+1];
} Chat;

// GameOptions is sent with GAME_OPTIONS
struct
{
char options[m_lanMaxOptionsLength+1];
} GameOptions;

};
};
#pragma pack(pop)
4 changes: 4 additions & 0 deletions Core/GameEngine/Include/GameNetwork/LANAPICallbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ extern const Color chatSystemColor;
extern const Color chatSystemColor;
extern const Color acceptTrueColor;
extern const Color acceptFalseColor;
extern const Color gameColorCommunityPatch;
extern const Color gameInProgressColorCommunityPatch;
extern const Color playerColorCommunityPatch;
extern const Color playerGrayedColorCommunityPatch;


void lanUpdateSlotList( void );
Expand Down
5 changes: 4 additions & 1 deletion Core/GameEngine/Include/GameNetwork/LANPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
class LANPlayer
{
public:
LANPlayer() { m_name = m_login = m_host = L""; m_lastHeard = 0; m_next = NULL; m_IP = 0; }
LANPlayer() { m_name = m_login = m_host = L""; m_lastHeard = 0; m_next = NULL; m_IP = 0; m_productInfoFlags = 0; }

// Access functions
inline UnicodeString getName( void ) { return m_name; }
Expand All @@ -52,6 +52,8 @@ class LANPlayer
inline void setNext( LANPlayer *next ) { m_next = next; }
inline UnsignedInt getIP( void ) { return m_IP; }
inline void setIP( UnsignedInt IP ) { m_IP = IP; }
inline void setProductInfoFlags(UnsignedInt productInfoFlags) { m_productInfoFlags = productInfoFlags; }
inline UnsignedInt getProductInfoFlags() const { return m_productInfoFlags; }

protected:
UnicodeString m_name; ///< Player name
Expand All @@ -60,4 +62,5 @@ class LANPlayer
UnsignedInt m_lastHeard; ///< The last time we heard from this player (for timeout purposes)
LANPlayer *m_next; ///< Linked list pointer
UnsignedInt m_IP; ///< Player's IP
UnsignedInt m_productInfoFlags; ///< Community made product information flags
};
Loading
Loading