- 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 {
|
||||
GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface();
|
||||
string text;
|
||||
string sender;
|
||||
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();
|
||||
|
||||
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__);
|
||||
|
||||
gameNetworkInterface->clearChatInfo();
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
}
|
||||
catch(const std::exception &ex) {
|
||||
|
|
|
@ -401,7 +401,7 @@ Command* Commander::buildCommand(const NetworkCommand* networkCommand) const{
|
|||
//validate command type
|
||||
if(ct == NULL) {
|
||||
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());
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n",szBuf);
|
||||
|
|
|
@ -687,6 +687,9 @@ void ClientInterface::waitForMessage()
|
|||
|
||||
if(chrono.getMillis() > messageWaitTimeout) {
|
||||
//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);
|
||||
DisplayErrorMessage("Timeout waiting for message");
|
||||
quit= true;
|
||||
|
@ -703,16 +706,17 @@ void ClientInterface::waitForMessage()
|
|||
|
||||
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)
|
||||
{
|
||||
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!";
|
||||
sendTextMessage(sQuitText,-1);
|
||||
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()
|
||||
|
|
|
@ -144,8 +144,10 @@ void ConnectionSlotThread::execute() {
|
|||
// 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->playerIndex = playerIndex;
|
||||
this->socket = NULL;
|
||||
|
@ -153,8 +155,8 @@ ConnectionSlot::ConnectionSlot(ServerInterface* serverInterface, int playerIndex
|
|||
this->slotThreadWorker = new ConnectionSlotThread(this->serverInterface);
|
||||
this->slotThreadWorker->start();
|
||||
|
||||
this->ready= false;
|
||||
this->gotIntro = false;
|
||||
this->ready = false;
|
||||
this->gotIntro = false;
|
||||
|
||||
networkGameDataSynchCheckOkMap = false;
|
||||
networkGameDataSynchCheckOkTile = false;
|
||||
|
@ -256,7 +258,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||
chatSender = networkMessageText.getSender();
|
||||
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;
|
||||
|
@ -480,7 +482,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
@ -496,9 +498,14 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||
void ConnectionSlot::close() {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s LINE: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
BaseThread::shutdownAndWait(slotThreadWorker);
|
||||
delete slotThreadWorker;
|
||||
slotThreadWorker = NULL;
|
||||
// In case we are closing from within the context of the thread
|
||||
// only signal it to quit here
|
||||
//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__);
|
||||
|
||||
|
@ -507,14 +514,18 @@ void ConnectionSlot::close() {
|
|||
|
||||
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;
|
||||
|
||||
if(ready == false) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s LINE: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
serverInterface->updateListen();
|
||||
}
|
||||
|
||||
ready = false;
|
||||
gotIntro = false;
|
||||
|
||||
serverInterface->updateListen();
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
|
||||
}
|
||||
|
||||
|
|
|
@ -108,8 +108,14 @@ void NetworkInterface::DisplayErrorMessage(string sErr, bool closeSocket) {
|
|||
else {
|
||||
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;}
|
||||
int getChatTeamIndex() const {return chatTeamIndex;}
|
||||
|
||||
void clearChatInfo();
|
||||
|
||||
virtual bool getConnectHasHandshaked() const= 0;
|
||||
};
|
||||
|
||||
|
|
|
@ -44,6 +44,9 @@ NetworkCommand::NetworkCommand(World *world, int networkCommandType, int unitId,
|
|||
|
||||
//validate unit
|
||||
if(unit != NULL) {
|
||||
this->unitFactionIndex = unit->getFaction()->getIndex();
|
||||
this->unitFactionUnitCount = unit->getFaction()->getUnitCount();
|
||||
|
||||
const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), this->unitTypeId);
|
||||
const CommandType *ct = unit->getType()->findCommandTypeById(this->commandTypeId);
|
||||
if(ct != NULL && ct->getClass() == ccBuild) {
|
||||
|
@ -75,8 +78,8 @@ void NetworkCommand::preprocessNetworkCommand(World *world) {
|
|||
|
||||
string NetworkCommand::toString() const {
|
||||
char szBuf[1024]="";
|
||||
sprintf(szBuf,"networkCommandType = %d\nunitId = %d\ncommandTypeId = %d\npositionX = %d\npositionY = %d\nunitTypeId = %d\ntargetId = %d\nwantQueue= %d\nfromFactionIndex = %d",
|
||||
networkCommandType,unitId,commandTypeId,positionX,this->positionY,unitTypeId,targetId,wantQueue,fromFactionIndex);
|
||||
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,unitFactionUnitCount,unitFactionIndex);
|
||||
|
||||
string result = szBuf;
|
||||
return result;
|
||||
|
|
|
@ -69,6 +69,8 @@ private:
|
|||
int16 targetId;
|
||||
int16 wantQueue;
|
||||
int16 fromFactionIndex;
|
||||
int16 unitFactionUnitCount;
|
||||
int16 unitFactionIndex;
|
||||
|
||||
public:
|
||||
NetworkCommand(){};
|
||||
|
|
|
@ -199,9 +199,9 @@ void ServerInterface::update() {
|
|||
|
||||
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;
|
||||
|
||||
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
|
||||
for(int i= 0; i< GameConstants::maxPlayers; ++i) {
|
||||
ConnectionSlot* connectionSlot= slots[i];
|
||||
if(connectionSlot != NULL && connectionSlot->isConnected() == true &&
|
||||
if(connectionSlot != NULL &&
|
||||
connectionSlot->getChatText().empty() == false) {
|
||||
chatText = connectionSlot->getChatText();
|
||||
chatSender = connectionSlot->getChatSender();
|
||||
chatTeamIndex = connectionSlot->getChatTeamIndex();
|
||||
string newChatText = connectionSlot->getChatText().c_str();
|
||||
string newChatSender = connectionSlot->getChatSender().c_str();
|
||||
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());
|
||||
|
||||
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
|
||||
if(chatText.empty() == true) {
|
||||
chatText.clear();
|
||||
chatSender.clear();
|
||||
chatTeamIndex= -1;
|
||||
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];
|
||||
|
|
Loading…
Reference in New Issue