]> git.lizzy.rs Git - minetest.git/blobdiff - src/client.cpp
* better glass graphics
[minetest.git] / src / client.cpp
index ec2504bc823f45920f9d82335eb7181696e47e58..5869dc77bbab1714d1e12d6395b890811578327a 100644 (file)
@@ -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<u8> data(2+1+PLAYERNAME_SIZE);
+                       // [23] u8[28] password
+                       SharedBuffer<u8> 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);
                }
@@ -546,8 +552,6 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
 
        //dstream<<"Client received command="<<(int)command<<std::endl;
 
-       // Execute fast commands straight away
-
        if(command == TOCLIENT_INIT)
        {
                if(datasize < 3)
@@ -599,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<<DTIME<<"WARNING: Client: Server serialization"
@@ -1180,31 +1193,23 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
                if(datasize < 4)
                        return;
                
-               u16 time = readU16(&data[2]);
-               time = time % 24000;
-               m_time_of_day = time;
-               //dstream<<"Client: time="<<time<<std::endl;
+               u16 time_of_day = readU16(&data[2]);
+               time_of_day = time_of_day % 24000;
+               //dstream<<"Client: time_of_day="<<time_of_day<<std::endl;
                
                /*
-                       Day/night
-
                        time_of_day:
                        0 = midnight
                        12000 = midday
                */
                {
-                       u32 dr = time_to_daynight_ratio(m_time_of_day);
+                       m_env.setTimeOfDay(time_of_day);
 
-                       dstream<<"Client: time_of_day="<<m_time_of_day
+                       u32 dr = m_env.getDayNightRatio();
+
+                       dstream<<"Client: time_of_day="<<time_of_day
                                        <<", dr="<<dr
                                        <<std::endl;
-                       
-                       if(dr != m_env.getDayNightRatio())
-                       {
-                               dout_client<<DTIME<<"Client: changing day-night ratio"<<std::endl;
-                               m_env.setDayNightRatio(dr);
-                               m_env.expireMeshes(true);
-                       }
                }
 
        }
@@ -1597,6 +1602,43 @@ void Client::sendChatMessage(const std::wstring &message)
        Send(0, data, true);
 }
 
+void Client::sendChangePassword(const std::wstring oldpassword,
+               const std::wstring newpassword)
+{
+       Player *player = m_env.getLocalPlayer();
+       if(player == NULL)
+               return;
+
+       std::string playername = player->getName();
+       std::string oldpwd = translatePassword(playername, oldpassword);
+       std::string newpwd = translatePassword(playername, newpassword);
+
+       std::ostringstream os(std::ios_base::binary);
+       u8 buf[2+PASSWORD_SIZE*2];
+       /*
+               [0] u16 TOSERVER_PASSWORD
+               [2] u8[28] old password
+               [30] u8[28] new password
+       */
+
+       writeU16(buf, TOSERVER_PASSWORD);
+       for(u32 i=0;i<PASSWORD_SIZE-1;i++)
+       {
+               buf[2+i] = i<oldpwd.length()?oldpwd[i]:0;
+               buf[30+i] = i<newpwd.length()?newpwd[i]:0;
+       }
+       buf[2+PASSWORD_SIZE-1] = 0;
+       buf[30+PASSWORD_SIZE-1] = 0;
+       os.write((char*)buf, 2+PASSWORD_SIZE*2);
+
+       // Make data buffer
+       std::string s = os.str();
+       SharedBuffer<u8> data((u8*)s.c_str(), s.size());
+       // Send as reliable
+       Send(0, data, true);
+}
+
+
 void Client::sendDamage(u8 damage)
 {
        DSTACK(__FUNCTION_NAME);