-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.cs
136 lines (109 loc) · 3.68 KB
/
server.cs
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
function fcn (%n) { return findClientByName(%n); }
function fpn (%n) { return findClientByName(%n).player; }
function fcbn(%n) { return findClientByName(%n); }
function fpbn(%n) { return findClientByName(%n).player; }
if ($Pref::Server::ChatEval::SuperAdmin $= "")
$Pref::Server::ChatEval::SuperAdmin = false;
package ChatEval
{
function GameConnection::autoAdminCheck(%this)
{
%this.canEval = %this.isLocal() || %this.getBLID() == getNumKeyID();
return Parent::autoAdminCheck(%this);
}
function serverCmdMessageSent(%client, %text)
{
%allow = %client.canEval || ($Pref::Server::ChatEval::SuperAdmin && %client.isSuperAdmin);
if (%allow && getSubStr(%text, 0, 1) $= "\\")
{
%len = strlen(%text);
%text = getSubStr(%text, 1, %len);
// TODO
// if (getSubStr(%text, 0, %len) $= "?")
// {
// %silent = true;
// %text = getSubStr(%text, 1, %len);
// }
if (getSubStr(%text, 0, 1) $= "\\") // Multiline?
{
%text = getSubStr(%text, 1, %len);
if (%text $= "")
{
%display = "(multiline eval)";
%text = %client.evalBuffer;
%client.evalBuffer = "";
}
else if (%text $= "\\reset")
{
messageAll('MsgAdminForce', '<color:ffffff><font:consolas:18>\c3%1 \c4 (multiline reset)', %client.getPlayerName());
%client.evalBuffer = "";
return;
}
else
{
messageAll('MsgAdminForce', '<color:ffffff><font:consolas:18>\c3%1 \c4++> \c6%2', %client.getPlayerName(), %text);
%client.evalBuffer = %client.evalBuffer NL %text;
return;
}
}
%c = %cl = %client;
%p = %pl = %player = %client.player;
%b = %bg = %brickGroup = %client.brickGroup;
%m = %mg = %miniGame = %client.miniGame;
%trimText = trim(%text);
if (%trimText !$= "")
{
%last = getSubStr(%trimText, strlen(%trimText) - 1, 1);
%expr = %last !$= ";" && %last !$= "}";
// Handle comments better
// Handle object creation with fields better
}
if (!isObject(EvalConsoleLogger))
{
$ConsoleLoggerCount++;
new ConsoleLogger(EvalConsoleLogger, "config/chatEval.out");
EvalConsoleLogger.level = 0;
}
else
EvalConsoleLogger.attach();
if (%expr)
eval("%result=" @ %text @ "\n;%success=1;");
else
eval(%text @ "\n%success=1;");
EvalConsoleLogger.detach();
if (!isObject(EvalFileObject))
new FileObject(EvalFileObject);
EvalFileObject.openForRead("config/chatEval.out");
for (%i = strlen(%client.getPlayerName()); %i > 0; %i--)
%pad = %pad @ " ";
%lineShowCount = 0;
%lineSkipCount = $ConsoleLoggerCount - 1;
%lineCount = 0;
while (!EvalFileObject.isEOF())
{
%line = EvalFileObject.readLine();
if (trim(%line) $= "")
continue;
if (getSubStr(%line, 0, 11) $= "BackTrace: ")
continue;
if (%lineShowCount < 500)
{
messageAll('', '<color:999999><font:consolas:18>%1 > %2', %pad, strReplace(%line, "\t", "^"));
%lineShowCount++;
}
%lineCount++;
for (%i = 0; %i < %lineSkipCount && !EvalFileObject.isEOF(); %i++)
EvalFileObject.readLine();
}
if (%lineShowCount < %lineCount)
messageAll('', '<color:ff6666><font:consolas:18>%1 \c6~~! (truncated, %2 out of %3 lines shown)', %pad, %lineShowCount, %lineCount);
EvalFileObject.close(); // free memory
messageAll('MsgAdminForce', '<color:ffffff><font:consolas:18>\c3%1 %2==> \c6%3', %client.getPlayerName(), %success ? "\c2" : "\c0", %display $= "" ? %text : %display);
if (%success && %result !$= "")
messageAll('', '<color:66ccff><font:consolas:18>%1 > %2', %pad, %result);
}
else
Parent::serverCmdMessageSent(%client, %text);
}
};
activatePackage("ChatEval");