From 198632673196c87c5ba549721300d2e2b452f28b Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Tue, 18 Jan 2011 00:26:09 +0200 Subject: [PATCH] fixed erroneus handling of many players with no peer existing at same time --- src/server.cpp | 35 +++++++++++++++++++++++++++++++---- src/server.h | 13 ++++++++----- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/server.cpp b/src/server.cpp index 17004a80..d962c481 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1567,9 +1567,18 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) playername[playername_size-1] = 0; // Get player - Player *player = emergePlayer(playername, ""); + Player *player = emergePlayer(playername, "", peer_id); //Player *player = m_env.getPlayer(peer_id); + // If failed, cancel + if(player == NULL) + { + derr_server<peer_id != 0) { @@ -1579,9 +1588,9 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) <peer_id<<")"<peer_id = peer_id; + */ // Check if player doesn't exist if(player == NULL) @@ -3091,7 +3100,8 @@ RemoteClient* Server::getClient(u16 peer_id) return n->getValue(); } -Player *Server::emergePlayer(const char *name, const char *password) +Player *Server::emergePlayer(const char *name, const char *password, + u16 peer_id) { /* Try to get an existing player @@ -3099,9 +3109,25 @@ Player *Server::emergePlayer(const char *name, const char *password) Player *player = m_env.getPlayer(name); if(player != NULL) { + // If player is already connected, cancel + if(player->peer_id != 0) + { + dstream<<"emergePlayer(): Player already connected"<peer_id = c.peer_id; - player->peer_id = PEER_ID_INEXISTENT; + //player->peer_id = PEER_ID_INEXISTENT; + player->peer_id = peer_id; player->updateName(name); /* diff --git a/src/server.h b/src/server.h index 4bdaa845..9c655b9a 100644 --- a/src/server.h +++ b/src/server.h @@ -437,11 +437,14 @@ private: // When called, connection mutex should be locked RemoteClient* getClient(u16 peer_id); - // Gets a player from memory or creates one. - // Caller should check isClientConnected() and set it appropriately. - // - // Call with env and con locked. - Player *emergePlayer(const char *name, const char *password); + /* + Get a player from memory or creates one. + If player is already connected, return NULL + + Call with env and con locked. + */ + Player *emergePlayer(const char *name, const char *password, + u16 peer_id); /* Update water pressure.