-
Notifications
You must be signed in to change notification settings - Fork 0
/
collector.inc
81 lines (64 loc) · 1.5 KB
/
collector.inc
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
#include <a_samp>
#include <redis>
#include <requests>
#include <YSI-Coding\y_hooks>
#include "redis-config.inc"
#include "player-store.inc"
static
Redis:gClient;
#define EVENT_MAX_DATA_LENGTH (256)
/*
* Hooks
*/
hook OnGameModeInit()
{
Redis_Connect(REDIS_HOST, REDIS_PORT, REDIS_AUTH, gClient);
return 1;
}
hook OnGameModeExit()
{
Redis_Disconnect(gClient);
return 1;
}
hook OnPlayerConnect(playerid)
{
Redis_StorePlayerInfo(gClient, playerid);
return 1;
}
/*
* Helpers
*/
stock Redis_PublishJson(Redis:client, const channel[], Node:node)
{
new jsonString[EVENT_MAX_DATA_LENGTH];
JsonStringify(node, jsonString);
return Redis_Publish(client, channel, jsonString);
}
stock History_GetRoodNode(const event[], &Node:node)
{
node = JsonObject(
"event", JsonString(event)
);
}
/*
* Collectors
*/
stock History_CollectGeneralEvent(const event[], Node:params)
{
new
Node:rootNode;
History_GetRoodNode(event, rootNode);
JsonSetObject(rootNode, event, params);
return Redis_PublishJson(gClient, HISTORY_DC_CHANNEL_GENERAL, rootNode);
}
stock History_CollectPlayerEvent(const event[], playerid, Node:params)
{
new
Node:rootNode,
Node:playerNode;
History_GetRoodNode(event, rootNode);
Redis_GetPlayerInfo(gClient, playerid, playerNode);
JsonSetObject(rootNode, "player", playerNode);
JsonSetObject(rootNode, event, params);
return Redis_PublishJson(gClient, HISTORY_DC_CHANNEL_PLAYER, rootNode);
}