- added ability to show a user is disconnected from the game
This commit is contained in:
parent
cb7bd8ff04
commit
b965343496
|
@ -479,6 +479,11 @@ void Commander::tryResumeGame() const {
|
||||||
pushNetworkCommand(&command);
|
pushNetworkCommand(&command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Commander::tryNetworkPlayerDisconnected(int factionIndex) const {
|
||||||
|
NetworkCommand command(this->world,nctPlayerStatusChange, factionIndex, 1);
|
||||||
|
pushNetworkCommand(&command);
|
||||||
|
}
|
||||||
|
|
||||||
// ==================== PRIVATE ====================
|
// ==================== PRIVATE ====================
|
||||||
|
|
||||||
CommandResult Commander::computeResult(const CommandResultContainer &results) const {
|
CommandResult Commander::computeResult(const CommandResultContainer &results) const {
|
||||||
|
@ -801,7 +806,8 @@ void Commander::giveNetworkCommand(NetworkCommand* networkCommand) const {
|
||||||
}
|
}
|
||||||
break;
|
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__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found nctPauseResume\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
commandWasHandled = true;
|
commandWasHandled = true;
|
||||||
|
@ -812,12 +818,29 @@ void Commander::giveNetworkCommand(NetworkCommand* networkCommand) const {
|
||||||
//printf("nctPauseResume pauseGame = %d\n",pauseGame);
|
//printf("nctPauseResume pauseGame = %d\n",pauseGame);
|
||||||
game->setPaused(pauseGame,true);
|
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 nctPauseResume\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
}
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found nctSetMeetingPoint\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
}
|
|
||||||
break;
|
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -113,7 +113,7 @@ public:
|
||||||
void trySwitchTeamVote(const Faction* faction, SwitchTeamVote *vote) const;
|
void trySwitchTeamVote(const Faction* faction, SwitchTeamVote *vote) const;
|
||||||
void tryPauseGame() const;
|
void tryPauseGame() const;
|
||||||
void tryResumeGame() const;
|
void tryResumeGame() const;
|
||||||
|
void tryNetworkPlayerDisconnected(int factionIndex) const;
|
||||||
|
|
||||||
Command* buildCommand(const NetworkCommand* networkCommand) const;
|
Command* buildCommand(const NetworkCommand* networkCommand) const;
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ using namespace Shared::Platform;
|
||||||
|
|
||||||
namespace Glest{ namespace Game{
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
|
string GameSettings::playerDisconnectedText = "";
|
||||||
Game *thisGamePtr = NULL;
|
Game *thisGamePtr = NULL;
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
@ -838,6 +839,8 @@ void Game::init(bool initForPreviewOnly) {
|
||||||
Map *map= world.getMap();
|
Map *map= world.getMap();
|
||||||
NetworkManager &networkManager= NetworkManager::getInstance();
|
NetworkManager &networkManager= NetworkManager::getInstance();
|
||||||
|
|
||||||
|
GameSettings::playerDisconnectedText = "*" + lang.get("Disconnect") + "* - ";
|
||||||
|
|
||||||
if(map == NULL) {
|
if(map == NULL) {
|
||||||
throw megaglest_runtime_error("map == NULL");
|
throw megaglest_runtime_error("map == NULL");
|
||||||
}
|
}
|
||||||
|
@ -1549,7 +1552,9 @@ void Game::ReplaceDisconnectedNetworkPlayersWithAI(bool isNetworkGame, NetworkRo
|
||||||
server->isClientConnected(faction->getStartLocationIndex()) == false) {
|
server->isClientConnected(faction->getStartLocationIndex()) == false) {
|
||||||
faction->setFactionDisconnectHandled(true);
|
faction->setFactionDisconnectHandled(true);
|
||||||
|
|
||||||
char szBuf[1024]="";
|
Lang &lang= Lang::getInstance();
|
||||||
|
|
||||||
|
char szBuf[4096]="";
|
||||||
if(faction->getPersonalityType() != fpt_Observer) {
|
if(faction->getPersonalityType() != fpt_Observer) {
|
||||||
faction->setControlType(ctCpu);
|
faction->setControlType(ctCpu);
|
||||||
aiInterfaces[i] = new AiInterface(*this, i, faction->getTeam(), faction->getStartLocationIndex());
|
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);
|
sprintf(szBuf,Lang::getInstance().get("LogScreenGameLoadingCreatingAIFaction","",true).c_str(),i);
|
||||||
logger.add(szBuf, true);
|
logger.add(szBuf, true);
|
||||||
|
|
||||||
Lang &lang= Lang::getInstance();
|
|
||||||
string msg = "Player #%d [%s] has disconnected, switching player to AI mode!";
|
string msg = "Player #%d [%s] has disconnected, switching player to AI mode!";
|
||||||
if(lang.hasString("GameSwitchPlayerToAI")) {
|
if(lang.hasString("GameSwitchPlayerToAI")) {
|
||||||
msg = lang.get("GameSwitchPlayerToAI");
|
msg = lang.get("GameSwitchPlayerToAI");
|
||||||
}
|
}
|
||||||
sprintf(szBuf,msg.c_str(),i+1,this->gameSettings.getNetworkPlayerName(i).c_str());
|
sprintf(szBuf,msg.c_str(),i+1,this->gameSettings.getNetworkPlayerName(i).c_str());
|
||||||
|
|
||||||
|
commander.tryNetworkPlayerDisconnected(i);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Lang &lang= Lang::getInstance();
|
|
||||||
string msg = "Player #%d [%s] has disconnected, but player was only an observer!";
|
string msg = "Player #%d [%s] has disconnected, but player was only an observer!";
|
||||||
if(lang.hasString("GameSwitchPlayerObserverToAI")) {
|
if(lang.hasString("GameSwitchPlayerObserverToAI")) {
|
||||||
msg = lang.get("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());
|
sprintf(szBuf,msg.c_str(),i+1,this->gameSettings.getNetworkPlayerName(i).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
Lang &lang= Lang::getInstance();
|
|
||||||
const vector<string> languageList = this->gameSettings.getUniqueNetworkPlayerLanguages();
|
const vector<string> languageList = this->gameSettings.getUniqueNetworkPlayerLanguages();
|
||||||
for(unsigned int j = 0; j < languageList.size(); ++j) {
|
for(unsigned int j = 0; j < languageList.size(); ++j) {
|
||||||
bool localEcho = (languageList[j] == lang.getLanguage());
|
bool localEcho = (languageList[j] == lang.getLanguage());
|
||||||
|
|
|
@ -54,6 +54,7 @@ private:
|
||||||
string networkPlayerNames[GameConstants::maxPlayers];
|
string networkPlayerNames[GameConstants::maxPlayers];
|
||||||
int networkPlayerStatuses[GameConstants::maxPlayers];
|
int networkPlayerStatuses[GameConstants::maxPlayers];
|
||||||
string networkPlayerLanguages[GameConstants::maxPlayers];
|
string networkPlayerLanguages[GameConstants::maxPlayers];
|
||||||
|
int networkPlayerGameStatus[GameConstants::maxPlayers];
|
||||||
|
|
||||||
ControlType factionControls[GameConstants::maxPlayers];
|
ControlType factionControls[GameConstants::maxPlayers];
|
||||||
int resourceMultiplierIndex[GameConstants::maxPlayers];
|
int resourceMultiplierIndex[GameConstants::maxPlayers];
|
||||||
|
@ -89,6 +90,8 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
static string playerDisconnectedText;
|
||||||
|
|
||||||
GameSettings() {
|
GameSettings() {
|
||||||
defaultUnits=false;
|
defaultUnits=false;
|
||||||
defaultResources=false;
|
defaultResources=false;
|
||||||
|
@ -114,6 +117,7 @@ public:
|
||||||
resourceMultiplierIndex[i] = 1.0f;
|
resourceMultiplierIndex[i] = 1.0f;
|
||||||
teams[i] = 0;
|
teams[i] = 0;
|
||||||
startLocationIndex[i] = i;
|
startLocationIndex[i] = i;
|
||||||
|
networkPlayerGameStatus[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
flagTypes1 = ft1_none;
|
flagTypes1 = ft1_none;
|
||||||
|
@ -129,17 +133,25 @@ public:
|
||||||
// default copy constructor will do fine, and will maintain itself ;)
|
// default copy constructor will do fine, and will maintain itself ;)
|
||||||
|
|
||||||
//get
|
//get
|
||||||
const string &getDescription() const {return description;}
|
const string &getDescription() const {return description;}
|
||||||
const string &getMap() const {return map;}
|
const string &getMap() const {return map;}
|
||||||
const string &getTileset() const {return tileset;}
|
const string &getTileset() const {return tileset;}
|
||||||
const string &getTech() const {return tech;}
|
const string &getTech() const {return tech;}
|
||||||
const string &getScenario() const {return scenario;}
|
const string &getScenario() const {return scenario;}
|
||||||
const string &getScenarioDir() const {return scenarioDir;}
|
const string &getScenarioDir() const {return scenarioDir;}
|
||||||
const string &getFactionTypeName(int factionIndex) const {return factionTypeNames[factionIndex];}
|
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 int getNetworkPlayerStatuses(int factionIndex) const { return networkPlayerStatuses[factionIndex];}
|
||||||
const string getNetworkPlayerLanguages(int factionIndex) const { return networkPlayerLanguages[factionIndex];}
|
const string getNetworkPlayerLanguages(int factionIndex) const { return networkPlayerLanguages[factionIndex];}
|
||||||
|
|
||||||
|
const int getNetworkPlayerGameStatus(int factionIndex) const { return networkPlayerGameStatus[factionIndex];}
|
||||||
|
|
||||||
const vector<string> getUniqueNetworkPlayerLanguages() const {
|
const vector<string> getUniqueNetworkPlayerLanguages() const {
|
||||||
vector<string> languageList;
|
vector<string> languageList;
|
||||||
for(int i = 0; i < GameConstants::maxPlayers; ++i) {
|
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 setFactionTypeName(int factionIndex, const string& factionTypeName) {this->factionTypeNames[factionIndex]= factionTypeName;}
|
||||||
void setNetworkPlayerName(int factionIndex,const string& playername) {this->networkPlayerNames[factionIndex]= playername;}
|
void setNetworkPlayerName(int factionIndex,const string& playername) {this->networkPlayerNames[factionIndex]= playername;}
|
||||||
void setNetworkPlayerStatuses(int factionIndex,int status) {this->networkPlayerStatuses[factionIndex]= status;}
|
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 setNetworkPlayerLanguages(int factionIndex, string language) {this->networkPlayerLanguages[factionIndex]=language;}
|
||||||
|
|
||||||
void setFactionControl(int factionIndex, ControlType controller) {this->factionControls[factionIndex]= controller;}
|
void setFactionControl(int factionIndex, ControlType controller) {this->factionControls[factionIndex]= controller;}
|
||||||
|
@ -334,6 +348,14 @@ public:
|
||||||
networkPlayerStatusesNode->addAttribute("status",intToStr(networkPlayerStatuses[idx]), mapTagReplacements);
|
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];
|
// string networkPlayerLanguages[GameConstants::maxPlayers];
|
||||||
for(int idx =0; idx < GameConstants::maxPlayers; idx++) {
|
for(int idx =0; idx < GameConstants::maxPlayers; idx++) {
|
||||||
XmlNode *networkPlayerLanguagesNode = gameSettingsNode->addChild("networkPlayerLanguages");
|
XmlNode *networkPlayerLanguagesNode = gameSettingsNode->addChild("networkPlayerLanguages");
|
||||||
|
@ -451,6 +473,12 @@ public:
|
||||||
networkPlayerStatuses[idx] = networkPlayerStatusesNode->getAttribute("status")->getIntValue();
|
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];
|
// string networkPlayerLanguages[GameConstants::maxPlayers];
|
||||||
for(int idx =0; idx < GameConstants::maxPlayers; idx++) {
|
for(int idx =0; idx < GameConstants::maxPlayers; idx++) {
|
||||||
const XmlNode *networkPlayerLanguagesNode = gameSettingsNode->getChild("networkPlayerLanguages",idx);
|
const XmlNode *networkPlayerLanguagesNode = gameSettingsNode->getChild("networkPlayerLanguages",idx);
|
||||||
|
|
|
@ -74,7 +74,8 @@ enum NetworkCommandType {
|
||||||
nctSetMeetingPoint,
|
nctSetMeetingPoint,
|
||||||
nctSwitchTeam,
|
nctSwitchTeam,
|
||||||
nctSwitchTeamVote,
|
nctSwitchTeamVote,
|
||||||
nctPauseResume
|
nctPauseResume,
|
||||||
|
nctPlayerStatusChange
|
||||||
//nctNetworkCommand
|
//nctNetworkCommand
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user