- added ability to show a user is disconnected from the game

This commit is contained in:
Mark Vejvoda 2012-06-09 15:21:18 +00:00
parent cb7bd8ff04
commit b965343496
5 changed files with 74 additions and 18 deletions

View File

@ -479,6 +479,11 @@ void Commander::tryResumeGame() const {
pushNetworkCommand(&command);
}
void Commander::tryNetworkPlayerDisconnected(int factionIndex) const {
NetworkCommand command(this->world,nctPlayerStatusChange, factionIndex, 1);
pushNetworkCommand(&command);
}
// ==================== PRIVATE ====================
CommandResult Commander::computeResult(const CommandResultContainer &results) const {
@ -801,7 +806,8 @@ void Commander::giveNetworkCommand(NetworkCommand* networkCommand) const {
}
break;
case nctPauseResume: {
case nctPauseResume:
{
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found nctPauseResume\n",__FILE__,__FUNCTION__,__LINE__);
commandWasHandled = true;
@ -812,12 +818,29 @@ void Commander::giveNetworkCommand(NetworkCommand* networkCommand) const {
//printf("nctPauseResume pauseGame = %d\n",pauseGame);
game->setPaused(pauseGame,true);
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld [after unit->setMeetingPos]\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found nctSetMeetingPoint\n",__FILE__,__FUNCTION__,__LINE__);
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found nctPauseResume\n",__FILE__,__FUNCTION__,__LINE__);
}
break;
case nctPlayerStatusChange:
{
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found nctPlayerStatusChange\n",__FILE__,__FUNCTION__,__LINE__);
commandWasHandled = true;
int factionIndex = networkCommand->getUnitId();
int playerStatus = networkCommand->getCommandTypeId();
if(playerStatus == 1) {
GameSettings *settings = world->getGameSettingsPtr();
settings->setNetworkPlayerGameStatus(factionIndex,1);
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found nctPlayerStatusChange\n",__FILE__,__FUNCTION__,__LINE__);
}
break;
}
/*

View File

@ -113,7 +113,7 @@ public:
void trySwitchTeamVote(const Faction* faction, SwitchTeamVote *vote) const;
void tryPauseGame() const;
void tryResumeGame() const;
void tryNetworkPlayerDisconnected(int factionIndex) const;
Command* buildCommand(const NetworkCommand* networkCommand) const;

View File

@ -34,6 +34,7 @@ using namespace Shared::Platform;
namespace Glest{ namespace Game{
string GameSettings::playerDisconnectedText = "";
Game *thisGamePtr = NULL;
// =====================================================
@ -838,6 +839,8 @@ void Game::init(bool initForPreviewOnly) {
Map *map= world.getMap();
NetworkManager &networkManager= NetworkManager::getInstance();
GameSettings::playerDisconnectedText = "*" + lang.get("Disconnect") + "* - ";
if(map == NULL) {
throw megaglest_runtime_error("map == NULL");
}
@ -1549,7 +1552,9 @@ void Game::ReplaceDisconnectedNetworkPlayersWithAI(bool isNetworkGame, NetworkRo
server->isClientConnected(faction->getStartLocationIndex()) == false) {
faction->setFactionDisconnectHandled(true);
char szBuf[1024]="";
Lang &lang= Lang::getInstance();
char szBuf[4096]="";
if(faction->getPersonalityType() != fpt_Observer) {
faction->setControlType(ctCpu);
aiInterfaces[i] = new AiInterface(*this, i, faction->getTeam(), faction->getStartLocationIndex());
@ -1557,15 +1562,15 @@ void Game::ReplaceDisconnectedNetworkPlayersWithAI(bool isNetworkGame, NetworkRo
sprintf(szBuf,Lang::getInstance().get("LogScreenGameLoadingCreatingAIFaction","",true).c_str(),i);
logger.add(szBuf, true);
Lang &lang= Lang::getInstance();
string msg = "Player #%d [%s] has disconnected, switching player to AI mode!";
if(lang.hasString("GameSwitchPlayerToAI")) {
msg = lang.get("GameSwitchPlayerToAI");
}
sprintf(szBuf,msg.c_str(),i+1,this->gameSettings.getNetworkPlayerName(i).c_str());
commander.tryNetworkPlayerDisconnected(i);
}
else {
Lang &lang= Lang::getInstance();
string msg = "Player #%d [%s] has disconnected, but player was only an observer!";
if(lang.hasString("GameSwitchPlayerObserverToAI")) {
msg = lang.get("GameSwitchPlayerObserverToAI");
@ -1573,7 +1578,6 @@ void Game::ReplaceDisconnectedNetworkPlayersWithAI(bool isNetworkGame, NetworkRo
sprintf(szBuf,msg.c_str(),i+1,this->gameSettings.getNetworkPlayerName(i).c_str());
}
Lang &lang= Lang::getInstance();
const vector<string> languageList = this->gameSettings.getUniqueNetworkPlayerLanguages();
for(unsigned int j = 0; j < languageList.size(); ++j) {
bool localEcho = (languageList[j] == lang.getLanguage());

View File

@ -54,6 +54,7 @@ private:
string networkPlayerNames[GameConstants::maxPlayers];
int networkPlayerStatuses[GameConstants::maxPlayers];
string networkPlayerLanguages[GameConstants::maxPlayers];
int networkPlayerGameStatus[GameConstants::maxPlayers];
ControlType factionControls[GameConstants::maxPlayers];
int resourceMultiplierIndex[GameConstants::maxPlayers];
@ -89,6 +90,8 @@ private:
public:
static string playerDisconnectedText;
GameSettings() {
defaultUnits=false;
defaultResources=false;
@ -114,6 +117,7 @@ public:
resourceMultiplierIndex[i] = 1.0f;
teams[i] = 0;
startLocationIndex[i] = i;
networkPlayerGameStatus[i] = 0;
}
flagTypes1 = ft1_none;
@ -129,17 +133,25 @@ public:
// default copy constructor will do fine, and will maintain itself ;)
//get
const string &getDescription() const {return description;}
const string &getMap() const {return map;}
const string &getTileset() const {return tileset;}
const string &getTech() const {return tech;}
const string &getScenario() const {return scenario;}
const string &getScenarioDir() const {return scenarioDir;}
const string &getDescription() const {return description;}
const string &getMap() const {return map;}
const string &getTileset() const {return tileset;}
const string &getTech() const {return tech;}
const string &getScenario() const {return scenario;}
const string &getScenarioDir() const {return scenarioDir;}
const string &getFactionTypeName(int factionIndex) const {return factionTypeNames[factionIndex];}
const string &getNetworkPlayerName(int factionIndex) const {return networkPlayerNames[factionIndex];}
string getNetworkPlayerName(int factionIndex) const {
string result = networkPlayerNames[factionIndex];
if(networkPlayerGameStatus[factionIndex] == 1) {
result = playerDisconnectedText + result;
}
return result;
}
const int getNetworkPlayerStatuses(int factionIndex) const { return networkPlayerStatuses[factionIndex];}
const string getNetworkPlayerLanguages(int factionIndex) const { return networkPlayerLanguages[factionIndex];}
const int getNetworkPlayerGameStatus(int factionIndex) const { return networkPlayerGameStatus[factionIndex];}
const vector<string> getUniqueNetworkPlayerLanguages() const {
vector<string> languageList;
for(int i = 0; i < GameConstants::maxPlayers; ++i) {
@ -213,6 +225,8 @@ public:
void setFactionTypeName(int factionIndex, const string& factionTypeName) {this->factionTypeNames[factionIndex]= factionTypeName;}
void setNetworkPlayerName(int factionIndex,const string& playername) {this->networkPlayerNames[factionIndex]= playername;}
void setNetworkPlayerStatuses(int factionIndex,int status) {this->networkPlayerStatuses[factionIndex]= status;}
void setNetworkPlayerGameStatus(int factionIndex,int status) {this->networkPlayerGameStatus[factionIndex]= status;}
void setNetworkPlayerLanguages(int factionIndex, string language) {this->networkPlayerLanguages[factionIndex]=language;}
void setFactionControl(int factionIndex, ControlType controller) {this->factionControls[factionIndex]= controller;}
@ -334,6 +348,14 @@ public:
networkPlayerStatusesNode->addAttribute("status",intToStr(networkPlayerStatuses[idx]), mapTagReplacements);
}
// int networkPlayerStatuses[GameConstants::maxPlayers];
for(int idx =0; idx < GameConstants::maxPlayers; idx++) {
XmlNode *networkPlayerStatusesNode = gameSettingsNode->addChild("networkPlayerGameStatus");
networkPlayerStatusesNode->addAttribute("game_status",intToStr(networkPlayerGameStatus[idx]), mapTagReplacements);
}
// string networkPlayerLanguages[GameConstants::maxPlayers];
for(int idx =0; idx < GameConstants::maxPlayers; idx++) {
XmlNode *networkPlayerLanguagesNode = gameSettingsNode->addChild("networkPlayerLanguages");
@ -451,6 +473,12 @@ public:
networkPlayerStatuses[idx] = networkPlayerStatusesNode->getAttribute("status")->getIntValue();
}
// int networkPlayerStatuses[GameConstants::maxPlayers];
for(int idx =0; idx < GameConstants::maxPlayers; idx++) {
const XmlNode *networkPlayerGameStatusNode = gameSettingsNode->getChild("networkPlayerGameStatus",idx);
networkPlayerGameStatus[idx] = networkPlayerGameStatusNode->getAttribute("game_status")->getIntValue();
}
// string networkPlayerLanguages[GameConstants::maxPlayers];
for(int idx =0; idx < GameConstants::maxPlayers; idx++) {
const XmlNode *networkPlayerLanguagesNode = gameSettingsNode->getChild("networkPlayerLanguages",idx);

View File

@ -74,7 +74,8 @@ enum NetworkCommandType {
nctSetMeetingPoint,
nctSwitchTeam,
nctSwitchTeamVote,
nctPauseResume
nctPauseResume,
nctPlayerStatusChange
//nctNetworkCommand
};