- more attempts at stability for network games
This commit is contained in:
parent
07cbcc0bec
commit
d08c8300f0
|
@ -608,7 +608,8 @@ bool ConnectionSlot::updateCompleted() {
|
||||||
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex);
|
//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->getQuitStatus() == false &&
|
||||||
slotThreadWorker->getRunningStatus() == true);
|
slotThreadWorker->getRunningStatus() == true);
|
||||||
|
|
||||||
|
|
|
@ -101,6 +101,7 @@ void ServerInterface::addSlot(int playerIndex){
|
||||||
|
|
||||||
assert(playerIndex>=0 && playerIndex<GameConstants::maxPlayers);
|
assert(playerIndex>=0 && playerIndex<GameConstants::maxPlayers);
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutex(&serverSynchAccessor);
|
||||||
if(serverSocket.isPortBound() == false) {
|
if(serverSocket.isPortBound() == false) {
|
||||||
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__);
|
||||||
serverSocket.bind(serverSocket.getBindPort());
|
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__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
slots[playerIndex]= new ConnectionSlot(this, playerIndex);
|
slots[playerIndex]= new ConnectionSlot(this, playerIndex);
|
||||||
|
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
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__);
|
||||||
updateListen();
|
updateListen();
|
||||||
|
|
||||||
|
@ -127,18 +130,24 @@ bool ServerInterface::switchSlot(int fromPlayerIndex,int toPlayerIndex){
|
||||||
if(fromPlayerIndex==toPlayerIndex) return false;// doubleclicked or whatever
|
if(fromPlayerIndex==toPlayerIndex) return false;// doubleclicked or whatever
|
||||||
|
|
||||||
//printf(" checking if slot %d is free?\n",toPlayerIndex);
|
//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");
|
//printf(" yes, its free :)\n");
|
||||||
slots[fromPlayerIndex]->setPlayerIndex(toPlayerIndex);
|
slots[fromPlayerIndex]->setPlayerIndex(toPlayerIndex);
|
||||||
slots[toPlayerIndex]->setPlayerIndex(fromPlayerIndex);
|
slots[toPlayerIndex]->setPlayerIndex(fromPlayerIndex);
|
||||||
ConnectionSlot *tmp=slots[toPlayerIndex];
|
ConnectionSlot *tmp=slots[toPlayerIndex];
|
||||||
slots[toPlayerIndex]= slots[fromPlayerIndex];
|
slots[toPlayerIndex]= slots[fromPlayerIndex];
|
||||||
slots[fromPlayerIndex]=tmp;
|
slots[fromPlayerIndex]=tmp;
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
PlayerIndexMessage playerIndexMessage(toPlayerIndex);
|
PlayerIndexMessage playerIndexMessage(toPlayerIndex);
|
||||||
slots[toPlayerIndex]->sendMessage(&playerIndexMessage);
|
slots[toPlayerIndex]->sendMessage(&playerIndexMessage);
|
||||||
result=true;
|
result=true;
|
||||||
updateListen();
|
updateListen();
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
|
}
|
||||||
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__);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -146,6 +155,7 @@ bool ServerInterface::switchSlot(int fromPlayerIndex,int toPlayerIndex){
|
||||||
void ServerInterface::removeSlot(int playerIndex) {
|
void ServerInterface::removeSlot(int playerIndex) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,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
|
// Mention to everyone that this player is disconnected
|
||||||
ConnectionSlot *slot = slots[playerIndex];
|
ConnectionSlot *slot = slots[playerIndex];
|
||||||
|
|
||||||
|
@ -171,6 +181,8 @@ void ServerInterface::removeSlot(int playerIndex) {
|
||||||
delete slots[playerIndex];
|
delete slots[playerIndex];
|
||||||
slots[playerIndex]= NULL;
|
slots[playerIndex]= NULL;
|
||||||
|
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex);
|
||||||
|
|
||||||
updateListen();
|
updateListen();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user