blob: d07f804d9bbdb975a5ca241ed5b1e9ea53e8fae2 (
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
|
/*
core/gameinterface.cc
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
#include <stdlib.h>
#include <iostream>
class GameInterface;
#include "core/application.h"
#include "core/gameinterface.h"
#include "core/player.h"
#include "sys/sys.h"
namespace core
{
GameInterface *game()
{
return GameInterface::instance();
}
GameInterface *GameInterface::gameinterface_instance = 0;
GameInterface::GameInterface(const char *gamename)
{
gameinterface_instance = this;
connected = false;
if (gamename)
game_name.assign(gamename);
else
game_name.clear();
}
GameInterface::~GameInterface()
{
gameinterface_instance = 0;
}
GameInterface *GameInterface::instance()
{
return gameinterface_instance;
}
std::string const &GameInterface::name()
{
return game_name;
}
void message_broadcast(std::string const & message, int ignoreplayer)
{
// send to console
con_print << message << std::endl;
// broadcast to remote clients
if (application()->netserver) {
std::string netmessage("msg info ");
netmessage.append(message);
netmessage += '\n';
application()->netserver->broadcast(netmessage, ignoreplayer);
}
}
void message_send(Player const &player, const char *protohdr, std::string message)
{
// send to console
if (&player == &localplayer) {
con_print << message << std::endl;
}
// send to remote clients
if (application()->netserver) {
NetClient *client = application()->netserver->find_client(player);
if (client) {
std::string netmessage("msg info ");
netmessage.append(message);
netmessage += '\n';
application()->netserver->send(client, message);
}
}
}
} // namespace core
|