Created
June 19, 2017 19:15
-
-
Save Orpheon/ab3777a5095590576928e315401a6060 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ServerNetworker::registerlobby(Gamestate &state) | |
{ | |
xg::Guid message_type(LOBBY_MESSAGE_TYPE_REGISTER); | |
xg::Guid lobbyid(GG2_IDENTIFIER); | |
xg::Guid compatibility(COMPATIBILITY_IDENTIFIER); | |
WriteBuffer buffer; | |
// See https://github.com/Medo42/Faucet-Lobby/blob/master/Protocol%20Spec.txt for reference | |
// https://github.com/PyGG2/PyGG2/blob/master/server/lobby.py is also helpful | |
// Message type for lobby | |
for (auto& byte : message_type._bytes) | |
{ | |
buffer.write<uint8_t>(byte); | |
} | |
// Server id | |
for (auto& byte : serverid._bytes) | |
{ | |
buffer.write<uint8_t>(byte); | |
} | |
// Lobby id | |
for (auto& byte : lobbyid._bytes) | |
{ | |
buffer.write<uint8_t>(byte); | |
} | |
// Transport protocol (0=TCP, 1=UDP) | |
buffer.write<uint8_t>(1); | |
// Port number | |
buffer.write<uint16_t>(host->address.port); | |
// Number of total player slots | |
buffer.write<uint16_t>(PLAYER_LIMIT); | |
// Number of players ingame | |
buffer.write<uint16_t>(static_cast<uint16_t>(state.playerlist.size())); | |
// Number of AI bots | |
buffer.write<uint16_t>(0); | |
// Flags | |
buffer.write<uint16_t>(0); | |
std::map<std::string, std::string> data = { | |
{"name", "Vanguard test server"}, | |
{"game", GAME_NAME}, | |
{"game_short", GAME_NAME_SHORT}, | |
{"game_ver", GAME_VERSION}, | |
{"game_url", GAME_URL}, | |
{"map", state.currentmap->name} | |
}; | |
// Extra data | |
// Write number of key/value pairs | |
// Protocol_id isn't a string but fixed so doing it separately | |
buffer.write<uint16_t>(data.size() + 1); | |
// Compatibility flag | |
buffer.write<uint8_t>(std::string("protocol_id").size()); | |
buffer.writestring("protocol_id"); | |
buffer.write<uint16_t>(16); | |
for (auto& byte : compatibility._bytes) | |
{ | |
buffer.write<uint8_t>(byte); | |
} | |
// Everything else | |
for (auto& entry : data) | |
{ | |
buffer.write<uint8_t>(entry.first.size()); | |
buffer.writestring(entry.first); | |
buffer.write<uint16_t>(entry.second.size()); | |
buffer.writestring(entry.second); | |
} | |
std::ofstream file("lobby_registration.bin", std::ios_base::binary); | |
file.write(static_cast<char*>(buffer.getdata()), buffer.length()); | |
file.close(); | |
Global::logging().print(__FILE__, __LINE__, "Sent packet to lobby"); | |
ENetPacket *lobbypacket = enet_packet_create(buffer.getdata(), buffer.length(), ENET_PACKET_FLAG_RELIABLE); | |
enet_peer_send(lobby, 0, lobbypacket); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment