mail[Wesnoth-commits] r28630 - in /trunk/src: menu_events.cpp multiplayer.cpp multiplayer_ui.cpp multiplayer_ui.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by thomas . baumhauer on August 16, 2008 - 12:36:
Author: baufo
Date: Sat Aug 16 12:36:09 2008
New Revision: 28630

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28630&view=rev
Log:
Initial commit of client registration code

Modified:
    trunk/src/menu_events.cpp
    trunk/src/multiplayer.cpp
    trunk/src/multiplayer_ui.cpp
    trunk/src/multiplayer_ui.hpp

Modified: trunk/src/menu_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/menu_events.cpp?rev=28630&r1=28629&r2=28630&view=diff
==============================================================================
--- trunk/src/menu_events.cpp (original)
+++ trunk/src/menu_events.cpp Sat Aug 16 12:36:09 2008
@@ -2071,6 +2071,22 @@
                        void do_remove();
                        void do_display();
                        void do_version();
+
+                       //! Ask the server to register the currently used nick
+                       void do_register();
+
+                       //! Ask the server do drop the currently used (and 
registered) nick
+                       void do_drop();
+
+                       //! Update details for the currently used username
+                       void do_set();
+
+                       //! Request information about a user from the server
+                       void do_info();
+
+                       //! Request a list of details that can be set for a 
username
+                       //! as these might vary depending on the 
configuration of the server
+                       void do_details();
 
                        void print(const std::string& title, const 
std::string& message)
                        {
@@ -2115,6 +2131,17 @@
                                register_alias("list", "display");
                                register_command("version", 
&chat_command_handler::do_version,
                                        _("Display version information."));
+                               register_command("register", 
&chat_command_handler::do_register,
+                                       _("Register your nick"), "<password> 
<email (optional)>");
+                               register_command("drop", 
&chat_command_handler::do_drop,
+                                       _("Drop your nick."));
+                               register_command("set", 
&chat_command_handler::do_set,
+                                       _("Update details for your username. 
For possible details see /details"),
+                                       "<detail> <value>");
+                               register_command("info", 
&chat_command_handler::do_info,
+                                       _("Request information about a 
user."), "<nick>");
+                               register_command("details", 
&chat_command_handler::do_details,
+                                       _("Request a list of details you can 
set for your registered username."));
                        }
                private:
                        chat_handler& chat_handler_;
@@ -2462,6 +2489,69 @@
                print("version", game_config::revision);
        }
 
+       void chat_command_handler::do_register() {
+               config data;
+               config& nickserv = data.add_child("nickserv");
+
+               if (get_data(1).empty()) return command_failed_need_arg(1);
+
+               nickserv.add_child("register")["password"] = get_arg(1);
+               if(!get_data(2).empty()) {
+                       (*(nickserv.child("register")))["mail"] = get_arg(2);
+               }
+               print("nick registration", "registering with password *** and 
" +
+                               (get_data(2).empty() ? "no email address" : 
"email address " + get_data(2)));
+
+               network::send_data(data, 0, true);
+       }
+
+       void chat_command_handler::do_drop() {
+               config data;
+               config& nickserv = data.add_child("nickserv");
+
+               nickserv.add_child("drop");
+
+               print("nick registration", "dropping your username");
+
+               network::send_data(data, 0, true);
+       }
+
+       void chat_command_handler::do_set() {
+               config data;
+               config& nickserv = data.add_child("nickserv");
+
+               if (get_data(1).empty()) return command_failed_need_arg(1);
+               if (get_data(2).empty()) return command_failed_need_arg(2);
+
+               config &set = nickserv.add_child("set");
+               set["detail"] = get_arg(1);
+               set["value"] = get_data(2);
+               print("nick registration", "setting " + get_arg(1) + " to " + 
get_data(2));
+
+               network::send_data(data, 0, true);
+       }
+
+       void chat_command_handler::do_info() {
+               if (get_data(1).empty()) return command_failed_need_arg(1);
+
+               config data;
+               config& nickserv = data.add_child("nickserv");
+
+               nickserv.add_child("info")["name"] = get_data(1);
+               print("nick registration", "requesting information for user " 
+ get_data(1));
+
+               network::send_data(data, 0, true);
+       }
+
+       void chat_command_handler::do_details() {
+
+               config data;
+               config& nickserv = data.add_child("nickserv");
+               nickserv.add_child("details");
+
+               network::send_data(data, 0, true);
+       }
+
        void menu_handler::send_chat_message(const std::string& message, bool 
allies_only)
        {
                config cfg;

Modified: trunk/src/multiplayer.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/multiplayer.cpp?rev=28630&r1=28629&r2=28630&view=diff
==============================================================================
--- trunk/src/multiplayer.cpp (original)
+++ trunk/src/multiplayer.cpp Sat Aug 16 12:36:09 2008
@@ -41,6 +41,8 @@
 #include "upload_log.hpp"
 #include "wml_separators.hpp"
 
+#include "server/forum_auth/md5.hpp"
+
 #define LOG_NW LOG_STREAM(info, network)
 
 namespace {
@@ -146,7 +148,7 @@
                        } else {
                                return ABORT_SERVER;
                        }
-                       
+
                } else {
                        gui::dialog d(disp, _("Connect to Host"), "", 
gui::OK_CANCEL);
                        d.set_textbox(_("Choose host to connect to: "), 
preferences::network_host());
@@ -235,21 +237,57 @@
                        bool first_time = true;
                        config* error = NULL;
 
+                       std::vector<std::string> opts;
+                       opts.push_back(_("Log in with password"));
+                       opts.push_back(_("Request password reminder for this 
username"));
+                       opts.push_back(_("Choose a different username"));
+
                        do {
                                if(error != NULL) {
                                        
gui::dialog(disp,"",(*error)["message"],gui::OK_ONLY).show();
                                }
 
                                std::string login = preferences::login();
+                               std::string password = "";
+                               std::string password_reminder = "";
 
                                if(!first_time) {
-                                       const int res = 
gui::show_dialog(disp, NULL, "",
-                                                       _("You must log in to 
this server"), gui::OK_CANCEL,
-                                                       NULL, NULL, _("Login: 
"), &login, mp::max_login_size);
-                                       if(res != 0 || login.empty()) {
-                                               return ABORT_SERVER;
+
+                                       //Somewhat hacky implementation, 
including a goto of death
+
+                                       //! @todo A fancy textbox that 
displays characters as dots or asterisks would nice
+                                       
if(!((*error)["password_request"].empty())) {
+                                               const int res = 
gui::show_dialog(disp, NULL, _("Login"),
+                                                               
(*error)["message"], gui::OK_CANCEL,
+                                                               &opts, NULL, 
_("Password: "), &password, mp::max_login_size);
+
+                                               switch(res) {
+                                                       //Log in with password
+                                                       case 0:
+                                                               break;
+                                                       //Request a password 
reminder
+                                                       case 1:
+                                                               
password_reminder = "yes";
+                                                               break;
+                                                       //Choose a different 
username
+                                                       case 2:
+                                                               password = "";
+                                                               goto 
new_username;
+                                                               break;
+                                                       default: return 
ABORT_SERVER;
+                                               }
+
+                                       } else {
+                                               new_username:
+
+                                               const int res = 
gui::show_dialog(disp, NULL, "",
+                                                               _("You must 
log in to this server"), gui::OK_CANCEL,
+                                                               NULL, NULL, 
_("Login: "), &login, mp::max_login_size);
+                                               if(res != 0 || login.empty()) 
{
+                                                       return ABORT_SERVER;
+                                               }
+                                               preferences::set_login(login);
                                        }
-                                       preferences::set_login(login);
                                }
 
                                first_time = false;
@@ -257,6 +295,73 @@
                                config response ;
                                config &sp = response.add_child("login") ;
                                sp["username"] = login ;
+                               sp["password_reminder"] = password_reminder;
+
+                               //If password is not empty start hashing
+
+                               std::string result;
+                               if(!(password.empty())) {
+                                       std::string 
itoa64("./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
+
+                                       std::string salt = (*error)["salt"];
+                                       int hash_seed;
+                                       try {
+                                               hash_seed = 
lexical_cast_default<int>((*error)["hash_seed"]);
+                                       } catch (bad_lexical_cast) {
+                                               std::cerr << "Bad lexical 
cast reading hash_seed\n";
+                                               return ABORT_SERVER;
+                                       }
+
+                                       // Start the MD5 hashing
+                                       salt.append(password);
+                                       MD5 md5_worker;
+                                       md5_worker.update((unsigned char 
*)salt.c_str(),salt.length());
+                                       md5_worker.finalize();
+                                       unsigned char * output = (unsigned 
char *) malloc (sizeof(unsigned char) * 16);
+                                       output = md5_worker.raw_digest();
+                                       std::string temp_hash;
+                                       do {
+                                               temp_hash = std::string((char 
*) output, (char *) output + 16);
+                                               temp_hash.append(password);   
                                                                  
+                                               md5_worker.~MD5();
+                                               MD5 md5_worker;
+                                               md5_worker.update((unsigned 
char *)temp_hash.c_str(),temp_hash.length());
+                                               md5_worker.finalize();
+                                               output =  
md5_worker.raw_digest();
+                                       } while (--hash_seed);
+                                       temp_hash = std::string((char *) 
output, (char *) output + 16);
+
+                                       // Now encode the resulting mix
+                                       std::string encoded_hash; 
+                                       unsigned int i = 0, value;
+                                       do {
+                                               value = output[i++];
+                                               
encoded_hash.append(itoa64.substr(value & 0x3f,1));
+                                               if(i < 16)
+                                                       value |= 
(int)output[i] << 8;
+                                               
encoded_hash.append(itoa64.substr((value >> 6) & 0x3f,1));
+                                               if(i++ >= 16)
+                                                       break;
+                                               if(i < 16)
+                                                       value |= 
(int)output[i] << 16;
+                                               
encoded_hash.append(itoa64.substr((value >> 12) & 0x3f,1));
+                                               if(i++ >= 16)
+                                                       break;
+                                               
encoded_hash.append(itoa64.substr((value >> 18) & 0x3f,1));
+                                       } while (i < 16);
+                                       free (output);
+
+                                       // Now mix the resulting hash with 
the random seed
+                                       result = encoded_hash + 
(*error)["random_salt"];
+
+                                       MD5 md5_worker2;        
+                                       md5_worker2.update((unsigned char 
*)result.c_str(), result.size());
+                                       md5_worker2.finalize();
+
+                                       result = 
std::string(md5_worker2.hex_digest());
+                               }
+
+                               sp["password"] = result;
 
                                // Login and enable selective pings -- saves 
server bandwidth
                                // If ping_timeout has a non-zero value, do 
not enable

Modified: trunk/src/multiplayer_ui.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/multiplayer_ui.cpp?rev=28630&r1=28629&r2=28630&view=diff
==============================================================================
--- trunk/src/multiplayer_ui.cpp (original)
+++ trunk/src/multiplayer_ui.cpp Sat Aug 16 12:36:09 2008
@@ -600,6 +600,7 @@
                u_elem.game_id = "";
                u_elem.location = "";
                u_elem.state = (**user)["available"] == "no" ? GAME : LOBBY;
+               u_elem.registered = 
utils::string_bool((**user)["registered"]);
                if(!(**user)["game_id"].empty()) {
                        u_elem.game_id = (**user)["game_id"];
                        if (u_elem.game_id == selected_game_) {
@@ -633,6 +634,10 @@
        const std::string ingame_color_tag  = "#";
        const std::string selgame_color_tag = "<0,191,255>";
 
+       // for now I just disregard the above till I know something better,
+       // it works for me anyways
+       const std::string registered_user_tag = "~";
+
        std::string const imgpre = IMAGE_PREFIX + std::string("misc/status-");
        std::vector<std::string> user_strings;
        std::vector<std::string> menu_strings;
@@ -643,6 +648,7 @@
                                ((u_itor->state == LOBBY) ? "" : " (" + 
u_itor->location + ")");
                std::string img_str = "";
                std::string color_str = "";
+               std::string reg_str = "";
                switch (u_itor->state) {
                        case LOBBY:    color_str = lobby_color_tag;   break;
                        case GAME:     color_str = ingame_color_tag;  break;
@@ -656,8 +662,9 @@
                                case ME:      img_str = imgpre + "self.png"   
 + IMG_TEXT_SEPARATOR; break;
                        }
                }
+               reg_str = u_itor->registered ? registered_user_tag : "";
                user_strings.push_back(u_itor->name);
-               menu_strings.push_back(img_str + color_str + name_str + 
HELP_STRING_SEPARATOR + name_str);
+               menu_strings.push_back(img_str + reg_str + color_str + 
name_str + HELP_STRING_SEPARATOR + name_str);
                u_itor++;
        }
 

Modified: trunk/src/multiplayer_ui.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/multiplayer_ui.hpp?rev=28630&r1=28629&r2=28630&view=diff
==============================================================================
--- trunk/src/multiplayer_ui.hpp (original)
+++ trunk/src/multiplayer_ui.hpp Sat Aug 16 12:36:09 2008
@@ -218,7 +218,8 @@
                        game_id(),
                        location(),
                        relation(ME),
-                       state(LOBBY)
+                       state(LOBBY),
+                       registered()
                {
                }
 
@@ -227,6 +228,8 @@
                std::string    location;
                user_relation  relation;
                user_state     state;
+               // True if this user is registered on the server
+               bool           registered;
                bool operator> (const user_info& b) const;
        };
 };




Related Messages


Powered by MHonArc, Updated Sat Aug 16 13:20:42 2008