/* 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 "sys/timer.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: enum Mode {SinglePlayer = 1, MultiPlayer = 2}; GameServer(); virtual ~GameServer(); /*----- inspectors ------------------------------------------------ */ /// current module inline Module *module() { return server_module; } /*----- 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 virtual void frame(const unsigned long timestamp); /// server timer inline const sys::Timer & timer() { return server_timer; } /// a player sends a chat message to the global chat channel void shout(Player *player, std::string const &args); /// a player sends a chat message to the local chat 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); /*----- messages -------------------------------------------------- */ /// send a message to a single player void message(Player *player, core::Message::Channel channel, const std::string text); /// broadcast an Info message to all players void broadcast(std::string const message, Player *ignore_player = 0); /// broadcast an Info message to all players in a particular zone void broadcast(Zone *zone, std::string const message, Player *ignore_player = 0); /// broadcast a message to all players on a specified channel void broadcast(Message::Channel const channel, std::string const message, Player *ignore_player = 0); /// broadcast a sound to all players void broadcast_sound(std::string const sound, Player *ignore_player = 0); /// send a messagebox to a single player void messagebox(Player *player, const std::string & text, const std::string &label1, const std::string command1, const std::string &label2, const std::string command2); /// a player sends a command to the game server void exec(Player *player, std::string const &cmdline); /// request info record with id virtual Info *request_info(const unsigned int id); /// request inventory for entity with id virtual Inventory *request_inventory(Entity *entity); inline Mode mode() const { return server_mode; } /*----- static ---------------------------------------------------- */ /// return the current game server static inline GameServer *instance() { return server_instance; } private: void load_config(); void save_config(); Module *server_module; static GameServer *server_instance; NetServer *server_network; unsigned int server_maxplayerid; unsigned long server_previoustime; sys::Timer server_timer; Mode server_mode; }; inline GameServer *server() { return GameServer::instance(); } } #endif // __INCLUDED_CORE_GAMESERVER_H__