wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src server/game.hpp server/server.cpp s...


From: David White
Subject: [Wesnoth-cvs-commits] wesnoth/src server/game.hpp server/server.cpp s...
Date: Sun, 31 Oct 2004 01:19:03 -0400

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     David White <address@hidden>    04/10/31 05:13:22

Modified files:
        src/server     : game.hpp server.cpp metrics.hpp metrics.cpp 
        src            : playturn.cpp playlevel.cpp 
                         multiplayer_lobby.cpp 

Log message:
        added server facility to record the way games end

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/server/game.hpp.diff?tr1=1.14&tr2=1.15&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/server/server.cpp.diff?tr1=1.58&tr2=1.59&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/server/metrics.hpp.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/server/metrics.cpp.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/playturn.cpp.diff?tr1=1.281&tr2=1.282&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/playlevel.cpp.diff?tr1=1.157&tr2=1.158&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/multiplayer_lobby.cpp.diff?tr1=1.44&tr2=1.45&r1=text&r2=text

Patches:
Index: wesnoth/src/multiplayer_lobby.cpp
diff -u wesnoth/src/multiplayer_lobby.cpp:1.44 
wesnoth/src/multiplayer_lobby.cpp:1.45
--- wesnoth/src/multiplayer_lobby.cpp:1.44      Sat Oct 30 15:36:51 2004
+++ wesnoth/src/multiplayer_lobby.cpp   Sun Oct 31 05:13:22 2004
@@ -312,17 +312,30 @@
 
                        const bool enter = key[SDLK_RETURN] && !old_enter;
                        old_enter = key[SDLK_RETURN];
