[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-cvs-commits] wesnoth/src multiplayer_lobby.cpp network_worke...
From: |
Pauli Manninen |
Subject: |
[Wesnoth-cvs-commits] wesnoth/src multiplayer_lobby.cpp network_worke... |
Date: |
Sun, 31 Oct 2004 10:32:40 -0500 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: Pauli Manninen <address@hidden> 04/10/31 15:21:04
Modified files:
src : multiplayer_lobby.cpp network_worker.cpp
playlevel.cpp
src/server : game.hpp metrics.cpp metrics.hpp server.cpp
Log message:
dos2unix
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/multiplayer_lobby.cpp.diff?tr1=1.45&tr2=1.46&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/network_worker.cpp.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/playlevel.cpp.diff?tr1=1.158&tr2=1.159&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/server/game.hpp.diff?tr1=1.15&tr2=1.16&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/server/metrics.cpp.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/server/metrics.hpp.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/server/server.cpp.diff?tr1=1.59&tr2=1.60&r1=text&r2=text
Patches:
Index: wesnoth/src/multiplayer_lobby.cpp
diff -u wesnoth/src/multiplayer_lobby.cpp:1.45
wesnoth/src/multiplayer_lobby.cpp:1.46
--- wesnoth/src/multiplayer_lobby.cpp:1.45 Sun Oct 31 05:13:22 2004
+++ wesnoth/src/multiplayer_lobby.cpp Sun Oct 31 15:21:03 2004
@@ -312,17 +312,17 @@
const bool enter = key[SDLK_RETURN] && !old_enter;
old_enter = key[SDLK_RETURN];
- 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 {
+ 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");
@@ -332,9 +332,9 @@
std::stringstream message;
message << "<" << child["sender"] << ">
" << child["message"];
- messages.push_back(message.str());
- }
-
+ messages.push_back(message.str());
+ }
+
message_entry.clear();
}
Index: wesnoth/src/network_worker.cpp
diff -u wesnoth/src/network_worker.cpp:1.11 wesnoth/src/network_worker.cpp:1.12
--- wesnoth/src/network_worker.cpp:1.11 Sat Oct 30 08:46:28 2004
+++ wesnoth/src/network_worker.cpp Sun Oct 31 15:21:03 2004
@@ -168,35 +168,35 @@
}
void close_socket(TCPsocket sock)
-{
- for(bool first_time = true; ; first_time = false) {
- if(!first_time) {
- SDL_Delay(10);
- }
-
- const threading::lock lock(*global_mutex);
-
- const socket_state_map::iterator lock_it =
sockets_locked.find(sock);
-
- if(lock_it == sockets_locked.end() || lock_it->second !=
SOCKET_LOCKED) {
- if(lock_it != sockets_locked.end()) {
- sockets_locked.erase(lock_it);
- }
+{
+ for(bool first_time = true; ; first_time = false) {
+ if(!first_time) {
+ SDL_Delay(10);
+ }
+
+ const threading::lock lock(*global_mutex);
+
+ const socket_state_map::iterator lock_it =
sockets_locked.find(sock);
+
+ if(lock_it == sockets_locked.end() || lock_it->second !=
SOCKET_LOCKED) {
+ if(lock_it != sockets_locked.end()) {
+ sockets_locked.erase(lock_it);
+ }
size_t size = bufs.size();
buffer_set new_bufs;
new_bufs.reserve(size);
for(buffer_set::iterator i = bufs.begin(), i_end =
bufs.end(); i != i_end; ++i) {
if ((*i)->sock == sock)
- delete *i;
+ delete *i;
else
new_bufs.push_back(*i);
}
bufs.swap(new_bufs);
-
- break;
- }
- }
+
+ break;
+ }
+ }
}
TCPsocket detect_error()
Index: wesnoth/src/playlevel.cpp
diff -u wesnoth/src/playlevel.cpp:1.158 wesnoth/src/playlevel.cpp:1.159
--- wesnoth/src/playlevel.cpp:1.158 Sun Oct 31 05:13:22 2004
+++ wesnoth/src/playlevel.cpp Sun Oct 31 15:21:03 2004
@@ -1,4 +1,4 @@
-/* $Id: playlevel.cpp,v 1.158 2004/10/31 05:13:22 Sirp Exp $ */
+/* $Id: playlevel.cpp,v 1.159 2004/10/31 15:21:03 gakusho Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -699,16 +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 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/server/game.hpp
diff -u wesnoth/src/server/game.hpp:1.15 wesnoth/src/server/game.hpp:1.16
--- wesnoth/src/server/game.hpp:1.15 Sun Oct 31 05:13:22 2004
+++ wesnoth/src/server/game.hpp Sun Oct 31 15:21:04 2004
@@ -76,15 +76,15 @@
bool started() const;
- 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; }
+ 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:
@@ -130,8 +130,8 @@
std::string ipaddress;
};
- std::vector<ban> bans_;
-
+ std::vector<ban> bans_;
+
std::string termination_;
};
Index: wesnoth/src/server/metrics.cpp
diff -u wesnoth/src/server/metrics.cpp:1.2 wesnoth/src/server/metrics.cpp:1.3
--- wesnoth/src/server/metrics.cpp:1.2 Sun Oct 31 05:13:22 2004
+++ wesnoth/src/server/metrics.cpp Sun Oct 31 15:21:04 2004
@@ -24,11 +24,11 @@
void metrics::no_requests()
{
current_requests_ = 0;
-}
-
-void metrics::game_terminated(const std::string& reason)
-{
- terminations_[reason]++;
+}
+
+void metrics::game_terminated(const std::string& reason)
+{
+ terminations_[reason]++;
}
std::ostream& operator<<(std::ostream& out, metrics& met)
@@ -45,15 +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";
-
- 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";
+ << "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.2 wesnoth/src/server/metrics.hpp:1.3
--- wesnoth/src/server/metrics.hpp:1.2 Sun Oct 31 05:13:22 2004
+++ wesnoth/src/server/metrics.hpp Sun Oct 31 15:21:04 2004
@@ -1,9 +1,9 @@
#ifndef METRICS_HPP_INCLUDED
#define METRICS_HPP_INCLUDED
-#include <iosfwd>
-
-#include <map>
+#include <iosfwd>
+
+#include <map>
#include <string>
class metrics
@@ -12,8 +12,8 @@
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);
@@ -23,7 +23,7 @@
int current_requests_;
int nrequests_;
int nrequests_waited_;
- const time_t started_at_;
+ const time_t started_at_;
std::map<std::string,int> terminations_;
};
Index: wesnoth/src/server/server.cpp
diff -u wesnoth/src/server/server.cpp:1.59 wesnoth/src/server/server.cpp:1.60
--- wesnoth/src/server/server.cpp:1.59 Sun Oct 31 05:13:22 2004
+++ wesnoth/src/server/server.cpp Sun Oct 31 15:21:04 2004
@@ -350,18 +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(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) {
@@ -456,14 +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 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
@@ -639,7 +639,7 @@
//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);
@@ -790,8 +790,8 @@
}
void server::delete_game(std::vector<game>::iterator i)
-{
- metrics_.game_terminated(i->termination_reason());
+{
+ metrics_.game_terminated(i->termination_reason());
//delete the game's configuration
config* const gamelist = initial_response_.child("gamelist");
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Wesnoth-cvs-commits] wesnoth/src multiplayer_lobby.cpp network_worke...,
Pauli Manninen <=