minor network fixes
This commit is contained in:
parent
81d5bbf3bb
commit
21779b22ed
5 changed files with 22 additions and 13 deletions
|
@ -17,6 +17,7 @@
|
|||
#include "multiplayer_client.hpp"
|
||||
#include "network.hpp"
|
||||
#include "playlevel.hpp"
|
||||
#include "preferences.hpp"
|
||||
#include "replay.hpp"
|
||||
#include "show_dialog.hpp"
|
||||
|
||||
|
@ -111,7 +112,7 @@ int connection_acceptor::do_action()
|
|||
}
|
||||
|
||||
if(sock) {
|
||||
const int side_drop = atoi(cfg.values["side_drop"].c_str())-1;
|
||||
const int side_drop = atoi(cfg["side_drop"].c_str())-1;
|
||||
if(side_drop >= 0 && side_drop < int(sides.size())) {
|
||||
positions_map::iterator pos = positions_.find(sides[side_drop]);
|
||||
if(pos != positions_.end()) {
|
||||
|
@ -121,7 +122,7 @@ int connection_acceptor::do_action()
|
|||
}
|
||||
}
|
||||
|
||||
const int side_taken = atoi(cfg.values["side"].c_str())-1;
|
||||
const int side_taken = atoi(cfg["side"].c_str())-1;
|
||||
if(side_taken >= 0 && side_taken < int(sides.size())) {
|
||||
positions_map::iterator pos = positions_.find(sides[side_taken]);
|
||||
if(pos != positions_.end()) {
|
||||
|
@ -130,6 +131,7 @@ int connection_acceptor::do_action()
|
|||
|
||||
//broadcast to everyone the new game status
|
||||
pos->first->values["taken"] = "yes";
|
||||
pos->first->values["description"] = cfg["description"];
|
||||
positions_[sides[side_taken]] = sock;
|
||||
network::send_data(players_);
|
||||
|
||||
|
@ -199,7 +201,7 @@ std::vector<std::string> connection_acceptor::get_positions_status() const
|
|||
for(positions_map::const_iterator i = positions_.begin();
|
||||
i != positions_.end(); ++i) {
|
||||
result.push_back(i->first->values["name"] + "," +
|
||||
(i->second ? ("@" + string_table["position_taken"]) :
|
||||
(i->second ? ("@" + i->first->values["description"]) :
|
||||
string_table["position_vacant"]));
|
||||
}
|
||||
|
||||
|
@ -332,6 +334,9 @@ void play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
if((*sd)->values["recruitment_pattern"].empty())
|
||||
(*sd)->values["recruitment_pattern"] =
|
||||
possible_sides.front()->values["recruitment_pattern"];
|
||||
|
||||
if((*sd)->values["description"].empty())
|
||||
(*sd)->values["description"] = preferences::login();
|
||||
}
|
||||
|
||||
res = 0;
|
||||
|
@ -388,6 +393,7 @@ void play_multiplayer(display& disp, game_data& units_data, config cfg,
|
|||
std::string controller = "network";
|
||||
if(result < int(choices.size())/3) {
|
||||
controller = "human";
|
||||
sides[res]->values["description"] = preferences::login();
|
||||
} else if(result < int(choices.size()/3)*2) {
|
||||
controller = "ai";
|
||||
result -= choices.size()/3;
|
||||
|
|
|
@ -179,7 +179,7 @@ void play_multiplayer_client(display& disp, game_data& units_data, config& cfg,
|
|||
response.add_child("login")["username"] = login;
|
||||
network::send_data(response);
|
||||
|
||||
data_res = network::receive_data(data,0,10000);
|
||||
data_res = network::receive_data(data,0,5000);
|
||||
check_response(data_res,data);
|
||||
}
|
||||
|
||||
|
@ -204,7 +204,7 @@ void play_multiplayer_client(display& disp, game_data& units_data, config& cfg,
|
|||
}
|
||||
|
||||
for(;;) {
|
||||
data_res = network::receive_data(sides,0,10000);
|
||||
data_res = network::receive_data(sides,0,5000);
|
||||
check_response(data_res,data);
|
||||
|
||||
//if we have got valid side data
|
||||
|
@ -216,7 +216,6 @@ void play_multiplayer_client(display& disp, game_data& units_data, config& cfg,
|
|||
sides = data;
|
||||
}
|
||||
|
||||
|
||||
std::map<int,int> choice_map;
|
||||
std::vector<std::string> choices;
|
||||
choices.push_back(string_table["observer"]);
|
||||
|
@ -246,7 +245,8 @@ void play_multiplayer_client(display& disp, game_data& units_data, config& cfg,
|
|||
config response;
|
||||
std::stringstream stream;
|
||||
stream << team_num;
|
||||
response.values["side"] = stream.str();
|
||||
response["side"] = stream.str();
|
||||
response["description"] = preferences::login();
|
||||
network::send_data(response);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,9 +23,11 @@ void game::start_game()
|
|||
started_ = true;
|
||||
}
|
||||
|
||||
bool game::take_side(network::connection player, const std::string& side)
|
||||
bool game::take_side(network::connection player, const config& cfg)
|
||||
{
|
||||
assert(is_member(player));
|
||||
|
||||
const std::string& side = cfg["side"];
|
||||
|
||||
//if the player is already on a side or the side is already taken
|
||||
if(sides_.count(player) || sides_taken_.count(side))
|
||||
|
@ -36,8 +38,6 @@ bool game::take_side(network::connection player, const std::string& side)
|
|||
|
||||
//send host notification of taking this side
|
||||
if(players_.empty() == false) {
|
||||
config cfg;
|
||||
cfg["side"] = side;
|
||||
network::send_data(cfg,players_.front());
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ public:
|
|||
|
||||
void start_game();
|
||||
|
||||
bool take_side(network::connection player, const std::string& side);
|
||||
bool take_side(network::connection player, const config& cfg);
|
||||
|
||||
|
||||
void add_player(network::connection player);
|
||||
|
|
|
@ -172,9 +172,11 @@ int main()
|
|||
//if this is data describing the level for a game
|
||||
if(data.child("side") != NULL) {
|
||||
|
||||
const bool is_init = g->level_init();
|
||||
|
||||
//if this game is having its level-data initialized
|
||||
//for the first time, and is ready for players to join
|
||||
if(!g->level_init()) {
|
||||
if(!is_init) {
|
||||
|
||||
//update our config object which describes the
|
||||
//open games
|
||||
|
@ -190,6 +192,7 @@ int main()
|
|||
//record the new level data, and send to all players
|
||||
//who are in the game
|
||||
g->level() = data;
|
||||
|
||||
g->send_data(data,sock);
|
||||
continue;
|
||||
}
|
||||
|
@ -197,7 +200,7 @@ int main()
|
|||
const string_map::const_iterator side =
|
||||
data.values.find("side");
|
||||
if(side != data.values.end()) {
|
||||
const bool res = g->take_side(sock,side->second);
|
||||
const bool res = g->take_side(sock,data);
|
||||
config response;
|
||||
if(res) {
|
||||
std::cerr << "played joined side\n";
|
||||
|
|
Loading…
Add table
Reference in a new issue