blob: ab4976d79b0178aa82eb559a81a4a3dbe9a61e3b (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
 | /*
   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);
	/// 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);
	/// 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__
 |