Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 31cfca6db3b93aae08f60186fa307c14caf05f56 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
   core/gameserver.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_GAMESERVER_H__
#define __INCLUDED_CORE_GAMESERVER_H__

#include "core/gameinterface.h"
#include "core/message.h"
#include "core/module.h"
#include "core/netserver.h"

namespace core
{

/// the core game server
/** the core game server runs the game module. Network access is enabled
 * for the dedicated server or the client with private server enabled.
 */
class GameServer : public GameInterface
{
public:
	GameServer();
	~GameServer();

/*----- inspectors ------------------------------------------------ */

	/// returns true if the game server can run a time frime
	inline bool running() const { return server_running; }

	/// returns true if the game server can not run a time frime
	inline bool error() const { return !server_running; }

	/// returns true if the game is running an interactive module
	virtual bool interactive() const;

	/// current server game time
	virtual inline unsigned long timestamp() const { return server_timestamp; }

	/// current module
	inline const Module *module() const { return server_module; }

/*----- mutators -------------------------------------------------- */

	/// is called when a player connects to the game server
	void player_connect(Player *player);

	/// is  called when a player disconnects from the game server
	void player_disconnect(Player *player);

	/// run a game server time frame
	void frame(unsigned long timestamp);
	
	/// a player sends a chat message to the public channel
	void say(Player *player, std::string const &args);

	/// a player sends a private message to another player
	void private_message(Player *player, std::string const &args);

	/// kick a player from the server
	void kick(Player *player, std::string const &reason);

	/// broadcast an Info message to all players
	void broadcast(std::string const message, Player *ignore_player = 0);

	/// broadcast a message to all players on a specified channel
	void broadcast(Message::Channel const channel, std::string const message, Player *ignore_player = 0);

	/// broadcast a sound to all players
	void broadcast_sound(std::string const sound, Player *ignore_player = 0);

	/// a player sends a command to the game server
	void exec(Player *player, std::string const &cmdline);

	/// time the server was started
	inline const unsigned long startup() const { return server_startup; }

/*----- static ---------------------------------------------------- */
	
	/// return the current game server
	static inline GameServer *instance() { return server_instance; }

protected:
	/// abort runing
	void abort();

private:
	void			load_config();
	void			save_config();
	bool			server_running;
	Module			*server_module;
	static GameServer	*server_instance;
	NetServer		*server_network;

	unsigned int		server_maxplayerid;

	unsigned long		server_timestamp;
	unsigned long		server_previoustime;
	unsigned long		server_startup;
};

inline GameServer *server() { return GameServer::instance(); }

}

#endif // __INCLUDED_CORE_GAMESERVER_H__