- made some stability improvements
- Fixed chat message processing
This commit is contained in:
parent
908b155d62
commit
a03853ad13
|
@ -133,16 +133,16 @@ 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();
|
||||||
|
|
||||||
if(!gameNetworkInterface->getChatText().empty())
|
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();
|
int teamIndex= gameNetworkInterface->getChatTeamIndex();
|
||||||
|
|
||||||
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__,gameNetworkInterface->getChatText().c_str(),teamIndex);
|
||||||
|
@ -154,6 +154,10 @@ void ChatManager::updateNetwork()
|
||||||
}
|
}
|
||||||
|
|
||||||
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__);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(const std::exception &ex) {
|
catch(const std::exception &ex) {
|
||||||
|
|
|
@ -401,7 +401,7 @@ Command* Commander::buildCommand(const NetworkCommand* networkCommand) const{
|
||||||
//validate command type
|
//validate command type
|
||||||
if(ct == NULL) {
|
if(ct == NULL) {
|
||||||
char szBuf[1024]="";
|
char szBuf[1024]="";
|
||||||
sprintf(szBuf,"In [%s::%s Line: %d] Can not find command type for network command = [%s]\n%s\n in unit = %d [%s][%s].\nGame out of synch.",
|
sprintf(szBuf,"In [%s::%s Line: %d] Can not find command type for\nnetwork command = [%s]\n%s\n in unit = %d [%s][%s].\nGame out of synch.",
|
||||||
__FILE__,__FUNCTION__,__LINE__,networkCommand->toString().c_str(),unit->getType()->getCommandTypeListDesc().c_str(),unit->getId(), unit->getFullName().c_str(),unit->getDesc().c_str());
|
__FILE__,__FUNCTION__,__LINE__,networkCommand->toString().c_str(),unit->getType()->getCommandTypeListDesc().c_str(),unit->getId(), unit->getFullName().c_str(),unit->getDesc().c_str());
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n",szBuf);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n",szBuf);
|
||||||
|
|
|
@ -687,6 +687,9 @@ void ClientInterface::waitForMessage()
|
||||||
|
|
||||||
if(chrono.getMillis() > messageWaitTimeout) {
|
if(chrono.getMillis() > messageWaitTimeout) {
|
||||||
//throw runtime_error("Timeout waiting for message");
|
//throw runtime_error("Timeout waiting for message");
|
||||||
|
|
||||||
|
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);
|
||||||
DisplayErrorMessage("Timeout waiting for message");
|
DisplayErrorMessage("Timeout waiting for message");
|
||||||
quit= true;
|
quit= true;
|
||||||
|
@ -703,16 +706,17 @@ void ClientInterface::waitForMessage()
|
||||||
|
|
||||||
void ClientInterface::quitGame(bool userManuallyQuit)
|
void ClientInterface::quitGame(bool userManuallyQuit)
|
||||||
{
|
{
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] userManuallyQuit = %d\n",__FILE__,__FUNCTION__,__LINE__,userManuallyQuit);
|
||||||
|
|
||||||
if(clientSocket != NULL && userManuallyQuit == true)
|
if(clientSocket != NULL && userManuallyQuit == true)
|
||||||
{
|
{
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
string sQuitText = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + " has chosen to leave the game!";
|
string sQuitText = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + " has chosen to leave the game!";
|
||||||
sendTextMessage(sQuitText,-1);
|
sendTextMessage(sQuitText,-1);
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientInterface::close()
|
void ClientInterface::close()
|
||||||
|
|
|
@ -144,8 +144,10 @@ void ConnectionSlotThread::execute() {
|
||||||
// class ConnectionSlot
|
// class ConnectionSlot
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
ConnectionSlot::ConnectionSlot(ServerInterface* serverInterface, int playerIndex)
|
ConnectionSlot::ConnectionSlot(ServerInterface* serverInterface, int playerIndex) {
|
||||||
{
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
this->serverInterface = serverInterface;
|
this->serverInterface = serverInterface;
|
||||||
this->playerIndex = playerIndex;
|
this->playerIndex = playerIndex;
|
||||||
this->socket = NULL;
|
this->socket = NULL;
|
||||||
|
@ -153,8 +155,8 @@ ConnectionSlot::ConnectionSlot(ServerInterface* serverInterface, int playerIndex
|
||||||
this->slotThreadWorker = new ConnectionSlotThread(this->serverInterface);
|
this->slotThreadWorker = new ConnectionSlotThread(this->serverInterface);
|
||||||
this->slotThreadWorker->start();
|
this->slotThreadWorker->start();
|
||||||
|
|
||||||
this->ready= false;
|
this->ready = false;
|
||||||
this->gotIntro = false;
|
this->gotIntro = false;
|
||||||
|
|
||||||
networkGameDataSynchCheckOkMap = false;
|
networkGameDataSynchCheckOkMap = false;
|
||||||
networkGameDataSynchCheckOkTile = false;
|
networkGameDataSynchCheckOkTile = false;
|
||||||
|
@ -256,7 +258,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
||||||
chatSender = networkMessageText.getSender();
|
chatSender = networkMessageText.getSender();
|
||||||
chatTeamIndex = networkMessageText.getTeamIndex();
|
chatTeamIndex = networkMessageText.getTeamIndex();
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] chatText [%s] chatSender [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,chatText.c_str(),chatSender.c_str(),chatTeamIndex);
|
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;
|
||||||
|
@ -480,7 +482,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] calling close...\n",__FILE__,__FUNCTION__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] calling close...\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
@ -496,9 +498,14 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
||||||
void ConnectionSlot::close() {
|
void ConnectionSlot::close() {
|
||||||
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__);
|
||||||
|
|
||||||
BaseThread::shutdownAndWait(slotThreadWorker);
|
// In case we are closing from within the context of the thread
|
||||||
delete slotThreadWorker;
|
// only signal it to quit here
|
||||||
slotThreadWorker = NULL;
|
//if(slotThreadWorker != NULL) {
|
||||||
|
// slotThreadWorker->signalQuit();
|
||||||
|
//}
|
||||||
|
//BaseThread::shutdownAndWait(slotThreadWorker);
|
||||||
|
//delete slotThreadWorker;
|
||||||
|
//slotThreadWorker = NULL;
|
||||||
|
|
||||||
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__);
|
||||||
|
|
||||||
|
@ -507,14 +514,18 @@ void ConnectionSlot::close() {
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
if(ready == false) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s LINE: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
serverInterface->updateListen();
|
||||||
|
}
|
||||||
|
|
||||||
ready = false;
|
ready = false;
|
||||||
gotIntro = false;
|
gotIntro = false;
|
||||||
|
|
||||||
serverInterface->updateListen();
|
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,8 +108,14 @@ void NetworkInterface::DisplayErrorMessage(string sErr, bool closeSocket) {
|
||||||
else {
|
else {
|
||||||
throw runtime_error(sErr);
|
throw runtime_error(sErr);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetworkInterface::clearChatInfo() {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
chatText.clear();
|
||||||
|
chatSender.clear();
|
||||||
|
chatTeamIndex= -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
|
@ -101,6 +101,8 @@ public:
|
||||||
const string getChatSender() const {return chatSender;}
|
const string getChatSender() const {return chatSender;}
|
||||||
int getChatTeamIndex() const {return chatTeamIndex;}
|
int getChatTeamIndex() const {return chatTeamIndex;}
|
||||||
|
|
||||||
|
void clearChatInfo();
|
||||||
|
|
||||||
virtual bool getConnectHasHandshaked() const= 0;
|
virtual bool getConnectHasHandshaked() const= 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,9 @@ NetworkCommand::NetworkCommand(World *world, int networkCommandType, int unitId,
|
||||||
|
|
||||||
//validate unit
|
//validate unit
|
||||||
if(unit != NULL) {
|
if(unit != NULL) {
|
||||||
|
this->unitFactionIndex = unit->getFaction()->getIndex();
|
||||||
|
this->unitFactionUnitCount = unit->getFaction()->getUnitCount();
|
||||||
|
|
||||||
const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), this->unitTypeId);
|
const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), this->unitTypeId);
|
||||||
const CommandType *ct = unit->getType()->findCommandTypeById(this->commandTypeId);
|
const CommandType *ct = unit->getType()->findCommandTypeById(this->commandTypeId);
|
||||||
if(ct != NULL && ct->getClass() == ccBuild) {
|
if(ct != NULL && ct->getClass() == ccBuild) {
|
||||||
|
@ -75,8 +78,8 @@ void NetworkCommand::preprocessNetworkCommand(World *world) {
|
||||||
|
|
||||||
string NetworkCommand::toString() const {
|
string NetworkCommand::toString() const {
|
||||||
char szBuf[1024]="";
|
char szBuf[1024]="";
|
||||||
sprintf(szBuf,"networkCommandType = %d\nunitId = %d\ncommandTypeId = %d\npositionX = %d\npositionY = %d\nunitTypeId = %d\ntargetId = %d\nwantQueue= %d\nfromFactionIndex = %d",
|
sprintf(szBuf,"networkCommandType = %d\nunitId = %d\ncommandTypeId = %d\npositionX = %d\npositionY = %d\nunitTypeId = %d\ntargetId = %d\nwantQueue= %d\nfromFactionIndex = %d\nunitFactionUnitCount = %d\nunitFactionIndex = %d",
|
||||||
networkCommandType,unitId,commandTypeId,positionX,this->positionY,unitTypeId,targetId,wantQueue,fromFactionIndex);
|
networkCommandType,unitId,commandTypeId,positionX,this->positionY,unitTypeId,targetId,wantQueue,fromFactionIndex,unitFactionUnitCount,unitFactionIndex);
|
||||||
|
|
||||||
string result = szBuf;
|
string result = szBuf;
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -69,6 +69,8 @@ private:
|
||||||
int16 targetId;
|
int16 targetId;
|
||||||
int16 wantQueue;
|
int16 wantQueue;
|
||||||
int16 fromFactionIndex;
|
int16 fromFactionIndex;
|
||||||
|
int16 unitFactionUnitCount;
|
||||||
|
int16 unitFactionIndex;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NetworkCommand(){};
|
NetworkCommand(){};
|
||||||
|
|
|
@ -199,9 +199,9 @@ 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__);
|
||||||
|
|
||||||
chatText.clear();
|
//chatText.clear();
|
||||||
chatSender.clear();
|
//chatSender.clear();
|
||||||
chatTeamIndex= -1;
|
//chatTeamIndex= -1;
|
||||||
|
|
||||||
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__);
|
||||||
|
|
||||||
|
@ -328,18 +328,26 @@ void ServerInterface::update() {
|
||||||
// Step #4 dispatch pending chat messages
|
// Step #4 dispatch pending chat messages
|
||||||
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 && connectionSlot->isConnected() == true &&
|
if(connectionSlot != NULL &&
|
||||||
connectionSlot->getChatText().empty() == false) {
|
connectionSlot->getChatText().empty() == false) {
|
||||||
chatText = connectionSlot->getChatText();
|
string newChatText = connectionSlot->getChatText().c_str();
|
||||||
chatSender = connectionSlot->getChatSender();
|
string newChatSender = connectionSlot->getChatSender().c_str();
|
||||||
chatTeamIndex = connectionSlot->getChatTeamIndex();
|
int newChatTeamIndex = connectionSlot->getChatTeamIndex();
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 about to broadcast nmtText 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] #1 about to broadcast nmtText chatText [%s] chatSender [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,newChatText.c_str(),newChatSender.c_str(),newChatTeamIndex);
|
||||||
|
|
||||||
NetworkMessageText networkMessageText(chatText,chatSender,chatTeamIndex);
|
NetworkMessageText networkMessageText(newChatText,newChatSender,newChatTeamIndex);
|
||||||
broadcastMessage(&networkMessageText, connectionSlot->getPlayerIndex());
|
broadcastMessage(&networkMessageText, connectionSlot->getPlayerIndex());
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after broadcast nmtText chatText [%s] chatSender [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,newChatText.c_str(),newChatSender.c_str(),newChatTeamIndex);
|
||||||
|
|
||||||
|
connectionSlot->clearChatInfo();
|
||||||
|
|
||||||
|
chatText = newChatText.c_str();
|
||||||
|
chatSender = newChatSender.c_str();
|
||||||
|
chatTeamIndex = newChatTeamIndex;
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,9 +355,10 @@ void ServerInterface::update() {
|
||||||
|
|
||||||
//process text messages
|
//process text messages
|
||||||
if(chatText.empty() == true) {
|
if(chatText.empty() == true) {
|
||||||
chatText.clear();
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
chatSender.clear();
|
//chatText.clear();
|
||||||
chatTeamIndex= -1;
|
//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];
|
||||||
|
|
Loading…
Reference in New Issue