-                       if(enter && message_entry.text().empty() == false) {
-                               config msg;
-                               config& child = msg.add_child("message");
-                               child["message"] = message_entry.text();
-                               child["sender"] = preferences::login();
-                               network::send_data(msg);
-                               message_entry.clear();
+                       if(enter && message_entry.text().empty() == false) {
+                               const std::string& text = message_entry.text();
+
+                               static const std::string query = "/query ";
+                               if(text.size() >= query.size() && 
std::equal(query.begin(),query.end(),text.begin())) {
+                                       const std::string args = 
text.substr(query.size());
+
+                                       config cfg;
+                                       cfg.add_child("query")["type"] = args;
+                                       network::send_data(cfg);
+                               } else {
+
+                                       config msg;
+                                       config& child = 
msg.add_child("message");
+                                       child["message"] = text;
+                                       child["sender"] = preferences::login();
+                                       network::send_data(msg);
 
-                               std::stringstream message;
-                               message << "<" << child["sender"] << ">  " << 
child["message"];
-                               messages.push_back(message.str());
+                                       std::stringstream message;
+                                       message << "<" << child["sender"] << "> 
 " << child["message"];
+                                       messages.push_back(message.str());
+                               }
+
+                               message_entry.clear();
                        }
 
                        if(last_escape == false && key[SDLK_ESCAPE] || dlg == 
NULL && quit_game.process(mousex,mousey,left_button)){
Index: wesnoth/src/playlevel.cpp
diff -u wesnoth/src/playlevel.cpp:1.157 wesnoth/src/playlevel.cpp:1.158
--- wesnoth/src/playlevel.cpp:1.157     Tue Oct 12 03:35:57 2004
+++ wesnoth/src/playlevel.cpp   Sun Oct 31 05:13:22 2004
@@ -1,4 +1,4 @@
-/* $Id: playlevel.cpp,v 1.157 2004/10/12 03:35:57 Sirp Exp $ */
+/* $Id: playlevel.cpp,v 1.158 2004/10/31 05:13:22 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -699,6 +699,16 @@
                        gui::show_dialog(gui,NULL,_("Game Over"),
                                                  _("The game is over."), 
gui::OK_ONLY);
                        return end_level.result;
+               }
+
+               //if we're a player, and the result is victory/defeat, then 
send a message to notify
+               //the server of the reason for the game ending
+               if(end_level.result == DEFEAT || end_level.result == VICTORY && 
network::nconnections() > 0) {
+                       config cfg;
+                       config& info = cfg.add_child("info");
+                       info["type"] = "termination";
+                       info["condition"] = "game over";
+                       network::send_data(cfg);
                }
 
                if(end_level.result == QUIT) {
Index: wesnoth/src/playturn.cpp
diff -u wesnoth/src/playturn.cpp:1.281 wesnoth/src/playturn.cpp:1.282
--- wesnoth/src/playturn.cpp:1.281      Sat Oct 30 21:00:26 2004
+++ wesnoth/src/playturn.cpp    Sun Oct 31 05:13:22 2004
@@ -1,4 +1,4 @@
-/* $Id: playturn.cpp,v 1.281 2004/10/30 21:00:26 Sirp Exp $ */
+/* $Id: playturn.cpp,v 1.282 2004/10/31 05:13:22 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -2422,7 +2422,14 @@
                        try {
                                turn_end = 
do_replay(gui_,map_,gameinfo_,units_,teams_,
                                team_num_,status_,state_of_game_,&replay_obj);
-                       } catch(replay::error& e) {
+                       } catch(replay::error& e) {
+                               //notify remote hosts of out of sync error
+                               config cfg;
+                               config& info = cfg.add_child("info");
+                               info["type"] = "termination";
+                               info["condition"] = "out of sync";
+                               network::send_data(cfg);
+
                                save_game(_("The games are out of sync and will 
have to exit. Do you want to save an error log of your game?"),gui::YES_NO);
 
                                //throw e;
@@ -2505,7 +2512,7 @@
 
                        teams_[side].make_human();
                        return PROCESS_RESTART_TURN;
-               }
+               }
 
                throw network::error("");
        }
Index: wesnoth/src/server/game.hpp
diff -u wesnoth/src/server/game.hpp:1.14 wesnoth/src/server/game.hpp:1.15
--- wesnoth/src/server/game.hpp:1.14    Sat Aug 21 22:21:05 2004
+++ wesnoth/src/server/game.hpp Sun Oct 31 05:13:22 2004
@@ -76,7 +76,16 @@
 
        bool started() const;
 
-       size_t nplayers() const { return players_.size(); }
+       size_t nplayers() const { return players_.size(); }
+
+       const std::string& termination_reason() const {
+               static const std::string aborted = "aborted";
+               return termination_.empty() ? aborted : termination_;
+       }
+
+       void set_termination_reason(const std::string& reason) {
+               if(termination_.empty()) { termination_ = reason; }
+       }
 
 private:
 
@@ -121,7 +130,9 @@
                std::string ipaddress;
        };
 
-       std::vector<ban> bans_;
+       std::vector<ban> bans_;
+
+       std::string termination_;
 };
 
 struct game_id_matches
Index: wesnoth/src/server/metrics.cpp
diff -u wesnoth/src/server/metrics.cpp:1.1 wesnoth/src/server/metrics.cpp:1.2
--- wesnoth/src/server/metrics.cpp:1.1  Sun Aug  1 02:50:45 2004
+++ wesnoth/src/server/metrics.cpp      Sun Oct 31 05:13:22 2004
@@ -24,6 +24,11 @@
 void metrics::no_requests()
 {
        current_requests_ = 0;
+}
+
+void metrics::game_terminated(const std::string& reason)
+{
+       terminations_[reason]++;
 }
 
 std::ostream& operator<<(std::ostream& out, metrics& met)
@@ -40,5 +45,15 @@
            << met.nrequests_ << " requests serviced. " << requests_immediate
            << " (" << percent_immediate << "%) "
            << " requests were serviced immediately\n"
-           << "longest burst of requests was " << 
met.most_consecutive_requests_ << "\n----\n";
+           << "longest burst of requests was " << 
met.most_consecutive_requests_ << "\n";
+
+       if(met.terminations_.empty() == false) {
+               out << "Games have been terminated in the following ways: \n";
+               for(std::map<std::string,int>::const_iterator i = 
met.terminations_.begin(); i != met.terminations_.end(); ++i) {
+                       out << i->first << ": " << i->second << "\n";
+               }
+       }
+
+       out << "----\n";
+       return out;
 }
Index: wesnoth/src/server/metrics.hpp
diff -u wesnoth/src/server/metrics.hpp:1.1 wesnoth/src/server/metrics.hpp:1.2
--- wesnoth/src/server/metrics.hpp:1.1  Sun Aug  1 02:50:45 2004
+++ wesnoth/src/server/metrics.hpp      Sun Oct 31 05:13:22 2004
@@ -1,7 +1,10 @@
 #ifndef METRICS_HPP_INCLUDED
 #define METRICS_HPP_INCLUDED
 
-#include <iosfwd>
+#include <iosfwd>
+
+#include <map>
+#include <string>
 
 class metrics
 {
@@ -9,7 +12,9 @@
        metrics();
 
        void service_request();
-       void no_requests();
+       void no_requests();
+
+       void game_terminated(const std::string& reason);
 
        friend std::ostream& operator<<(std::ostream& out, metrics& met);
 
@@ -18,7 +23,8 @@
        int current_requests_;
        int nrequests_;
        int nrequests_waited_;
-       const time_t started_at_;
+       const time_t started_at_;
+       std::map<std::string,int> terminations_;
 };
 
 std::ostream& operator<<(std::ostream& out, metrics& met);
Index: wesnoth/src/server/server.cpp
diff -u wesnoth/src/server/server.cpp:1.58 wesnoth/src/server/server.cpp:1.59
--- wesnoth/src/server/server.cpp:1.58  Mon Oct 11 23:46:44 2004
+++ wesnoth/src/server/server.cpp       Sun Oct 31 05:13:22 2004
@@ -350,6 +350,18 @@
                                                
g->send_data_observers(construct_server_message(username + " has logged into 
the lobby",*g));
                                        }
 
+                               } else if(const config* query = 
data.child("query")) {
+
+                                       //process queries from clients in here
+                                       std::ostringstream response;
+                                       if((*query)["type"] == "metrics") {
+                                               //a query for server data from 
a player
+                                               response << metrics_;   
+                                       } else {
+                                               response << "Error: 
unrecognized query";
+                                       }
+                                       
+                                       
network::send_data(construct_server_message(response.str(),lobby_players_),sock);
                                } else if(lobby_players_.is_member(sock)) {
                                        const config* const create_game = 
data.child("create_game");
                                        if(create_game != NULL) {
@@ -444,6 +456,14 @@
                                        if(g == games_.end()) {
                                                std::cerr << "ERROR: unknown 
socket " << games_.size() << "\n";
                                                continue;
+                                       }
+
+                                       //if info is being provided about the 
game state
+                                       if(data.child("info") != NULL) {
+                                               const config& info = 
*data.child("info");
+                                               if(info["type"] == 
"termination") {
+                                                       
g->set_termination_reason(info["condition"]);
+                                               }
                                        }
 
                                        //if the owner is changing the 
controller for a side
@@ -619,7 +639,8 @@
 
                                                        //put the players back 
in the lobby and send
                                                        //them the game list 
and user list again
-                                                       
g->send_data(initial_response_);
+                                                       
g->send_data(initial_response_);
+                                                       
metrics_.game_terminated(g->termination_reason());
                                                        
lobby_players_.add_players(*g);
                                                        games_.erase(g);
 
@@ -769,7 +790,9 @@
 }
 
 void server::delete_game(std::vector<game>::iterator i)
-{
+{
+       metrics_.game_terminated(i->termination_reason());
+
        //delete the game's configuration
        config* const gamelist = initial_response_.child("gamelist");
        assert(gamelist != NULL);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]