diff options
author | Loic Blot <loic.blot@unix-experience.fr> | 2015-03-13 16:35:21 +0100 |
---|---|---|
committer | Loic Blot <loic.blot@unix-experience.fr> | 2015-03-13 20:23:03 +0100 |
commit | 74d34da6cbb06a4d5659eb3287a87239c31da22c (patch) | |
tree | 639e35ad15a662006442431fdcc53b441f415e7f /src/server.cpp | |
parent | 9f3fc7201beedc66f974d54415b8e3fedb13ccb3 (diff) | |
download | minetest-74d34da6cbb06a4d5659eb3287a87239c31da22c.tar.gz minetest-74d34da6cbb06a4d5659eb3287a87239c31da22c.tar.bz2 minetest-74d34da6cbb06a4d5659eb3287a87239c31da22c.zip |
Prepare Protocol v25 init & authentication.
* TOSERVER_INIT and TOCLIENT_INIT renamed to _LEGACY
* TOSERVER_PASSWORD merged from dev-0.5, can use protocol v24 and v25
* TOCLIENT_ACCESS_DENIED merged from dev-0.5, can use protocol v24 and v25, with normalized strings an a custom id for custom errors
* new TOSERVER_INIT packet only send MT version, supported compressions, protocols and serialization, this permit to rework everything later without break the _INIT packet
* new TOSERVER_AUTH packet which auth the client
* new TOCLIENT_HELLO packet which send server serialization version atm
* new TOCLIENT_AUTH_ACCEPTED which is send when TOCLIENT_AUTH was okay. After this packet, the client load datas from servers, like after TOCLIENT_INIT_LEGACY packet
Diffstat (limited to 'src/server.cpp')
-rw-r--r-- | src/server.cpp | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/src/server.cpp b/src/server.cpp index b230ffd18..7e0ee7d03 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1040,7 +1040,7 @@ void Server::Receive() } catch(ClientStateError &e) { errorstream << "ProcessData: peer=" << peer_id << e.what() << std::endl; - DenyAccess(peer_id, L"Your client sent something server didn't expect." + DenyAccess_Legacy(peer_id, L"Your client sent something server didn't expect." L"Try reconnecting or updating your client"); } catch(con::PeerNotFoundException &e) { @@ -1073,13 +1073,13 @@ PlayerSAO* Server::StageTwoClientInit(u16 peer_id) if(player && player->peer_id != 0) { 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 " + DenyAccess_Legacy(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."); + DenyAccess_Legacy(peer_id, L"Could not allocate player."); } return NULL; } @@ -1173,7 +1173,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) << addr_s << "; banned name was " << ban_name << std::endl; // This actually doesn't seem to transfer to the client - DenyAccess(peer_id, L"Your ip is banned. Banned name was " + DenyAccess_Legacy(peer_id, L"Your ip is banned. Banned name was " + narrow_to_wide(ban_name)); return; } @@ -1502,7 +1502,20 @@ void Server::SendBreath(u16 peer_id, u16 breath) Send(pkt); } -void Server::SendAccessDenied(u16 peer_id,const std::wstring &reason) +void Server::SendAccessDenied(u16 peer_id, AccessDeniedCode reason, const std::wstring &custom_reason) +{ + DSTACK(__FUNCTION_NAME); + + NetworkPacket pkt(TOCLIENT_ACCESS_DENIED, 1, peer_id); + pkt << (u8) reason; + + if (reason == SERVER_ACCESSDENIED_CUSTOM_STRING) { + pkt << custom_reason; + } + Send(&pkt); +} + +void Server::SendAccessDenied_Legacy(u16 peer_id,const std::wstring &reason) { DSTACK(__FUNCTION_NAME); @@ -2525,11 +2538,22 @@ void Server::RespawnPlayer(u16 peer_id) } } -void Server::DenyAccess(u16 peer_id, const std::wstring &reason) +void Server::DenyAccess(u16 peer_id, AccessDeniedCode reason, const std::wstring &custom_reason) +{ + DSTACK(__FUNCTION_NAME); + + SendAccessDenied(peer_id, reason, custom_reason); + m_clients.event(peer_id, CSE_SetDenied); + m_con.DisconnectPeer(peer_id); +} + +// 13/03/15: remove this function when protocol version 25 will become +// the minimum version for MT users, maybe in 1 year +void Server::DenyAccess_Legacy(u16 peer_id, const std::wstring &reason) { DSTACK(__FUNCTION_NAME); - SendAccessDenied(peer_id, reason); + SendAccessDenied_Legacy(peer_id, reason); m_clients.event(peer_id, CSE_SetDenied); m_con.DisconnectPeer(peer_id); } |