-
Notifications
You must be signed in to change notification settings - Fork 4
/
_log.gsc
86 lines (70 loc) · 1.49 KB
/
_log.gsc
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
#include scripts\_utility;
STORAGE_KEY = "_log__chat";
init()
{
setDvarIfUninitialized("src_log_chat_maxlength", 16);
level thread OnPlayerSaid();
}
// ##### PUBLIC START #####
logChat(text)
{
msg = spawnStruct();
msg.guid = self.guid;
msg.name = self.name;
msg.time = getTime();
msg.systemTime = getSystemTime();
msg.text = text;
log = getChatLog();
log[log.size] = msg;
if (log.size > getDvarInt("src_log_chat_maxlength"))
log = arrayRemoveIndex(log, 0);
setChatLog(log);
}
getChatLog()
{
array = [];
i = 0;
while (storageHas(STORAGE_KEY + "[" + i + "]"))
{
raw = strTok(storageGet(STORAGE_KEY + "[" + i + "]"), "%");
msg = spawnStruct();
msg.guid = raw[0];
msg.name = raw[1];
msg.time = int(raw[2]);
msg.systemTime = int(raw[3]);
msg.text = ternary(raw[4] == " ", "", raw[4]);
array[array.size] = msg;
i++;
}
return array;
}
// ##### PUBLIC END #####
setChatLog(array)
{
clearChatLog();
foreach (i, msg in array)
{
// Make empty messages a space to prevent strTok() from skipping
// the entry entirely and messing up deserialization.
text = ternary(msg.text == "", " ", msg.text);
str = msg.guid + "%" + msg.name + "%" + msg.time + "%" + msg.systemTime + "%" + text;
storageSet(STORAGE_KEY + "[" + i + "]", str);
}
}
clearChatLog()
{
i = 0;
while (storageHas(STORAGE_KEY + "[" + i + "]"))
{
storageRemove(STORAGE_KEY + "[" + i + "]");
i++;
}
}
OnPlayerSaid()
{
for (;;)
{
level waittill("say", text, player);
player logChat(text);
}
}