blob: 4de87bedc7334578558f0d607fecae8b4bbeb64d (
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
|
/*
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::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);
std::list<NetClient *> clients;
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);
fd_set serverset;
int fdmax;
};
}
#endif // __INCLUDED_CORE_NETSERVER_H__
|