Skip to content

Commit 61f2409

Browse files
committedAug 6, 2013
Clean up server's log messages and give a better error to client when its player is in use
1 parent 14eab22 commit 61f2409

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed
 

‎src/server.cpp

+26-19
Original file line numberDiff line numberDiff line change
@@ -1810,14 +1810,13 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
18101810
if(datasize < 2+1+PLAYERNAME_SIZE)
18111811
return;
18121812

1813-
verbosestream<<"Server: Got TOSERVER_INIT from "
1814-
<<peer_id<<std::endl;
1813+
verbosestream<<"Server: Got TOSERVER_INIT from "<<addr_s<<std::endl;
18151814

18161815
// Do not allow multiple players in simple singleplayer mode.
18171816
// This isn't a perfect way to do it, but will suffice for now.
18181817
if(m_simple_singleplayer_mode && m_clients.size() > 1){
1819-
infostream<<"Server: Not allowing another client to connect in"
1820-
<<" simple singleplayer mode"<<std::endl;
1818+
infostream<<"Server: Not allowing another client ("<<addr_s
1819+
<<") to connect in simple singleplayer mode"<<std::endl;
18211820
DenyAccess(peer_id, L"Running in simple singleplayer mode.");
18221821
return;
18231822
}
@@ -1839,9 +1838,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
18391838
{
18401839
actionstream<<"Server: A mismatched client tried to connect from "
18411840
<<addr_s<<std::endl;
1842-
infostream<<"Server: Cannot negotiate "
1843-
"serialization version with peer "
1844-
<<peer_id<<std::endl;
1841+
infostream<<"Server: Cannot negotiate serialization version with "
1842+
<<addr_s<<std::endl;
18451843
DenyAccess(peer_id, std::wstring(
18461844
L"Your client's version is not supported.\n"
18471845
L"Server version is ")
@@ -1879,7 +1877,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
18791877
net_proto_version = max_net_proto_version;
18801878
}
18811879

1882-
verbosestream<<"Server: "<<peer_id<<" Protocol version: min: "
1880+
verbosestream<<"Server: "<<addr_s<<": Protocol version: min: "
18831881
<<min_net_proto_version<<", max: "<<max_net_proto_version
18841882
<<", chosen: "<<net_proto_version<<std::endl;
18851883

@@ -1888,8 +1886,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
18881886
if(net_proto_version < SERVER_PROTOCOL_VERSION_MIN ||
18891887
net_proto_version > SERVER_PROTOCOL_VERSION_MAX)
18901888
{
1891-
actionstream<<"Server: A mismatched client tried to connect from "<<addr_s
1892-
<<std::endl;
1889+
actionstream<<"Server: A mismatched client tried to connect from "
1890+
<<addr_s<<std::endl;
18931891
DenyAccess(peer_id, std::wstring(
18941892
L"Your client's version is not supported.\n"
18951893
L"Server version is ")
@@ -1957,14 +1955,14 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
19571955

19581956
if(!isSingleplayer() && strcasecmp(playername, "singleplayer") == 0)
19591957
{
1960-
actionstream<<"Server: Player with an invalid name "
1958+
actionstream<<"Server: Player with the name \"singleplayer\" "
19611959
<<"tried to connect from "<<addr_s<<std::endl;
19621960
DenyAccess(peer_id, L"Name is not allowed");
19631961
return;
19641962
}
19651963

19661964
infostream<<"Server: New connection: \""<<playername<<"\" from "
1967-
<<m_con.GetPeerAddress(peer_id).serializeString()<<std::endl;
1965+
<<addr_s<<" (peer_id="<<peer_id<<")"<<std::endl;
19681966

19691967
// Get password
19701968
char given_password[PASSWORD_SIZE];
@@ -2041,9 +2039,9 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
20412039
}
20422040

20432041
if(given_password != checkpwd){
2044-
actionstream<<"Server: "<<playername<<" supplied invalid password"
2045-
<<" (peer_id="<<peer_id<<")"<<std::endl;
2046-
DenyAccess(peer_id, L"Invalid password");
2042+
actionstream<<"Server: "<<playername<<" supplied wrong password"
2043+
<<std::endl;
2044+
DenyAccess(peer_id, L"Wrong password");
20472045
return;
20482046
}
20492047

@@ -2053,10 +2051,19 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
20532051
// If failed, cancel
20542052
if(playersao == NULL)
20552053
{
2056-
errorstream<<"Server: peer_id="<<peer_id
2057-
<<": failed to emerge player"<<std::endl;
2058-
DenyAccess(peer_id, L"Could not allocate player. You"
2059-
" may need to wait for a timeout.");
2054+
RemotePlayer *player =
2055+
static_cast<RemotePlayer*>(m_env->getPlayer(playername));
2056+
if(player && player->peer_id != 0){
2057+
errorstream<<"Server: "<<playername<<": Failed to emerge player"
2058+
<<" (player allocated to an another client)"<<std::endl;
2059+
DenyAccess(peer_id, L"Another client is connected with this "
2060+
L"name. If your client closed unexpectedly, try again in "
2061+
L"a minute.");
2062+
} else {
2063+
errorstream<<"Server: "<<playername<<": Failed to emerge player"
2064+
<<std::endl;
2065+
DenyAccess(peer_id, L"Could not allocate player.");
2066+
}
20602067
return;
20612068
}
20622069

0 commit comments

Comments
 (0)
Please sign in to comment.