- bugfixes for when players disconnect, do not switch observers to AI and only show message once.
- Attempts to debug/improve network performance
This commit is contained in:
parent
508a2a8277
commit
31e722287f
|
@ -40,7 +40,7 @@ namespace Glest{ namespace Game{
|
||||||
const int PathFinder::maxFreeSearchRadius = 10;
|
const int PathFinder::maxFreeSearchRadius = 10;
|
||||||
//const int PathFinder::pathFindNodesMax= 400;
|
//const int PathFinder::pathFindNodesMax= 400;
|
||||||
int PathFinder::pathFindNodesMax = 1000;
|
int PathFinder::pathFindNodesMax = 1000;
|
||||||
const int PathFinder::pathFindRefresh = 20;
|
const int PathFinder::pathFindRefresh = 10;
|
||||||
const int PathFinder::pathFindBailoutRadius = 20;
|
const int PathFinder::pathFindBailoutRadius = 20;
|
||||||
|
|
||||||
|
|
||||||
|
@ -325,7 +325,12 @@ void PathFinder::processNode(Unit *unit, Node *node,const Vec2i finalPos, int i,
|
||||||
sucNode->prev= node;
|
sucNode->prev= node;
|
||||||
sucNode->next= NULL;
|
sucNode->next= NULL;
|
||||||
sucNode->exploredCell= map->getSurfaceCell(Map::toSurfCoords(sucPos))->isExplored(unit->getTeam());
|
sucNode->exploredCell= map->getSurfaceCell(Map::toSurfCoords(sucPos))->isExplored(unit->getTeam());
|
||||||
openNodesList[sucNode->heuristic].push_back(sucNode);
|
std::map<float, Nodes>::iterator iterFind = openNodesList.find(sucNode->heuristic);
|
||||||
|
if(iterFind == openNodesList.end()) {
|
||||||
|
openNodesList[sucNode->heuristic].reserve(PathFinder::pathFindNodesMax / 3);
|
||||||
|
iterFind = openNodesList.find(sucNode->heuristic);
|
||||||
|
}
|
||||||
|
iterFind->second.push_back(sucNode);
|
||||||
openPosList[sucNode->pos] = true;
|
openPosList[sucNode->pos] = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -484,7 +489,13 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
||||||
firstNode->pos= unitPos;
|
firstNode->pos= unitPos;
|
||||||
firstNode->heuristic= heuristic(unitPos, finalPos);
|
firstNode->heuristic= heuristic(unitPos, finalPos);
|
||||||
firstNode->exploredCell= true;
|
firstNode->exploredCell= true;
|
||||||
openNodesList[firstNode->heuristic].push_back(firstNode);
|
|
||||||
|
std::map<float, Nodes>::iterator iterFind = openNodesList.find(firstNode->heuristic);
|
||||||
|
if(iterFind == openNodesList.end()) {
|
||||||
|
openNodesList[firstNode->heuristic].reserve(PathFinder::pathFindNodesMax / 3);
|
||||||
|
iterFind = openNodesList.find(firstNode->heuristic);
|
||||||
|
}
|
||||||
|
iterFind->second.push_back(firstNode);
|
||||||
openPosList[firstNode->pos] = true;
|
openPosList[firstNode->pos] = true;
|
||||||
|
|
||||||
//b) loop
|
//b) loop
|
||||||
|
@ -516,7 +527,12 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
||||||
|
|
||||||
//b4) move this node from closedNodes to openNodes
|
//b4) move this node from closedNodes to openNodes
|
||||||
//add all succesors that are not in closedNodes or openNodes to openNodes
|
//add all succesors that are not in closedNodes or openNodes to openNodes
|
||||||
closedNodesList[node->heuristic].push_back(node);
|
std::map<float, Nodes>::iterator iterFind = closedNodesList.find(node->heuristic);
|
||||||
|
if(iterFind == closedNodesList.end()) {
|
||||||
|
closedNodesList[node->heuristic].reserve(PathFinder::pathFindNodesMax / 3);
|
||||||
|
iterFind = closedNodesList.find(node->heuristic);
|
||||||
|
}
|
||||||
|
iterFind->second.push_back(node);
|
||||||
openPosList[node->pos] = true;
|
openPosList[node->pos] = true;
|
||||||
|
|
||||||
int tryDirection = random.randRange(0,3);
|
int tryDirection = random.randRange(0,3);
|
||||||
|
@ -550,7 +566,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
||||||
}
|
}
|
||||||
} //while
|
} //while
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
|
||||||
Node *lastNode= node;
|
Node *lastNode= node;
|
||||||
|
|
||||||
|
|
|
@ -852,20 +852,27 @@ void Game::ReplaceDisconnectedNetworkPlayersWithAI(bool isNetworkGame, NetworkRo
|
||||||
|
|
||||||
for(int i = 0; i < world.getFactionCount(); ++i) {
|
for(int i = 0; i < world.getFactionCount(); ++i) {
|
||||||
Faction *faction = world.getFaction(i);
|
Faction *faction = world.getFaction(i);
|
||||||
if( faction->getControlType() == ctNetwork ||
|
if( faction->getFactionDisconnectHandled() == false &&
|
||||||
|
(faction->getControlType() == ctNetwork ||
|
||||||
faction->getControlType() == ctNetworkCpuEasy ||
|
faction->getControlType() == ctNetworkCpuEasy ||
|
||||||
faction->getControlType() == ctNetworkCpu ||
|
faction->getControlType() == ctNetworkCpu ||
|
||||||
faction->getControlType() == ctNetworkCpuUltra ||
|
faction->getControlType() == ctNetworkCpuUltra ||
|
||||||
faction->getControlType() == ctNetworkCpuMega) {
|
faction->getControlType() == ctNetworkCpuMega)) {
|
||||||
ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex());
|
ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex());
|
||||||
if(aiInterfaces[i] == NULL && (slot == NULL || slot->isConnected() == false)) {
|
if(aiInterfaces[i] == NULL && (slot == NULL || slot->isConnected() == false)) {
|
||||||
|
faction->setFactionDisconnectHandled(true);
|
||||||
faction->setControlType(ctCpu);
|
|
||||||
aiInterfaces[i] = new AiInterface(*this, i, faction->getTeam(), faction->getStartLocationIndex());
|
|
||||||
logger.add("Creating AI for faction " + intToStr(i), true);
|
|
||||||
|
|
||||||
char szBuf[255]="";
|
char szBuf[255]="";
|
||||||
sprintf(szBuf,"Player #%d [%s] has disconnected, switching player to AI mode!",i+1,this->gameSettings.getNetworkPlayerName(i).c_str());
|
if(faction->getType()->getPersonalityType() != fpt_Observer) {
|
||||||
|
faction->setControlType(ctCpu);
|
||||||
|
aiInterfaces[i] = new AiInterface(*this, i, faction->getTeam(), faction->getStartLocationIndex());
|
||||||
|
logger.add("Creating AI for faction " + intToStr(i), true);
|
||||||
|
|
||||||
|
sprintf(szBuf,"Player #%d [%s] has disconnected, switching player to AI mode!",i+1,this->gameSettings.getNetworkPlayerName(i).c_str());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sprintf(szBuf,"Player #%d [%s] has disconnected, but player was only an observer!",i+1,this->gameSettings.getNetworkPlayerName(i).c_str());
|
||||||
|
}
|
||||||
server->sendTextMessage(szBuf,-1,true);
|
server->sendTextMessage(szBuf,-1,true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,16 +125,16 @@ void ClientInterface::update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
double lastSendElapsed = difftime(time(NULL),lastNetworkCommandListSendTime);
|
double lastSendElapsed = difftime(time(NULL),lastNetworkCommandListSendTime);
|
||||||
if(lastSendElapsed > 0) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] lastSendElapsed = %f, networkMessageCommandList.getCommandCount() = %d, requestedCommands.empty() = %d\n",__FILE__,__FUNCTION__,__LINE__,lastSendElapsed,networkMessageCommandList.getCommandCount(),requestedCommands.empty());
|
//if(lastSendElapsed > 0) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] lastSendElapsed = %f, networkMessageCommandList.getCommandCount() = %d, requestedCommands.empty() = %d\n",__FILE__,__FUNCTION__,__LINE__,lastSendElapsed,networkMessageCommandList.getCommandCount(),requestedCommands.empty());
|
||||||
|
|
||||||
if(networkMessageCommandList.getCommandCount() > 0 ||
|
if(networkMessageCommandList.getCommandCount() > 0 ||
|
||||||
(lastNetworkCommandListSendTime > 0 && lastSendElapsed >= ClientInterface::maxNetworkCommandListSendTimeWait)) {
|
(lastNetworkCommandListSendTime > 0 && lastSendElapsed >= ClientInterface::maxNetworkCommandListSendTimeWait)) {
|
||||||
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__);
|
||||||
|
|
||||||
lastNetworkCommandListSendTime = time(NULL);
|
lastNetworkCommandListSendTime = time(NULL);
|
||||||
sendMessage(&networkMessageCommandList);
|
sendMessage(&networkMessageCommandList);
|
||||||
|
|
||||||
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__);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Possible cause of out of synch since we have more commands that need
|
// Possible cause of out of synch since we have more commands that need
|
||||||
|
@ -508,13 +508,14 @@ void ClientInterface::updateLobby() {
|
||||||
void ClientInterface::updateKeyframe(int frameCount) {
|
void ClientInterface::updateKeyframe(int frameCount) {
|
||||||
currentFrameCount = frameCount;
|
currentFrameCount = frameCount;
|
||||||
|
|
||||||
|
int simulateLag = Config::getInstance().getInt("SimulateClientLag","0");
|
||||||
bool done= false;
|
bool done= false;
|
||||||
while(done == false) {
|
while(done == false) {
|
||||||
//wait for the next message
|
//wait for the next message
|
||||||
waitForMessage();
|
NetworkMessageType networkMessageType = waitForMessage();
|
||||||
|
|
||||||
// START: Test simulating lag for the client
|
// START: Test simulating lag for the client
|
||||||
if(Config::getInstance().getInt("SimulateClientLag","0") > 0) {
|
if(simulateLag > 0) {
|
||||||
if(clientSimulationLagStartTime == 0) {
|
if(clientSimulationLagStartTime == 0) {
|
||||||
clientSimulationLagStartTime = time(NULL);
|
clientSimulationLagStartTime = time(NULL);
|
||||||
}
|
}
|
||||||
|
@ -525,7 +526,7 @@ void ClientInterface::updateKeyframe(int frameCount) {
|
||||||
// END: Test simulating lag for the client
|
// END: Test simulating lag for the client
|
||||||
|
|
||||||
//check we have an expected message
|
//check we have an expected message
|
||||||
NetworkMessageType networkMessageType= getNextMessageType(true);
|
//NetworkMessageType networkMessageType= getNextMessageType(true);
|
||||||
|
|
||||||
switch(networkMessageType)
|
switch(networkMessageType)
|
||||||
{
|
{
|
||||||
|
@ -811,7 +812,7 @@ string ClientInterface::getNetworkStatus() {
|
||||||
return szBuf;
|
return szBuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientInterface::waitForMessage()
|
NetworkMessageType ClientInterface::waitForMessage()
|
||||||
{
|
{
|
||||||
// Debug!
|
// Debug!
|
||||||
/*
|
/*
|
||||||
|
@ -825,41 +826,47 @@ void ClientInterface::waitForMessage()
|
||||||
Chrono chrono;
|
Chrono chrono;
|
||||||
chrono.start();
|
chrono.start();
|
||||||
|
|
||||||
|
NetworkMessageType msg = nmtInvalid;
|
||||||
int waitLoopCount = 0;
|
int waitLoopCount = 0;
|
||||||
while(getNextMessageType(true) == nmtInvalid) {
|
while(msg == nmtInvalid) {
|
||||||
if(isConnected() == false) {
|
msg = getNextMessageType(true);
|
||||||
if(quit == false) {
|
if(msg == nmtInvalid) {
|
||||||
//throw runtime_error("Disconnected");
|
if(chrono.getMillis() % 150 == 0 && isConnected() == false) {
|
||||||
//sendTextMessage("Server has Disconnected.",-1);
|
if(quit == false) {
|
||||||
DisplayErrorMessage("Server has Disconnected.");
|
//throw runtime_error("Disconnected");
|
||||||
quit= true;
|
//sendTextMessage("Server has Disconnected.",-1);
|
||||||
|
DisplayErrorMessage("Server has Disconnected.");
|
||||||
|
quit= true;
|
||||||
|
}
|
||||||
|
close();
|
||||||
|
return msg;
|
||||||
}
|
}
|
||||||
close();
|
|
||||||
return;
|
if(chrono.getMillis() > messageWaitTimeout) {
|
||||||
|
//if(1) {
|
||||||
|
//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, true);
|
||||||
|
DisplayErrorMessage("Timeout waiting for message");
|
||||||
|
quit= true;
|
||||||
|
close();
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
// Sleep ever second we wait to let other threads work
|
||||||
|
//else if(chrono.getMillis() % 1000 == 0) {
|
||||||
|
//sleep(0);
|
||||||
|
//}
|
||||||
|
|
||||||
|
//sleep(waitSleepTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(chrono.getMillis() > messageWaitTimeout) {
|
|
||||||
//if(1) {
|
|
||||||
//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, true);
|
|
||||||
DisplayErrorMessage("Timeout waiting for message");
|
|
||||||
quit= true;
|
|
||||||
close();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Sleep ever second we wait to let other threads work
|
|
||||||
else if(chrono.getMillis() % 1000 == 0) {
|
|
||||||
//sleep(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//sleep(waitSleepTime);
|
|
||||||
waitLoopCount++;
|
waitLoopCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] waiting took %lld msecs, waitLoopCount = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),waitLoopCount);
|
if(chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] waiting took %lld msecs, waitLoopCount = %d, msg = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),waitLoopCount,msg);
|
||||||
|
|
||||||
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientInterface::quitGame(bool userManuallyQuit)
|
void ClientInterface::quitGame(bool userManuallyQuit)
|
||||||
|
|
|
@ -110,7 +110,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
Mutex * getServerSynchAccessor() { return NULL; }
|
Mutex * getServerSynchAccessor() { return NULL; }
|
||||||
void waitForMessage();
|
NetworkMessageType waitForMessage();
|
||||||
bool shouldDiscardNetworkMessage(NetworkMessageType networkMessageType);
|
bool shouldDiscardNetworkMessage(NetworkMessageType networkMessageType);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -58,9 +58,7 @@ NetworkMessageType NetworkInterface::getNextMessageType(bool checkHasDataFirst)
|
||||||
int dataSize = socket->getDataToRead();
|
int dataSize = socket->getDataToRead();
|
||||||
if(dataSize >= sizeof(messageType)){
|
if(dataSize >= sizeof(messageType)){
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket->getDataToRead() dataSize = %d\n",__FILE__,__FUNCTION__,__LINE__,dataSize);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket->getDataToRead() dataSize = %d\n",__FILE__,__FUNCTION__,__LINE__,dataSize);
|
||||||
|
|
||||||
int iPeek = socket->peek(&messageType, sizeof(messageType));
|
int iPeek = socket->peek(&messageType, sizeof(messageType));
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket->getDataToRead() iPeek = %d, messageType = %d [size = %d]\n",__FILE__,__FUNCTION__,__LINE__,iPeek,messageType,sizeof(messageType));
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket->getDataToRead() iPeek = %d, messageType = %d [size = %d]\n",__FILE__,__FUNCTION__,__LINE__,iPeek,messageType,sizeof(messageType));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -742,19 +742,28 @@ void ServerInterface::dispatchPendingChatMessages(std::vector <string> &errorMsg
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerInterface::update() {
|
void ServerInterface::update() {
|
||||||
|
//Chrono chrono;
|
||||||
|
//chrono.start();
|
||||||
|
|
||||||
std::vector <string> errorMsgList;
|
std::vector <string> errorMsgList;
|
||||||
try {
|
try {
|
||||||
// The first thing we will do is check all clients to ensure they have
|
// The first thing we will do is check all clients to ensure they have
|
||||||
// properly identified themselves within the alloted time period
|
// properly identified themselves within the alloted time period
|
||||||
validateConnectedClients();
|
validateConnectedClients();
|
||||||
|
|
||||||
|
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] method running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
|
|
||||||
processTextMessageQueue();
|
processTextMessageQueue();
|
||||||
processBroadCastMessageQueue();
|
processBroadCastMessageQueue();
|
||||||
|
|
||||||
|
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] method running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
|
|
||||||
std::map<PLATFORM_SOCKET,bool> socketTriggeredList;
|
std::map<PLATFORM_SOCKET,bool> socketTriggeredList;
|
||||||
//update all slots
|
//update all slots
|
||||||
updateSocketTriggeredList(socketTriggeredList);
|
updateSocketTriggeredList(socketTriggeredList);
|
||||||
|
|
||||||
|
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] method running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
|
|
||||||
if(gameHasBeenInitiated == false || socketTriggeredList.size() > 0) {
|
if(gameHasBeenInitiated == false || socketTriggeredList.size() > 0) {
|
||||||
std::map<int,ConnectionSlotEvent> eventList;
|
std::map<int,ConnectionSlotEvent> eventList;
|
||||||
bool hasData = Socket::hasDataToRead(socketTriggeredList);
|
bool hasData = Socket::hasDataToRead(socketTriggeredList);
|
||||||
|
@ -768,22 +777,34 @@ void ServerInterface::update() {
|
||||||
signalClientsToRecieveData(socketTriggeredList, eventList, mapSlotSignalledList);
|
signalClientsToRecieveData(socketTriggeredList, eventList, mapSlotSignalledList);
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #2\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #2\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] method running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
|
|
||||||
// Step #2 check all connection slot worker threads for completed status
|
// Step #2 check all connection slot worker threads for completed status
|
||||||
checkForCompletedClients(mapSlotSignalledList,errorMsgList, eventList);
|
checkForCompletedClients(mapSlotSignalledList,errorMsgList, eventList);
|
||||||
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__);
|
||||||
|
|
||||||
|
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] method running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
|
|
||||||
// Step #3 check clients for any lagging scenarios and try to deal with them
|
// Step #3 check clients for any lagging scenarios and try to deal with them
|
||||||
checForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList);
|
checForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList);
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #4\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #4\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] method running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
|
|
||||||
// Step #4 dispatch network commands to the pending list so that they are done in proper order
|
// Step #4 dispatch network commands to the pending list so that they are done in proper order
|
||||||
executeNetworkCommandsFromClients();
|
executeNetworkCommandsFromClients();
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #5\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #5\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] method running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
|
|
||||||
// Step #5 dispatch pending chat messages
|
// Step #5 dispatch pending chat messages
|
||||||
dispatchPendingChatMessages(errorMsgList);
|
dispatchPendingChatMessages(errorMsgList);
|
||||||
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(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] method running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] method running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(const exception &ex) {
|
catch(const exception &ex) {
|
||||||
|
@ -798,9 +819,9 @@ void ServerInterface::update() {
|
||||||
DisplayErrorMessage(sErr);
|
DisplayErrorMessage(sErr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] method running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerInterface::updateKeyframe(int frameCount) {
|
void ServerInterface::updateKeyframe(int frameCount) {
|
||||||
|
@ -1148,6 +1169,18 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(bOkToStart == true) {
|
if(bOkToStart == true) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
|
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],string(__FILE__) + "_" + intToStr(__LINE__) + "_" + intToStr(i));
|
||||||
|
ConnectionSlot *connectionSlot= slots[i];
|
||||||
|
if(connectionSlot != NULL &&
|
||||||
|
connectionSlot->isConnected()) {
|
||||||
|
connectionSlot->getSocket()->setBlock(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] needToRepublishToMasterserver = %d\n",__FILE__,__FUNCTION__,__LINE__,needToRepublishToMasterserver);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] needToRepublishToMasterserver = %d\n",__FILE__,__FUNCTION__,__LINE__,needToRepublishToMasterserver);
|
||||||
|
|
||||||
serverSocket.stopBroadCastThread();
|
serverSocket.stopBroadCastThread();
|
||||||
|
@ -1187,19 +1220,6 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) {
|
||||||
delete ftpServer;
|
delete ftpServer;
|
||||||
ftpServer = NULL;
|
ftpServer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],string(__FILE__) + "_" + intToStr(__LINE__) + "_" + intToStr(i));
|
|
||||||
ConnectionSlot *connectionSlot= slots[i];
|
|
||||||
if(connectionSlot != NULL &&
|
|
||||||
connectionSlot->isConnected()) {
|
|
||||||
connectionSlot->getSocket()->setBlock(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__);
|
||||||
return bOkToStart;
|
return bOkToStart;
|
||||||
|
|
|
@ -36,6 +36,7 @@ Faction::Faction() {
|
||||||
texture = NULL;
|
texture = NULL;
|
||||||
//lastResourceTargettListPurge = 0;
|
//lastResourceTargettListPurge = 0;
|
||||||
cachingDisabled=false;
|
cachingDisabled=false;
|
||||||
|
factionDisconnectHandled=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Faction::~Faction() {
|
Faction::~Faction() {
|
||||||
|
|
|
@ -84,6 +84,8 @@ private:
|
||||||
|
|
||||||
bool thisFaction;
|
bool thisFaction;
|
||||||
|
|
||||||
|
bool factionDisconnectHandled;
|
||||||
|
|
||||||
bool cachingDisabled;
|
bool cachingDisabled;
|
||||||
std::map<Vec2i, std::vector<FactionPathSuccessCache> > successfulPathFinderTargetList;
|
std::map<Vec2i, std::vector<FactionPathSuccessCache> > successfulPathFinderTargetList;
|
||||||
std::map<Vec2i,int> cacheResourceTargetList;
|
std::map<Vec2i,int> cacheResourceTargetList;
|
||||||
|
@ -105,6 +107,9 @@ public:
|
||||||
int factionIndex, int teamIndex, int startLocationIndex, bool thisFaction, bool giveResources);
|
int factionIndex, int teamIndex, int startLocationIndex, bool thisFaction, bool giveResources);
|
||||||
void end();
|
void end();
|
||||||
|
|
||||||
|
bool getFactionDisconnectHandled() const { return factionDisconnectHandled;}
|
||||||
|
void setFactionDisconnectHandled(bool value) { factionDisconnectHandled=value;}
|
||||||
|
|
||||||
//get
|
//get
|
||||||
const Resource *getResource(const ResourceType *rt) const;
|
const Resource *getResource(const ResourceType *rt) const;
|
||||||
const Resource *getResource(int i) const {return &resources[i];}
|
const Resource *getResource(int i) const {return &resources[i];}
|
||||||
|
|
|
@ -844,7 +844,7 @@ void Socket::disconnectSocket() {
|
||||||
::closesocket(sock);
|
::closesocket(sock);
|
||||||
sock = -1;
|
sock = -1;
|
||||||
#endif
|
#endif
|
||||||
safeMutex.ReleaseLock();
|
//safeMutex.ReleaseLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END closing socket = %d...\n",__FILE__,__FUNCTION__,sock);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END closing socket = %d...\n",__FILE__,__FUNCTION__,sock);
|
||||||
|
@ -1041,7 +1041,7 @@ int Socket::send(const void *data, int dataSize) {
|
||||||
#else
|
#else
|
||||||
bytesSent = ::send(sock, (const char *)data, dataSize, MSG_NOSIGNAL | MSG_DONTWAIT);
|
bytesSent = ::send(sock, (const char *)data, dataSize, MSG_NOSIGNAL | MSG_DONTWAIT);
|
||||||
#endif
|
#endif
|
||||||
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__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1078,7 +1078,7 @@ int Socket::send(const void *data, int dataSize) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
safeMutex.ReleaseLock();
|
//safeMutex.ReleaseLock();
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 EAGAIN during send, trying again returned: %d\n",__FILE__,__FUNCTION__,__LINE__,bytesSent);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 EAGAIN during send, trying again returned: %d\n",__FILE__,__FUNCTION__,__LINE__,bytesSent);
|
||||||
}
|
}
|
||||||
|
@ -1124,7 +1124,7 @@ int Socket::send(const void *data, int dataSize) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
safeMutex.ReleaseLock();
|
//safeMutex.ReleaseLock();
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] retry send returned: %d\n",__FILE__,__FUNCTION__,__LINE__,bytesSent);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] retry send returned: %d\n",__FILE__,__FUNCTION__,__LINE__,bytesSent);
|
||||||
}
|
}
|
||||||
|
@ -1171,7 +1171,7 @@ int Socket::receive(void *data, int dataSize) {
|
||||||
if(isSocketValid() == true) {
|
if(isSocketValid() == true) {
|
||||||
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
|
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
bytesReceived = recv(sock, reinterpret_cast<char*>(data), dataSize, 0);
|
bytesReceived = recv(sock, reinterpret_cast<char*>(data), dataSize, 0);
|
||||||
safeMutex.ReleaseLock();
|
//safeMutex.ReleaseLock();
|
||||||
}
|
}
|
||||||
if(bytesReceived < 0 && getLastSocketError() != PLATFORM_SOCKET_TRY_AGAIN) {
|
if(bytesReceived < 0 && getLastSocketError() != PLATFORM_SOCKET_TRY_AGAIN) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] ERROR READING SOCKET DATA error while sending socket data, bytesSent = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,bytesReceived,getLastSocketErrorFormattedText().c_str());
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] ERROR READING SOCKET DATA error while sending socket data, bytesSent = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,bytesReceived,getLastSocketErrorFormattedText().c_str());
|
||||||
|
@ -1193,7 +1193,7 @@ int Socket::receive(void *data, int dataSize) {
|
||||||
else if(Socket::isReadable() == true) {
|
else if(Socket::isReadable() == true) {
|
||||||
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
|
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
bytesReceived = recv(sock, reinterpret_cast<char*>(data), dataSize, 0);
|
bytesReceived = recv(sock, reinterpret_cast<char*>(data), dataSize, 0);
|
||||||
safeMutex.ReleaseLock();
|
//safeMutex.ReleaseLock();
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 EAGAIN during receive, trying again returned: %d\n",__FILE__,__FUNCTION__,__LINE__,bytesReceived);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 EAGAIN during receive, trying again returned: %d\n",__FILE__,__FUNCTION__,__LINE__,bytesReceived);
|
||||||
}
|
}
|
||||||
|
@ -1211,8 +1211,8 @@ int Socket::receive(void *data, int dataSize) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int Socket::peek(void *data, int dataSize,bool mustGetData) {
|
int Socket::peek(void *data, int dataSize,bool mustGetData) {
|
||||||
//Chrono chrono;
|
Chrono chrono;
|
||||||
//chrono.start();
|
chrono.start();
|
||||||
|
|
||||||
const int MAX_PEEK_WAIT_SECONDS = 3;
|
const int MAX_PEEK_WAIT_SECONDS = 3;
|
||||||
|
|
||||||
|
@ -1220,14 +1220,15 @@ int Socket::peek(void *data, int dataSize,bool mustGetData) {
|
||||||
if(isSocketValid() == true) {
|
if(isSocketValid() == true) {
|
||||||
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
|
|
||||||
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__) + "_" + intToStr(sock) + "_" + intToStr(dataSize));
|
//MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__) + "_" + intToStr(sock) + "_" + intToStr(dataSize));
|
||||||
|
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + string("_") + intToStr(__LINE__));
|
||||||
|
|
||||||
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
|
|
||||||
err = recv(sock, reinterpret_cast<char*>(data), dataSize, MSG_PEEK);
|
err = recv(sock, reinterpret_cast<char*>(data), dataSize, MSG_PEEK);
|
||||||
safeMutex.ReleaseLock();
|
//safeMutex.ReleaseLock();
|
||||||
|
|
||||||
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
if(chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
}
|
}
|
||||||
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
|
|
||||||
|
@ -1249,6 +1250,7 @@ int Socket::peek(void *data, int dataSize,bool mustGetData) {
|
||||||
time_t tStartTimer = time(NULL);
|
time_t tStartTimer = time(NULL);
|
||||||
while((err < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) &&
|
while((err < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) &&
|
||||||
(difftime(time(NULL),tStartTimer) <= MAX_PEEK_WAIT_SECONDS)) {
|
(difftime(time(NULL),tStartTimer) <= MAX_PEEK_WAIT_SECONDS)) {
|
||||||
|
/*
|
||||||
if(isConnected() == false) {
|
if(isConnected() == false) {
|
||||||
int iErr = getLastSocketError();
|
int iErr = getLastSocketError();
|
||||||
disconnectSocket();
|
disconnectSocket();
|
||||||
|
@ -1256,11 +1258,14 @@ int Socket::peek(void *data, int dataSize,bool mustGetData) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] DISCONNECTED SOCKET error while peeking socket data, err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,err,getLastSocketErrorFormattedText(&iErr).c_str());
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] DISCONNECTED SOCKET error while peeking socket data, err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,err,getLastSocketErrorFormattedText(&iErr).c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if(Socket::isReadable() == true) {
|
*/
|
||||||
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
|
if(Socket::isReadable() == true) {
|
||||||
|
//MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__) + "_" + intToStr(sock) + "_" + intToStr(dataSize));
|
||||||
|
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + string("_") + intToStr(__LINE__));
|
||||||
err = recv(sock, reinterpret_cast<char*>(data), dataSize, MSG_PEEK);
|
err = recv(sock, reinterpret_cast<char*>(data), dataSize, MSG_PEEK);
|
||||||
safeMutex.ReleaseLock();
|
//safeMutex.ReleaseLock();
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 EAGAIN during peek, trying again returned: %d\n",__FILE__,__FUNCTION__,__LINE__,err);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 EAGAIN during peek, trying again returned: %d\n",__FILE__,__FUNCTION__,__LINE__,err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1326,7 +1331,7 @@ bool Socket::isReadable() {
|
||||||
{
|
{
|
||||||
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
|
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
i= select((int)sock + 1, &set, NULL, NULL, &tv);
|
i= select((int)sock + 1, &set, NULL, NULL, &tv);
|
||||||
safeMutex.ReleaseLock();
|
//safeMutex.ReleaseLock();
|
||||||
}
|
}
|
||||||
if(i < 0) {
|
if(i < 0) {
|
||||||
//if(difftime(time(NULL),lastDebugEvent) >= 1) {
|
//if(difftime(time(NULL),lastDebugEvent) >= 1) {
|
||||||
|
@ -1365,7 +1370,7 @@ bool Socket::isWritable(bool waitOnDelayedResponse) {
|
||||||
{
|
{
|
||||||
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
|
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
i = select((int)sock + 1, NULL, &set, NULL, &tv);
|
i = select((int)sock + 1, NULL, &set, NULL, &tv);
|
||||||
safeMutex.ReleaseLock();
|
//safeMutex.ReleaseLock();
|
||||||
}
|
}
|
||||||
if(i < 0 ) {
|
if(i < 0 ) {
|
||||||
//if(difftime(time(NULL),lastDebugEvent) >= 1) {
|
//if(difftime(time(NULL),lastDebugEvent) >= 1) {
|
||||||
|
@ -1548,7 +1553,7 @@ void ClientSocket::connect(const Ip &ip, int port)
|
||||||
{
|
{
|
||||||
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
|
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
err = select((int)sock + 1, NULL, &myset, NULL, &tv);
|
err = select((int)sock + 1, NULL, &myset, NULL, &tv);
|
||||||
safeMutex.ReleaseLock();
|
//safeMutex.ReleaseLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err < 0 && getLastSocketError() != PLATFORM_SOCKET_INTERRUPTED) {
|
if (err < 0 && getLastSocketError() != PLATFORM_SOCKET_INTERRUPTED) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user