From 715d0c3952a3a1d59b64074e472d0a9a3b414351 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 14 Feb 2008 18:04:25 +0000 Subject: dedicated server accepts incoming connections --- src/core/netserver.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/core/netserver.h (limited to 'src/core/netserver.h') diff --git a/src/core/netserver.h b/src/core/netserver.h new file mode 100644 index 0000000..4d1eb73 --- /dev/null +++ b/src/core/netserver.h @@ -0,0 +1,60 @@ +/* + 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::ostringstream &osstream, int ignorefd=-1); + + /// send a message to a client + void send(NetClient * client, std::ostringstream &osstream); + + /// send a message to a client + void send(NetClient * client, std::string message); + +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); + + /// parse client variable + void parse_client_variable(NetClient * client, const std::string varname, std::istringstream &istringstream); + + std::list clients; + fd_set serverset; + int fdmax; +}; + +} + +#endif // __INCLUDED_CORE_NETSERVER_H__ -- cgit v1.2.3