mirror of
https://github.com/glest/glest-source.git
synced 2025-09-03 04:52:34 +02:00
- more bugfixes for ping logic
This commit is contained in:
@@ -49,6 +49,7 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
|
|||||||
MenuState(program, mainMenu, "connected-game") //← set on connected-game
|
MenuState(program, mainMenu, "connected-game") //← set on connected-game
|
||||||
{
|
{
|
||||||
lastNetworkSendPing = 0;
|
lastNetworkSendPing = 0;
|
||||||
|
pingCount = 0;
|
||||||
|
|
||||||
returnMenuInfo=joinMenuInfo;
|
returnMenuInfo=joinMenuInfo;
|
||||||
Lang &lang= Lang::getInstance();
|
Lang &lang= Lang::getInstance();
|
||||||
@@ -366,15 +367,19 @@ void MenuStateConnectedGame::update()
|
|||||||
if(difftime(time(NULL),lastNetworkSendPing) >= GameConstants::networkPingInterval) {
|
if(difftime(time(NULL),lastNetworkSendPing) >= GameConstants::networkPingInterval) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to sendPingMessage...\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to sendPingMessage...\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
bool isFirstPing = (lastNetworkSendPing == 0);
|
|
||||||
lastNetworkSendPing = time(NULL);
|
lastNetworkSendPing = time(NULL);
|
||||||
clientInterface->sendPingMessage(GameConstants::networkPingInterval, time(NULL));
|
clientInterface->sendPingMessage(GameConstants::networkPingInterval, time(NULL));
|
||||||
|
|
||||||
if(isFirstPing == false && clientInterface->getLastPingLag() >= (GameConstants::networkPingInterval * 2)) {
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] pingCount = %d, clientInterface->getLastPingLag() = %f, GameConstants::networkPingInterval = %d\n",__FILE__,__FUNCTION__,__LINE__,pingCount, clientInterface->getLastPingLag(),GameConstants::networkPingInterval);
|
||||||
|
|
||||||
|
// Starting checking timeout after sending at least 3 pings to server
|
||||||
|
if(pingCount >= 3 && clientInterface->getLastPingLag() >= (GameConstants::networkPingInterval * 3)) {
|
||||||
string playerNameStr = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str());
|
string playerNameStr = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str());
|
||||||
clientInterface->sendTextMessage(playerNameStr + "'s connection timed out communicating with server.",-1);
|
clientInterface->sendTextMessage(playerNameStr + "'s connection timed out communicating with server.",-1);
|
||||||
clientInterface->close();
|
clientInterface->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pingCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -72,6 +72,7 @@ private:
|
|||||||
JoinMenu returnMenuInfo;
|
JoinMenu returnMenuInfo;
|
||||||
bool settingsReceivedFromServer;
|
bool settingsReceivedFromServer;
|
||||||
time_t lastNetworkSendPing;
|
time_t lastNetworkSendPing;
|
||||||
|
int pingCount;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@@ -140,7 +140,7 @@ public:
|
|||||||
|
|
||||||
NetworkMessagePing getLastPingInfo() const { return lastPingInfo; }
|
NetworkMessagePing getLastPingInfo() const { return lastPingInfo; }
|
||||||
double getLastPingLag() const {
|
double getLastPingLag() const {
|
||||||
return difftime(time(NULL),lastPingInfo.getPingTime());
|
return difftime(time(NULL),lastPingInfo.getPingReceivedLocalTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getIpAddress();
|
std::string getIpAddress();
|
||||||
|
@@ -147,6 +147,7 @@ void NetworkMessageIntro::send(Socket* socket) const{
|
|||||||
|
|
||||||
NetworkMessagePing::NetworkMessagePing(){
|
NetworkMessagePing::NetworkMessagePing(){
|
||||||
data.messageType= nmtPing;
|
data.messageType= nmtPing;
|
||||||
|
pingReceivedLocalTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkMessagePing::NetworkMessagePing(int32 pingFrequency, int64 pingTime){
|
NetworkMessagePing::NetworkMessagePing(int32 pingFrequency, int64 pingTime){
|
||||||
@@ -156,7 +157,9 @@ NetworkMessagePing::NetworkMessagePing(int32 pingFrequency, int64 pingTime){
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool NetworkMessagePing::receive(Socket* socket){
|
bool NetworkMessagePing::receive(Socket* socket){
|
||||||
return NetworkMessage::receive(socket, &data, sizeof(data));
|
bool result = NetworkMessage::receive(socket, &data, sizeof(data));
|
||||||
|
pingReceivedLocalTime = time(NULL);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkMessagePing::send(Socket* socket) const{
|
void NetworkMessagePing::send(Socket* socket) const{
|
||||||
|
@@ -122,6 +122,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Data data;
|
Data data;
|
||||||
|
int64 pingReceivedLocalTime;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NetworkMessagePing();
|
NetworkMessagePing();
|
||||||
@@ -129,6 +130,7 @@ public:
|
|||||||
|
|
||||||
int32 getPingFrequency() const {return data.pingFrequency;}
|
int32 getPingFrequency() const {return data.pingFrequency;}
|
||||||
int64 getPingTime() const {return data.pingTime;}
|
int64 getPingTime() const {return data.pingTime;}
|
||||||
|
int64 getPingReceivedLocalTime() const { return pingReceivedLocalTime; }
|
||||||
|
|
||||||
virtual bool receive(Socket* socket);
|
virtual bool receive(Socket* socket);
|
||||||
virtual void send(Socket* socket) const;
|
virtual void send(Socket* socket) const;
|
||||||
|
Reference in New Issue
Block a user