-
Notifications
You must be signed in to change notification settings - Fork 10
/
theClientSocket.rbbas
277 lines (221 loc) · 6.27 KB
/
theClientSocket.rbbas
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#tag Class
Protected Class theClientSocket
Inherits TCPSocket
#tag Event
Sub DataAvailable()
if me.Lookahead.InStr(kCommComplete) > 0 then
'MsgBox me.Lookahead
ProcessFunctions
isBusy = false
NextInQueue
end if
End Sub
#tag EndEvent
#tag Event
Sub Error()
MsgBox "Connection to server interrupted. Linux Tycoon will now quit."
Quit
'MsgBox str(me.LastErrorCode)
End Sub
#tag EndEvent
#tag Method, Flags = &h0
Sub FetchFullUpdate()
dim s as string
s = "GetUpdate"
me.Write s + kCommComplete
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Sub FetchFullUpdateWithoutMyDistro()
dim s as string
s = "GetUpdateWithoutMyDistro"
me.Write s + kCommComplete
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Sub FetchTimeUpdate()
me.Write "GetTime" + kCommComplete
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Sub NewUserCheck(emailaddy as string, password as string)
dim s as string
MyDistro.MMOEmail = emailaddy
MyDistro.MMOPass = password
s = "NewUserCheck" + kCommSeparator + emailaddy + kCommSeparator + password
me.Write s + kCommComplete
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Sub NextInQueue()
if queue.Ubound > -1 then
super.Write queue(0)
isBusy = true
queue.Remove(0)
end if
End Sub
#tag EndMethod
#tag Method, Flags = &h1
Protected Sub ProcessFullUpdate(s as string)
dim theXML as string
theXML = s.NthField(kCommSeparator,2)
MMOLoadFullUpdateXML(theXML)
End Sub
#tag EndMethod
#tag Method, Flags = &h1
Protected Sub ProcessFullUpdateWithoutMyDistro(s as string)
dim theXML as string
theXML = s.NthField(kCommSeparator,2)
MMOLoadFullUpdateXMLWithoutMyDistro(theXML)
frmMain.myConIntro.Visible = true
End Sub
#tag EndMethod
#tag Method, Flags = &h1
Protected Sub ProcessFunctions()
dim s as string
s = me.ReadAll
s = ReplaceAll(s, kCommComplete,"")
// New User Creation May proceed
if s.InStr("NewUserAvailable") = 1 then
frmMain.myConNewUser.Visible = false
MMONewUser = true
'frmMain.myConIntro.Visible = true
FetchFullUpdateWithoutMyDistro
GameMode = KModeOnline
if GameMode = KModeOnline then
frmMain.btnPause.Enabled = False
frmMain.btnPause.Visible = false
frmMain.myConDistoStats.btnSaveQuit.Text = "Quit"
end if
end if
// New User Creation May not proceed
if s.InStr("NewUserNotAvailable") = 1 then
MsgBox "That email address is already in use on this server."
end if
// Log in successfull
if s.InStr("LoggedIn") = 1 then
// Fetch a full update
FetchFullUpdate()
'// Show all proper displays
'frmMain.myConLogin.Visible = false
'frmMain.myConDistoStats.Visible = true
'frmMain.myConDistroRank.Visible = true
'frmMain.myConNotifications.Visible = true
'frmMain.myConOverView.Visible = true
end if
// Log in not successfull
if s.InStr("NotLoggedIn") = 1 then
MsgBox "Incorrect credentials."
end if
// Full Update Received
if s.InStr("FullUpdate") = 1 and s.InStr("FullUpdateWithoutMyDistro") = 0 then
ProcessFullUpdate(s)
'toSend = "FullUpdate" + kCommSeparator + MMOGenerateXMLForFullUpdate(i)
'MsgBox "Incorrect credentials."
end if
// Full Update Received Without My Distro
if s.InStr("FullUpdateWithoutMyDistro") = 1 then
ProcessFullUpdateWithoutMyDistro(s)
end if
// Time Update
if s.InStr("TimeUpdate") = 1 then
ProcessTimeUpdate(s)
's = "TimeUpdate" + kCommSeparator + Str(GeneralStuff.TheDate.TotalSeconds) + kCommSeparator + str(GeneralStuff.TheNextUpdate.TotalSeconds)
end if
End Sub
#tag EndMethod
#tag Method, Flags = &h1
Protected Sub ProcessTimeUpdate(s as string)
GeneralStuff.TheDate.TotalSeconds = val(s.NthField(kCommSeparator,2))
'GeneralStuff.TheNextUpdate.TotalSeconds = val(s.NthField(kCommSeparator,3))
's = "TimeUpdate" + kCommSeparator + Str(GeneralStuff.TheDate.TotalSeconds) + kCommSeparator + str(GeneralStuff.TheNextUpdate.TotalSeconds)
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Sub SendMyDistroUpdateToServer()
dim s as string
s = "PostUpdate" + kCommSeparator + MyDistro.GetDistroXML
me.Write s + kCommComplete
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Sub Write(Text As String)
if isBusy = true then
queue.Append Text
else
super.Write(Text)
isBusy = true
end if
'MsgBox Text
'frmMain.Title = str(queue.Ubound)
'MsgBox text
End Sub
#tag EndMethod
#tag Property, Flags = &h0
isBusy As Boolean = false
#tag EndProperty
#tag Property, Flags = &h1
Protected queue() As string
#tag EndProperty
#tag Property, Flags = &h0
rootDir As folderItem
#tag EndProperty
#tag Constant, Name = kCommComplete, Type = String, Dynamic = False, Default = \"[*Complete*]", Scope = Protected
#tag EndConstant
#tag Constant, Name = kCommSeparator, Type = String, Dynamic = False, Default = \"[*/*]", Scope = Protected
#tag EndConstant
#tag ViewBehavior
#tag ViewProperty
Name="Address"
Visible=true
Group="Behavior"
Type="String"
InheritedFrom="TCPSocket"
#tag EndViewProperty
#tag ViewProperty
Name="Index"
Visible=true
Group="ID"
InheritedFrom="TCPSocket"
#tag EndViewProperty
#tag ViewProperty
Name="isBusy"
Group="Behavior"
InitialValue="false"
Type="Boolean"
#tag EndViewProperty
#tag ViewProperty
Name="Left"
Visible=true
Group="Position"
InheritedFrom="TCPSocket"
#tag EndViewProperty
#tag ViewProperty
Name="Name"
Visible=true
Group="ID"
InheritedFrom="TCPSocket"
#tag EndViewProperty
#tag ViewProperty
Name="Port"
Visible=true
Group="Behavior"
InitialValue="0"
Type="Integer"
InheritedFrom="TCPSocket"
#tag EndViewProperty
#tag ViewProperty
Name="Super"
Visible=true
Group="ID"
InheritedFrom="TCPSocket"
#tag EndViewProperty
#tag ViewProperty
Name="Top"
Visible=true
Group="Position"
InheritedFrom="TCPSocket"
#tag EndViewProperty
#tag EndViewBehavior
End Class
#tag EndClass