- mutex cleanup in network classes to try to avoid game freeze( hangs)
This commit is contained in:
parent
bf8be83ccc
commit
b006e72b53
|
@ -117,15 +117,15 @@ void ConnectionSlotThread::execute() {
|
||||||
|
|
||||||
MutexSafeWrapper safeMutex(&triggerIdMutex);
|
MutexSafeWrapper safeMutex(&triggerIdMutex);
|
||||||
int eventCount = eventList.size();
|
int eventCount = eventList.size();
|
||||||
safeMutex.ReleaseLock(true);
|
|
||||||
|
|
||||||
if(eventCount > 0) {
|
if(eventCount > 0) {
|
||||||
safeMutex.Lock();
|
|
||||||
ConnectionSlotEvent *event = eventList[0];
|
ConnectionSlotEvent *event = eventList[0];
|
||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
this->slotInterface->slotUpdateTask(event);
|
this->slotInterface->slotUpdateTask(event);
|
||||||
setTaskCompleted(event);
|
setTaskCompleted(event);
|
||||||
|
}
|
||||||
|
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__);
|
||||||
|
|
||||||
|
@ -723,7 +723,6 @@ bool ConnectionSlot::updateCompleted(ConnectionSlotEvent *event) {
|
||||||
void ConnectionSlot::sendMessage(const NetworkMessage* networkMessage) {
|
void ConnectionSlot::sendMessage(const NetworkMessage* networkMessage) {
|
||||||
MutexSafeWrapper safeMutex(&socketSynchAccessor);
|
MutexSafeWrapper safeMutex(&socketSynchAccessor);
|
||||||
NetworkInterface::sendMessage(networkMessage);
|
NetworkInterface::sendMessage(networkMessage);
|
||||||
safeMutex.ReleaseLock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string ConnectionSlot::getHumanPlayerName(int index) {
|
string ConnectionSlot::getHumanPlayerName(int index) {
|
||||||
|
|
|
@ -95,9 +95,11 @@ ServerInterface::~ServerInterface() {
|
||||||
slots[i]=NULL;
|
slots[i]=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(switchSetupRequests[i] != NULL) {
|
||||||
delete switchSetupRequests[i];
|
delete switchSetupRequests[i];
|
||||||
switchSetupRequests[i]=NULL;
|
switchSetupRequests[i]=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__);
|
||||||
|
|
||||||
|
@ -117,10 +119,10 @@ ServerInterface::~ServerInterface() {
|
||||||
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__);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerInterface::addSlot(int playerIndex){
|
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__);
|
||||||
|
|
||||||
assert(playerIndex>=0 && playerIndex<GameConstants::maxPlayers);
|
assert(playerIndex >= 0 && playerIndex < GameConstants::maxPlayers);
|
||||||
|
|
||||||
MutexSafeWrapper safeMutex(&serverSynchAccessor,intToStr(__LINE__));
|
MutexSafeWrapper safeMutex(&serverSynchAccessor,intToStr(__LINE__));
|
||||||
if(serverSocket.isPortBound() == false) {
|
if(serverSocket.isPortBound() == false) {
|
||||||
|
@ -131,20 +133,25 @@ 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__);
|
||||||
|
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[playerIndex],intToStr(__LINE__) + "_" + intToStr(playerIndex));
|
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[playerIndex],intToStr(__LINE__) + "_" + intToStr(playerIndex));
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
delete slots[playerIndex];
|
delete slots[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);
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
safeMutexSlot.ReleaseLock();
|
safeMutexSlot.ReleaseLock();
|
||||||
|
|
||||||
safeMutex.ReleaseLock();
|
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();
|
||||||
|
|
||||||
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__);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerInterface::switchSlot(int fromPlayerIndex,int toPlayerIndex){
|
bool ServerInterface::switchSlot(int fromPlayerIndex,int toPlayerIndex) {
|
||||||
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__);
|
||||||
|
|
||||||
bool result=false;
|
bool result=false;
|
||||||
|
@ -186,12 +193,17 @@ bool ServerInterface::switchSlot(int fromPlayerIndex,int toPlayerIndex){
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerInterface::removeSlot(int playerIndex) {
|
void ServerInterface::removeSlot(int playerIndex,int lockedSlotIndex) {
|
||||||
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,intToStr(__LINE__));
|
MutexSafeWrapper safeMutex(&serverSynchAccessor,intToStr(__LINE__));
|
||||||
// Mention to everyone that this player is disconnected
|
// Mention to everyone that this player is disconnected
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[playerIndex],intToStr(__LINE__) + "_" + intToStr(playerIndex));
|
|
||||||
|
MutexSafeWrapper safeMutexSlot(NULL,intToStr(__LINE__) + "_" + intToStr(playerIndex));
|
||||||
|
if(playerIndex != lockedSlotIndex) {
|
||||||
|
safeMutexSlot.setMutex(&slotAccessorMutexes[playerIndex],intToStr(__LINE__) + "_" + intToStr(playerIndex));
|
||||||
|
}
|
||||||
|
|
||||||
ConnectionSlot *slot = slots[playerIndex];
|
ConnectionSlot *slot = slots[playerIndex];
|
||||||
|
|
||||||
bool notifyDisconnect = false;
|
bool notifyDisconnect = false;
|
||||||
|
@ -228,14 +240,15 @@ void ServerInterface::removeSlot(int playerIndex) {
|
||||||
if(notifyDisconnect == true) {
|
if(notifyDisconnect == true) {
|
||||||
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);
|
||||||
string sMsg = szBuf;
|
string sMsg = szBuf;
|
||||||
sendTextMessage(sMsg,-1, true);
|
sendTextMessage(sMsg,-1, true, lockedSlotIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionSlot* ServerInterface::getSlot(int playerIndex) {
|
ConnectionSlot* ServerInterface::getSlot(int playerIndex) {
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[playerIndex],intToStr(__LINE__) + "_" + intToStr(playerIndex));
|
//!!! Don't think this is useful
|
||||||
|
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[playerIndex],intToStr(__LINE__) + "_" + intToStr(playerIndex));
|
||||||
return slots[playerIndex];
|
return slots[playerIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,7 +304,6 @@ void ServerInterface::updateSlot(ConnectionSlotEvent *event) {
|
||||||
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(event != NULL) {
|
if(event != NULL) {
|
||||||
//ConnectionSlot *connectionSlot = event->connectionSlot;
|
|
||||||
bool &socketTriggered = event->socketTriggered;
|
bool &socketTriggered = event->socketTriggered;
|
||||||
bool checkForNewClients = true;
|
bool checkForNewClients = true;
|
||||||
|
|
||||||
|
@ -306,19 +318,6 @@ void ServerInterface::updateSlot(ConnectionSlotEvent *event) {
|
||||||
(gameHasBeenInitiated == false ||
|
(gameHasBeenInitiated == false ||
|
||||||
(connectionSlot->getSocket() != NULL && socketTriggered == true))) {
|
(connectionSlot->getSocket() != NULL && socketTriggered == true))) {
|
||||||
if(connectionSlot->isConnected() == false || socketTriggered == true) {
|
if(connectionSlot->isConnected() == false || socketTriggered == true) {
|
||||||
/*
|
|
||||||
if(gameHasBeenInitiated) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socketTriggeredList[i] = %i\n",__FILE__,__FUNCTION__,(socketTriggered ? 1 : 0));
|
|
||||||
|
|
||||||
if(connectionSlot->isConnected()) {
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] about to call connectionSlot->update() for socketId = %d\n",__FILE__,__FUNCTION__,__LINE__,connectionSlot->getSocket()->getSocketId());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(gameHasBeenInitiated) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] getSocket() == NULL\n",__FILE__,__FUNCTION__);
|
|
||||||
}
|
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
*/
|
|
||||||
|
|
||||||
connectionSlot->update(checkForNewClients);
|
connectionSlot->update(checkForNewClients);
|
||||||
|
|
||||||
// This means no clients are trying to connect at the moment
|
// This means no clients are trying to connect at the moment
|
||||||
|
@ -355,8 +354,11 @@ std::pair<bool,bool> ServerInterface::clientLagCheck(ConnectionSlot* connectionS
|
||||||
if(this->getCurrentFrameCount() > 0) {
|
if(this->getCurrentFrameCount() > 0) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, clientLag = %f, clientLagCount = %f, this->getCurrentFrameCount() = %d, connectionSlot->getCurrentFrameCount() = %d, clientLagTime = %f\n",
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, clientLag = %f, clientLagCount = %f, this->getCurrentFrameCount() = %d, connectionSlot->getCurrentFrameCount() = %d, clientLagTime = %f\n",
|
||||||
__FILE__,__FUNCTION__,__LINE__,
|
__FILE__,__FUNCTION__,__LINE__,
|
||||||
connectionSlot->getPlayerIndex(),clientLag,clientLagCount,
|
connectionSlot->getPlayerIndex(),
|
||||||
this->getCurrentFrameCount(),connectionSlot->getCurrentFrameCount(),clientLagTime);
|
clientLag,clientLagCount,
|
||||||
|
this->getCurrentFrameCount(),
|
||||||
|
connectionSlot->getCurrentFrameCount(),
|
||||||
|
clientLagTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TEST LAG Error and warnings!!!
|
// TEST LAG Error and warnings!!!
|
||||||
|
@ -393,7 +395,7 @@ std::pair<bool,bool> ServerInterface::clientLagCheck(ConnectionSlot* connectionS
|
||||||
|
|
||||||
if(skipNetworkBroadCast == false) {
|
if(skipNetworkBroadCast == false) {
|
||||||
string sMsg = szBuf;
|
string sMsg = szBuf;
|
||||||
sendTextMessage(sMsg,-1, true);
|
sendTextMessage(sMsg,-1, true, connectionSlot->getPlayerIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(gameSettings.getNetworkPauseGameForLaggedClients() == false ||
|
if(gameSettings.getNetworkPauseGameForLaggedClients() == false ||
|
||||||
|
@ -423,7 +425,7 @@ std::pair<bool,bool> ServerInterface::clientLagCheck(ConnectionSlot* connectionS
|
||||||
|
|
||||||
if(skipNetworkBroadCast == false) {
|
if(skipNetworkBroadCast == false) {
|
||||||
string sMsg = szBuf;
|
string sMsg = szBuf;
|
||||||
sendTextMessage(sMsg,-1, true);
|
sendTextMessage(sMsg,-1, true, connectionSlot->getPlayerIndex());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -528,7 +530,10 @@ 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__);
|
||||||
|
|
||||||
bool socketTriggered = (connectionSlot != NULL && connectionSlot->getSocket() != NULL ? socketTriggeredList[connectionSlot->getSocket()->getSocketId()] : false);
|
bool socketTriggered = false;
|
||||||
|
if(connectionSlot != NULL && connectionSlot->getSocket() != NULL) {
|
||||||
|
socketTriggered = socketTriggeredList[connectionSlot->getSocket()->getSocketId()];
|
||||||
|
}
|
||||||
ConnectionSlotEvent &event = eventList[i];
|
ConnectionSlotEvent &event = eventList[i];
|
||||||
mapSlotSignalledList[i] = signalClientReceiveCommands(connectionSlot,i,socketTriggered,event);
|
mapSlotSignalledList[i] = signalClientReceiveCommands(connectionSlot,i,socketTriggered,event);
|
||||||
}
|
}
|
||||||
|
@ -561,8 +566,6 @@ void ServerInterface::update() {
|
||||||
connectionSlot->clearThreadErrorList();
|
connectionSlot->clearThreadErrorList();
|
||||||
}
|
}
|
||||||
|
|
||||||
//connectionSlot = slots[i];
|
|
||||||
|
|
||||||
// Not done waiting for data yet
|
// Not done waiting for data yet
|
||||||
bool updateFinished = (connectionSlot != NULL ? connectionSlot->updateCompleted(&eventList[i]) : true);
|
bool updateFinished = (connectionSlot != NULL ? connectionSlot->updateCompleted(&eventList[i]) : true);
|
||||||
if(updateFinished == false) {
|
if(updateFinished == false) {
|
||||||
|
@ -580,9 +583,6 @@ void ServerInterface::update() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//if(threadsDone == false) {
|
|
||||||
// sleep(0);
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #3\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #3\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
@ -615,18 +615,13 @@ void ServerInterface::update() {
|
||||||
connectionSlot->clearThreadErrorList();
|
connectionSlot->clearThreadErrorList();
|
||||||
}
|
}
|
||||||
|
|
||||||
connectionSlot = slots[i];
|
|
||||||
|
|
||||||
// Not done waiting for data yet
|
// Not done waiting for data yet
|
||||||
bool updateFinished = (connectionSlot != NULL ? connectionSlot->updateCompleted(&eventList[i]) : true);
|
bool updateFinished = (connectionSlot != NULL ? connectionSlot->updateCompleted(&eventList[i]) : true);
|
||||||
if(updateFinished == false) {
|
if(updateFinished == false) {
|
||||||
threadsDone = false;
|
threadsDone = false;
|
||||||
//sleep(0);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//connectionSlot = slots[i];
|
|
||||||
|
|
||||||
// New lag check
|
// New lag check
|
||||||
std::pair<bool,bool> clientLagExceededOrWarned = std::make_pair(false,false);
|
std::pair<bool,bool> clientLagExceededOrWarned = std::make_pair(false,false);
|
||||||
if( gameHasBeenInitiated == true && connectionSlot != NULL &&
|
if( gameHasBeenInitiated == true && connectionSlot != NULL &&
|
||||||
|
@ -648,21 +643,15 @@ void ServerInterface::update() {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d, clientLagExceededOrWarned.first = %d, clientLagExceededOrWarned.second = %d, difftime(time(NULL),waitForClientsElapsed) = %.2f, MAX_CLIENT_WAIT_SECONDS_FOR_PAUSE = %.2f\n",__FILE__,__FUNCTION__,__LINE__,clientLagExceededOrWarned.first,clientLagExceededOrWarned.second,difftime(time(NULL),waitForClientsElapsed),MAX_CLIENT_WAIT_SECONDS_FOR_PAUSE);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d, clientLagExceededOrWarned.first = %d, clientLagExceededOrWarned.second = %d, difftime(time(NULL),waitForClientsElapsed) = %.2f, MAX_CLIENT_WAIT_SECONDS_FOR_PAUSE = %.2f\n",__FILE__,__FUNCTION__,__LINE__,clientLagExceededOrWarned.first,clientLagExceededOrWarned.second,difftime(time(NULL),waitForClientsElapsed),MAX_CLIENT_WAIT_SECONDS_FOR_PAUSE);
|
||||||
|
|
||||||
if(difftime(time(NULL),waitForClientsElapsed) < MAX_CLIENT_WAIT_SECONDS_FOR_PAUSE) {
|
if(difftime(time(NULL),waitForClientsElapsed) < MAX_CLIENT_WAIT_SECONDS_FOR_PAUSE) {
|
||||||
connectionSlot = slots[i];
|
|
||||||
if(connectionSlot != NULL) {
|
if(connectionSlot != NULL) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d, clientLagExceededOrWarned.first = %d, clientLagExceededOrWarned.second = %d\n",__FILE__,__FUNCTION__,__LINE__,clientLagExceededOrWarned.first,clientLagExceededOrWarned.second);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d, clientLagExceededOrWarned.first = %d, clientLagExceededOrWarned.second = %d\n",__FILE__,__FUNCTION__,__LINE__,clientLagExceededOrWarned.first,clientLagExceededOrWarned.second);
|
||||||
|
|
||||||
bool socketTriggered = (connectionSlot != NULL && connectionSlot->getSocket() != NULL ? socketTriggeredList[connectionSlot->getSocket()->getSocketId()] : false);
|
bool socketTriggered = (connectionSlot != NULL && connectionSlot->getSocket() != NULL ? socketTriggeredList[connectionSlot->getSocket()->getSocketId()] : false);
|
||||||
ConnectionSlotEvent &event = eventList[i];
|
ConnectionSlotEvent &event = eventList[i];
|
||||||
mapSlotSignalledList[i] = signalClientReceiveCommands(connectionSlot,i,socketTriggered,event);
|
mapSlotSignalledList[i] = signalClientReceiveCommands(connectionSlot,i,socketTriggered,event);
|
||||||
//sleep(0);
|
|
||||||
threadsDone = false;
|
threadsDone = false;
|
||||||
}
|
}
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d, clientLagExceededOrWarned.first = %d, clientLagExceededOrWarned.second = %d\n",__FILE__,__FUNCTION__,__LINE__,clientLagExceededOrWarned.first,clientLagExceededOrWarned.second);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d, clientLagExceededOrWarned.first = %d, clientLagExceededOrWarned.second = %d\n",__FILE__,__FUNCTION__,__LINE__,clientLagExceededOrWarned.first,clientLagExceededOrWarned.second);
|
||||||
|
|
||||||
//if(gameSettings.getNetworkPauseGameForLaggedClients() == false) {
|
|
||||||
// slotsWarnedAndRetried[i] = true;
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -719,7 +708,7 @@ void ServerInterface::update() {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 about to broadcast nmtText chatText [%s] chatTeamIndex = %d, newChatPlayerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex,newChatPlayerIndex);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 about to broadcast nmtText chatText [%s] chatTeamIndex = %d, newChatPlayerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex,newChatPlayerIndex);
|
||||||
|
|
||||||
NetworkMessageText networkMessageText(newChatText.c_str(),newChatTeamIndex,newChatPlayerIndex);
|
NetworkMessageText networkMessageText(newChatText.c_str(),newChatTeamIndex,newChatPlayerIndex);
|
||||||
broadcastMessage(&networkMessageText, connectionSlot->getPlayerIndex());
|
broadcastMessage(&networkMessageText, connectionSlot->getPlayerIndex(),i);
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after broadcast nmtText chatText [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after broadcast nmtText chatText [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex);
|
||||||
}
|
}
|
||||||
|
@ -939,7 +928,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, true);
|
sendTextMessage(sErr,-1, true,i);
|
||||||
DisplayErrorMessage(sErr);
|
DisplayErrorMessage(sErr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1007,11 +996,15 @@ void ServerInterface::waitUntilReady(Checksum* checksum) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerInterface::sendTextMessage(const string &text, int teamIndex, bool echoLocal) {
|
void ServerInterface::sendTextMessage(const string &text, int teamIndex, bool echoLocal) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] text [%s] teamIndex = %d, echoLocal = %d\n",__FILE__,__FUNCTION__,__LINE__,text.c_str(),teamIndex,echoLocal);
|
sendTextMessage(text, teamIndex, echoLocal, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServerInterface::sendTextMessage(const string &text, int teamIndex, bool echoLocal, int lockedSlotIndex) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] text [%s] teamIndex = %d, echoLocal = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,text.c_str(),teamIndex,echoLocal,lockedSlotIndex);
|
||||||
|
|
||||||
//NetworkMessageText networkMessageText(text, getHumanPlayerName().c_str(), teamIndex, getHumanPlayerIndex());
|
//NetworkMessageText networkMessageText(text, getHumanPlayerName().c_str(), teamIndex, getHumanPlayerIndex());
|
||||||
NetworkMessageText networkMessageText(text, teamIndex, getHumanPlayerIndex());
|
NetworkMessageText networkMessageText(text, teamIndex, getHumanPlayerIndex());
|
||||||
broadcastMessage(&networkMessageText);
|
broadcastMessage(&networkMessageText,-1,lockedSlotIndex);
|
||||||
|
|
||||||
if(echoLocal == true) {
|
if(echoLocal == 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__);
|
||||||
|
@ -1063,8 +1056,7 @@ string ServerInterface::getNetworkStatus() {
|
||||||
str+= connectionSlot->getName() + string(szBuf);
|
str+= connectionSlot->getName() + string(szBuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
str+= lang.get("NotConnected");
|
str+= lang.get("NotConnected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1138,25 +1130,21 @@ void ServerInterface::broadcastGameSetup(const GameSettings* gameSettings) {
|
||||||
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__);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerInterface::broadcastMessage(const NetworkMessage* networkMessage, int excludeSlot){
|
void ServerInterface::broadcastMessage(const NetworkMessage* networkMessage, int excludeSlot, int lockedSlotIndex) {
|
||||||
//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 {
|
try {
|
||||||
|
|
||||||
if(enabledThreadedClientCommandBroadcast == true) {
|
if(enabledThreadedClientCommandBroadcast == true) {
|
||||||
// Step #1 signal worker threads to send this broadcast to each client
|
// Step #1 signal worker threads to send this broadcast to each client
|
||||||
std::map<int,ConnectionSlotEvent> eventList;
|
std::map<int,ConnectionSlotEvent> eventList;
|
||||||
for(int i= 0; i<GameConstants::maxPlayers; ++i) {
|
for(int i= 0; i<GameConstants::maxPlayers; ++i) {
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(i));
|
MutexSafeWrapper safeMutexSlot(NULL,intToStr(__LINE__) + "_" + intToStr(i));
|
||||||
|
if(i != lockedSlotIndex) {
|
||||||
|
safeMutexSlot.setMutex(&slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(i));
|
||||||
|
}
|
||||||
|
|
||||||
ConnectionSlot* connectionSlot = slots[i];
|
ConnectionSlot* connectionSlot = slots[i];
|
||||||
|
|
||||||
// New lag check
|
|
||||||
//std::pair<bool,bool> clientLagExceededOrWarned = std::make_pair(false,false);
|
|
||||||
//if( gameHasBeenInitiated == true && connectionSlot != NULL &&
|
|
||||||
// connectionSlot->isConnected() == true) {
|
|
||||||
// clientLagExceededOrWarned = clientLagCheck(connectionSlot);
|
|
||||||
//}
|
|
||||||
//if(clientLagExceededOrWarned.first == false) {
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] networkMessage = %p\n",__FILE__,__FUNCTION__,__LINE__,networkMessage);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] networkMessage = %p\n",__FILE__,__FUNCTION__,__LINE__,networkMessage);
|
||||||
|
|
||||||
ConnectionSlotEvent &event = eventList[i];
|
ConnectionSlotEvent &event = eventList[i];
|
||||||
|
@ -1166,26 +1154,26 @@ void ServerInterface::broadcastMessage(const NetworkMessage* networkMessage, int
|
||||||
event.socketTriggered = true;
|
event.socketTriggered = true;
|
||||||
event.triggerId = i;
|
event.triggerId = i;
|
||||||
|
|
||||||
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__);
|
||||||
|
|
||||||
// Step #1 tell all connection slot worker threads to receive socket data
|
// Step #1 tell all connection slot worker threads to receive socket data
|
||||||
if(i != excludeSlot && connectionSlot != NULL) {
|
if(i != excludeSlot && connectionSlot != NULL) {
|
||||||
if(connectionSlot->isConnected()) {
|
if(connectionSlot->isConnected()) {
|
||||||
connectionSlot->signalUpdate(&event);
|
connectionSlot->signalUpdate(&event);
|
||||||
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__);
|
||||||
}
|
}
|
||||||
else if(gameHasBeenInitiated == true) {
|
else if(gameHasBeenInitiated == true) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 before removeSlot for slot# %d\n",__FILE__,__FUNCTION__,__LINE__,i);
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #1 before removeSlot for slot# %d\n",__FILE__,__FUNCTION__,i);
|
removeSlot(i,i);
|
||||||
removeSlot(i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(i == excludeSlot && gameHasBeenInitiated == true &&
|
else if(i == excludeSlot &&
|
||||||
connectionSlot != NULL && connectionSlot->isConnected() == false) {
|
gameHasBeenInitiated == true &&
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #2 before removeSlot for slot# %d\n",__FILE__,__FUNCTION__,i);
|
connectionSlot != NULL &&
|
||||||
removeSlot(i);
|
connectionSlot->isConnected() == false) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 before removeSlot for slot# %d\n",__FILE__,__FUNCTION__,__LINE__,i);
|
||||||
|
removeSlot(i,i);
|
||||||
}
|
}
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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__);
|
||||||
|
@ -1196,7 +1184,11 @@ void ServerInterface::broadcastMessage(const NetworkMessage* networkMessage, int
|
||||||
threadsDone = true;
|
threadsDone = true;
|
||||||
// Examine all threads for completion of delegation
|
// Examine all threads for completion of delegation
|
||||||
for(int i= 0; i< GameConstants::maxPlayers; ++i) {
|
for(int i= 0; i< GameConstants::maxPlayers; ++i) {
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(i));
|
MutexSafeWrapper safeMutexSlot(NULL,intToStr(__LINE__) + "_" + intToStr(i));
|
||||||
|
if(i != lockedSlotIndex) {
|
||||||
|
safeMutexSlot.setMutex(&slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(i));
|
||||||
|
}
|
||||||
|
|
||||||
ConnectionSlot* connectionSlot = slots[i];
|
ConnectionSlot* connectionSlot = slots[i];
|
||||||
if(connectionSlot != NULL && slotsCompleted.find(i) == slotsCompleted.end()) {
|
if(connectionSlot != NULL && slotsCompleted.find(i) == slotsCompleted.end()) {
|
||||||
std::vector<std::string> errorList = connectionSlot->getThreadErrorList();
|
std::vector<std::string> errorList = connectionSlot->getThreadErrorList();
|
||||||
|
@ -1217,39 +1209,33 @@ void ServerInterface::broadcastMessage(const NetworkMessage* networkMessage, int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//sleep(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for(int i= 0; i<GameConstants::maxPlayers; ++i) {
|
for(int i= 0; i<GameConstants::maxPlayers; ++i) {
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(i));
|
MutexSafeWrapper safeMutexSlot(NULL,intToStr(__LINE__) + "_" + intToStr(i));
|
||||||
|
if(i != lockedSlotIndex) {
|
||||||
|
safeMutexSlot.setMutex(&slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(i));
|
||||||
|
}
|
||||||
|
|
||||||
ConnectionSlot* connectionSlot= slots[i];
|
ConnectionSlot* connectionSlot= slots[i];
|
||||||
|
|
||||||
if(i != excludeSlot && connectionSlot != NULL) {
|
if(i != excludeSlot && connectionSlot != NULL) {
|
||||||
// New lag check
|
|
||||||
//std::pair<bool,bool> clientLagExceededOrWarned = std::make_pair(false,false);
|
|
||||||
//if( gameHasBeenInitiated == true && connectionSlot != NULL &&
|
|
||||||
// connectionSlot->isConnected() == true) {
|
|
||||||
// clientLagExceededOrWarned = clientLagCheck(connectionSlot);
|
|
||||||
//}
|
|
||||||
//if(clientLagExceededOrWarned.first == false) {
|
|
||||||
if(connectionSlot->isConnected()) {
|
if(connectionSlot->isConnected()) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] before sendMessage\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] before sendMessage\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
connectionSlot->sendMessage(networkMessage);
|
connectionSlot->sendMessage(networkMessage);
|
||||||
}
|
}
|
||||||
else if(gameHasBeenInitiated == true) {
|
else if(gameHasBeenInitiated == true) {
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 before removeSlot for slot# %d\n",__FILE__,__FUNCTION__,__LINE__,i);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 before removeSlot for slot# %d\n",__FILE__,__FUNCTION__,__LINE__,i);
|
||||||
safeMutexSlot.ReleaseLock();
|
//safeMutexSlot.ReleaseLock();
|
||||||
removeSlot(i);
|
removeSlot(i,i);
|
||||||
}
|
}
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
else if(i == excludeSlot && gameHasBeenInitiated == true &&
|
else if(i == excludeSlot && gameHasBeenInitiated == true &&
|
||||||
connectionSlot != NULL && connectionSlot->isConnected() == false) {
|
connectionSlot != NULL && connectionSlot->isConnected() == false) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] #2 before removeSlot for slot# %d\n",__FILE__,__FUNCTION__,i);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 before removeSlot for slot# %d\n",__FILE__,__FUNCTION__,__LINE__,i);
|
||||||
safeMutexSlot.ReleaseLock();
|
//safeMutexSlot.ReleaseLock();
|
||||||
removeSlot(i);
|
removeSlot(i,i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1261,7 +1247,7 @@ void ServerInterface::broadcastMessage(const NetworkMessage* networkMessage, int
|
||||||
|
|
||||||
//DisplayErrorMessage(ex.what());
|
//DisplayErrorMessage(ex.what());
|
||||||
string sMsg = ex.what();
|
string sMsg = ex.what();
|
||||||
sendTextMessage(sMsg,-1, true);
|
sendTextMessage(sMsg,-1, true, lockedSlotIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
//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__);
|
||||||
|
|
|
@ -65,6 +65,8 @@ public:
|
||||||
|
|
||||||
// message sending
|
// message sending
|
||||||
virtual void sendTextMessage(const string &text, int teamIndex, bool echoLocal=false);
|
virtual void sendTextMessage(const string &text, int teamIndex, bool echoLocal=false);
|
||||||
|
void sendTextMessage(const string &text, int teamIndex, bool echoLocal, int lockedSlotIndex);
|
||||||
|
|
||||||
virtual void quitGame(bool userManuallyQuit);
|
virtual void quitGame(bool userManuallyQuit);
|
||||||
|
|
||||||
//misc
|
//misc
|
||||||
|
@ -74,7 +76,7 @@ public:
|
||||||
SwitchSetupRequest** getSwitchSetupRequests() {return &switchSetupRequests[0];}
|
SwitchSetupRequest** getSwitchSetupRequests() {return &switchSetupRequests[0];}
|
||||||
void addSlot(int playerIndex);
|
void addSlot(int playerIndex);
|
||||||
bool switchSlot(int fromPlayerIndex,int toPlayerIndex);
|
bool switchSlot(int fromPlayerIndex,int toPlayerIndex);
|
||||||
void removeSlot(int playerIndex);
|
void removeSlot(int playerIndex, int lockedSlotIndex=-1);
|
||||||
ConnectionSlot* getSlot(int playerIndex);
|
ConnectionSlot* getSlot(int playerIndex);
|
||||||
int getConnectedSlotCount();
|
int getConnectedSlotCount();
|
||||||
int getOpenSlotCount();
|
int getOpenSlotCount();
|
||||||
|
@ -117,7 +119,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void broadcastMessage(const NetworkMessage* networkMessage, int excludeSlot= -1);
|
void broadcastMessage(const NetworkMessage* networkMessage, int excludeSlot= -1,int lockedSlotIndex=-1);
|
||||||
void broadcastMessageToConnectedClients(const NetworkMessage* networkMessage, int excludeSlot = -1);
|
void broadcastMessageToConnectedClients(const NetworkMessage* networkMessage, int excludeSlot = -1);
|
||||||
bool shouldDiscardNetworkMessage(NetworkMessageType networkMessageType,ConnectionSlot* connectionSlot);
|
bool shouldDiscardNetworkMessage(NetworkMessageType networkMessageType,ConnectionSlot* connectionSlot);
|
||||||
void updateSlot(ConnectionSlotEvent *event);
|
void updateSlot(ConnectionSlotEvent *event);
|
||||||
|
|
|
@ -86,6 +86,12 @@ public:
|
||||||
ReleaseLock();
|
ReleaseLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setMutex(Mutex *mutex,string ownerId="") {
|
||||||
|
this->mutex = mutex;
|
||||||
|
this->ownerId = ownerId;
|
||||||
|
Lock();
|
||||||
|
}
|
||||||
|
|
||||||
void Lock() {
|
void Lock() {
|
||||||
if(this->mutex != NULL) {
|
if(this->mutex != NULL) {
|
||||||
#ifdef DEBUG_MUTEXES
|
#ifdef DEBUG_MUTEXES
|
||||||
|
|
Loading…
Reference in New Issue
Block a user