Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-02-14 18:04:25 +0000
committerStijn Buys <ingar@osirion.org>2008-02-14 18:04:25 +0000
commit715d0c3952a3a1d59b64074e472d0a9a3b414351 (patch)
treea5d0ddd0613caaf4f9fe01f9a3bd34e823651ad5 /src/core/netserver.h
parent83e8023c5e46635753a609329cf9805a3520001e (diff)
dedicated server accepts incoming connections
Diffstat (limited to 'src/core/netserver.h')
-rw-r--r--src/core/netserver.h60
1 files changed, 60 insertions, 0 deletions
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 <sys/select.h>
+
+#include <list>
+#include <string>
+
+#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<NetClient *> clients;
+ fd_set serverset;
+ int fdmax;
+};
+
+}
+
+#endif // __INCLUDED_CORE_NETSERVER_H__