mail[Wesnoth-commits] r24782 - in /branches/mp_registration/src: ./ server/


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

Header


Content

Posted by baufo on March 18, 2008 - 19:16:
Author: baufo
Date: Tue Mar 18 19:16:37 2008
New Revision: 24782

URL: http://svn.gna.org/viewcvs/wesnoth?rev=24782&view=rev
Log:
General clean up + marking registered players in the client

Modified:
    branches/mp_registration/src/multiplayer_ui.cpp
    branches/mp_registration/src/multiplayer_ui.hpp
    branches/mp_registration/src/server/player.cpp
    branches/mp_registration/src/server/player.hpp
    branches/mp_registration/src/server/server.cpp
    branches/mp_registration/src/server/user_handler.cpp
    branches/mp_registration/src/server/user_handler.hpp

Modified: branches/mp_registration/src/multiplayer_ui.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/mp_registration/src/multiplayer_ui.cpp?rev=24782&r1=24781&r2=24782&view=diff
==============================================================================
--- branches/mp_registration/src/multiplayer_ui.cpp (original)
+++ branches/mp_registration/src/multiplayer_ui.cpp Tue Mar 18 19:16:37 2008
@@ -29,6 +29,7 @@
 #include "video.hpp"
 #include "replay.hpp"
 #include "wml_separators.hpp"
+#include "serialization/string_utils.hpp"
 
 #define LOG_NG LOG_STREAM(info, engine)
 #define ERR_NG LOG_STREAM(err, engine)
@@ -62,7 +63,7 @@
        }
 
        user_menu_style umenu_style;
-       
+
 } // anon namespace
 
 namespace mp {
@@ -597,6 +598,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_) {
@@ -630,6 +632,8 @@
        const std::string ingame_color_tag  = "#";
        const std::string selgame_color_tag = "<0,191,255>";
 
+       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;
@@ -639,6 +643,7 @@
                const std::string game_str = (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;
@@ -652,8 +657,9 @@
                                case ME:      img_str = imgpre + "self.png"   
 + COLUMN_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 + u_itor->name + 
game_str + HELP_STRING_SEPARATOR + u_itor->name + game_str);
+               menu_strings.push_back(img_str + reg_str + color_str + 
u_itor->name + game_str + HELP_STRING_SEPARATOR + u_itor->name + game_str);
                u_itor++;
        }
 

Modified: branches/mp_registration/src/multiplayer_ui.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/mp_registration/src/multiplayer_ui.hpp?rev=24782&r1=24781&r2=24782&view=diff
==============================================================================
--- branches/mp_registration/src/multiplayer_ui.hpp (original)
+++ branches/mp_registration/src/multiplayer_ui.hpp Tue Mar 18 19:16:37 2008
@@ -218,6 +218,7 @@
                std::string    location;
                user_relation  relation;
                user_state     state;
+               bool           registered;
                bool operator> (const user_info& b) const;
        };
 };

Modified: branches/mp_registration/src/server/player.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/mp_registration/src/server/player.cpp?rev=24782&r1=24781&r2=24782&view=diff
==============================================================================
--- branches/mp_registration/src/server/player.cpp (original)
+++ branches/mp_registration/src/server/player.cpp Tue Mar 18 19:16:37 2008
@@ -22,6 +22,7 @@
 {
        cfg_.set_attr_dup("name", n.c_str());
        mark_available();
+       mark_registered(false);
 }
 
 // keep 'available' and game name ('location') for backward compatibility
@@ -30,6 +31,10 @@
        cfg_.set_attr("available", (game_id == 0) ? "yes" : "no");
        cfg_.set_attr_dup("game_id", 
lexical_cast<std::string>(game_id).c_str());
        cfg_.set_attr_dup("location", location.c_str());
+}
+
+void player::mark_registered(bool registered) const {
+    cfg_.set_attr("registered", registered ? "yes" : "no");
 }
 
 bool player::is_message_flooding() {

Modified: branches/mp_registration/src/server/player.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/mp_registration/src/server/player.hpp?rev=24782&r1=24781&r2=24782&view=diff
==============================================================================
--- branches/mp_registration/src/server/player.hpp (original)
+++ branches/mp_registration/src/server/player.hpp Tue Mar 18 19:16:37 2008
@@ -30,6 +30,8 @@
        // mark a player as member of the game 'game_id' or as located in the 
lobby
        void mark_available(const int game_id=0, const std::string 
location="");
 
+       void mark_registered(bool registered =true) const;
+
 
        const std::string& name() const { return name_; }
 

Modified: branches/mp_registration/src/server/server.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/mp_registration/src/server/server.cpp?rev=24782&r1=24781&r2=24782&view=diff
==============================================================================
--- branches/mp_registration/src/server/server.cpp (original)
+++ branches/mp_registration/src/server/server.cpp Tue Mar 18 19:16:37 2008
@@ -715,33 +715,36 @@
        }
 
     //Check for password
