-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustom_MOTD.uc
207 lines (169 loc) · 4.53 KB
/
Custom_MOTD.uc
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
class Custom_MOTD extends KFMOTD
config(MOTD_Config);
const VERSION = 31;
var String mutByMsg;
var config String getRequest, newsSource, newsIPAddr;
var automated GUIHTMLTextBox HTMLText;
function InitComponent(GUIController MyController, GUIComponent MyOwner)
{
super.InitComponent(MyController, MyOwner);
GetNewNews();
// HTMLText.SetContents(myMOTD); // Remove duplicate overlapping message
PanelCaption="News source: "$newsSource;
}
event Opened(GUIComponent Sender)
{
l_Version.Caption = "News Fixer:"@"v"$VERSION$" -- "$VersionString@"v"$PlayerOwner().Level.ROVersion;
super(Ut2k4Browser_Page).Opened(Sender);
}
protected function ROBufferedTCPLink CreateNewLink()
{
local class<ROBufferedTCPLink> NewLinkClass;
local ROBufferedTCPLink NewLink;
if ( PlayerOwner() == None )
return None;
if ( LinkClassName != "" )
{
NewLinkClass = class<ROBufferedTCPLink>(DynamicLoadObject( LinkClassName, class'Class'));
}
if ( NewLinkClass != None )
{
NewLink = PlayerOwner().Spawn( NewLinkClass );
}
NewLink.ResetBuffer();
return NewLink;
}
function ReceivedMOTD(MasterServerClient.EMOTDResponse Command, string Data)
{
}
function GetNewNews()
{
if(myLink == None)
{
myLink = CreateNewLink();
}
if(myLink != None)
{
myLink.ServerIpAddr.Port = 0;
sendGet = true;
myLink.Resolve(newsIPAddr); // NOTE: This is a non-blocking operation
SetTimer(ReReadyPause, true);
}
else
{
myMOTD = myMOTD$"|| myLink is None";
}
}
event Timer()
{
local string text;
local string page;
local string command;
if(myLink != None)
{
if ( myLink.ServerIpAddr.Port != 0)
{
if(myLink.IsConnected())
{
if(sendGet)
{
command = getRequest$myLink.CRLF$"Host: "$newsIPAddr$myLink.CRLF$myLink.CRLF;
myLink.SendCommand(command);
pageWait = true;
myLink.WaitForCount(1,20,1); // 20 sec timeout
sendGet = false;
}
else
{
if(pageWait)
{
myMOTD = myMOTD$".";
HTMLText.SetContents(myMOTD);
}
}
}
}
else
{
if (myRetryCount++ > myRetryMax)
{
myMOTD = myMOTD$"|| Retries Failed";
KillTimer();
HTMLText.SetContents(myMOTD);
}
}
if(myLink.PeekChar() != 0)
{
pageWait = false;
// data waiting
page = "";
while(myLink.ReadBufferedLine(text))
{
page = page$text;
}
NewsParse(page);
myMOTD = "<br>"$page;
HTMLText.SetContents(myMOTD);
myLink.DestroyLink();
myLink = none;
KillTimer();
}
}
SetTimer(ReReadyPause, true);
}
function NewsParse(out string page)
{
local string junk, joinedMsg, velsanMail, marcoMail, velsanCreds, marcoCreds, urlNote;
local int i;
junk = page;
Caps(junk);
i = InStr(junk, "<html>");
if ( i > -1 )
{
velsanMail="http://steamcommunity.com/id/Vel-San/";
marcoMail="http://steamcommunity.com/profiles/76561197975509070";
velsanCreds="<font color=yellow size=2>- Fixed by: <a href="$velsanMail$">Vel-San</a></font>";
marcoCreds="<font color=yellow size=2>- Base HTML Rendering Enhanced by Vel-San, Originally Created by <a href="$marcoMail$">Marco</a></font>";
urlNote="<hr><body BGCOLOR=black>";
mutByMsg=velsanCreds$"<br>"$marcoCreds;
joinedMsg=mutByMsg$urlNote;
// Replace page <BODY>
page = Repl(page, "<html>", joinedMsg, false);
// Remove all header from string
page = Right(page, len(page) - i);
}
junk = page;
Caps(junk);
i = InStr(junk, "</body>");
if ( i > -1 )
{
// remove all footers from string
page = Left(page, i);
}
page = Repl(page, "’", "'", false);
}
defaultproperties
{
VersionString="KF:"
myMOTD="Retrieving Latest Updates From The Server..."
Begin Object Class=GUIHTMLTextBox Name=MyMOTDText
WinTop=0.001679
WinHeight=0.833203
WinLeft=0.01
WinWidth=0.99
RenderWeight=0.600000
TabOrder=1
bNeverFocus=True
End Object
HTMLText=GUIHTMLTextBox'KFGui.Custom_MOTD.MyMOTDText'
Begin Object Class=GUILabel Name=VersionNum
TextAlign=TXTA_Right
StyleName="TextLabel"
WinTop=-0.043415
WinLeft=0.738500
WinWidth=0.252128
WinHeight=0.040000
RenderWeight=20.700001
End Object
l_Version=GUILabel'KFGui.Custom_MOTD.VersionNum'
}