various improvements to server.

made observers see perspective of currently playing player
This commit is contained in:
Dave White 2004-04-28 06:10:17 +00:00
parent c80f0a5e9d
commit 1e6b5a9061
15 changed files with 105 additions and 49 deletions

View file

@ -305,6 +305,7 @@ start_game="Start Game!"
game_cancelled="The game has been cancelled"
side_unavailable="The side you have chosen is no longer available"
waiting_start="Waiting for game to start..."
waiting_other_players="Waiting for network players to join"
getting_game_data="Getting game data..."
receive_game_list="Receiving game list..."
connecting_remote="Connecting to remote host..."

View file

@ -1234,6 +1234,7 @@ void check_victory(std::map<gamemap::location,unit>& units,
std::cout << "\n";
}
std::cerr << "throwing end level exception...\n";
throw end_level_exception(found_human ? VICTORY : DEFEAT);
}

View file

@ -448,11 +448,9 @@ config::config(const std::string& data,
read(data,line_sources);
}
config::config(const config& cfg) : values(cfg.values)
config::config(const config& cfg)
{
for(all_children_iterator j = cfg.ordered_begin(); j != cfg.ordered_end(); ++j) {
add_child(*(*j).first,*(*j).second);
}
append(cfg);
}
config::~config()
@ -468,15 +466,23 @@ config& config::operator=(const config& cfg)
clear();
values = cfg.values;
for(all_children_iterator j = cfg.ordered_begin(); j != cfg.ordered_end(); ++j) {
add_child(*(*j).first,*(*j).second);
}
append(cfg);
return *this;
}
void config::append(const config& cfg)
{
for(all_children_iterator i = cfg.ordered_begin(); i != cfg.ordered_end(); ++i) {
const std::pair<const std::string*,const config*>& value = *i;
add_child(*value.first,*value.second);
}
for(string_map::const_iterator j = cfg.values.begin(); j != cfg.values.end(); ++j) {
values[j->first] = j->second;
}
}
void config::read(const std::string& data,
const std::vector<line_source>* line_sources)
{

View file

@ -205,6 +205,10 @@ struct config
void apply_diff(const config& diff); //throw error
//append data from another config object to this one. attributes in the
//latter config object will clobber attributes in this one.
void append(const config& cfg);
//all the attributes of this node.
string_map values;

View file

@ -158,7 +158,6 @@ void cycle_focus()
bool has_focus(const handler* ptr)
{
std::cerr << "focus query " << (int)ptr << "\n";
if(event_contexts.empty()) {
return true;
}

View file

@ -913,6 +913,7 @@ bool event_handler::handle_event_command(const queued_event& event_info, const s
} else if(result == "continue") {
throw end_level_exception(CONTINUE);
} else {
std::cerr << "throwing event defeat...\n";
throw end_level_exception(DEFEAT);
}
}
@ -1171,10 +1172,13 @@ bool pump()
const std::string& event_name = ev.name;
typedef std::multimap<std::string,event_handler>::iterator itor;
std::cerr << "pumping event '" << event_name << "'\n";
//find all handlers for this event in the map
std::pair<itor,itor> i = events_map.equal_range(event_name);
while(i.first != i.second) {
std::cerr << "processing event '" << event_name << "'\n";
event_handler& handler = i.first->second;
if(process_event(handler, ev))
result = true;

View file

@ -253,8 +253,6 @@ SDL_Surface* get_image(const std::string& filename, TYPE type, COLOUR_ADJUSTMENT
//commented out pending reply from SDL team about bug report
//SDL_BlitSurface(mask,NULL,result,NULL);
}
} else {
std::cerr << "getting unmasked image...\n";
}
if(type == UNMASKED) {

View file

@ -104,12 +104,12 @@ void receive_gamelist(display& disp, config& data)
{
for(;;) {
const network::connection res = gui::network_data_dialog(disp,string_table["receive_game_list"],data);
check_response(res,data);
if(data.child("gamelist")) {
break;
}
const network::connection res = gui::network_data_dialog(disp,string_table["receive_game_list"],data);
check_response(res,data);
}
}
@ -258,11 +258,13 @@ 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,5000);
data_res = network::receive_data(data,0,3000);
if(!data_res) {
throw network::error(string_table["connection_timeout"]);
}
std::cerr << "login response: '" << data.write() << "'\n";
error = data.child("error");
} while(error != NULL);
@ -277,6 +279,8 @@ void play_multiplayer_client(display& disp, game_data& units_data, config& cfg,
receive_gamelist(disp,data);
}
std::cerr << "when receiving gamelist got '" << data.write() << "'\n";
//if we got a gamelist back - otherwise we have
//got a description of the game back
const config* const gamelist = data.child("gamelist");

View file

@ -47,7 +47,8 @@ mp_connect::mp_connect(display& disp, std::string game_name,
combos_team_(), combos_color_(), sliders_gold_(),
launch_(gui::button(disp, string_table["im_ready"])),
cancel_(gui::button(disp, string_table["cancel"])),
ai_(gui::button(disp, string_table["ai_players"]))
ai_(gui::button(disp, string_table["ai_players"])),
message_full_(true)
{
// Send Initial information
config response;
@ -493,7 +494,21 @@ void mp_connect::gui_update()
side["gold"],
rect.x, rect.y);
update_rect(rect);
}
const bool full = is_full();
if(full != message_full_) {
message_full_ = full;
if(full) {
message_bg_.restore();
message_bg_ = surface_restorer();
} else {
SDL_Rect rect = font::draw_text(NULL,rect_,12,font::NORMAL_COLOUR,string_table["waiting_other_players"],0,0);
rect.x = ai_.location().x + ai_.location().w + 10;
rect.y = ai_.location().y;
message_bg_ = surface_restorer(&disp_->video(),rect);
font::draw_text(disp_,rect,12,font::NORMAL_COLOUR,string_table["waiting_other_players"],rect.x,rect.y);
}
}
}
@ -647,10 +662,6 @@ lobby::RESULT mp_connect::process()
update_positions();
update_network();
events::pump();
disp_->video().flip();
SDL_Delay(20);
return lobby::CONTINUE;
}

View file

@ -95,6 +95,9 @@ private:
std::vector<surface_restorer> gold_bg_;
surface_restorer message_bg_;
bool message_full_;
std::deque<config> network_data_;
};

View file

@ -478,6 +478,10 @@ void set_default_send_size(size_t max_size)
void send_data(const config& cfg, connection connection_num, size_t max_size)
{
if(cfg.empty()) {
return;
}
if(bad_sockets.count(connection_num) || bad_sockets.count(0)) {
return;
}

View file

@ -94,6 +94,17 @@ namespace {
}
}
}
bool is_observer(const std::vector<team>& teams)
{
for(std::vector<team>::const_iterator i = teams.begin(); i != teams.end(); ++i) {
if(i->is_human()) {
return false;
}
}
return true;
}
}
LEVEL_RESULT play_level(game_data& gameinfo, const config& game_config,
@ -355,6 +366,10 @@ LEVEL_RESULT play_level(game_data& gameinfo, const config& game_config,
if(team_units(units,player_number) == 0)
continue;
if(is_observer(teams)) {
gui.set_team(size_t(player_number-1));
}
std::stringstream player_number_str;
player_number_str << player_number;
game_events::set_variable("side_number",player_number_str.str());
@ -515,7 +530,9 @@ redo_turn:
std::cout << "time over (draw)\n";
}
std::cerr << "firing time over event...\n";
game_events::fire("time over");
std::cerr << "done firing time over event...\n";
throw end_level_exception(DEFEAT);
}

View file

@ -1032,8 +1032,9 @@ void turn_info::cycle_units()
gui_.select_hex(selected_hex_);
current_route_.steps.clear();
gui_.set_route(NULL);
} else
} else {
next_unit_ = gamemap::location();
}
}
void turn_info::end_turn()
@ -2073,8 +2074,6 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
for(config::child_list::const_iterator ob = observers.begin(); ob != observers.end(); ++ob) {
gui_.add_observer((**ob)["name"]);
}
return PROCESS_CONTINUE;
}
if(cfg.child("observer_quit") != NULL) {
@ -2082,14 +2081,37 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
for(config::child_list::const_iterator ob = observers.begin(); ob != observers.end(); ++ob) {
gui_.remove_observer((**ob)["name"]);
}
return PROCESS_CONTINUE;
}
if(cfg.child("leave_game") != NULL) {
throw network::error("");
}
bool turn_end = false;
const config::child_list& turns = cfg.get_children("turn");
if(turns.empty() == false) {
//forward the data to other peers
network::send_data_all_except(cfg,from);
}
for(config::child_list::const_iterator t = turns.begin(); t != turns.end(); ++t) {
replay replay_obj(**t);
replay_obj.start_replay();
try {
turn_end |= do_replay(gui_,map_,gameinfo_,units_,teams_,
team_num_,status_,state_of_game_,&replay_obj);
} catch(replay::error& e) {
save_game(string_table["network_sync_error"]);
//throw e;
}
recorder.add_config(**t,replay::MARK_AS_SENT);
}
//if a side has dropped out of the game.
if(cfg["side_drop"] != "") {
const size_t side = atoi(cfg["side_drop"].c_str())-1;
@ -2128,26 +2150,5 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
}
}
bool turn_end = false;
if(cfg.child("turn") != NULL) {
//forward the data to other peers
network::send_data_all_except(cfg,from);
replay replay_obj(*cfg.child("turn"));
replay_obj.start_replay();
try {
turn_end = do_replay(gui_,map_,gameinfo_,units_,teams_,
team_num_,status_,state_of_game_,&replay_obj);
} catch(replay::error& e) {
save_game(string_table["network_sync_error"]);
//throw e;
}
recorder.add_config(*cfg.child("turn"),replay::MARK_AS_SENT);
}
return turn_end ? PROCESS_END_TURN : PROCESS_CONTINUE;
}

View file

@ -357,14 +357,15 @@ void server::run()
const player_map::iterator pl = players_.find(sock);
if(pl != players_.end()) {
pl->second.mark_available(true);
lobby_players_.send_data(sync_initial_response());
} else {
std::cerr << "ERROR: Could not find player in map\n";
}
//send the player who has quit the game list
network::send_data(initial_response_,sock);
//send all other players in the lobby the update to the lobby
lobby_players_.send_data(sync_initial_response(),sock);
}
continue;

View file

@ -188,6 +188,8 @@ bool scrollbar::set_grip_position(int pos)
pos = location().h - grip_height_;
grip_position_ = pos;
set_dirty();
return true;
}