diff options
Diffstat (limited to 'src/client.cpp')
-rw-r--r-- | src/client.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/client.cpp b/src/client.cpp index c85d6e9e2..5869dc77b 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1602,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); |