/* core/gameserver.h This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_CORE_GAMESERVER_H__ #define __INCLUDED_CORE_GAMESERVER_H__ #include "core/gameinterface.h" #include "core/message.h" #include "core/module.h" #include "core/netserver.h" namespace core { /// the core game server /** the core game server runs the game module. Network access is enabled * for the dedicated server or the client with private server enabled. */ class GameServer : public GameInterface { public: GameServer(); ~GameServer(); /*----- inspectors ------------------------------------------------ */ /// returns true if the game server can run a time frime inline bool running() { return server_running; } /// returns true if the game server can not run a time frime inline bool error() { return !server_running; } /// returns true if the game is running an interactive module bool interactive(); /// show the current time void showtime(); /// current server game time inline float time() const { return server_time; } /*----- mutators -------------------------------------------------- */ /// is called when a player connects to the game server void player_connect(Player *player); /// is called when a player disconnects from the game server void player_disconnect(Player *player); /// run a game server time frame void frame(float seconds); /// a player sends a chat message to the public channel void say(Player *player, std::string const &args); /// a player sends a private message to another player void private_message(Player *player, std::string const &args); /// kick a player from the server void kick(Player *player, std::string const &reason); /// broadcast an Info message to all players void broadcast(std::string const message, Player *ignore_player = 0); /// broadcast a message to all players on a specified channel void broadcast_message(Message::Channel const channel, std::string const message, Player *ignore_player = 0); /// send an Info message to a single player void send(Player *player, std::string const message); /// send a RCon message to a single player void send_rcon(Player *player, std::string const message); /// send a message on the specific channel to the specified Player void send_message(Message::Channel const channel, Player *player, std::string const message); /// broadcast a sound to all players void broadcast_sound(std::string const sound, Player *ignore_player = 0); /// send a sound to a single player void send_sound(Player *player, std::string const sound); /// a player sends a command to the game server void exec(Player *player, std::string const &cmdline); /// find the first player who's id or name matches the search string Player *find_player(std::string const search); /*----- static ---------------------------------------------------- */ /// return the current game server static inline GameServer *instance() { return server_instance; } protected: /// abort runing void abort(); private: void load_config(); void save_config(); bool server_running; Module *server_module; static GameServer *server_instance; NetServer *server_network; unsigned int server_maxplayerid; float server_frametime; float server_time; float server_previoustime; }; inline GameServer *server() { return GameServer::instance(); } } #endif // __INCLUDED_CORE_GAMESERVER_H__