diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index 95d78d942..088e222b8 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -837,15 +837,21 @@ void CVCMIServer::setPlayer(PlayerColor clickedColor) void CVCMIServer::setPlayerName(PlayerColor color, std::string name) { - PlayerSettings & player = si->playerInfos[color]; + if(color == PlayerColor::CANNOT_DETERMINE) + return; - if(player.isControlledByHuman()) - { - int nameID = *(player.connectedPlayerIDs.begin()); //if not AI - set appropiate ID + PlayerSettings & player = si->playerInfos.at(color); - playerNames[nameID].name = name; - setPlayerConnectedId(player, nameID); - } + if(!player.isControlledByHuman()) + return; + + if(!player.connectedPlayerIDs.size()) + return; + + int nameID = *(player.connectedPlayerIDs.begin()); //if not AI - set appropiate ID + + playerNames[nameID].name = name; + setPlayerConnectedId(player, nameID); } void CVCMIServer::optionNextCastle(PlayerColor player, int dir)