+    bool registered = false;
        if(user_handler_) {
         std::string password = (*login)["password"].to_string();
-           //This name is registered and no password provided
-           if(user_handler_->user_exists(username) && password.empty()) {
-               send_password_request(sock, "This username is registered on 
this server.");
-               return;
-           }
-           //This name is registered and an incorrect password provided
-           else if(user_handler_->user_exists(username) && 
!(user_handler_->login(username, password))) {
-               send_password_request(sock, "The password you provided was 
incorrect");
-
-               LOG_SERVER << network::ip_address(sock) << "\t"
-                    << "Login attempt with incorrect password for username 
'" << username << "'\n.";
-
-               //! @todo Stop brute-force attacks by rejecting  further 
login attempts by
-               //! this IP for a few seconds or something similar
-               return;
-           }
-       }
-
-       //! @todo Somehow mark unregistered players
+        if(user_handler_->user_exists(username)) {
+            //This name is registered and no password provided
+            if(password.empty()) {
+                send_password_request(sock, "This username is registered on 
this server.");
+                return;
+            }
+            //This name is registered and an incorrect password provided
+            else if(!(user_handler_->login(username, password))) {
+                send_password_request(sock, "The password you provided was 
incorrect");
+
+                LOG_SERVER << network::ip_address(sock) << "\t"
+                        << "Login attempt with incorrect password for 
username '" << username << "'\n.";
+
+                //! @todo Stop brute-force attacks by rejecting  further 
login attempts by
+                //! this IP for a few seconds or something similar
+                return;
+            }
+           registered = true;
+        }
+       }
 
        send_doc(join_lobby_response_, sock);
 
        simple_wml::node& player_cfg = 
games_and_users_list_.root().add_child("user");
        const player new_player(username, player_cfg, default_max_messages_,
                default_time_period_);
+    new_player.mark_registered(registered);
        players_.insert(std::pair<network::connection,player>(sock, 
new_player));
 
        not_logged_in_.remove_player(sock);
@@ -755,11 +758,9 @@
        }
 
        //If the username is not registered suggest to do so
-       if(user_handler_) {
-        if (!(user_handler_->user_exists(username))) {
+       if(user_handler_ && !registered) {
            lobby_.send_server_message("Your username is not registered. To 
prevent others from using \
 it type '/register <password> <email>'.", sock);
-        }
        }
 
 
@@ -1052,6 +1053,15 @@
                                        
((*data.child("register"))["mail"].empty() ?
                                        " It is recommended that you provide 
an email address for password recovery." : "");
             lobby_.send_server_message(msg.str().c_str(), sock);
+
+            //Mark the player as registered and send the other clients
+            //an update to dislpay this change
+            pl->second.mark_registered();
+
+            simple_wml::document diff;
+            make_change_diff(games_and_users_list_.root(), NULL,
+                                "user", pl->second.config_address(), diff);
+            lobby_.send_data(diff);
 
         } catch (user_handler::error e) {
             lobby_.send_server_message(("There was and error registering 
your username. The error message was: "

Modified: branches/mp_registration/src/server/user_handler.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/mp_registration/src/server/user_handler.cpp?rev=24782&r1=24781&r2=24782&view=diff
==============================================================================
--- branches/mp_registration/src/server/user_handler.cpp (original)
+++ branches/mp_registration/src/server/user_handler.cpp Tue Mar 18 19:16:37 
2008
@@ -47,6 +47,9 @@
 void user_handler::load_config() {
 
     //Load configuration and initialize with default values if we don't find 
values
+
+    #ifndef NO_MAIL
+
     cfg_["from_address"] = cfg_["from_address"].empty() ? 
"NOREPLY@xxxxxxxxxxx" : cfg_["from_address"];
     cfg_["mail_server"] = cfg_["mail_server"].empty() ? "127.0.0.1" : 
cfg_["mail_server"];
 
@@ -62,6 +65,8 @@
         mail_port_ = lexical_cast_default<unsigned short>(cfg_["mail_port"]);
     }
 
+    #endif //NO_MAIL
+
     //Check if we already have users and
     //if we don't create a child for them
     if(cfg_.child("users")) {
@@ -85,6 +90,8 @@
 
 bool user_handler::send_mail(const char* to_address, const char* subject, 
const char* message) {
 
+    #ifndef NO_MAIL
+
     jwsmtp::mailer m(to_address, cfg_["from_address"].c_str(), subject, 
message,
             cfg_["mail_server"].c_str(), mail_port_, false);
     if(!(cfg_["mail_user"].empty())) {
@@ -103,7 +110,12 @@
     if(m.response().substr(0,3) != "250") {
         return false;
     }
+
     return true;
+
+    #endif //NO_MAIL
+
+    return false;
 
 }
 
@@ -116,6 +128,8 @@
 
     // Check if provided values are sane
     // (e.g. the email is either empty or looks like user@domain)
+    // We also check the email with NO_MAIL defined because we
+    // might later decide to run the server with mailing enabled
     check_password(password);
     check_mail(mail);
 
@@ -124,7 +138,16 @@
         throw error("Could not add new user. A user with the name '" + name 
+ "' already exists.");
     }
 
-    //! @todo I guess we should only allow every email address to be 
registered only once
+    //Check if the given email is not yet registered
+    if(!mail.empty()) {
+        const config::child_map& user_childs = users_->all_children();
+        for(config::child_map::const_iterator i = user_childs.begin(); i != 
user_childs.end(); ++i) {
+            std::cout << (*(users_->child(i->first)))["mail"] << std::endl;
+            if((*(users_->child(i->first)))["mail"] == mail) {
+                throw error("Could not add new user. The email address '" + 
mail + "' is already in use.");
+            }
+        }
+    }
 
     config& user = users_->add_child(name);
     user["mail"] = mail;
@@ -135,6 +158,8 @@
     save_config();
 
     std::cout << "Created new user '" << name << "'\n";
+
+    #ifndef NO_MAIL
 
     //Don't send a confirmation mail if we don't have an email
     if(mail.empty()) {
@@ -147,9 +172,13 @@
             "Your password: " << user["password"];
 
     send_mail(user["mail"].c_str(), "Wesnoth Multiplayer Server 
Registration", msg.str().c_str());
+
+    #endif //NO_MAIL
 }
 
 void user_handler::password_reminder(const std::string& name) {
+    #ifndef NO_MAIL
+
     if(!user_exists(name)) {
         throw error("Could not send password reminder. No user with the name 
'" + name + "' exists.");
     }
@@ -168,6 +197,11 @@
     if(!(send_mail(user["mail"].c_str(), "Wesnoth Multiplayer Server 
Password Reminder", msg.str().c_str()))) {
         throw error("Could not send password reminder. There was an error 
sending the reminder email");
     }
+    return;
+
+    #endif //NO_MAIL
+
+    throw error("Could not send password reminder. This server is configured 
not to send emails.");
 
 }
 

Modified: branches/mp_registration/src/server/user_handler.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/mp_registration/src/server/user_handler.hpp?rev=24782&r1=24781&r2=24782&view=diff
==============================================================================
--- branches/mp_registration/src/server/user_handler.hpp (original)
+++ branches/mp_registration/src/server/user_handler.hpp Tue Mar 18 19:16:37 
2008
@@ -10,9 +10,9 @@
 #include "../serialization/preprocessor.hpp"
 #include "../serialization/string_utils.hpp"
 
+#ifndef NO_MAIL
 #include <jwsmtp/jwsmtp.h>
-
-//! @todo Generally write nice log/error messages for all user_handler 
functions
+#endif
 
 class user_handler {
     public:
@@ -53,7 +53,7 @@
         };
 
     private:
-        //! Sends an e-mail to a specified address. Requires access to an 
SMTP server.
+        //! Sends an email to a specified address. Requires access to an 
SMTP server.
         //! Returns false if the mail could not be sent.
         bool send_mail(const char* to_address, const char* subject, const 
char* message);
 




Related Messages


Powered by MHonArc, Updated Tue Mar 18 22:02:03 2008