Author: alink
Date: Tue Jul 8 21:31:49 2008
New Revision: 27847
URL: http://svn.gna.org/viewcvs/wesnoth?rev=27847&view=rev
Log:
Some cleaning of the code searching a vacant slot when joining a MP game.
A bit safer for full game and maybe fix "allow_changes" key for side > 1.
This will also allow joiner to know which side and color they will get, before
choosing its faction and leader (UI feature in next commit).
Modified:
trunk/src/multiplayer_wait.cpp
Modified: trunk/src/multiplayer_wait.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/multiplayer_wait.cpp?rev=27847&r1=27846&r2=27847&view=diff
==============================================================================
--- trunk/src/multiplayer_wait.cpp (original)
+++ trunk/src/multiplayer_wait.cpp Tue Jul 8 21:31:49 2008
@@ -234,26 +234,26 @@
if (!observe) {
const config::child_list& sides_list =
level_.get_children("side");
- if(sides_list.empty()) {
- set_result(QUIT);
- throw config::error(_("No multiplayer sides available
in this game"));
- return;
- }
-
//search for an appropriate vacant slot. If a description is set
//(i.e. we're loading from a saved game), then prefer to get
the side
//with the same description as our login. Otherwise just choose
the first
//available side.
- int side_choice = 0;
+ int side_choice = -1;
for(config::child_list::const_iterator s = sides_list.begin();
s != sides_list.end(); ++s) {
if((**s)["controller"] == "network" &&
(**s)["id"].empty()) {
+ side_choice = s - sides_list.begin();
if((**s)["save_id"] == preferences::login() ||
(**s)["current_player"] == preferences::login()) {
- side_choice = s - sides_list.begin();
+ break; // found the prefered one
}
}
}
+ if (side_choice < 0 || side_choice >= sides_list.size()) {
+ set_result(QUIT);
+ throw config::error(_("No multiplayer sides available
in this game"));
+ return;
+ }
+
const bool allow_changes =
(*sides_list[side_choice])["allow_changes"] != "no";
-
//if the client is allowed to choose their team, instead of
having
//it set by the server, do that here.
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits