try to be more judicious when cleaning up idlers and entering and leaving sessions

This commit is contained in:
Tim Felgentreff 2017-06-07 15:25:57 +02:00
parent f5b1ede7f7
commit bbad7f22be
3 changed files with 12 additions and 4 deletions

View file

@ -89,6 +89,9 @@ void CreateGame(Session *session, char *description, char *map,
game->Prev = NULL;
Games = game;
if (session->Game) {
PartGame(session);
}
session->Game = game;
}
@ -120,6 +123,7 @@ int CancelGame(Session *session)
game->Sessions[i]->Game = NULL;
}
session->Game = NULL;
delete game;
return 0;
}
@ -145,7 +149,7 @@ int JoinGame(Session *session, int id, char *password, unsigned long *host, int
GameData *game;
if (session->Game) {
return -1; // Already in a game
PartGame(session);
}
game = Games;

View file

@ -42,6 +42,7 @@
#endif
#include "stratagus.h"
#include "games.h"
#include "netdriver.h"
#include "net_lowlevel.h"
@ -228,6 +229,7 @@ static int KillSession(Session *session)
NetCloseTCP(session->Sock);
Pool->Sockets->DelSocket(session->Sock);
UNLINK(Pool->First, session, Pool->Last, Pool->Count);
PartGame(session);
delete session;
return 0;
}

View file

@ -157,9 +157,11 @@ void CMetaClient::Close()
int CMetaClient::Send(const std::string cmd)
{
int ret = -1;
std::string mes(cmd);
mes.append("\n");
ret = metaSocket.Send(mes.c_str(), mes.size());
if (metaSocket.IsValid()) {
std::string mes(cmd);
mes.append("\n");
ret = metaSocket.Send(mes.c_str(), mes.size());
}
return ret;
}