- added an earlier attempt to help lagging clients recover when they start to fall behind.
This commit is contained in:
parent
8feaebb503
commit
a8a3275036
|
@ -264,12 +264,12 @@ void ServerInterface::updateSlot(ConnectionSlotEvent *event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only call when client has just sent us data
|
// Only call when client has just sent us data
|
||||||
bool ServerInterface::clientLagCheck(ConnectionSlot* connectionSlot) {
|
std::pair<bool,bool> ServerInterface::clientLagCheck(ConnectionSlot* connectionSlot) {
|
||||||
bool clientLagExceeded = false;
|
std::pair<bool,bool> clientLagExceededOrWarned = std::make_pair(false,false);
|
||||||
|
|
||||||
static bool alreadyInLagCheck = false;
|
static bool alreadyInLagCheck = false;
|
||||||
if(alreadyInLagCheck == true) {
|
if(alreadyInLagCheck == true) {
|
||||||
return clientLagExceeded;
|
return clientLagExceededOrWarned;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -306,7 +306,7 @@ bool ServerInterface::clientLagCheck(ConnectionSlot* connectionSlot) {
|
||||||
// New lag check
|
// New lag check
|
||||||
if((maxFrameCountLagAllowed > 0 && clientLagCount > maxFrameCountLagAllowed) ||
|
if((maxFrameCountLagAllowed > 0 && clientLagCount > maxFrameCountLagAllowed) ||
|
||||||
(maxClientLagTimeAllowed > 0 && clientLagTime > maxClientLagTimeAllowed)) {
|
(maxClientLagTimeAllowed > 0 && clientLagTime > maxClientLagTimeAllowed)) {
|
||||||
clientLagExceeded = true;
|
clientLagExceededOrWarned.first = true;
|
||||||
char szBuf[4096]="";
|
char szBuf[4096]="";
|
||||||
|
|
||||||
const char* msgTemplate = "DROPPING %s, exceeded max allowed LAG count of %f [time = %f], clientLag = %f [%f], disconnecting client.";
|
const char* msgTemplate = "DROPPING %s, exceeded max allowed LAG count of %f [time = %f], clientLag = %f [%f], disconnecting client.";
|
||||||
|
@ -332,6 +332,8 @@ bool ServerInterface::clientLagCheck(ConnectionSlot* connectionSlot) {
|
||||||
clientLagCount > (maxFrameCountLagAllowed * warnFrameCountLagPercent)) ||
|
clientLagCount > (maxFrameCountLagAllowed * warnFrameCountLagPercent)) ||
|
||||||
(maxClientLagTimeAllowed > 0 && warnFrameCountLagPercent > 0 &&
|
(maxClientLagTimeAllowed > 0 && warnFrameCountLagPercent > 0 &&
|
||||||
clientLagTime > (maxClientLagTimeAllowed * warnFrameCountLagPercent)) ) {
|
clientLagTime > (maxClientLagTimeAllowed * warnFrameCountLagPercent)) ) {
|
||||||
|
clientLagExceededOrWarned.second = true;
|
||||||
|
|
||||||
if(connectionSlot->getLagCountWarning() == false) {
|
if(connectionSlot->getLagCountWarning() == false) {
|
||||||
connectionSlot->setLagCountWarning(true);
|
connectionSlot->setLagCountWarning(true);
|
||||||
|
|
||||||
|
@ -363,7 +365,7 @@ bool ServerInterface::clientLagCheck(ConnectionSlot* connectionSlot) {
|
||||||
}
|
}
|
||||||
alreadyInLagCheck = false;
|
alreadyInLagCheck = false;
|
||||||
|
|
||||||
return clientLagExceeded;
|
return clientLagExceededOrWarned;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerInterface::signalClientReceiveCommands(ConnectionSlot* connectionSlot,
|
bool ServerInterface::signalClientReceiveCommands(ConnectionSlot* connectionSlot,
|
||||||
|
@ -439,14 +441,14 @@ void ServerInterface::update() {
|
||||||
|
|
||||||
// Step #2 check all connection slot worker threads for completed status
|
// Step #2 check all connection slot worker threads for completed status
|
||||||
std::map<int,bool> slotsCompleted;
|
std::map<int,bool> slotsCompleted;
|
||||||
|
std::map<int,bool> slotsWarnedAndRetried;
|
||||||
for(bool threadsDone = false; threadsDone == false;) {
|
for(bool threadsDone = false; threadsDone == false;) {
|
||||||
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) {
|
||||||
ConnectionSlot* connectionSlot = slots[i];
|
ConnectionSlot* connectionSlot = slots[i];
|
||||||
if(connectionSlot != NULL &&
|
if(connectionSlot != NULL && mapSlotSignalledList[i] == true &&
|
||||||
mapSlotSignalledList[i] == true &&
|
slotsCompleted.find(i) == slotsCompleted.end()) {
|
||||||
slotsCompleted.find(i) == slotsCompleted.end()) {
|
|
||||||
try {
|
try {
|
||||||
std::vector<std::string> errorList = connectionSlot->getThreadErrorList();
|
std::vector<std::string> errorList = connectionSlot->getThreadErrorList();
|
||||||
// Show any collected errors from threads
|
// Show any collected errors from threads
|
||||||
|
@ -474,19 +476,24 @@ void ServerInterface::update() {
|
||||||
connectionSlot = slots[i];
|
connectionSlot = slots[i];
|
||||||
|
|
||||||
// New lag check
|
// New lag check
|
||||||
bool clientLagExceeded = false;
|
std::pair<bool,bool> clientLagExceededOrWarned = std::make_pair(false,false);
|
||||||
if( gameHasBeenInitiated == true && connectionSlot != NULL &&
|
if( gameHasBeenInitiated == true && connectionSlot != NULL &&
|
||||||
connectionSlot->isConnected() == true) {
|
connectionSlot->isConnected() == true) {
|
||||||
clientLagExceeded = clientLagCheck(connectionSlot);
|
clientLagExceededOrWarned = clientLagCheck(connectionSlot);
|
||||||
}
|
}
|
||||||
// If the client has exceeded lag and the server wants
|
// If the client has exceeded lag and the server wants
|
||||||
// to pause while they catch up, re-trigger the
|
// to pause while they catch up, re-trigger the
|
||||||
// client reader thread
|
// client reader thread
|
||||||
if(clientLagExceeded == true && gameSettings.getNetworkPauseGameForLaggedClients() == true) {
|
if((clientLagExceededOrWarned.first == true && gameSettings.getNetworkPauseGameForLaggedClients() == true) ||
|
||||||
|
(clientLagExceededOrWarned.second == true && slotsWarnedAndRetried[i] == false)) {
|
||||||
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];
|
||||||
signalClientReceiveCommands(connectionSlot,i,socketTriggered,event);
|
signalClientReceiveCommands(connectionSlot,i,socketTriggered,event);
|
||||||
sleep(0);
|
sleep(0);
|
||||||
|
|
||||||
|
if(gameSettings.getNetworkPauseGameForLaggedClients() == false) {
|
||||||
|
slotsWarnedAndRetried[i] = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
slotsCompleted[i] = true;
|
slotsCompleted[i] = true;
|
||||||
|
@ -510,9 +517,9 @@ void ServerInterface::update() {
|
||||||
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
||||||
if(connectionSlot->getPendingNetworkCommandList().size() > 0) {
|
if(connectionSlot->getPendingNetworkCommandList().size() > 0) {
|
||||||
// New lag check
|
// New lag check
|
||||||
bool clientLagExceeded = clientLagCheck(connectionSlot);
|
std::pair<bool,bool> clientLagExceededOrWarned = clientLagCheck(connectionSlot);
|
||||||
if(clientLagExceeded) {
|
if(clientLagExceededOrWarned.first == true) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] slotIndex = %d, clientLagExceeded = %d\n",__FILE__,__FUNCTION__,__LINE__,i,clientLagExceeded);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] slotIndex = %d, clientLagExceeded = %d, warned = %d\n",__FILE__,__FUNCTION__,__LINE__,i,clientLagExceededOrWarned.first,clientLagExceededOrWarned.second);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
vector<NetworkCommand> vctPendingNetworkCommandList = connectionSlot->getPendingNetworkCommandList();
|
vector<NetworkCommand> vctPendingNetworkCommandList = connectionSlot->getPendingNetworkCommandList();
|
||||||
|
@ -983,12 +990,12 @@ void ServerInterface::broadcastMessage(const NetworkMessage* networkMessage, int
|
||||||
ConnectionSlot* connectionSlot = slots[i];
|
ConnectionSlot* connectionSlot = slots[i];
|
||||||
|
|
||||||
// New lag check
|
// New lag check
|
||||||
bool clientLagExceeded = false;
|
std::pair<bool,bool> clientLagExceededOrWarned = std::make_pair(false,false);
|
||||||
if( gameHasBeenInitiated == true && connectionSlot != NULL &&
|
if( gameHasBeenInitiated == true && connectionSlot != NULL &&
|
||||||
connectionSlot->isConnected() == true) {
|
connectionSlot->isConnected() == true) {
|
||||||
clientLagExceeded = clientLagCheck(connectionSlot);
|
clientLagExceededOrWarned = clientLagCheck(connectionSlot);
|
||||||
}
|
}
|
||||||
if(clientLagExceeded == false) {
|
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];
|
||||||
|
@ -1057,12 +1064,12 @@ void ServerInterface::broadcastMessage(const NetworkMessage* networkMessage, int
|
||||||
|
|
||||||
if(i != excludeSlot && connectionSlot != NULL) {
|
if(i != excludeSlot && connectionSlot != NULL) {
|
||||||
// New lag check
|
// New lag check
|
||||||
bool clientLagExceeded = false;
|
std::pair<bool,bool> clientLagExceededOrWarned = std::make_pair(false,false);
|
||||||
if( gameHasBeenInitiated == true && connectionSlot != NULL &&
|
if( gameHasBeenInitiated == true && connectionSlot != NULL &&
|
||||||
connectionSlot->isConnected() == true) {
|
connectionSlot->isConnected() == true) {
|
||||||
clientLagExceeded = clientLagCheck(connectionSlot);
|
clientLagExceededOrWarned = clientLagCheck(connectionSlot);
|
||||||
}
|
}
|
||||||
if(clientLagExceeded == false) {
|
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);
|
||||||
|
|
|
@ -80,7 +80,7 @@ public:
|
||||||
virtual void slotUpdateTask(ConnectionSlotEvent *event);
|
virtual void slotUpdateTask(ConnectionSlotEvent *event);
|
||||||
bool hasClientConnection();
|
bool hasClientConnection();
|
||||||
int getCurrentFrameCount() const { return currentFrameCount; }
|
int getCurrentFrameCount() const { return currentFrameCount; }
|
||||||
bool clientLagCheck(ConnectionSlot* connectionSlot);
|
std::pair<bool,bool> clientLagCheck(ConnectionSlot* connectionSlot);
|
||||||
|
|
||||||
bool signalClientReceiveCommands(ConnectionSlot* connectionSlot,
|
bool signalClientReceiveCommands(ConnectionSlot* connectionSlot,
|
||||||
int slotIndex,
|
int slotIndex,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user