Skip to content

Commit

Permalink
ping clients who haven't finished logging in
Browse files Browse the repository at this point in the history
I noticed that we were only pinging clients that have successfully logged all the way in.  Maybe it will help to ping clients that are having troubles connecting?  Or maybe it won't help at all.  We'll find out.

I made it so that it only sends a 1-way "poke" to those clients like we do with in-game players.
  • Loading branch information
tra committed Feb 12, 2025
1 parent 71111ac commit b10a9af
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
36 changes: 26 additions & 10 deletions src/game/CNetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,17 +925,33 @@ void CNetManager::ViewControl() {
playerTable[itsCommManager->myId]->ViewControl();
}

void CNetManager::SendPingCommand(int trips) {
void CNetManager::SendPingCommand(int pingTrips) {
// there & back = 2 trips... send less to/from players in game
int notMe = totalDistribution & ~(1 << itsCommManager->myId);
int playingDist = (itsGame->gameStatus == kPlayingStatus) ? activePlayersDistribution : 0;
// only send 1-way pings to/from active players just to keep the connection alive
int activeTrips = 1;
int inactiveTrips = isPlaying ? activeTrips : trips;
itsCommManager->SendPacket(playingDist & notMe,
kpPing, 0, 0, activeTrips-1, 0, NULL);
itsCommManager->SendPacket(~playingDist & notMe,
kpPing, 0, 0, inactiveTrips-1, 0, NULL);
// a "poke" is a one-way ping, for just keeping the connection open with less traffic
int pokeTrips = 1;
int pokeDist = activePlayersDistribution;

// send periodic poke to those who have NOT finished logging in in hopes that it will help get their connection going
pokeDist |= ~totalDistribution;

if (isPlaying) {
// if I'm playing, ONLY send pokes
pokeDist = kdEveryone;
}

// normal pings for everyone else
int pingDist = ~pokeDist;

// but don't ping/poke myself
pokeDist &= ~(1 << itsCommManager->myId);
pingDist &= ~(1 << itsCommManager->myId);

// SDL_Log("pokeDist = %x, pingDist = %x\n", pokeDist, pingDist);

itsCommManager->SendPacket(pokeDist,
kpPing, 0, 0, pokeTrips-1, 0, NULL);
itsCommManager->SendPacket(pingDist,
kpPing, 0, 0, pingTrips-1, 0, NULL);
}

bool CNetManager::CanPlay() {
Expand Down
4 changes: 4 additions & 0 deletions src/net/CUDPComm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,10 @@ void CUDPComm::ReadComplete(UDPpacket *packet) {
char *inEnd;
short inLen;

#if PACKET_DEBUG > 2
SDL_Log("CUDPComm::ReadComplete raw packet from=%s\n", FormatAddr(packet->address).c_str());
#endif

#if SIMULATE_LATENCY_ON_CLIENTS
SIMULATE_LATENCY_CODE("read")
#endif
Expand Down

0 comments on commit b10a9af

Please sign in to comment.