/* core/netserver.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_NETSERVER_H__ #define __INCLUDED_CORE_NETSERVER_H__ #include #include #include #include "net/tcpserver.h" #include "core/netclient.h" namespace core { /// Network server class NetServer : public net::TCPServer { public: NetServer(std::string const host, unsigned int const port); virtual ~NetServer(); /// run one server frame void frame(float seconds); /// broadcast a message to all clients void broadcast(std::string const & message, int ignorefd=-1); /// send a message to a client void send(NetClient * client, std::string const & message); /// find the client corresponding to a player NetClient *find_client(Player const *player); protected: /// called by accept() when a new client connects virtual void client_connect(int const clientfd, std::string const host, int const port); /// remove terminated clients void reap(); /// parse incoming client messages void parse_incoming_message(NetClient *client, const std::string & message); std::list clients; fd_set serverset; int fdmax; }; } #endif // __INCLUDED_CORE_NETSERVER_H__