aboutsummaryrefslogtreecommitdiff
path: root/src/server.cpp
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-01-18 00:26:09 +0200
committerPerttu Ahola <celeron55@gmail.com>2011-01-18 00:26:09 +0200
commit198632673196c87c5ba549721300d2e2b452f28b (patch)
treea5cbc09d84cdaaf32a04699de0e94c8c28effb4e /src/server.cpp
parenta35d8dabcf5cdb5677849b84b4fbfb09a6fafad5 (diff)
downloadminetest-198632673196c87c5ba549721300d2e2b452f28b.tar.gz
minetest-198632673196c87c5ba549721300d2e2b452f28b.tar.bz2
minetest-198632673196c87c5ba549721300d2e2b452f28b.zip
fixed erroneus handling of many players with no peer existing at same time
Diffstat (limited to 'src/server.cpp')
-rw-r--r--src/server.cpp35
1 files changed, 31 insertions, 4 deletions
diff --git a/src/server.cpp b/src/server.cpp
index 17004a803..d962c4811 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<<DTIME<<"Server: peer_id="<<peer_id
+ <<": failed to emerge player"<<std::endl;
+ return;
+ }
+
+ /*
// If a client is already connected to the player, cancel
if(player->peer_id != 0)
{
@@ -1579,9 +1588,9 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
<<player->peer_id<<")"<<std::endl;
return;
}
-
// Set client of player
player->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"<<std::endl;
+ return NULL;
+ }
// Got one.
return player;
}
+
+ /*
+ If player with the wanted peer_id already exists, cancel.
+ */
+ if(m_env.getPlayer(peer_id) != NULL)
+ {
+ dstream<<"emergePlayer(): Player with wrong name but same"
+ " peer_id already exists"<<std::endl;
+ return NULL;
+ }
/*
Create a new player
@@ -3109,7 +3135,8 @@ Player *Server::emergePlayer(const char *name, const char *password)
{
player = new ServerRemotePlayer();
//player->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);
/*