mirror of
https://github.com/glest/glest-source.git
synced 2025-09-26 23:49:03 +02:00
- bugfixes related to chat message processing and error processing. We now stack up messages and process them in a more safe manner
This commit is contained in:
@@ -148,28 +148,29 @@ void ChatManager::keyPress(char c){
|
||||
void ChatManager::updateNetwork() {
|
||||
try {
|
||||
GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface();
|
||||
string text;
|
||||
string sender;
|
||||
//string text;
|
||||
//string sender;
|
||||
Config &config= Config::getInstance();
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] gameNetworkInterface->getChatText() [%s]\n",__FILE__,__FUNCTION__,__LINE__,gameNetworkInterface->getChatText().c_str());
|
||||
|
||||
if(gameNetworkInterface->getChatText().empty() == false) {
|
||||
int teamIndex= gameNetworkInterface->getChatTeamIndex();
|
||||
if(gameNetworkInterface->getChatTextList().empty() == false) {
|
||||
for(int idx = 0; idx < gameNetworkInterface->getChatTextList().size(); idx++) {
|
||||
const ChatMsgInfo &msg = gameNetworkInterface->getChatTextList()[idx];
|
||||
int teamIndex= msg.chatTeamIndex;
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] got nmtText [%s] for team = %d\n",__FILE__,__FUNCTION__,gameNetworkInterface->getChatText().c_str(),teamIndex);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] got nmtText [%s] for team = %d\n",__FILE__,__FUNCTION__,msg.chatText.c_str(),teamIndex);
|
||||
|
||||
if(teamIndex==-1 || teamIndex==thisTeamIndex){
|
||||
console->addLine(gameNetworkInterface->getChatText(), true);
|
||||
console->addLine(msg.chatText, true);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Added text to console\n",__FILE__,__FUNCTION__);
|
||||
}
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
gameNetworkInterface->clearChatInfo();
|
||||
|
||||
}
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
gameNetworkInterface->clearChatInfo();
|
||||
}
|
||||
}
|
||||
catch(const std::exception &ex) {
|
||||
|
@@ -606,7 +606,7 @@ bool MenuStateConnectedGame::loadFactions(const GameSettings *gameSettings, bool
|
||||
|
||||
char szMsg[1024]="";
|
||||
sprintf(szMsg,"Player: %s is missing the techtree: %s",Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()).c_str(),gameSettings->getTech().c_str());
|
||||
clientInterface->sendTextMessage(szMsg,-1);
|
||||
clientInterface->sendTextMessage(szMsg,-1, true);
|
||||
|
||||
foundFactions = false;
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
@@ -127,13 +127,14 @@ void ClientInterface::update()
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING / ERROR, requestedCommands.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,requestedCommands.size());
|
||||
|
||||
string sMsg = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + " may go out of synch: client requestedCommands.size() = " + intToStr(requestedCommands.size());
|
||||
sendTextMessage(sMsg,-1);
|
||||
sendTextMessage(sMsg,-1, true);
|
||||
}
|
||||
|
||||
//clear chat variables
|
||||
chatText.clear();
|
||||
chatSender.clear();
|
||||
chatTeamIndex= -1;
|
||||
//chatText.clear();
|
||||
//chatSender.clear();
|
||||
//chatTeamIndex= -1;
|
||||
clearChatInfo();
|
||||
}
|
||||
|
||||
std::string ClientInterface::getServerIpAddress() {
|
||||
@@ -143,9 +144,10 @@ std::string ClientInterface::getServerIpAddress() {
|
||||
void ClientInterface::updateLobby()
|
||||
{
|
||||
//clear chat variables
|
||||
chatText.clear();
|
||||
chatSender.clear();
|
||||
chatTeamIndex= -1;
|
||||
//chatText.clear();
|
||||
//chatSender.clear();
|
||||
//chatTeamIndex= -1;
|
||||
clearChatInfo();
|
||||
|
||||
NetworkMessageType networkMessageType = getNextMessageType(true);
|
||||
|
||||
@@ -175,9 +177,9 @@ void ClientInterface::updateLobby()
|
||||
"\nClient: " + getNetworkVersionString();
|
||||
printf("%s\n",sErr.c_str());
|
||||
|
||||
sendTextMessage("Server and client binary mismatch!!",-1);
|
||||
sendTextMessage(" Server:" + networkMessageIntro.getVersionString(),-1);
|
||||
sendTextMessage(" Client: "+ getNetworkVersionString(),-1);
|
||||
sendTextMessage("Server and client binary mismatch!!",-1, true);
|
||||
sendTextMessage(" Server:" + networkMessageIntro.getVersionString(),-1, true);
|
||||
sendTextMessage(" Client: "+ getNetworkVersionString(),-1, true);
|
||||
}
|
||||
else {
|
||||
versionMatched = true;
|
||||
@@ -185,9 +187,9 @@ void ClientInterface::updateLobby()
|
||||
networkMessageIntro.getVersionString() + "\nClient: " + getNetworkVersionString();
|
||||
printf("%s\n",sErr.c_str());
|
||||
|
||||
sendTextMessage("Server and client platform mismatch.",-1);
|
||||
sendTextMessage(" Server:" + networkMessageIntro.getVersionString(),-1);
|
||||
sendTextMessage(" Client: "+ getNetworkVersionString(),-1);
|
||||
sendTextMessage("Server and client platform mismatch.",-1, true);
|
||||
sendTextMessage(" Server:" + networkMessageIntro.getVersionString(),-1, true);
|
||||
sendTextMessage(" Client: "+ getNetworkVersionString(),-1, true);
|
||||
}
|
||||
|
||||
if(Config::getInstance().getBool("PlatformConsistencyChecks","true") &&
|
||||
@@ -356,9 +358,12 @@ void ClientInterface::updateLobby()
|
||||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtText\n",__FILE__,__FUNCTION__);
|
||||
|
||||
chatText = networkMessageText.getText();
|
||||
chatSender = networkMessageText.getSender();
|
||||
chatTeamIndex = networkMessageText.getTeamIndex();
|
||||
//chatText = networkMessageText.getText();
|
||||
//chatSender = networkMessageText.getSender();
|
||||
//chatTeamIndex = networkMessageText.getTeamIndex();
|
||||
|
||||
ChatMsgInfo msg(networkMessageText.getText().c_str(),networkMessageText.getSender().c_str(),networkMessageText.getTeamIndex());
|
||||
this->addChatInfo(msg);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -434,7 +439,7 @@ void ClientInterface::updateLobby()
|
||||
{
|
||||
string sErr = string(__FILE__) + "::" + string(__FUNCTION__) + " Unexpected network message: " + intToStr(networkMessageType);
|
||||
//throw runtime_error(string(__FILE__) + "::" + string(__FUNCTION__) + " Unexpected network message: " + intToStr(networkMessageType));
|
||||
sendTextMessage("Unexpected network message: " + intToStr(networkMessageType),-1);
|
||||
sendTextMessage("Unexpected network message: " + intToStr(networkMessageType),-1, true);
|
||||
DisplayErrorMessage(sErr);
|
||||
quit= true;
|
||||
close();
|
||||
@@ -484,7 +489,7 @@ void ClientInterface::updateKeyframe(int frameCount)
|
||||
if(networkMessageCommandList.getFrameCount() != frameCount) {
|
||||
string sErr = "Network synchronization error, frame counts do not match, server frameCount = " + intToStr(networkMessageCommandList.getFrameCount()) + ", local frameCount = " + intToStr(frameCount);
|
||||
//throw runtime_error("Network synchronization error, frame counts do not match");
|
||||
sendTextMessage(sErr,-1);
|
||||
sendTextMessage(sErr,-1, true);
|
||||
DisplayErrorMessage(sErr);
|
||||
quit= true;
|
||||
close();
|
||||
@@ -523,9 +528,11 @@ void ClientInterface::updateKeyframe(int frameCount)
|
||||
sleep(0);
|
||||
}
|
||||
|
||||
chatText = networkMessageText.getText();
|
||||
chatSender = networkMessageText.getSender();
|
||||
chatTeamIndex = networkMessageText.getTeamIndex();
|
||||
//chatText = networkMessageText.getText();
|
||||
//chatSender = networkMessageText.getSender();
|
||||
//chatTeamIndex = networkMessageText.getTeamIndex();
|
||||
ChatMsgInfo msg(networkMessageText.getText().c_str(),networkMessageText.getSender().c_str(),networkMessageText.getTeamIndex());
|
||||
this->addChatInfo(msg);
|
||||
}
|
||||
break;
|
||||
case nmtInvalid:
|
||||
@@ -535,7 +542,7 @@ void ClientInterface::updateKeyframe(int frameCount)
|
||||
{
|
||||
//throw runtime_error(string(__FILE__) + "::" + string(__FUNCTION__) + " Unexpected message in client interface: " + intToStr(networkMessageType));
|
||||
|
||||
sendTextMessage("Unexpected message in client interface: " + intToStr(networkMessageType),-1);
|
||||
sendTextMessage("Unexpected message in client interface: " + intToStr(networkMessageType),-1, true);
|
||||
DisplayErrorMessage(string(__FILE__) + "::" + string(__FUNCTION__) + " Unexpected message in client interface: " + intToStr(networkMessageType));
|
||||
quit= true;
|
||||
close();
|
||||
@@ -600,7 +607,7 @@ void ClientInterface::waitUntilReady(Checksum* checksum) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
//throw runtime_error("Timeout waiting for server");
|
||||
string sErr = "Timeout waiting for server";
|
||||
sendTextMessage(sErr,-1);
|
||||
sendTextMessage(sErr,-1, true);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
@@ -627,7 +634,7 @@ void ClientInterface::waitUntilReady(Checksum* checksum) {
|
||||
else {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
//throw runtime_error(string(__FILE__) + "::" + string(__FUNCTION__) + " Unexpected network message: " + intToStr(networkMessageType) );
|
||||
sendTextMessage("Unexpected network message: " + intToStr(networkMessageType),-1);
|
||||
sendTextMessage("Unexpected network message: " + intToStr(networkMessageType),-1, true);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
@@ -653,13 +660,13 @@ void ClientInterface::waitUntilReady(Checksum* checksum) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
string sErr = "Checksum error, you don't have the same data as the server";
|
||||
sendTextMessage(sErr,-1);
|
||||
sendTextMessage(sErr,-1, true);
|
||||
|
||||
string sErr1 = "Client Checksum: " + intToStr(checksum->getSum());
|
||||
sendTextMessage(sErr1,-1);
|
||||
sendTextMessage(sErr1,-1, true);
|
||||
|
||||
string sErr2 = "Server Checksum: " + intToStr(networkMessageReady.getChecksum());
|
||||
sendTextMessage(sErr2,-1);
|
||||
sendTextMessage(sErr2,-1, true);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d %s %s %s\n",__FILE__,__FUNCTION__,__LINE__,sErr.c_str(),sErr1.c_str(),sErr2.c_str());
|
||||
|
||||
@@ -688,9 +695,15 @@ void ClientInterface::waitUntilReady(Checksum* checksum) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
|
||||
}
|
||||
|
||||
void ClientInterface::sendTextMessage(const string &text, int teamIndex){
|
||||
void ClientInterface::sendTextMessage(const string &text, int teamIndex, bool echoLocal){
|
||||
NetworkMessageText networkMessageText(text, getHostName(), teamIndex);
|
||||
sendMessage(&networkMessageText);
|
||||
|
||||
if(echoLocal == true) {
|
||||
ChatMsgInfo msg(networkMessageText.getText().c_str(),networkMessageText.getSender().c_str(),networkMessageText.getTeamIndex());
|
||||
this->addChatInfo(msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
string ClientInterface::getNetworkStatus() {
|
||||
@@ -720,7 +733,7 @@ void ClientInterface::waitForMessage()
|
||||
while(getNextMessageType(true) == nmtInvalid) {
|
||||
if(isConnected() == false) {
|
||||
//throw runtime_error("Disconnected");
|
||||
sendTextMessage("Server has Disconnected.",-1);
|
||||
//sendTextMessage("Server has Disconnected.",-1);
|
||||
DisplayErrorMessage("Server has Disconnected.");
|
||||
quit= true;
|
||||
close();
|
||||
@@ -733,7 +746,7 @@ void ClientInterface::waitForMessage()
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
sendTextMessage("Timeout waiting for message",-1);
|
||||
sendTextMessage("Timeout waiting for message",-1, true);
|
||||
DisplayErrorMessage("Timeout waiting for message");
|
||||
quit= true;
|
||||
close();
|
||||
|
@@ -67,7 +67,7 @@ public:
|
||||
virtual void waitUntilReady(Checksum* checksum);
|
||||
|
||||
// message sending
|
||||
virtual void sendTextMessage(const string &text, int teamIndex);
|
||||
virtual void sendTextMessage(const string &text, int teamIndex, bool echoLocal=false);
|
||||
virtual void quitGame(bool userManuallyQuit);
|
||||
|
||||
//misc
|
||||
|
@@ -172,9 +172,10 @@ ConnectionSlot::ConnectionSlot(ServerInterface* serverInterface, int playerIndex
|
||||
networkGameDataSynchCheckOkTech = false;
|
||||
//networkGameDataSynchCheckOkFogOfWar = false;
|
||||
|
||||
chatText.clear();
|
||||
chatSender.clear();
|
||||
chatTeamIndex= -1;
|
||||
//chatText.clear();
|
||||
//chatSender.clear();
|
||||
//chatTeamIndex= -1;
|
||||
this->clearChatInfo();
|
||||
}
|
||||
|
||||
ConnectionSlot::~ConnectionSlot()
|
||||
@@ -228,9 +229,10 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] accepted new client connection, serverInterface->getOpenSlotCount() = %d\n",__FILE__,__FUNCTION__,serverInterface->getOpenSlotCount());
|
||||
connectedTime = time(NULL);
|
||||
|
||||
chatText.clear();
|
||||
chatSender.clear();
|
||||
chatTeamIndex= -1;
|
||||
//chatText.clear();
|
||||
//chatSender.clear();
|
||||
//chatTeamIndex= -1;
|
||||
this->clearChatInfo();
|
||||
|
||||
if(hasOpenSlots == false) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] no open slots, disconnecting client\n",__FILE__,__FUNCTION__);
|
||||
@@ -253,9 +255,10 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
if(socket->isConnected()) {
|
||||
chatText.clear();
|
||||
chatSender.clear();
|
||||
chatTeamIndex= -1;
|
||||
//chatText.clear();
|
||||
//chatSender.clear();
|
||||
//chatTeamIndex= -1;
|
||||
this->clearChatInfo();
|
||||
|
||||
if(socket->hasDataToRead() == true) {
|
||||
NetworkMessageType networkMessageType= getNextMessageType();
|
||||
@@ -275,11 +278,14 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
||||
|
||||
NetworkMessageText networkMessageText;
|
||||
if(receiveMessage(&networkMessageText)) {
|
||||
chatText = networkMessageText.getText();
|
||||
chatSender = networkMessageText.getSender();
|
||||
chatTeamIndex = networkMessageText.getTeamIndex();
|
||||
//chatText = networkMessageText.getText();
|
||||
//chatSender = networkMessageText.getSender();
|
||||
//chatTeamIndex = networkMessageText.getTeamIndex();
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] chatText [%s] chatSender [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,chatText.c_str(),chatSender.c_str(),chatTeamIndex);
|
||||
ChatMsgInfo msg(networkMessageText.getText().c_str(),networkMessageText.getSender().c_str(),networkMessageText.getTeamIndex());
|
||||
this->addChatInfo(msg);
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] chatText [%s] chatSender [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,chatText.c_str(),chatSender.c_str(),chatTeamIndex);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@@ -113,9 +113,10 @@ void NetworkInterface::DisplayErrorMessage(string sErr, bool closeSocket) {
|
||||
void NetworkInterface::clearChatInfo() {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
chatText.clear();
|
||||
chatSender.clear();
|
||||
chatTeamIndex= -1;
|
||||
//chatText.clear();
|
||||
//chatSender.clear();
|
||||
//chatTeamIndex= -1;
|
||||
chatTextList.clear();
|
||||
}
|
||||
|
||||
std::string NetworkInterface::getIpAddress() {
|
||||
|
@@ -38,6 +38,41 @@ namespace Glest{ namespace Game{
|
||||
// class NetworkInterface
|
||||
// =====================================================
|
||||
|
||||
class ChatMsgInfo {
|
||||
|
||||
protected:
|
||||
|
||||
void copyAll(const ChatMsgInfo &obj) {
|
||||
this->chatText = obj.chatText.c_str();
|
||||
this->chatSender = obj.chatSender.c_str();
|
||||
this->chatTeamIndex = obj.chatTeamIndex;
|
||||
}
|
||||
public:
|
||||
|
||||
ChatMsgInfo() {
|
||||
this->chatText = "";
|
||||
this->chatSender = "";
|
||||
this->chatTeamIndex = -1;
|
||||
}
|
||||
ChatMsgInfo(string chatText, string chatSender,int chatTeamIndex) {
|
||||
this->chatText = chatText;
|
||||
this->chatSender = chatSender;
|
||||
this->chatTeamIndex = chatTeamIndex;
|
||||
}
|
||||
ChatMsgInfo(const ChatMsgInfo& obj) {
|
||||
copyAll(obj);
|
||||
}
|
||||
ChatMsgInfo & operator=(const ChatMsgInfo & obj) {
|
||||
copyAll(obj);
|
||||
return *this;
|
||||
}
|
||||
|
||||
string chatText;
|
||||
string chatSender;
|
||||
int chatTeamIndex;
|
||||
|
||||
};
|
||||
|
||||
typedef int (*DisplayMessageFunction)(const char *msg, bool exit);
|
||||
|
||||
class NetworkInterface {
|
||||
@@ -49,9 +84,11 @@ protected:
|
||||
bool networkGameDataSynchCheckOkTile;
|
||||
bool networkGameDataSynchCheckOkTech;
|
||||
|
||||
string chatText;
|
||||
string chatSender;
|
||||
int chatTeamIndex;
|
||||
//string chatText;
|
||||
//string chatSender;
|
||||
//int chatTeamIndex;
|
||||
std::vector<ChatMsgInfo> chatTextList;
|
||||
|
||||
static DisplayMessageFunction pCB_DisplayMessage;
|
||||
void DisplayErrorMessage(string sErr, bool closeSocket=true);
|
||||
|
||||
@@ -99,11 +136,13 @@ public:
|
||||
//virtual bool getNetworkGameDataSynchCheckOkFogOfWar() { return networkGameDataSynchCheckOkFogOfWar; }
|
||||
//virtual void setNetworkGameDataSynchCheckOkFogOfWar(bool value) { networkGameDataSynchCheckOkFogOfWar = value; }
|
||||
|
||||
const string getChatText() const {return chatText;}
|
||||
const string getChatSender() const {return chatSender;}
|
||||
int getChatTeamIndex() const {return chatTeamIndex;}
|
||||
//const string getChatText() const {return chatText;}
|
||||
//const string getChatSender() const {return chatSender;}
|
||||
//int getChatTeamIndex() const {return chatTeamIndex;}
|
||||
|
||||
const std::vector<ChatMsgInfo> & getChatTextList() const { return chatTextList; }
|
||||
void clearChatInfo();
|
||||
void addChatInfo(const ChatMsgInfo &msg) { chatTextList.push_back(msg); }
|
||||
|
||||
virtual bool getConnectHasHandshaked() const= 0;
|
||||
|
||||
@@ -138,7 +177,7 @@ public:
|
||||
virtual void waitUntilReady(Checksum* checksum)= 0;
|
||||
|
||||
//message sending
|
||||
virtual void sendTextMessage(const string &text, int teamIndex)= 0;
|
||||
virtual void sendTextMessage(const string &text, int teamIndex,bool echoLocal=false)= 0;
|
||||
virtual void quitGame(bool userManuallyQuit)=0;
|
||||
|
||||
//misc
|
||||
|
@@ -39,9 +39,9 @@ namespace Glest{ namespace Game{
|
||||
bool enabledThreadedClientCommandBroadcast = false;
|
||||
|
||||
// The maximum amount of network update iterations a client is allowed to fall behind
|
||||
int maxFrameCountLagAllowed = 30;
|
||||
double maxFrameCountLagAllowed = 30;
|
||||
// The maximum amount of seconds a client is allowed to not communicate with the server
|
||||
int maxClientLagTimeAllowed = 20;
|
||||
double maxClientLagTimeAllowed = 20;
|
||||
|
||||
// 65% of max we warn all users about the lagged client
|
||||
double warnFrameCountLagPercent = 0.65;
|
||||
@@ -62,7 +62,7 @@ ServerInterface::ServerInterface(){
|
||||
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 = %d, maxClientLagTimeAllowed = %d, pauseGameForLaggedClients = %d\n",__FILE__,__FUNCTION__,__LINE__,enabledThreadedClientCommandBroadcast,maxFrameCountLagAllowed,maxClientLagTimeAllowed,pauseGameForLaggedClients);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] enabledThreadedClientCommandBroadcast = %d, maxFrameCountLagAllowed = %f, maxClientLagTimeAllowed = %d, pauseGameForLaggedClients = %d\n",__FILE__,__FUNCTION__,__LINE__,enabledThreadedClientCommandBroadcast,maxFrameCountLagAllowed,maxClientLagTimeAllowed,pauseGameForLaggedClients);
|
||||
|
||||
for(int i= 0; i<GameConstants::maxPlayers; ++i){
|
||||
slots[i]= NULL;
|
||||
@@ -228,8 +228,8 @@ bool ServerInterface::clientLagCheck(ConnectionSlot* connectionSlot) {
|
||||
bool clientLagExceeded = false;
|
||||
if(difftime(time(NULL),gameStartTime) >= LAG_CHECK_GRACE_PERIOD) {
|
||||
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
||||
int clientLag = this->getCurrentFrameCount() - connectionSlot->getCurrentFrameCount();
|
||||
int clientLagCount = (gameSettings.getNetworkFramePeriod() > 0 ? (clientLag / gameSettings.getNetworkFramePeriod()) : 0);
|
||||
double clientLag = this->getCurrentFrameCount() - connectionSlot->getCurrentFrameCount();
|
||||
double clientLagCount = (gameSettings.getNetworkFramePeriod() > 0 ? (clientLag / gameSettings.getNetworkFramePeriod()) : 0);
|
||||
connectionSlot->setCurrentLagCount(clientLagCount);
|
||||
|
||||
double clientLagTime = difftime(time(NULL),connectionSlot->getLastReceiveCommandListTime());
|
||||
@@ -238,15 +238,26 @@ bool ServerInterface::clientLagCheck(ConnectionSlot* connectionSlot) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, clientLag = %d, clientLagCount = %d, this->getCurrentFrameCount() = %d, connectionSlot->getCurrentFrameCount() = %d, clientLagTime = %f\n",__FILE__,__FUNCTION__,__LINE__,connectionSlot->getPlayerIndex(),clientLag,clientLagCount,this->getCurrentFrameCount(),connectionSlot->getCurrentFrameCount(),clientLagTime);
|
||||
}
|
||||
|
||||
// TEST LAG Error and warnings!!!
|
||||
//clientLagCount = maxFrameCountLagAllowed + 1;
|
||||
//clientLagTime = maxClientLagTimeAllowed + 1;
|
||||
//if(difftime(time(NULL),gameStartTime) >= LAG_CHECK_GRACE_PERIOD + 5) {
|
||||
// clientLagTime = maxClientLagTimeAllowed + 1;
|
||||
//}
|
||||
//else if(difftime(time(NULL),gameStartTime) >= LAG_CHECK_GRACE_PERIOD) {
|
||||
// clientLagTime = (maxClientLagTimeAllowed * warnFrameCountLagPercent) + 1;
|
||||
//}
|
||||
// END test
|
||||
|
||||
// New lag check
|
||||
if((maxFrameCountLagAllowed > 0 && clientLagCount > maxFrameCountLagAllowed) ||
|
||||
(maxClientLagTimeAllowed > 0 && clientLagTime > maxClientLagTimeAllowed)) {
|
||||
clientLagExceeded = true;
|
||||
char szBuf[4096]="";
|
||||
|
||||
const char* msgTemplate = "%s exceeded max allowed LAG count of %d [time = %d], clientLag = %d [%f], disconnecting client.";
|
||||
const char* msgTemplate = "%s exceeded max allowed LAG count of %f [time = %f], clientLag = %f [%f], disconnecting client.";
|
||||
if(pauseGameForLaggedClients == true) {
|
||||
msgTemplate = "%s exceeded max allowed LAG count of %d [time = %d], clientLag = %d [%f], pausing game to wait for client to catch up...";
|
||||
msgTemplate = "%s exceeded max allowed LAG count of %f [time = %f], clientLag = %f [%f], pausing game to wait for client to catch up...";
|
||||
}
|
||||
#ifdef WIN32
|
||||
_snprintf(szBuf,4095,msgTemplate,connectionSlot->getName().c_str() ,maxFrameCountLagAllowed,maxClientLagTimeAllowed,clientLagCount,clientLagTime);
|
||||
@@ -256,7 +267,7 @@ bool ServerInterface::clientLagCheck(ConnectionSlot* connectionSlot) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,szBuf);
|
||||
|
||||
string sMsg = szBuf;
|
||||
sendTextMessage(sMsg,-1);
|
||||
sendTextMessage(sMsg,-1, true);
|
||||
|
||||
if(pauseGameForLaggedClients == false) {
|
||||
connectionSlot->close();
|
||||
@@ -272,7 +283,7 @@ bool ServerInterface::clientLagCheck(ConnectionSlot* connectionSlot) {
|
||||
|
||||
char szBuf[4096]="";
|
||||
|
||||
const char* msgTemplate = "WARNING, %s may exceed max allowed LAG count of %d [time = %d], clientLag = %d [%f], WARNING...";
|
||||
const char* msgTemplate = "WARNING, %s may exceed max allowed LAG count of %f [time = %f], clientLag = %f [%f], WARNING...";
|
||||
#ifdef WIN32
|
||||
_snprintf(szBuf,4095,msgTemplate,connectionSlot->getName().c_str(),maxFrameCountLagAllowed,maxClientLagTimeAllowed,clientLagCount,clientLagTime);
|
||||
#else
|
||||
@@ -281,7 +292,7 @@ bool ServerInterface::clientLagCheck(ConnectionSlot* connectionSlot) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,szBuf);
|
||||
|
||||
string sMsg = szBuf;
|
||||
sendTextMessage(sMsg,-1);
|
||||
sendTextMessage(sMsg,-1, true);
|
||||
}
|
||||
}
|
||||
else if(connectionSlot->getLagCountWarning() == true) {
|
||||
@@ -335,6 +346,8 @@ void ServerInterface::updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> &
|
||||
void ServerInterface::update() {
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
std::vector<string> errorMsgList;
|
||||
try {
|
||||
std::map<PLATFORM_SOCKET,bool> socketTriggeredList;
|
||||
//update all slots
|
||||
updateSocketTriggeredList(socketTriggeredList);
|
||||
@@ -379,7 +392,8 @@ void ServerInterface::update() {
|
||||
for(int iErrIdx = 0; iErrIdx < errorList.size(); ++iErrIdx) {
|
||||
string &sErr = errorList[iErrIdx];
|
||||
if(sErr != "") {
|
||||
DisplayErrorMessage(sErr);
|
||||
//DisplayErrorMessage(sErr);
|
||||
errorMsgList.push_back(sErr);
|
||||
}
|
||||
}
|
||||
connectionSlot->clearThreadErrorList();
|
||||
@@ -414,7 +428,7 @@ void ServerInterface::update() {
|
||||
}
|
||||
catch(const exception &ex) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
||||
DisplayErrorMessage(ex.what());
|
||||
errorMsgList.push_back(ex.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -452,11 +466,14 @@ void ServerInterface::update() {
|
||||
for(int i= 0; i< GameConstants::maxPlayers; ++i) {
|
||||
ConnectionSlot* connectionSlot= slots[i];
|
||||
if(connectionSlot != NULL &&
|
||||
connectionSlot->getChatText().empty() == false) {
|
||||
connectionSlot->getChatTextList().empty() == false) {
|
||||
try {
|
||||
string newChatText = connectionSlot->getChatText().c_str();
|
||||
string newChatSender = connectionSlot->getChatSender().c_str();
|
||||
int newChatTeamIndex = connectionSlot->getChatTeamIndex();
|
||||
for(int chatIdx = 0; chatIdx < connectionSlot->getChatTextList().size(); chatIdx++) {
|
||||
const ChatMsgInfo &msg = connectionSlot->getChatTextList()[chatIdx];
|
||||
|
||||
string newChatText = msg.chatText.c_str();
|
||||
string newChatSender = msg.chatSender.c_str();
|
||||
int newChatTeamIndex = msg.chatTeamIndex;
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 about to broadcast nmtText chatText [%s] chatSender [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,newChatText.c_str(),newChatSender.c_str(),newChatTeamIndex);
|
||||
|
||||
@@ -467,15 +484,17 @@ void ServerInterface::update() {
|
||||
|
||||
connectionSlot->clearChatInfo();
|
||||
|
||||
chatText = newChatText.c_str();
|
||||
chatSender = newChatSender.c_str();
|
||||
chatTeamIndex = newChatTeamIndex;
|
||||
//chatText = newChatText.c_str();
|
||||
//chatSender = newChatSender.c_str();
|
||||
//chatTeamIndex = newChatTeamIndex;
|
||||
this->addChatInfo(msg);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after connectionSlot->clearChatInfo chatText [%s] chatSender [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,chatText.c_str(),chatSender.c_str(),chatTeamIndex);
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after connectionSlot->clearChatInfo chatText [%s] chatSender [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,chatText.c_str(),chatSender.c_str(),chatTeamIndex);
|
||||
}
|
||||
}
|
||||
catch(const exception &ex) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
||||
DisplayErrorMessage(ex.what());
|
||||
errorMsgList.push_back(ex.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -483,11 +502,8 @@ void ServerInterface::update() {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
//process text messages
|
||||
if(chatText.empty() == true) {
|
||||
if(this->getChatTextList().empty() == true) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
//chatText.clear();
|
||||
//chatSender.clear();
|
||||
//chatTeamIndex= -1;
|
||||
|
||||
for(int i= 0; i< GameConstants::maxPlayers; ++i) {
|
||||
ConnectionSlot* connectionSlot= slots[i];
|
||||
@@ -505,16 +521,20 @@ void ServerInterface::update() {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #2 about to broadcast nmtText msg for SlotIndex# %d\n",__FILE__,__FUNCTION__,i);
|
||||
|
||||
broadcastMessage(&networkMessageText, i);
|
||||
chatText= networkMessageText.getText();
|
||||
chatSender= networkMessageText.getSender();
|
||||
chatTeamIndex= networkMessageText.getTeamIndex();
|
||||
break;
|
||||
|
||||
//chatText= networkMessageText.getText();
|
||||
//chatSender= networkMessageText.getSender();
|
||||
//chatTeamIndex= networkMessageText.getTeamIndex();
|
||||
//break;
|
||||
|
||||
ChatMsgInfo msg(networkMessageText.getText().c_str(),networkMessageText.getSender().c_str(),networkMessageText.getTeamIndex());
|
||||
this->addChatInfo(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(const exception &ex) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
||||
DisplayErrorMessage(ex.what());
|
||||
errorMsgList.push_back(ex.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -524,6 +544,20 @@ void ServerInterface::update() {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(const exception &ex) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
||||
errorMsgList.push_back(ex.what());
|
||||
}
|
||||
|
||||
if(errorMsgList.size() > 0) {
|
||||
for(int iErrIdx = 0; iErrIdx < errorMsgList.size(); ++iErrIdx) {
|
||||
string &sErr = errorMsgList[iErrIdx];
|
||||
if(sErr != "") {
|
||||
DisplayErrorMessage(sErr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
@@ -556,7 +590,7 @@ void ServerInterface::updateKeyframe(int frameCount){
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING / ERROR, requestedCommands.size() = %d\n",__FILE__,__FUNCTION__,requestedCommands.size());
|
||||
|
||||
string sMsg = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + " may go out of synch: server requestedCommands.size() = " + intToStr(requestedCommands.size());
|
||||
sendTextMessage(sMsg,-1);
|
||||
sendTextMessage(sMsg,-1, true);
|
||||
}
|
||||
|
||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] build command list took %d msecs, networkMessageCommandList.getCommandCount() = %d, frameCount = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),networkMessageCommandList.getCommandCount(),frameCount);
|
||||
@@ -680,7 +714,7 @@ void ServerInterface::waitUntilReady(Checksum* checksum){
|
||||
else if(networkMessageType != nmtInvalid) {
|
||||
//throw runtime_error("Unexpected network message: " + intToStr(networkMessageType));
|
||||
string sErr = "Unexpected network message: " + intToStr(networkMessageType);
|
||||
sendTextMessage(sErr,-1);
|
||||
sendTextMessage(sErr,-1, true);
|
||||
DisplayErrorMessage(sErr);
|
||||
return;
|
||||
}
|
||||
@@ -698,7 +732,7 @@ void ServerInterface::waitUntilReady(Checksum* checksum){
|
||||
if(chrono.getMillis() > readyWaitTimeout) {
|
||||
//throw runtime_error("Timeout waiting for clients");
|
||||
string sErr = "Timeout waiting for clients.";
|
||||
sendTextMessage(sErr,-1);
|
||||
sendTextMessage(sErr,-1, true);
|
||||
DisplayErrorMessage(sErr);
|
||||
return;
|
||||
}
|
||||
@@ -745,12 +779,20 @@ void ServerInterface::waitUntilReady(Checksum* checksum){
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s] END\n",__FUNCTION__);
|
||||
}
|
||||
|
||||
void ServerInterface::sendTextMessage(const string &text, int teamIndex){
|
||||
void ServerInterface::sendTextMessage(const string &text, int teamIndex, bool echoLocal) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
NetworkMessageText networkMessageText(text, Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()), teamIndex);
|
||||
broadcastMessage(&networkMessageText);
|
||||
|
||||
if(echoLocal == true) {
|
||||
ChatMsgInfo msg(networkMessageText.getText().c_str(),networkMessageText.getSender().c_str(),networkMessageText.getTeamIndex());
|
||||
this->addChatInfo(msg);
|
||||
//chatText = newChatText.c_str();
|
||||
//chatSender = newChatSender.c_str();
|
||||
//chatTeamIndex = newChatTeamIndex;
|
||||
}
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
|
||||
@@ -947,7 +989,8 @@ void ServerInterface::broadcastMessage(const NetworkMessage* networkMessage, int
|
||||
}
|
||||
catch(const exception &ex) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
||||
throw runtime_error(ex.what());
|
||||
//throw runtime_error(ex.what());
|
||||
DisplayErrorMessage(ex.what());
|
||||
}
|
||||
//serverSynchAccessor.v();
|
||||
|
||||
@@ -957,6 +1000,7 @@ void ServerInterface::broadcastMessage(const NetworkMessage* networkMessage, int
|
||||
void ServerInterface::broadcastMessageToConnectedClients(const NetworkMessage* networkMessage, int excludeSlot){
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
try {
|
||||
for(int i= 0; i<GameConstants::maxPlayers; ++i) {
|
||||
ConnectionSlot* connectionSlot= slots[i];
|
||||
|
||||
@@ -968,6 +1012,12 @@ void ServerInterface::broadcastMessageToConnectedClients(const NetworkMessage* n
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(const exception &ex) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
||||
//throw runtime_error(ex.what());
|
||||
DisplayErrorMessage(ex.what());
|
||||
}
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
|
@@ -56,7 +56,7 @@ public:
|
||||
virtual void waitUntilReady(Checksum* checksum);
|
||||
|
||||
// message sending
|
||||
virtual void sendTextMessage(const string &text, int teamIndex);
|
||||
virtual void sendTextMessage(const string &text, int teamIndex, bool echoLocal=false);
|
||||
virtual void quitGame(bool userManuallyQuit);
|
||||
|
||||
//misc
|
||||
|
Reference in New Issue
Block a user