- more attempts at stability for network games

This commit is contained in:
Mark Vejvoda 2010-08-21 01:52:41 +00:00
parent 07cbcc0bec
commit d08c8300f0
2 changed files with 15 additions and 2 deletions

View File

@ -608,7 +608,8 @@ bool ConnectionSlot::updateCompleted() {
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex);
bool waitingForThread = (slotThreadWorker->isSignalCompleted() == false &&
bool waitingForThread = (slotThreadWorker != NULL &&
slotThreadWorker->isSignalCompleted() == false &&
slotThreadWorker->getQuitStatus() == false &&
slotThreadWorker->getRunningStatus() == true);

View File

@ -101,6 +101,7 @@ void ServerInterface::addSlot(int playerIndex){
assert(playerIndex>=0 && playerIndex<GameConstants::maxPlayers);
MutexSafeWrapper safeMutex(&serverSynchAccessor);
if(serverSocket.isPortBound() == false) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
serverSocket.bind(serverSocket.getBindPort());
@ -112,6 +113,8 @@ void ServerInterface::addSlot(int playerIndex){
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
slots[playerIndex]= new ConnectionSlot(this, playerIndex);
safeMutex.ReleaseLock();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
updateListen();
@ -127,18 +130,24 @@ bool ServerInterface::switchSlot(int fromPlayerIndex,int toPlayerIndex){
if(fromPlayerIndex==toPlayerIndex) return false;// doubleclicked or whatever
//printf(" checking if slot %d is free?\n",toPlayerIndex);
if( !slots[toPlayerIndex]->isConnected()) {
MutexSafeWrapper safeMutex(&serverSynchAccessor);
if( slots[toPlayerIndex]->isConnected() == false) {
//printf(" yes, its free :)\n");
slots[fromPlayerIndex]->setPlayerIndex(toPlayerIndex);
slots[toPlayerIndex]->setPlayerIndex(fromPlayerIndex);
ConnectionSlot *tmp=slots[toPlayerIndex];
slots[toPlayerIndex]= slots[fromPlayerIndex];
slots[fromPlayerIndex]=tmp;
safeMutex.ReleaseLock();
PlayerIndexMessage playerIndexMessage(toPlayerIndex);
slots[toPlayerIndex]->sendMessage(&playerIndexMessage);
result=true;
updateListen();
}
else {
safeMutex.ReleaseLock();
}
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
return result;
}
@ -146,6 +155,7 @@ bool ServerInterface::switchSlot(int fromPlayerIndex,int toPlayerIndex){
void ServerInterface::removeSlot(int playerIndex) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex);
MutexSafeWrapper safeMutex(&serverSynchAccessor);
// Mention to everyone that this player is disconnected
ConnectionSlot *slot = slots[playerIndex];
@ -171,6 +181,8 @@ void ServerInterface::removeSlot(int playerIndex) {
delete slots[playerIndex];
slots[playerIndex]= NULL;
safeMutex.ReleaseLock();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex);
updateListen();