diff --git a/src/include/net_message.h b/src/include/net_message.h index 0318a44de..da2059c8c 100644 --- a/src/include/net_message.h +++ b/src/include/net_message.h @@ -122,7 +122,7 @@ public: 1 + // Resources 1 + // RevealMap 4 + // Bitfield - 1 * PlayerMax + // Races + 4 * PlayerMax + // Races, PlayerColors, Teams, Types 1 * PlayerMax + // CompOpt 1 * PlayerMax; // Ready } diff --git a/src/network/net_message.cpp b/src/network/net_message.cpp index 58b2cd391..87641d164 100644 --- a/src/network/net_message.cpp +++ b/src/network/net_message.cpp @@ -256,6 +256,9 @@ size_t CServerSetup::Serialize(unsigned char *buf) const for (int i = 0; i < PlayerMax; ++i) { p += serialize8(p, static_cast<int8_t>(this->ServerGameSettings.Presets[i].Race)); + p += serialize8(p, static_cast<int8_t>(this->ServerGameSettings.Presets[i].PlayerColor)); + p += serialize8(p, static_cast<int8_t>(this->ServerGameSettings.Presets[i].Team)); + p += serialize8(p, static_cast<int8_t>(this->ServerGameSettings.Presets[i].Type)); } for (int i = 0; i < PlayerMax; ++i) { p += serialize8(p, static_cast<int8_t>(this->CompOpt[i])); @@ -285,6 +288,9 @@ size_t CServerSetup::Deserialize(const unsigned char *p) for (int i = 0; i < PlayerMax; ++i) { p += deserialize8(p, reinterpret_cast<int8_t*>(&this->ServerGameSettings.Presets[i].Race)); + p += deserialize8(p, reinterpret_cast<int8_t*>(&this->ServerGameSettings.Presets[i].PlayerColor)); + p += deserialize8(p, reinterpret_cast<int8_t*>(&this->ServerGameSettings.Presets[i].Team)); + p += deserialize8(p, reinterpret_cast<int8_t*>(&this->ServerGameSettings.Presets[i].Type)); } for (int i = 0; i < PlayerMax; ++i) { p += deserialize8(p, reinterpret_cast<int8_t*>(&this->CompOpt[i])); diff --git a/src/network/netconnect.cpp b/src/network/netconnect.cpp index 3a8e49c67..54bd7dd2f 100644 --- a/src/network/netconnect.cpp +++ b/src/network/netconnect.cpp @@ -1788,8 +1788,10 @@ void NetworkServerStartGame() } } - bool waitingForConfigAck[PlayerMax] = {true}; - bool waitingForInitAck[PlayerMax] = {false}; + bool waitingForConfigAck[PlayerMax]; + bool waitingForInitAck[PlayerMax]; + std::fill_n(waitingForConfigAck, PlayerMax, true); + std::fill_n(waitingForInitAck, PlayerMax, false); // Send all clients host:ports to all clients. // Slot 0 is the server! @@ -1819,18 +1821,22 @@ void NetworkServerStartGame() // Prepare the final state message: const CInitMessage_State statemsg(MessageInit_FromServer, ServerSetupState); - DebugPrint("Ready, sending InitConfig to %d host(s)\n" _C_ NetPlayers); - // Send all clients host:ports to all clients. int hostsToAck = NetPlayers - 1; + DebugPrint("Ready, sending InitConfig to %d host(s)\n" _C_ hostsToAck); + // Send all clients host:ports to all clients. while (hostsToAck) { breakout: - // Send to all clients, skip server host in Hosts[0] - for (int i = 1; i < NetPlayers; ++i) { - const CHost host(message.hosts[i].Host, message.hosts[i].Port); - if (waitingForConfigAck[i]) { // not acknowledged yet - NetworkSendICMessage_Log(NetworkFildes, host, message); - } else if (waitingForInitAck[i]) { - NetworkSendICMessage_Log(NetworkFildes, host, statemsg); + // Send to all clients, skip ourselves (the server) host in Hosts[0] + for (int i = 1; i <= PlayerMax; ++i) { + if (Hosts[i].IsValid()) { + const CHost host(message.hosts[i].Host, message.hosts[i].Port); + if (waitingForConfigAck[i]) { // not acknowledged yet + DebugPrint("Sending InitConfig to %s\n" _C_ host.toString().c_str()); + NetworkSendICMessage_Log(NetworkFildes, host, message); + } else if (waitingForInitAck[i]) { + DebugPrint("Sending InitState to %s\n" _C_ host.toString().c_str()); + NetworkSendICMessage_Log(NetworkFildes, host, statemsg); + } } } @@ -1986,7 +1992,7 @@ void NetworkGamePrepareGameSettings() GameSettings.NetGameType = NetGameTypes::SettingsMultiPlayerGame; printf("FINAL NETWORK GAME SETUP\n"); - for (int i = 0; i < PlayerMax - 1; i++) { + for (int i = 0; i < PlayerMax; i++) { printf("%02d: CO: %d Race: %d Name: ", i, (int)ServerSetupState.CompOpt[i], ServerSetupState.ServerGameSettings.Presets[i].Race); if (ServerSetupState.CompOpt[i] == SlotOption::Available) { for (auto h : Hosts) {