From d4d49ee8f4d425e7a4136d65f519728869680951 Mon Sep 17 00:00:00 2001 From: Ciaran Gultnieks Date: Fri, 20 May 2011 20:28:03 +0100 Subject: Passwords - password entry at main menu, stored and checked by server --- src/client.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/client.cpp') diff --git a/src/client.cpp b/src/client.cpp index ce862a002..e2cda97c1 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -68,6 +68,7 @@ void * MeshUpdateThread::Thread() Client::Client( IrrlichtDevice *device, const char *playername, + std::string password, MapDrawControl &control): m_mesh_update_thread(), m_env( @@ -83,7 +84,9 @@ Client::Client( m_server_ser_ver(SER_FMT_VER_INVALID), m_inventory_updated(false), m_time_of_day(0), - m_map_seed(0) + m_map_seed(0), + m_password(password), + m_access_denied(false) { m_packetcounter_timer = 0.0; m_delete_unused_sectors_timer = 0.0; @@ -299,11 +302,14 @@ void Client::step(float dtime) // [0] u16 TOSERVER_INIT // [2] u8 SER_FMT_VER_HIGHEST // [3] u8[20] player_name - SharedBuffer data(2+1+PLAYERNAME_SIZE); + // [23] u8[28] password + SharedBuffer data(2+1+PLAYERNAME_SIZE+PASSWORD_SIZE); writeU16(&data[0], TOSERVER_INIT); writeU8(&data[2], SER_FMT_VER_HIGHEST); memset((char*)&data[3], 0, PLAYERNAME_SIZE); snprintf((char*)&data[3], PLAYERNAME_SIZE, "%s", myplayer->getName()); + snprintf((char*)&data[23], PASSWORD_SIZE, "%s", m_password.c_str()); + // Send as unreliable Send(0, data, false); } @@ -597,7 +603,16 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) return; } - + + if(command == TOCLIENT_ACCESS_DENIED) + { + // The server didn't like our password. Note, this needs + // to be processed even if the serialisation format has + // not been agreed yet, the same as TOCLIENT_INIT. + m_access_denied = true; + return; + } + if(ser_version == SER_FMT_VER_INVALID) { dout_client<