mail[Wesnoth-commits] r34117 - in /branches/1.6/src/server: game.hpp server.cpp


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

Header


Content

Posted by soliton . de on March 25, 2009 - 19:12:
Author: soliton
Date: Wed Mar 25 19:12:54 2009
New Revision: 34117

URL: http://svn.gna.org/viewcvs/wesnoth?rev=34117&view=rev
Log:
disallow joining a second game; should fix bug #13252: MP Server: dogs and 
cats living together, mass hysteria

Modified:
    branches/1.6/src/server/game.hpp
    branches/1.6/src/server/server.cpp

Modified: branches/1.6/src/server/game.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/1.6/src/server/game.hpp?rev=34117&r1=34116&r2=34117&view=diff
==============================================================================
--- branches/1.6/src/server/game.hpp (original)
+++ branches/1.6/src/server/game.hpp Wed Mar 25 19:12:54 2009
@@ -308,6 +308,14 @@
        std::string termination_;
 };
 
+struct game_is_member {
+       game_is_member(network::connection sock) : sock_(sock) {};
+       bool operator()(const game* g) const { return g->is_owner(sock_) || 
g->is_member(sock_); }
+
+private:
+       network::connection sock_;
+};
+
 struct game_id_matches {
        game_id_matches(int id) : id_(id) {};
        bool operator()(const game* g) const { return g->id() == id_; }

Modified: branches/1.6/src/server/server.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/1.6/src/server/server.cpp?rev=34117&r1=34116&r2=34117&view=diff
==============================================================================
--- branches/1.6/src/server/server.cpp (original)
+++ branches/1.6/src/server/server.cpp Wed Mar 25 19:12:54 2009
@@ -1865,6 +1865,21 @@
                        send_doc(games_and_users_list_, sock);
                        return;
                }
+               const std::vector<wesnothd::game*>::iterator g2 =
+                       std::find_if(games_.begin(),games_.end(), 
wesnothd::game_is_member(sock));
+               if (g2 != games_.end()) {
+                       WRN_SERVER << network::ip_address(sock) << "\t" << 
pl->second.name()
+                               << "\tattempted to join a second game. He's 
already in game:\t\""
+                               << (*g2)->name() << "\" (" << (*g2)->id() << 
")." << "(socket: "
+                               << sock << ")\n";
+                       send_doc(leave_game_doc, sock);
+                       lobby_.send_server_message(("Attempt to join a second 
game."
+                                       " You're already in game: \"" + 
(*g2)->name() + "\"."
+                                       " (You may have to log off and back 
on to get your client"
+                                       " in sync again.)").c_str(), sock);
+                       send_doc(games_and_users_list_, sock);
+                       return;
+               }
                bool joined = (*g)->add_player(sock, observer, admin);
                if (!joined) {
                        WRN_SERVER << network::ip_address(sock) << "\t" << 
pl->second.name()




Related Messages


Powered by MHonArc, Updated Wed Mar 25 19:20:24 2009