- moved pause for lagged clients option to custom game menu

- bugfix to ignore 0.* ip addresses
This commit is contained in:
Mark Vejvoda 2010-07-16 16:53:19 +00:00
parent 9992f9cb79
commit a3ec4650c4
5 changed files with 54 additions and 19 deletions

View File

@ -50,6 +50,7 @@ private:
bool enableObserverModeAtEndGame;
bool enableServerControlledAI;
int networkFramePeriod;
bool networkPauseGameForLaggedClients;
public:
@ -59,6 +60,7 @@ public:
enableObserverModeAtEndGame = false;
enableServerControlledAI = false;
networkFramePeriod = GameConstants::networkFramePeriod;
networkPauseGameForLaggedClients = false;
for(int i = 0; i < GameConstants::maxPlayers; ++i) {
factionTypeNames[i] = "";
@ -105,6 +107,7 @@ public:
bool getEnableObserverModeAtEndGame() const {return enableObserverModeAtEndGame;}
bool getEnableServerControlledAI() const {return enableServerControlledAI;}
int getNetworkFramePeriod() const {return networkFramePeriod; }
bool getNetworkPauseGameForLaggedClients() const {return networkPauseGameForLaggedClients; }
//set
void setDescription(const string& description) {this->description= description;}
@ -130,6 +133,7 @@ public:
void setEnableObserverModeAtEndGame(bool value) {this->enableObserverModeAtEndGame = value;}
void setEnableServerControlledAI(bool value) {this->enableServerControlledAI = value;}
void setNetworkFramePeriod(int value) {this->networkFramePeriod = value; }
void setNetworkPauseGameForLaggedClients(bool value) {this->networkPauseGameForLaggedClients = value; }
string toString() const {
string result = "";
@ -160,6 +164,7 @@ public:
result += "enableObserverModeAtEndGame = " + intToStr(enableObserverModeAtEndGame) + "\n";
result += "enableServerControlledAI = " + intToStr(enableServerControlledAI) + "\n";
result += "networkFramePeriod = " + intToStr(networkFramePeriod) + "\n";
result += "networkPauseGameForLaggedClients = " + intToStr(networkPauseGameForLaggedClients) + "\n";
return result;
}

View File

@ -226,6 +226,14 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
listBoxNetworkFramePeriod.pushBackItem("40");
listBoxNetworkFramePeriod.setSelectedItem("20");
// Network Frame Period
labelNetworkPauseGameForLaggedClients.init(550, networkHeadPos, 80);
labelNetworkPauseGameForLaggedClients.setText(lang.get("NetworkPauseGameForLaggedClients"));
listBoxNetworkPauseGameForLaggedClients.init(560, networkPos, 80);
listBoxNetworkPauseGameForLaggedClients.pushBackItem(lang.get("No"));
listBoxNetworkPauseGameForLaggedClients.pushBackItem(lang.get("Yes"));
listBoxNetworkPauseGameForLaggedClients.setSelectedItem(lang.get("No"));
// Enable Server Controlled AI
labelEnableServerControlledAI.init(690, networkHeadPos, 80);
@ -590,6 +598,10 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
soundRenderer.playFx(coreData.getClickSoundC());
}
else if(listBoxNetworkPauseGameForLaggedClients.mouseClick(x, y)){
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
soundRenderer.playFx(coreData.getClickSoundC());
}
else {
for(int i=0; i<mapInfo.players; ++i) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
@ -678,6 +690,9 @@ void MenuStateCustomGame::mouseMove(int x, int y, const MouseState *ms){
listBoxEnableServerControlledAI.mouseMove(x, y);
labelNetworkFramePeriod.mouseMove(x, y);
listBoxNetworkFramePeriod.mouseMove(x, y);
labelNetworkPauseGameForLaggedClients.mouseMove(x, y);
listBoxNetworkPauseGameForLaggedClients.mouseMove(x, y);
}
void MenuStateCustomGame::render(){
@ -733,6 +748,8 @@ void MenuStateCustomGame::render(){
renderer.renderLabel(&labelEnableServerControlledAI);
renderer.renderLabel(&labelNetworkFramePeriod);
renderer.renderListBox(&listBoxNetworkFramePeriod);
renderer.renderLabel(&labelNetworkPauseGameForLaggedClients);
renderer.renderListBox(&listBoxNetworkPauseGameForLaggedClients);
}
}
@ -749,7 +766,7 @@ void MenuStateCustomGame::update() {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
try {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(serverInitError == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -769,7 +786,7 @@ void MenuStateCustomGame::update() {
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
Lang& lang= Lang::getInstance();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
bool haveAtLeastOneNetworkClientConnected = false;
bool hasOneNetworkSlotOpen = false;
@ -778,7 +795,7 @@ void MenuStateCustomGame::update() {
bool masterServerErr = showMasterserverError;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(masterServerErr)
{
@ -802,7 +819,7 @@ void MenuStateCustomGame::update() {
showMessageBox( generalErrorToShow, "Error", false);
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
// handle setting changes from clients
SwitchSetupRequest** switchSetupRequests=serverInterface->getSwitchSetupRequests();
@ -856,20 +873,20 @@ void MenuStateCustomGame::update() {
}
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] mapInfo.players = %d\n",__FILE__,__FUNCTION__,__LINE__,mapInfo.players);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] mapInfo.players = %d\n",__FILE__,__FUNCTION__,__LINE__,mapInfo.players);
for(int i= 0; i<mapInfo.players; ++i)
{
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork)
{
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
ConnectionSlot* connectionSlot= serverInterface->getSlot(i);
assert(connectionSlot!=NULL);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
hasOneNetworkSlotOpen=true;
@ -961,7 +978,7 @@ void MenuStateCustomGame::update() {
}
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
bool checkDataSynch = (serverInterface->getAllowGameDataSynchCheck() == true &&
//haveAtLeastOneNetworkClientConnected == true &&
@ -977,7 +994,7 @@ void MenuStateCustomGame::update() {
needToSetChangedGameSettings = false;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(hasOneNetworkSlotOpen) {
//listBoxPublishServer.setSelectedItemIndex(0);
@ -1035,7 +1052,7 @@ void MenuStateCustomGame::update() {
}
soundConnectionCount = currentConnectionCount;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
catch(const std::exception &ex) {
char szBuf[1024]="";
@ -1045,7 +1062,7 @@ void MenuStateCustomGame::update() {
showGeneralError=true;
generalErrorToShow = szBuf;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
void MenuStateCustomGame::publishToMasterserver()
@ -1263,6 +1280,7 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) {
gameSettings->setFactionCount(factionCount);
gameSettings->setEnableServerControlledAI(listBoxEnableServerControlledAI.getSelectedItemIndex() == 0);
gameSettings->setNetworkFramePeriod((listBoxNetworkFramePeriod.getSelectedItemIndex()+1)*10);
gameSettings->setNetworkPauseGameForLaggedClients((listBoxNetworkPauseGameForLaggedClients.getSelectedItemIndex()));
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] gameSettings->getTileset() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getTileset().c_str());
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] gameSettings->getTech() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getTech().c_str());
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] gameSettings->getMap() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getMap().c_str());
@ -1300,6 +1318,7 @@ void MenuStateCustomGame::saveGameSettingsToFile(std::string fileName) {
saveGameFile << "EnableObserverModeAtEndGame=" << gameSettings.getEnableObserverModeAtEndGame() << std::endl;
saveGameFile << "EnableServerControlledAI=" << gameSettings.getEnableServerControlledAI() << std::endl;
saveGameFile << "NetworkFramePeriod=" << gameSettings.getNetworkFramePeriod() << std::endl;
saveGameFile << "NetworkPauseGameForLaggedClients=" << gameSettings.getNetworkPauseGameForLaggedClients() << std::endl;
saveGameFile << "ExternalPortNumber=" << listBoxPublishServerExternalPort.getSelectedItem() << std::endl;
saveGameFile << "FactionThisFactionIndex=" << gameSettings.getThisFactionIndex() << std::endl;
@ -1351,6 +1370,7 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName)
gameSettings.setEnableObserverModeAtEndGame(properties.getBool("EnableObserverModeAtEndGame"));
gameSettings.setEnableServerControlledAI(properties.getBool("EnableServerControlledAI","false"));
gameSettings.setNetworkFramePeriod(properties.getInt("NetworkFramePeriod",intToStr(GameConstants::networkFramePeriod).c_str())/10*10);
gameSettings.setNetworkPauseGameForLaggedClients(properties.getBool("NetworkPauseGameForLaggedClients","false"));
gameSettings.setThisFactionIndex(properties.getInt("FactionThisFactionIndex"));
gameSettings.setFactionCount(properties.getInt("FactionCount"));
@ -1402,6 +1422,10 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName)
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
listBoxNetworkPauseGameForLaggedClients.setSelectedItemIndex(gameSettings.getNetworkPauseGameForLaggedClients());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
reloadFactions();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d] gameSettings.getFactionCount() = %d\n",__FILE__,__FUNCTION__,__LINE__,gameSettings.getFactionCount());

View File

@ -69,6 +69,9 @@ private:
GraphicListBox listBoxNetworkFramePeriod;
GraphicLabel labelNetworkFramePeriod;
GraphicLabel labelNetworkPauseGameForLaggedClients;
GraphicListBox listBoxNetworkPauseGameForLaggedClients;
bool needToSetChangedGameSettings;
time_t lastSetChangedGameSettings;

View File

@ -46,7 +46,7 @@ double maxClientLagTimeAllowed = 20;
// 65% of max we warn all users about the lagged client
double warnFrameCountLagPercent = 0.65;
// Should we wait for lagged clients instead of disconnect them?
bool pauseGameForLaggedClients = false;
//bool pauseGameForLaggedClients = false;
// Seconds grace period before we start checking LAG
double LAG_CHECK_GRACE_PERIOD = 15;
@ -61,8 +61,9 @@ ServerInterface::ServerInterface(){
maxFrameCountLagAllowed = Config::getInstance().getInt("MaxFrameCountLagAllowed",intToStr(maxFrameCountLagAllowed).c_str());
maxClientLagTimeAllowed = Config::getInstance().getInt("MaxClientLagTimeAllowed",intToStr(maxClientLagTimeAllowed).c_str());
warnFrameCountLagPercent = Config::getInstance().getFloat("WarnFrameCountLagPercent",doubleToStr(warnFrameCountLagPercent).c_str());
pauseGameForLaggedClients = Config::getInstance().getFloat("PauseGameForLaggedClients",boolToStr(pauseGameForLaggedClients).c_str());
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] enabledThreadedClientCommandBroadcast = %d, maxFrameCountLagAllowed = %f, maxClientLagTimeAllowed = %f, pauseGameForLaggedClients = %d\n",__FILE__,__FUNCTION__,__LINE__,enabledThreadedClientCommandBroadcast,maxFrameCountLagAllowed,maxClientLagTimeAllowed,pauseGameForLaggedClients);
//pauseGameForLaggedClients = Config::getInstance().getFloat("PauseGameForLaggedClients",boolToStr(pauseGameForLaggedClients).c_str());
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] enabledThreadedClientCommandBroadcast = %d, maxFrameCountLagAllowed = %f, maxClientLagTimeAllowed = %f, pauseGameForLaggedClients = %d\n",__FILE__,__FUNCTION__,__LINE__,enabledThreadedClientCommandBroadcast,maxFrameCountLagAllowed,maxClientLagTimeAllowed,pauseGameForLaggedClients);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] enabledThreadedClientCommandBroadcast = %d, maxFrameCountLagAllowed = %f, maxClientLagTimeAllowed = %f\n",__FILE__,__FUNCTION__,__LINE__,enabledThreadedClientCommandBroadcast,maxFrameCountLagAllowed,maxClientLagTimeAllowed);
for(int i= 0; i<GameConstants::maxPlayers; ++i){
slots[i]= NULL;
@ -309,7 +310,7 @@ bool ServerInterface::clientLagCheck(ConnectionSlot* connectionSlot) {
char szBuf[4096]="";
const char* msgTemplate = "DROPPING %s, exceeded max allowed LAG count of %f [time = %f], clientLag = %f [%f], disconnecting client.";
if(pauseGameForLaggedClients == true) {
if(gameSettings.getNetworkPauseGameForLaggedClients() == true) {
msgTemplate = "PAUSING GAME TEMPORARILY for %s, exceeded max allowed LAG count of %f [time = %f], clientLag = %f [%f], waiting for client to catch up...";
}
#ifdef WIN32
@ -322,7 +323,7 @@ bool ServerInterface::clientLagCheck(ConnectionSlot* connectionSlot) {
string sMsg = szBuf;
sendTextMessage(sMsg,-1, true);
if(pauseGameForLaggedClients == false) {
if(gameSettings.getNetworkPauseGameForLaggedClients() == false) {
connectionSlot->close();
}
}
@ -481,7 +482,7 @@ void ServerInterface::update() {
// If the client has exceeded lag and the server wants
// to pause while they catch up, re-trigger the
// client reader thread
if(clientLagExceeded == true && pauseGameForLaggedClients == true) {
if(clientLagExceeded == true && gameSettings.getNetworkPauseGameForLaggedClients() == true) {
bool socketTriggered = (connectionSlot != NULL && connectionSlot->getSocket() != NULL ? socketTriggeredList[connectionSlot->getSocket()->getSocketId()] : false);
ConnectionSlotEvent &event = eventList[i];
signalClientReceiveCommands(connectionSlot,i,socketTriggered,event);

View File

@ -618,7 +618,9 @@ std::vector<std::string> Socket::getLocalIPAddressList() {
//printf("%s\n",myhostaddr);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] myhostaddr = [%s]\n",__FILE__,__FUNCTION__,__LINE__,myhostaddr);
if(strlen(myhostaddr) > 0 && strncmp(myhostaddr,"127.",4) != 0) {
if(strlen(myhostaddr) > 0 &&
strncmp(myhostaddr,"127.",4) != 0 &&
strncmp(myhostaddr,"0.",2) != 0) {
ipList.push_back(myhostaddr);
}
ipIdx++;