fix game start, also serialize presets in server state
This commit is contained in:
parent
27e28b595e
commit
3cd6aff6d6
3 changed files with 25 additions and 13 deletions
src
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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]));
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue