game Class Reference

#include <game.hpp>

Collaboration diagram for game:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 game (player_map &players, const network::connection host=0, const std::string name="")
 ~game ()
int id () const
const std::string & name () const
bool is_owner (const network::connection player) const
bool is_member (const network::connection player) const
bool allow_observers () const
bool is_observer (const network::connection player) const
bool is_player (const network::connection player) const
bool player_is_banned (const network::connection player) const
bool level_init () const
bool started () const
size_t nplayers () const
size_t nobservers () const
size_t current_turn () const
void mute_all_observers ()
void mute_observer (const simple_wml::node &mute, const player_map::const_iterator muter)
 Mute an observer by name.
network::connection kick_member (const simple_wml::node &kick, const player_map::const_iterator kicker)
 Kick a member by name.
network::connection ban_user (const simple_wml::node &ban, const player_map::const_iterator banner)
 Ban and kick a user by name. He doesn't need to be in this game.
void add_player (const network::connection player, bool observer=false)
bool remove_player (const network::connection player, const bool disconnect=false)
const user_vector all_game_users () const
 Adds players and observers into one vector and returns that.
void add_players (const game &other_game, const bool observer=true)
 Adds players from one game to another.
void start_game (const player_map::const_iterator starter)
void load_next_scenario (const player_map::const_iterator user) const
 A user (player only?) asks for the next scenario to advance to.
void update_side_data ()
 Resets the side configuration according to the scenario data.
void transfer_side_control (const network::connection sock, const simple_wml::node &cfg)
 Let's a player owning a side give it to another player or observer.
void process_message (simple_wml::document &data, const player_map::iterator user)
bool process_turn (simple_wml::document &data, const player_map::const_iterator user)
 Filters and processes (some) commands.
bool describe_slots ()
 Set the description to the number of available slots.
void send_server_message_to_all (const char *message, network::connection exclude=0) const
void send_server_message (const char *message, network::connection sock=0, simple_wml::document *doc=NULL) const
void send_and_record_server_message (const char *message, const network::connection exclude=0)
 Send data to all players in this game except 'exclude'.
void send_data (simple_wml::document &data, const network::connection exclude=0) const
void send_to_one (simple_wml::document &data, const network::connection sock) const
void record_data (simple_wml::document *data)
simple_wml::documentlevel ()
 The full scenario data.
void set_description (simple_wml::node *desc)
 Functions to set/get the address of the game's summary description as sent to players in the lobby.
simple_wml::nodedescription () const
void set_password (const std::string &passwd)
bool password_matches (const std::string &passwd) const
const std::string & termination_reason () const
void set_termination_reason (const std::string &reason)

Private Member Functions

 game (const game &)
void operator= (const game &)
size_t current_side () const
network::connection current_player () const
bool is_current_player (const network::connection player) const
bool is_muted_observer (const network::connection player) const
bool all_observers_muted () const
bool take_side (const player_map::const_iterator user)
 Figures out which side to take and tells that side to the game owner.
void send_change_controller (const size_t side_num, const player_map::const_iterator newplayer, const bool player_left=true)
 Send [change_controller] message to tell all clients the new controller's name.
void transfer_ai_sides ()
void send_data_team (simple_wml::document &data, const simple_wml::string_span &team, const network::connection exclude=0) const
void send_data_observers (simple_wml::document &data, const network::connection exclude=0) const
void send_observerjoins (const network::connection sock=0) const
 Send [observer] tags of all the observers in the game to the user or everyone if none given.
void send_observerquit (const player_map::const_iterator observer) const
void send_history (const network::connection sock) const
void notify_new_host ()
 In case of a host transfer, notify the new host about its status.
player_map::const_iterator find_user (const simple_wml::string_span &name) const
 Convenience function for finding a user by name.
bool observers_can_label () const
bool observers_can_chat () const
bool is_legal_command (const simple_wml::node &command, bool is_player)
bool is_on_team (const simple_wml::string_span &team, const network::connection player) const
 Function which returns true iff 'player' is on 'team'.
bool end_turn ()
 Function which should be called every time a player ends their turn (i.e.
void send_user_list (const network::connection exclude=0) const
 Function to send a list of users to all clients.
std::string debug_player_info () const
 Helps debugging player and observer lists.

Private Attributes

player_mapplayer_info_
int id_
std::string name_
 The name of the game.
std::string password_
network::connection owner_
 The game host or later owner (if the host left).
user_vector players_
 A vector of players (members owning a side).
user_vector observers_
 A vector of observers (members not owning a side).
user_vector muted_observers_
side_vector sides_
 A vector of side owners.
std::vector< bool > sides_taken_
 A vector indicating what sides are actually taken. (Really needed?).
std::vector< std::string > side_controllers_
 A vector of controller strings indicating the type.
int nsides_
 Number of sides in the current scenario.
bool started_
simple_wml::document level_
 The current scenario data.
std::vector
< simple_wml::document * > 
history_
 Replay data.
simple_wml::nodedescription_
 Pointer to the game's description in the games_and_users_list_.
int end_turn_
bool all_observers_muted_
std::vector< std::string > bans_
std::string termination_

Static Private Attributes

static int id_num = 1


Detailed Description

Definition at line 32 of file game.hpp.


Constructor & Destructor Documentation

game::game ( player_map players,
const network::connection  host = 0,
const std::string  name = "" 
)

game::~game (  ) 

game::game ( const game  )  [private]


Member Function Documentation

int game::id (  )  const [inline]

Definition at line 38 of file game.hpp.

References id_.

Referenced by game_id_matches::operator()(), and server::process_data_game().

const std::string& game::name (  )  const [inline]

Definition at line 39 of file game.hpp.

References name_.

Referenced by ban_user(), kick_member(), mute_observer(), and server::process_data_game().

bool game::is_owner ( const network::connection  player  )  const [inline]

Definition at line 41 of file game.hpp.

References owner_.

Referenced by server::process_data_game().

bool game::is_member ( const network::connection  player  )  const [inline]

Definition at line 42 of file game.hpp.

References is_observer(), and is_player().

Referenced by add_player(), ban_user(), kick_member(), remove_player(), server::run(), and transfer_side_control().

bool game::allow_observers (  )  const

Referenced by add_player().

bool game::is_observer ( const network::connection  player  )  const

bool game::is_player ( const network::connection  player  )  const

bool game::player_is_banned ( const network::connection  player  )  const

Referenced by ban_user().

bool game::level_init (  )  const [inline]

Definition at line 48 of file game.hpp.

References simple_wml::document::child(), and level_.

Referenced by server::process_data_game().

bool game::started (  )  const [inline]

Definition at line 49 of file game.hpp.

References started_.

Referenced by server::process_data_game().

size_t game::nplayers (  )  const [inline]

Definition at line 51 of file game.hpp.

References players_.

Referenced by server::process_data_game().

size_t game::nobservers (  )  const [inline]

Definition at line 52 of file game.hpp.

References observers_.

Referenced by server::dump_stats(), and server::process_command().

size_t game::current_turn (  )  const [inline]

Definition at line 53 of file game.hpp.

References end_turn_, and nsides_.

Referenced by end_turn(), server::process_data_game(), and remove_player().

void game::mute_all_observers (  ) 

void game::mute_observer ( const simple_wml::node mute,
const player_map::const_iterator  muter 
)

Mute an observer by name.

Referenced by server::process_data_game().

network::connection game::kick_member ( const simple_wml::node kick,
const player_map::const_iterator  kicker 
)

Kick a member by name.

Referenced by server::process_data_game().

network::connection game::ban_user ( const simple_wml::node ban,
const player_map::const_iterator  banner 
)

Ban and kick a user by name. He doesn't need to be in this game.

Referenced by server::process_data_game().

void game::add_player ( const network::connection  player,
bool  observer = false 
)

bool game::remove_player ( const network::connection  player,
const bool  disconnect = false 
)

const user_vector game::all_game_users (  )  const

Adds players and observers into one vector and returns that.

Referenced by add_players(), send_data(), send_user_list(), and update_side_data().

void game::add_players ( const game other_game,
const bool  observer = true 
)

Adds players from one game to another.

This is used to add players and observers from a game to the lobby (which is also implemented as a game), if that game ends. The second parameter controls, wether the players are added to the players_ or observers_ vector (default observers_).

Referenced by server::delete_game().

void game::start_game ( const player_map::const_iterator  starter  ) 

void game::load_next_scenario ( const player_map::const_iterator  user  )  const

A user (player only?) asks for the next scenario to advance to.

Referenced by server::process_data_game().

void game::update_side_data (  ) 

Resets the side configuration according to the scenario data.

Referenced by server::process_data_game(), and start_game().

void game::transfer_side_control ( const network::connection  sock,
const simple_wml::node cfg 
)

Let's a player owning a side give it to another player or observer.

Referenced by server::process_data_game().

void game::process_message ( simple_wml::document data,
const player_map::iterator  user 
)

bool game::process_turn ( simple_wml::document data,
const player_map::const_iterator  user 
)

Filters and processes (some) commands.

Returns true iff the turn ended.

Referenced by server::process_data_game().

bool game::describe_slots (  ) 

Set the description to the number of available slots.

Returns true iff the number of slots has changed.

Referenced by server::process_data_game().

void game::send_server_message_to_all ( const char *  message,
network::connection  exclude = 0 
) const

void game::send_server_message ( const char *  message,
network::connection  sock = 0,
simple_wml::document doc = NULL 
) const

void game::send_and_record_server_message ( const char *  message,
const network::connection  exclude = 0 
)

void game::send_data ( simple_wml::document data,
const network::connection  exclude = 0 
) const

void game::send_to_one ( simple_wml::document data,
const network::connection  sock 
) const

void game::record_data ( simple_wml::document data  ) 

simple_wml::document& game::level (  )  [inline]

The full scenario data.

Definition at line 102 of file game.hpp.

References level_.

Referenced by server::process_data_game(), and server::process_data_lobby().

void game::set_description ( simple_wml::node desc  ) 

Functions to set/get the address of the game's summary description as sent to players in the lobby.

Referenced by server::process_data_game().

simple_wml::node* game::description (  )  const [inline]

Definition at line 107 of file game.hpp.

References description_.

Referenced by server::process_data_game(), and server::update_game_in_lobby().

void game::set_password ( const std::string &  passwd  )  [inline]

Definition at line 109 of file game.hpp.

References password_.

Referenced by server::process_data_lobby().

bool game::password_matches ( const std::string &  passwd  )  const [inline]

Definition at line 110 of file game.hpp.

References password_.

const std::string& game::termination_reason (  )  const [inline]

Definition at line 114 of file game.hpp.

References started_, and termination_.

Referenced by server::process_data_game(), and remove_player().

void game::set_termination_reason ( const std::string &  reason  ) 

void game::operator= ( const game  )  [private]

size_t game::current_side (  )  const [inline, private]

Definition at line 127 of file game.hpp.

References end_turn_, and nsides_.

Referenced by current_player(), end_turn(), and process_turn().

network::connection game::current_player (  )  const [inline, private]

Definition at line 128 of file game.hpp.

References current_side(), nsides_, and sides_.

Referenced by is_current_player(), and process_turn().

bool game::is_current_player ( const network::connection  player  )  const [inline, private]

Definition at line 130 of file game.hpp.

References current_player().

Referenced by process_turn().

bool game::is_muted_observer ( const network::connection  player  )  const [private]

Referenced by mute_observer(), and process_turn().

bool game::all_observers_muted (  )  const [inline, private]

Definition at line 133 of file game.hpp.

References all_observers_muted_.

bool game::take_side ( const player_map::const_iterator  user  )  [private]

Figures out which side to take and tells that side to the game owner.

Referenced by add_player().

void game::send_change_controller ( const size_t  side_num,
const player_map::const_iterator  newplayer,
const bool  player_left = true 
) [private]

Send [change_controller] message to tell all clients the new controller's name.

Referenced by remove_player(), and transfer_side_control().

void game::transfer_ai_sides (  )  [private]

void game::send_data_team ( simple_wml::document data,
const simple_wml::string_span team,
const network::connection  exclude = 0 
) const [private]

Referenced by process_turn().

void game::send_data_observers ( simple_wml::document data,
const network::connection  exclude = 0 
) const [private]

Referenced by process_turn().

void game::send_observerjoins ( const network::connection  sock = 0  )  const [private]

Send [observer] tags of all the observers in the game to the user or everyone if none given.

Referenced by add_player(), load_next_scenario(), and start_game().

void game::send_observerquit ( const player_map::const_iterator  observer  )  const [private]

void game::send_history ( const network::connection  sock  )  const [private]

Referenced by add_player(), and load_next_scenario().

void game::notify_new_host (  )  [private]

In case of a host transfer, notify the new host about its status.

Referenced by remove_player().

player_map::const_iterator game::find_user ( const simple_wml::string_span name  )  const [private]

Convenience function for finding a user by name.

Referenced by ban_user(), kick_member(), and mute_observer().

bool game::observers_can_label (  )  const [inline, private]

Definition at line 155 of file game.hpp.

bool game::observers_can_chat (  )  const [inline, private]

Definition at line 156 of file game.hpp.

bool game::is_legal_command ( const simple_wml::node command,
bool  is_player 
) [private]

Referenced by process_turn().

bool game::is_on_team ( const simple_wml::string_span team,
const network::connection  player 
) const [private]

Function which returns true iff 'player' is on 'team'.

Referenced by process_turn(), and send_data_team().

bool game::end_turn (  )  [private]

Function which should be called every time a player ends their turn (i.e.

[end_turn] received). This will update the 'turn' attribute for the game's description when appropriate. Will return true iff there has been a change.

Referenced by process_turn(), and start_game().

void game::send_user_list ( const network::connection  exclude = 0  )  const [private]

Function to send a list of users to all clients.

Only sends data if the game is initialized but not yet started.

Referenced by add_player(), and remove_player().

std::string game::debug_player_info (  )  const [private]

Helps debugging player and observer lists.

Referenced by add_player(), remove_player(), take_side(), and update_side_data().


Member Data Documentation

int game::id_num = 1 [static, private]

Definition at line 176 of file game.hpp.

int game::id_ [private]

std::string game::name_ [private]

The name of the game.

Definition at line 179 of file game.hpp.

Referenced by add_player(), ban_user(), game(), kick_member(), mute_observer(), name(), remove_player(), and start_game().

std::string game::password_ [private]

Definition at line 180 of file game.hpp.

Referenced by password_matches(), set_description(), and set_password().

A vector of players (members owning a side).

Definition at line 184 of file game.hpp.

Referenced by add_player(), add_players(), all_game_users(), debug_player_info(), game(), is_player(), nplayers(), remove_player(), send_data_team(), transfer_side_control(), and update_side_data().

Definition at line 187 of file game.hpp.

Referenced by is_muted_observer(), and mute_observer().

std::vector<bool> game::sides_taken_ [private]

A vector indicating what sides are actually taken. (Really needed?).

Definition at line 191 of file game.hpp.

Referenced by describe_slots(), remove_player(), take_side(), transfer_side_control(), and update_side_data().

std::vector<std::string> game::side_controllers_ [private]

A vector of controller strings indicating the type.

"network" - a side controlled by some member of the game (not the owner) "human" - a side controlled by the owner "ai" - a side of the owner controlled by an AI "null" - an empty side

Definition at line 197 of file game.hpp.

Referenced by end_turn(), remove_player(), take_side(), transfer_ai_sides(), transfer_side_control(), and update_side_data().

int game::nsides_ [private]

Number of sides in the current scenario.

Definition at line 200 of file game.hpp.

Referenced by current_player(), current_side(), current_turn(), end_turn(), and start_game().

bool game::started_ [private]

std::vector<simple_wml::document*> game::history_ [mutable, private]

Replay data.

Definition at line 206 of file game.hpp.

Referenced by record_data(), send_history(), start_game(), and ~game().

Pointer to the game's description in the games_and_users_list_.

Definition at line 208 of file game.hpp.

Referenced by describe_slots(), description(), end_turn(), send_user_list(), and set_description().

int game::end_turn_ [private]

Definition at line 210 of file game.hpp.

Referenced by current_side(), current_turn(), end_turn(), and start_game().

std::vector<std::string> game::bans_ [private]

Definition at line 214 of file game.hpp.

Referenced by ban_user(), and player_is_banned().

std::string game::termination_ [private]

Definition at line 216 of file game.hpp.

Referenced by set_termination_reason(), and termination_reason().


The documentation for this class was generated from the following files:

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs