This repository was archived by the owner on Mar 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomm.cs
More file actions
101 lines (82 loc) · 2.36 KB
/
Copy pathcomm.cs
File metadata and controls
101 lines (82 loc) · 2.36 KB
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
function GlassHosting::connectToServer(%instance) {
%tcp = new TCPObject(GlassHostingTCP);
%tcp.instance = %instance;
%tcp.connect(%instance.address @ ":" @ %instance.port);
%instance.tcp = %tcp;
%instance.connecting = true;
}
function GlassHostingTCP::onConnected(%this) {
echo("Connected to Glass Hosting " @ %this.instance.ident @ "!");
%instance = %this.instance;
%instance.connecting = false;
%instance.connected = true;
}
function GlassHostingTCP::onConnectFailed(%this) {
echo("Connect failed!");
cancel(%this.reconnect);
%instance = %this.instance;
%addr = %instance.address @ ":" @ %instance.port;
%this.reconnect = %this.schedule(1000, connect, %addr);
}
function GlassHostingTCP::onLine(%this, %line) {
%call = getField(%line, 0);
%json = getField(%line, 1);
if(%call $= "usage")
return;
echo(%call);
if(%call $= "console" || %call $= "chat")
%json = strReplace(%json, "\\u", "[{u}]");
if(%json !$= "") {
if(jettisonParse(%json)) {
echo("Glass Hosting parse failed");
return;
}
%data = $JSON::Value;
} else {
%data = "";
}
switch$(%call) {
case "serverStatus":
echo("Status: " @ %data.status);
%this.instance.status = %data.status;
%this.instance.setStatus(%data.status);
case "serverValue":
for(%i = 0; %i < %data.keyCount; %i++) {
%key = %data.keyName[%i];
%val = %data.value[%key];
%this.instance.value[%key] = %val;
%this.instance.onValueUpdate(%key, %val);
}
case "console":
for(%i = 0; %i < 10; %i++) {
if(%i == 9)
%char = "e";
else
%char = %i+1;
%data.line = strReplace(%data.line, "[{u}]000" @ %char, collapseEscape("\\c" @ %i));
}
%this.instance.pushConsole(%data.line);
case "chat":
for(%i = 0; %i < 10; %i++) {
if(%i == 9)
%char = "e";
else
%char = %i+1;
%data.text = strReplace(%data.text, "[{u}]000" @ %char, collapseEscape("\\c" @ %i));
}
%this.instance.pushChat(%data.text);
}
}
function GlassHostingTCP::emit(%this, %call, %data) {
if(%data !$= "") {
if(!isObject(%data)) {
error("%data must be a jettison object!");
return;
} else {
%json = jettisonStringify("object", %data);
}
} else {
%json = "";
}
%this.send(%call TAB %json @ "\r\n");
}