-
Notifications
You must be signed in to change notification settings - Fork 172
/
GMActions.cpp
63 lines (57 loc) · 1.55 KB
/
GMActions.cpp
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
#include "GMActions.h"
#include "engine.h"
#include "gameGlobalInfo.h"
#include <SDL_assert.h>
const static int16_t CMD_RUN_SCRIPT = 0x0000;
const static int16_t CMD_SEND_GLOBAL_MESSAGE = 0x0001;
P<GameMasterActions> gameMasterActions;
REGISTER_MULTIPLAYER_CLASS(GameMasterActions, "GameMasterActions")
GameMasterActions::GameMasterActions()
: MultiplayerObject("GameMasterActions")
{
SDL_assert(!gameMasterActions);
gameMasterActions = this;
}
void GameMasterActions::onReceiveClientCommand(int32_t client_id, sp::io::DataBuffer& packet)
{
int16_t command;
packet >> command;
switch(command)
{
case CMD_RUN_SCRIPT:
{
string code;
packet >> code;
if (code.length() > 0)
{
P<ScriptObject> so = new ScriptObject();
so->runCode(code);
so->destroy();
}
}
break;
case CMD_SEND_GLOBAL_MESSAGE:
{
string message;
packet >> message;
if (message.length() > 0)
{
gameGlobalInfo->global_message = message;
gameGlobalInfo->global_message_timeout = 5.0;
}
}
break;
}
}
void GameMasterActions::commandRunScript(string code)
{
sp::io::DataBuffer packet;
packet << CMD_RUN_SCRIPT << code;
sendClientCommand(packet);
}
void GameMasterActions::commandSendGlobalMessage(string message)
{
sp::io::DataBuffer packet;
packet << CMD_SEND_GLOBAL_MESSAGE << message;
sendClientCommand(packet);
}