aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorCiaran Gultnieks <ciaran@ciarang.com>2011-05-20 20:28:03 +0100
committerCiaran Gultnieks <ciaran@ciarang.com>2011-05-20 20:28:03 +0100
commitd4d49ee8f4d425e7a4136d65f519728869680951 (patch)
tree432202d226ebf03de47210ea5172d589815ab47e /src/main.cpp
parentb5ceaf445a68b9cda47fbd4246f074aa0a1d3966 (diff)
downloadhax-minetest-server-d4d49ee8f4d425e7a4136d65f519728869680951.tar.gz
hax-minetest-server-d4d49ee8f4d425e7a4136d65f519728869680951.zip
Passwords - password entry at main menu, stored and checked by server
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 5d607b2d8..0b181a36d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -325,6 +325,8 @@ Making it more portable:
#include "materials.h"
#include "game.h"
#include "keycode.h"
+#include "sha1.h"
+#include "base64.h"
// This makes textures
ITextureSource *g_texturesource = NULL;
@@ -1170,6 +1172,7 @@ int main(int argc, char *argv[])
return 0;
}
+
/*
More parameters
*/
@@ -1324,11 +1327,15 @@ int main(int argc, char *argv[])
*/
std::wstring error_message = L"";
+ // The password entered during the menu screen,
+ std::string password;
+
/*
Menu-game loop
*/
while(device->run() && kill == false)
{
+
// This is used for catching disconnects
try
{
@@ -1428,6 +1435,25 @@ int main(int argc, char *argv[])
}
playername = wide_to_narrow(menudata.name);
+
+ // Get an sha-1 hash of the player's name combined with
+ // the password entered. That's what the server uses as
+ // their password. (Exception : if the password field is
+ // blank, we send a blank password - this is for backwards
+ // compatibility with password-less players).
+ if(menudata.password.length() > 0)
+ {
+ std::string slt=playername + wide_to_narrow(menudata.password);
+ SHA1 *sha1 = new SHA1();
+ sha1->addBytes(slt.c_str(), slt.length());
+ unsigned char *digest = sha1->getDigest();
+ password = base64_encode(digest, 20);
+ }
+ else
+ {
+ password = "";
+ }
+
address = wide_to_narrow(menudata.address);
int newport = stoi(wide_to_narrow(menudata.port));
if(newport != 0)
@@ -1474,6 +1500,7 @@ int main(int argc, char *argv[])
font,
map_dir,
playername,
+ password,
address,
port,
error_message