Clean up server's log messages and give a better error to client when its player is in use

This commit is contained in:
Perttu Ahola 2013-08-06 18:13:11 +03:00
parent 14eab22d81
commit 61f240946a

@ -1810,14 +1810,13 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
if(datasize < 2+1+PLAYERNAME_SIZE) if(datasize < 2+1+PLAYERNAME_SIZE)
return; return;
verbosestream<<"Server: Got TOSERVER_INIT from " verbosestream<<"Server: Got TOSERVER_INIT from "<<addr_s<<std::endl;
<<peer_id<<std::endl;
// Do not allow multiple players in simple singleplayer mode. // Do not allow multiple players in simple singleplayer mode.
// This isn't a perfect way to do it, but will suffice for now. // This isn't a perfect way to do it, but will suffice for now.
if(m_simple_singleplayer_mode && m_clients.size() > 1){ if(m_simple_singleplayer_mode && m_clients.size() > 1){
infostream<<"Server: Not allowing another client to connect in" infostream<<"Server: Not allowing another client ("<<addr_s
<<" simple singleplayer mode"<<std::endl; <<") to connect in simple singleplayer mode"<<std::endl;
DenyAccess(peer_id, L"Running in simple singleplayer mode."); DenyAccess(peer_id, L"Running in simple singleplayer mode.");
return; return;
} }
@ -1839,9 +1838,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
{ {
actionstream<<"Server: A mismatched client tried to connect from " actionstream<<"Server: A mismatched client tried to connect from "
<<addr_s<<std::endl; <<addr_s<<std::endl;
infostream<<"Server: Cannot negotiate " infostream<<"Server: Cannot negotiate serialization version with "
"serialization version with peer " <<addr_s<<std::endl;
<<peer_id<<std::endl;
DenyAccess(peer_id, std::wstring( DenyAccess(peer_id, std::wstring(
L"Your client's version is not supported.\n" L"Your client's version is not supported.\n"
L"Server version is ") L"Server version is ")
@ -1879,7 +1877,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
net_proto_version = max_net_proto_version; net_proto_version = max_net_proto_version;
} }
verbosestream<<"Server: "<<peer_id<<" Protocol version: min: " verbosestream<<"Server: "<<addr_s<<": Protocol version: min: "
<<min_net_proto_version<<", max: "<<max_net_proto_version <<min_net_proto_version<<", max: "<<max_net_proto_version
<<", chosen: "<<net_proto_version<<std::endl; <<", chosen: "<<net_proto_version<<std::endl;
@ -1888,8 +1886,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
if(net_proto_version < SERVER_PROTOCOL_VERSION_MIN || if(net_proto_version < SERVER_PROTOCOL_VERSION_MIN ||
net_proto_version > SERVER_PROTOCOL_VERSION_MAX) net_proto_version > SERVER_PROTOCOL_VERSION_MAX)
{ {
actionstream<<"Server: A mismatched client tried to connect from "<<addr_s actionstream<<"Server: A mismatched client tried to connect from "
<<std::endl; <<addr_s<<std::endl;
DenyAccess(peer_id, std::wstring( DenyAccess(peer_id, std::wstring(
L"Your client's version is not supported.\n" L"Your client's version is not supported.\n"
L"Server version is ") L"Server version is ")
@ -1957,14 +1955,14 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
if(!isSingleplayer() && strcasecmp(playername, "singleplayer") == 0) if(!isSingleplayer() && strcasecmp(playername, "singleplayer") == 0)
{ {
actionstream<<"Server: Player with an invalid name " actionstream<<"Server: Player with the name \"singleplayer\" "
<<"tried to connect from "<<addr_s<<std::endl; <<"tried to connect from "<<addr_s<<std::endl;
DenyAccess(peer_id, L"Name is not allowed"); DenyAccess(peer_id, L"Name is not allowed");
return; return;
} }
infostream<<"Server: New connection: \""<<playername<<"\" from " infostream<<"Server: New connection: \""<<playername<<"\" from "
<<m_con.GetPeerAddress(peer_id).serializeString()<<std::endl; <<addr_s<<" (peer_id="<<peer_id<<")"<<std::endl;
// Get password // Get password
char given_password[PASSWORD_SIZE]; char given_password[PASSWORD_SIZE];
@ -2041,9 +2039,9 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
} }
if(given_password != checkpwd){ if(given_password != checkpwd){
actionstream<<"Server: "<<playername<<" supplied invalid password" actionstream<<"Server: "<<playername<<" supplied wrong password"
<<" (peer_id="<<peer_id<<")"<<std::endl; <<std::endl;
DenyAccess(peer_id, L"Invalid password"); DenyAccess(peer_id, L"Wrong password");
return; return;
} }
@ -2053,10 +2051,19 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
// If failed, cancel // If failed, cancel
if(playersao == NULL) if(playersao == NULL)
{ {
errorstream<<"Server: peer_id="<<peer_id RemotePlayer *player =
<<": failed to emerge player"<<std::endl; static_cast<RemotePlayer*>(m_env->getPlayer(playername));
DenyAccess(peer_id, L"Could not allocate player. You" if(player && player->peer_id != 0){
" may need to wait for a timeout."); errorstream<<"Server: "<<playername<<": Failed to emerge player"
<<" (player allocated to an another client)"<<std::endl;
DenyAccess(peer_id, L"Another client is connected with this "
L"name. If your client closed unexpectedly, try again in "
L"a minute.");
} else {
errorstream<<"Server: "<<playername<<": Failed to emerge player"
<<std::endl;
DenyAccess(peer_id, L"Could not allocate player.");
}
return; return;
} }