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() {
|
void ChatManager::updateNetwork() {
|
||||||
try {
|
try {
|
||||||
GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface();
|
GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface();
|
||||||
string text;
|
//string text;
|
||||||
string sender;
|
//string sender;
|
||||||
Config &config= Config::getInstance();
|
Config &config= Config::getInstance();
|
||||||
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] gameNetworkInterface->getChatText() [%s]\n",__FILE__,__FUNCTION__,__LINE__,gameNetworkInterface->getChatText().c_str());
|
//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) {
|
if(gameNetworkInterface->getChatTextList().empty() == false) {
|
||||||
int teamIndex= gameNetworkInterface->getChatTeamIndex();
|
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){
|
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] Added text to console\n",__FILE__,__FUNCTION__);
|
||||||
}
|
}
|
||||||
|
|
||||||
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__);
|
||||||
|
}
|
||||||
gameNetworkInterface->clearChatInfo();
|
|
||||||
|
|
||||||
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__);
|
||||||
|
gameNetworkInterface->clearChatInfo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(const std::exception &ex) {
|
catch(const std::exception &ex) {
|
||||||
|
@@ -606,7 +606,7 @@ bool MenuStateConnectedGame::loadFactions(const GameSettings *gameSettings, bool
|
|||||||
|
|
||||||
char szMsg[1024]="";
|
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());
|
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;
|
foundFactions = 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__);
|
||||||
|
@@ -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());
|
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());
|
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
|
//clear chat variables
|
||||||
chatText.clear();
|
//chatText.clear();
|
||||||
chatSender.clear();
|
//chatSender.clear();
|
||||||
chatTeamIndex= -1;
|
//chatTeamIndex= -1;
|
||||||
|
clearChatInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ClientInterface::getServerIpAddress() {
|
std::string ClientInterface::getServerIpAddress() {
|
||||||
@@ -143,9 +144,10 @@ std::string ClientInterface::getServerIpAddress() {
|
|||||||
void ClientInterface::updateLobby()
|
void ClientInterface::updateLobby()
|
||||||
{
|
{
|
||||||
//clear chat variables
|
//clear chat variables
|
||||||
chatText.clear();
|
//chatText.clear();
|
||||||
chatSender.clear();
|
//chatSender.clear();
|
||||||
chatTeamIndex= -1;
|
//chatTeamIndex= -1;
|
||||||
|
clearChatInfo();
|
||||||
|
|
||||||
NetworkMessageType networkMessageType = getNextMessageType(true);
|
NetworkMessageType networkMessageType = getNextMessageType(true);
|
||||||
|
|
||||||
@@ -175,9 +177,9 @@ void ClientInterface::updateLobby()
|
|||||||
"\nClient: " + getNetworkVersionString();
|
"\nClient: " + getNetworkVersionString();
|
||||||
printf("%s\n",sErr.c_str());
|
printf("%s\n",sErr.c_str());
|
||||||
|
|
||||||
sendTextMessage("Server and client binary mismatch!!",-1);
|
sendTextMessage("Server and client binary mismatch!!",-1, true);
|
||||||
sendTextMessage(" Server:" + networkMessageIntro.getVersionString(),-1);
|
sendTextMessage(" Server:" + networkMessageIntro.getVersionString(),-1, true);
|
||||||
sendTextMessage(" Client: "+ getNetworkVersionString(),-1);
|
sendTextMessage(" Client: "+ getNetworkVersionString(),-1, true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
versionMatched = true;
|
versionMatched = true;
|
||||||
@@ -185,9 +187,9 @@ void ClientInterface::updateLobby()
|
|||||||
networkMessageIntro.getVersionString() + "\nClient: " + getNetworkVersionString();
|
networkMessageIntro.getVersionString() + "\nClient: " + getNetworkVersionString();
|
||||||
printf("%s\n",sErr.c_str());
|
printf("%s\n",sErr.c_str());
|
||||||
|
|
||||||
sendTextMessage("Server and client platform mismatch.",-1);
|
sendTextMessage("Server and client platform mismatch.",-1, true);
|
||||||
sendTextMessage(" Server:" + networkMessageIntro.getVersionString(),-1);
|
sendTextMessage(" Server:" + networkMessageIntro.getVersionString(),-1, true);
|
||||||
sendTextMessage(" Client: "+ getNetworkVersionString(),-1);
|
sendTextMessage(" Client: "+ getNetworkVersionString(),-1, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Config::getInstance().getBool("PlatformConsistencyChecks","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__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtText\n",__FILE__,__FUNCTION__);
|
||||||
|
|
||||||
chatText = networkMessageText.getText();
|
//chatText = networkMessageText.getText();
|
||||||
chatSender = networkMessageText.getSender();
|
//chatSender = networkMessageText.getSender();
|
||||||
chatTeamIndex = networkMessageText.getTeamIndex();
|
//chatTeamIndex = networkMessageText.getTeamIndex();
|
||||||
|
|
||||||
|
ChatMsgInfo msg(networkMessageText.getText().c_str(),networkMessageText.getSender().c_str(),networkMessageText.getTeamIndex());
|
||||||
|
this->addChatInfo(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -434,7 +439,7 @@ void ClientInterface::updateLobby()
|
|||||||
{
|
{
|
||||||
string sErr = string(__FILE__) + "::" + string(__FUNCTION__) + " Unexpected network message: " + intToStr(networkMessageType);
|
string sErr = string(__FILE__) + "::" + string(__FUNCTION__) + " Unexpected network message: " + intToStr(networkMessageType);
|
||||||
//throw runtime_error(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);
|
DisplayErrorMessage(sErr);
|
||||||
quit= true;
|
quit= true;
|
||||||
close();
|
close();
|
||||||
@@ -484,7 +489,7 @@ void ClientInterface::updateKeyframe(int frameCount)
|
|||||||
if(networkMessageCommandList.getFrameCount() != frameCount) {
|
if(networkMessageCommandList.getFrameCount() != frameCount) {
|
||||||
string sErr = "Network synchronization error, frame counts do not match, server frameCount = " + intToStr(networkMessageCommandList.getFrameCount()) + ", local frameCount = " + intToStr(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");
|
//throw runtime_error("Network synchronization error, frame counts do not match");
|
||||||
sendTextMessage(sErr,-1);
|
sendTextMessage(sErr,-1, true);
|
||||||
DisplayErrorMessage(sErr);
|
DisplayErrorMessage(sErr);
|
||||||
quit= true;
|
quit= true;
|
||||||
close();
|
close();
|
||||||
@@ -523,9 +528,11 @@ void ClientInterface::updateKeyframe(int frameCount)
|
|||||||
sleep(0);
|
sleep(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
chatText = networkMessageText.getText();
|
//chatText = networkMessageText.getText();
|
||||||
chatSender = networkMessageText.getSender();
|
//chatSender = networkMessageText.getSender();
|
||||||
chatTeamIndex = networkMessageText.getTeamIndex();
|
//chatTeamIndex = networkMessageText.getTeamIndex();
|
||||||
|
ChatMsgInfo msg(networkMessageText.getText().c_str(),networkMessageText.getSender().c_str(),networkMessageText.getTeamIndex());
|
||||||
|
this->addChatInfo(msg);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case nmtInvalid:
|
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));
|
//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));
|
DisplayErrorMessage(string(__FILE__) + "::" + string(__FUNCTION__) + " Unexpected message in client interface: " + intToStr(networkMessageType));
|
||||||
quit= true;
|
quit= true;
|
||||||
close();
|
close();
|
||||||
@@ -600,7 +607,7 @@ void ClientInterface::waitUntilReady(Checksum* checksum) {
|
|||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
//throw runtime_error("Timeout waiting for server");
|
//throw runtime_error("Timeout waiting for server");
|
||||||
string sErr = "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__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
@@ -627,7 +634,7 @@ void ClientInterface::waitUntilReady(Checksum* checksum) {
|
|||||||
else {
|
else {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
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) );
|
//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__);
|
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__);
|
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";
|
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());
|
string sErr1 = "Client Checksum: " + intToStr(checksum->getSum());
|
||||||
sendTextMessage(sErr1,-1);
|
sendTextMessage(sErr1,-1, true);
|
||||||
|
|
||||||
string sErr2 = "Server Checksum: " + intToStr(networkMessageReady.getChecksum());
|
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());
|
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__);
|
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);
|
NetworkMessageText networkMessageText(text, getHostName(), teamIndex);
|
||||||
sendMessage(&networkMessageText);
|
sendMessage(&networkMessageText);
|
||||||
|
|
||||||
|
if(echoLocal == true) {
|
||||||
|
ChatMsgInfo msg(networkMessageText.getText().c_str(),networkMessageText.getSender().c_str(),networkMessageText.getTeamIndex());
|
||||||
|
this->addChatInfo(msg);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string ClientInterface::getNetworkStatus() {
|
string ClientInterface::getNetworkStatus() {
|
||||||
@@ -720,7 +733,7 @@ void ClientInterface::waitForMessage()
|
|||||||
while(getNextMessageType(true) == nmtInvalid) {
|
while(getNextMessageType(true) == nmtInvalid) {
|
||||||
if(isConnected() == false) {
|
if(isConnected() == false) {
|
||||||
//throw runtime_error("Disconnected");
|
//throw runtime_error("Disconnected");
|
||||||
sendTextMessage("Server has Disconnected.",-1);
|
//sendTextMessage("Server has Disconnected.",-1);
|
||||||
DisplayErrorMessage("Server has Disconnected.");
|
DisplayErrorMessage("Server has Disconnected.");
|
||||||
quit= true;
|
quit= true;
|
||||||
close();
|
close();
|
||||||
@@ -733,7 +746,7 @@ void ClientInterface::waitForMessage()
|
|||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
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");
|
DisplayErrorMessage("Timeout waiting for message");
|
||||||
quit= true;
|
quit= true;
|
||||||
close();
|
close();
|
||||||
|
@@ -67,7 +67,7 @@ public:
|
|||||||
virtual void waitUntilReady(Checksum* checksum);
|
virtual void waitUntilReady(Checksum* checksum);
|
||||||
|
|
||||||
// message sending
|
// 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);
|
virtual void quitGame(bool userManuallyQuit);
|
||||||
|
|
||||||
//misc
|
//misc
|
||||||
|
@@ -172,9 +172,10 @@ ConnectionSlot::ConnectionSlot(ServerInterface* serverInterface, int playerIndex
|
|||||||
networkGameDataSynchCheckOkTech = false;
|
networkGameDataSynchCheckOkTech = false;
|
||||||
//networkGameDataSynchCheckOkFogOfWar = false;
|
//networkGameDataSynchCheckOkFogOfWar = false;
|
||||||
|
|
||||||
chatText.clear();
|
//chatText.clear();
|
||||||
chatSender.clear();
|
//chatSender.clear();
|
||||||
chatTeamIndex= -1;
|
//chatTeamIndex= -1;
|
||||||
|
this->clearChatInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionSlot::~ConnectionSlot()
|
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());
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] accepted new client connection, serverInterface->getOpenSlotCount() = %d\n",__FILE__,__FUNCTION__,serverInterface->getOpenSlotCount());
|
||||||
connectedTime = time(NULL);
|
connectedTime = time(NULL);
|
||||||
|
|
||||||
chatText.clear();
|
//chatText.clear();
|
||||||
chatSender.clear();
|
//chatSender.clear();
|
||||||
chatTeamIndex= -1;
|
//chatTeamIndex= -1;
|
||||||
|
this->clearChatInfo();
|
||||||
|
|
||||||
if(hasOpenSlots == false) {
|
if(hasOpenSlots == false) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] no open slots, disconnecting client\n",__FILE__,__FUNCTION__);
|
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__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
if(socket->isConnected()) {
|
if(socket->isConnected()) {
|
||||||
chatText.clear();
|
//chatText.clear();
|
||||||
chatSender.clear();
|
//chatSender.clear();
|
||||||
chatTeamIndex= -1;
|
//chatTeamIndex= -1;
|
||||||
|
this->clearChatInfo();
|
||||||
|
|
||||||
if(socket->hasDataToRead() == true) {
|
if(socket->hasDataToRead() == true) {
|
||||||
NetworkMessageType networkMessageType= getNextMessageType();
|
NetworkMessageType networkMessageType= getNextMessageType();
|
||||||
@@ -275,11 +278,14 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||||||
|
|
||||||
NetworkMessageText networkMessageText;
|
NetworkMessageText networkMessageText;
|
||||||
if(receiveMessage(&networkMessageText)) {
|
if(receiveMessage(&networkMessageText)) {
|
||||||
chatText = networkMessageText.getText();
|
//chatText = networkMessageText.getText();
|
||||||
chatSender = networkMessageText.getSender();
|
//chatSender = networkMessageText.getSender();
|
||||||
chatTeamIndex = networkMessageText.getTeamIndex();
|
//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;
|
break;
|
||||||
|
@@ -113,9 +113,10 @@ void NetworkInterface::DisplayErrorMessage(string sErr, bool closeSocket) {
|
|||||||
void NetworkInterface::clearChatInfo() {
|
void NetworkInterface::clearChatInfo() {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
chatText.clear();
|
//chatText.clear();
|
||||||
chatSender.clear();
|
//chatSender.clear();
|
||||||
chatTeamIndex= -1;
|
//chatTeamIndex= -1;
|
||||||
|
chatTextList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string NetworkInterface::getIpAddress() {
|
std::string NetworkInterface::getIpAddress() {
|
||||||
|
@@ -38,6 +38,41 @@ namespace Glest{ namespace Game{
|
|||||||
// class NetworkInterface
|
// 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);
|
typedef int (*DisplayMessageFunction)(const char *msg, bool exit);
|
||||||
|
|
||||||
class NetworkInterface {
|
class NetworkInterface {
|
||||||
@@ -49,9 +84,11 @@ protected:
|
|||||||
bool networkGameDataSynchCheckOkTile;
|
bool networkGameDataSynchCheckOkTile;
|
||||||
bool networkGameDataSynchCheckOkTech;
|
bool networkGameDataSynchCheckOkTech;
|
||||||
|
|
||||||
string chatText;
|
//string chatText;
|
||||||
string chatSender;
|
//string chatSender;
|
||||||
int chatTeamIndex;
|
//int chatTeamIndex;
|
||||||
|
std::vector<ChatMsgInfo> chatTextList;
|
||||||
|
|
||||||
static DisplayMessageFunction pCB_DisplayMessage;
|
static DisplayMessageFunction pCB_DisplayMessage;
|
||||||
void DisplayErrorMessage(string sErr, bool closeSocket=true);
|
void DisplayErrorMessage(string sErr, bool closeSocket=true);
|
||||||
|
|
||||||
@@ -99,11 +136,13 @@ public:
|
|||||||
//virtual bool getNetworkGameDataSynchCheckOkFogOfWar() { return networkGameDataSynchCheckOkFogOfWar; }
|
//virtual bool getNetworkGameDataSynchCheckOkFogOfWar() { return networkGameDataSynchCheckOkFogOfWar; }
|
||||||
//virtual void setNetworkGameDataSynchCheckOkFogOfWar(bool value) { networkGameDataSynchCheckOkFogOfWar = value; }
|
//virtual void setNetworkGameDataSynchCheckOkFogOfWar(bool value) { networkGameDataSynchCheckOkFogOfWar = value; }
|
||||||
|
|
||||||
const string getChatText() const {return chatText;}
|
//const string getChatText() const {return chatText;}
|
||||||
const string getChatSender() const {return chatSender;}
|
//const string getChatSender() const {return chatSender;}
|
||||||
int getChatTeamIndex() const {return chatTeamIndex;}
|
//int getChatTeamIndex() const {return chatTeamIndex;}
|
||||||
|
|
||||||
|
const std::vector<ChatMsgInfo> & getChatTextList() const { return chatTextList; }
|
||||||
void clearChatInfo();
|
void clearChatInfo();
|
||||||
|
void addChatInfo(const ChatMsgInfo &msg) { chatTextList.push_back(msg); }
|
||||||
|
|
||||||
virtual bool getConnectHasHandshaked() const= 0;
|
virtual bool getConnectHasHandshaked() const= 0;
|
||||||
|
|
||||||
@@ -138,7 +177,7 @@ public:
|
|||||||
virtual void waitUntilReady(Checksum* checksum)= 0;
|
virtual void waitUntilReady(Checksum* checksum)= 0;
|
||||||
|
|
||||||
//message sending
|
//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;
|
virtual void quitGame(bool userManuallyQuit)=0;
|
||||||
|
|
||||||
//misc
|
//misc
|
||||||
|
@@ -39,9 +39,9 @@ namespace Glest{ namespace Game{
|
|||||||
bool enabledThreadedClientCommandBroadcast = false;
|
bool enabledThreadedClientCommandBroadcast = false;
|
||||||
|
|
||||||
// The maximum amount of network update iterations a client is allowed to fall behind
|
// 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
|
// 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
|
// 65% of max we warn all users about the lagged client
|
||||||
double warnFrameCountLagPercent = 0.65;
|
double warnFrameCountLagPercent = 0.65;
|
||||||
@@ -62,7 +62,7 @@ ServerInterface::ServerInterface(){
|
|||||||
maxClientLagTimeAllowed = Config::getInstance().getInt("MaxClientLagTimeAllowed",intToStr(maxClientLagTimeAllowed).c_str());
|
maxClientLagTimeAllowed = Config::getInstance().getInt("MaxClientLagTimeAllowed",intToStr(maxClientLagTimeAllowed).c_str());
|
||||||
warnFrameCountLagPercent = Config::getInstance().getFloat("WarnFrameCountLagPercent",doubleToStr(warnFrameCountLagPercent).c_str());
|
warnFrameCountLagPercent = Config::getInstance().getFloat("WarnFrameCountLagPercent",doubleToStr(warnFrameCountLagPercent).c_str());
|
||||||
pauseGameForLaggedClients = Config::getInstance().getFloat("PauseGameForLaggedClients",boolToStr(pauseGameForLaggedClients).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){
|
for(int i= 0; i<GameConstants::maxPlayers; ++i){
|
||||||
slots[i]= NULL;
|
slots[i]= NULL;
|
||||||
@@ -228,8 +228,8 @@ bool ServerInterface::clientLagCheck(ConnectionSlot* connectionSlot) {
|
|||||||
bool clientLagExceeded = false;
|
bool clientLagExceeded = false;
|
||||||
if(difftime(time(NULL),gameStartTime) >= LAG_CHECK_GRACE_PERIOD) {
|
if(difftime(time(NULL),gameStartTime) >= LAG_CHECK_GRACE_PERIOD) {
|
||||||
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
||||||
int clientLag = this->getCurrentFrameCount() - connectionSlot->getCurrentFrameCount();
|
double clientLag = this->getCurrentFrameCount() - connectionSlot->getCurrentFrameCount();
|
||||||
int clientLagCount = (gameSettings.getNetworkFramePeriod() > 0 ? (clientLag / gameSettings.getNetworkFramePeriod()) : 0);
|
double clientLagCount = (gameSettings.getNetworkFramePeriod() > 0 ? (clientLag / gameSettings.getNetworkFramePeriod()) : 0);
|
||||||
connectionSlot->setCurrentLagCount(clientLagCount);
|
connectionSlot->setCurrentLagCount(clientLagCount);
|
||||||
|
|
||||||
double clientLagTime = difftime(time(NULL),connectionSlot->getLastReceiveCommandListTime());
|
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);
|
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
|
// New lag check
|
||||||
if((maxFrameCountLagAllowed > 0 && clientLagCount > maxFrameCountLagAllowed) ||
|
if((maxFrameCountLagAllowed > 0 && clientLagCount > maxFrameCountLagAllowed) ||
|
||||||
(maxClientLagTimeAllowed > 0 && clientLagTime > maxClientLagTimeAllowed)) {
|
(maxClientLagTimeAllowed > 0 && clientLagTime > maxClientLagTimeAllowed)) {
|
||||||
clientLagExceeded = true;
|
clientLagExceeded = true;
|
||||||
char szBuf[4096]="";
|
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) {
|
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
|
#ifdef WIN32
|
||||||
_snprintf(szBuf,4095,msgTemplate,connectionSlot->getName().c_str() ,maxFrameCountLagAllowed,maxClientLagTimeAllowed,clientLagCount,clientLagTime);
|
_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);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,szBuf);
|
||||||
|
|
||||||
string sMsg = szBuf;
|
string sMsg = szBuf;
|
||||||
sendTextMessage(sMsg,-1);
|
sendTextMessage(sMsg,-1, true);
|
||||||
|
|
||||||
if(pauseGameForLaggedClients == false) {
|
if(pauseGameForLaggedClients == false) {
|
||||||
connectionSlot->close();
|
connectionSlot->close();
|
||||||
@@ -272,7 +283,7 @@ bool ServerInterface::clientLagCheck(ConnectionSlot* connectionSlot) {
|
|||||||
|
|
||||||
char szBuf[4096]="";
|
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
|
#ifdef WIN32
|
||||||
_snprintf(szBuf,4095,msgTemplate,connectionSlot->getName().c_str(),maxFrameCountLagAllowed,maxClientLagTimeAllowed,clientLagCount,clientLagTime);
|
_snprintf(szBuf,4095,msgTemplate,connectionSlot->getName().c_str(),maxFrameCountLagAllowed,maxClientLagTimeAllowed,clientLagCount,clientLagTime);
|
||||||
#else
|
#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);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,szBuf);
|
||||||
|
|
||||||
string sMsg = szBuf;
|
string sMsg = szBuf;
|
||||||
sendTextMessage(sMsg,-1);
|
sendTextMessage(sMsg,-1, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(connectionSlot->getLagCountWarning() == true) {
|
else if(connectionSlot->getLagCountWarning() == true) {
|
||||||
@@ -335,6 +346,8 @@ void ServerInterface::updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> &
|
|||||||
void ServerInterface::update() {
|
void ServerInterface::update() {
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
std::vector<string> errorMsgList;
|
||||||
|
try {
|
||||||
std::map<PLATFORM_SOCKET,bool> socketTriggeredList;
|
std::map<PLATFORM_SOCKET,bool> socketTriggeredList;
|
||||||
//update all slots
|
//update all slots
|
||||||
updateSocketTriggeredList(socketTriggeredList);
|
updateSocketTriggeredList(socketTriggeredList);
|
||||||
@@ -379,7 +392,8 @@ void ServerInterface::update() {
|
|||||||
for(int iErrIdx = 0; iErrIdx < errorList.size(); ++iErrIdx) {
|
for(int iErrIdx = 0; iErrIdx < errorList.size(); ++iErrIdx) {
|
||||||
string &sErr = errorList[iErrIdx];
|
string &sErr = errorList[iErrIdx];
|
||||||
if(sErr != "") {
|
if(sErr != "") {
|
||||||
DisplayErrorMessage(sErr);
|
//DisplayErrorMessage(sErr);
|
||||||
|
errorMsgList.push_back(sErr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
connectionSlot->clearThreadErrorList();
|
connectionSlot->clearThreadErrorList();
|
||||||
@@ -414,7 +428,7 @@ void ServerInterface::update() {
|
|||||||
}
|
}
|
||||||
catch(const exception &ex) {
|
catch(const exception &ex) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
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) {
|
for(int i= 0; i< GameConstants::maxPlayers; ++i) {
|
||||||
ConnectionSlot* connectionSlot= slots[i];
|
ConnectionSlot* connectionSlot= slots[i];
|
||||||
if(connectionSlot != NULL &&
|
if(connectionSlot != NULL &&
|
||||||
connectionSlot->getChatText().empty() == false) {
|
connectionSlot->getChatTextList().empty() == false) {
|
||||||
try {
|
try {
|
||||||
string newChatText = connectionSlot->getChatText().c_str();
|
for(int chatIdx = 0; chatIdx < connectionSlot->getChatTextList().size(); chatIdx++) {
|
||||||
string newChatSender = connectionSlot->getChatSender().c_str();
|
const ChatMsgInfo &msg = connectionSlot->getChatTextList()[chatIdx];
|
||||||
int newChatTeamIndex = connectionSlot->getChatTeamIndex();
|
|
||||||
|
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);
|
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();
|
connectionSlot->clearChatInfo();
|
||||||
|
|
||||||
chatText = newChatText.c_str();
|
//chatText = newChatText.c_str();
|
||||||
chatSender = newChatSender.c_str();
|
//chatSender = newChatSender.c_str();
|
||||||
chatTeamIndex = newChatTeamIndex;
|
//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) {
|
catch(const exception &ex) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
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__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
//process text messages
|
//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__);
|
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) {
|
for(int i= 0; i< GameConstants::maxPlayers; ++i) {
|
||||||
ConnectionSlot* connectionSlot= slots[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);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #2 about to broadcast nmtText msg for SlotIndex# %d\n",__FILE__,__FUNCTION__,i);
|
||||||
|
|
||||||
broadcastMessage(&networkMessageText, i);
|
broadcastMessage(&networkMessageText, i);
|
||||||
chatText= networkMessageText.getText();
|
|
||||||
chatSender= networkMessageText.getSender();
|
//chatText= networkMessageText.getText();
|
||||||
chatTeamIndex= networkMessageText.getTeamIndex();
|
//chatSender= networkMessageText.getSender();
|
||||||
break;
|
//chatTeamIndex= networkMessageText.getTeamIndex();
|
||||||
|
//break;
|
||||||
|
|
||||||
|
ChatMsgInfo msg(networkMessageText.getText().c_str(),networkMessageText.getSender().c_str(),networkMessageText.getTeamIndex());
|
||||||
|
this->addChatInfo(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(const exception &ex) {
|
catch(const exception &ex) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
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__);
|
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__);
|
//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());
|
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());
|
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);
|
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) {
|
else if(networkMessageType != nmtInvalid) {
|
||||||
//throw runtime_error("Unexpected network message: " + intToStr(networkMessageType));
|
//throw runtime_error("Unexpected network message: " + intToStr(networkMessageType));
|
||||||
string sErr = "Unexpected network message: " + intToStr(networkMessageType);
|
string sErr = "Unexpected network message: " + intToStr(networkMessageType);
|
||||||
sendTextMessage(sErr,-1);
|
sendTextMessage(sErr,-1, true);
|
||||||
DisplayErrorMessage(sErr);
|
DisplayErrorMessage(sErr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -698,7 +732,7 @@ void ServerInterface::waitUntilReady(Checksum* checksum){
|
|||||||
if(chrono.getMillis() > readyWaitTimeout) {
|
if(chrono.getMillis() > readyWaitTimeout) {
|
||||||
//throw runtime_error("Timeout waiting for clients");
|
//throw runtime_error("Timeout waiting for clients");
|
||||||
string sErr = "Timeout waiting for clients.";
|
string sErr = "Timeout waiting for clients.";
|
||||||
sendTextMessage(sErr,-1);
|
sendTextMessage(sErr,-1, true);
|
||||||
DisplayErrorMessage(sErr);
|
DisplayErrorMessage(sErr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -745,12 +779,20 @@ void ServerInterface::waitUntilReady(Checksum* checksum){
|
|||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s] END\n",__FUNCTION__);
|
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__);
|
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);
|
NetworkMessageText networkMessageText(text, Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()), teamIndex);
|
||||||
broadcastMessage(&networkMessageText);
|
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__);
|
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) {
|
catch(const exception &ex) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
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();
|
//serverSynchAccessor.v();
|
||||||
|
|
||||||
@@ -957,6 +1000,7 @@ void ServerInterface::broadcastMessage(const NetworkMessage* networkMessage, int
|
|||||||
void ServerInterface::broadcastMessageToConnectedClients(const NetworkMessage* networkMessage, int excludeSlot){
|
void ServerInterface::broadcastMessageToConnectedClients(const NetworkMessage* networkMessage, int excludeSlot){
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
try {
|
||||||
for(int i= 0; i<GameConstants::maxPlayers; ++i) {
|
for(int i= 0; i<GameConstants::maxPlayers; ++i) {
|
||||||
ConnectionSlot* connectionSlot= slots[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__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
@@ -56,7 +56,7 @@ public:
|
|||||||
virtual void waitUntilReady(Checksum* checksum);
|
virtual void waitUntilReady(Checksum* checksum);
|
||||||
|
|
||||||
// message sending
|
// 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);
|
virtual void quitGame(bool userManuallyQuit);
|
||||||
|
|
||||||
//misc
|
//misc
|
||||||
|
Reference in New Issue
Block a user