-
Notifications
You must be signed in to change notification settings - Fork 10
/
theServerSocket.rbbas
296 lines (222 loc) · 7.39 KB
/
theServerSocket.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#tag Class
Protected Class theServerSocket
Inherits TCPSocket
#tag Event
Sub DataAvailable()
ProcessFunctions
End Sub
#tag EndEvent
#tag Event
Sub Error()
'MsgBox str(me.LastErrorCode)
End Sub
#tag EndEvent
#tag Method, Flags = &h1
Protected Sub GetFullUpdate(s as string)
dim EmailAddy as string
dim Password as string
EmailAddy = Lowercase(s.NthField(kCommSeparator,2))
Password = s.NthField(kCommSeparator,3)
// Search for email and pass
dim toSend as string
dim i as integer
i = GetDistroIndexFromMMOEmail(EmailAddy)
if i = -1 then
else
if OtherDistros(i).MMOPass = Password then
toSend = "FullUpdate" + kCommSeparator + MMOGenerateXMLForFullUpdate(i)
me.Write toSend
end if
end if
End Sub
#tag EndMethod
#tag Method, Flags = &h1
Protected Sub GetFullUpdateWithoutMyDistro()
dim toSend as string
toSend = "FullUpdateWithoutMyDistro" + kCommSeparator + MMOGenerateXMLForFullUpdateWithoutMyDistro
me.Write toSend
End Sub
#tag EndMethod
#tag Method, Flags = &h1
Protected Sub GetTimeUpdate()
dim s as string
s = "TimeUpdate" + kCommSeparator + Str(GeneralStuff.TheDate.TotalSeconds) + kCommSeparator + str(GeneralStuff.TheNextUpdate.TotalSeconds)
me.Write s
End Sub
#tag EndMethod
#tag Method, Flags = &h1
Protected Sub Login(s as string)
dim EmailAddy as string
dim Password as string
EmailAddy = Lowercase(s.NthField(kCommSeparator,2))
Password = s.NthField(kCommSeparator,3)
// Search for email and pass
dim i as integer
dim result as string
i = GetDistroIndexFromMMOEmail(EmailAddy)
result = "NotLoggedIn"
if i = -1 then
else
if OtherDistros(i).MMOPass = Password then
result = "LoggedIn"
end if
end if
me.Write result
End Sub
#tag EndMethod
#tag Method, Flags = &h1
Protected Sub NewUserCheck(s as string)
dim EmailAddy as string
dim Password as string
EmailAddy = Lowercase(s.NthField(kCommSeparator,2))
Password = s.NthField(kCommSeparator,3)
// Search for email in use. Inform client.
dim i as integer
dim result as string
result = "NewUserAvailable"
for i = 0 to OtherDistros.Ubound
if OtherDistros(i).MMOEmail = EmailAddy then
result = "NewUserNotAvailable"
end if
next
me.Write result
End Sub
#tag EndMethod
#tag Method, Flags = &h1
Protected Sub ProcessFunctions()
dim s as string
s = me.ReadAll
// Log In
if s.InStr("Login") = 1 then
Login(s)
end if
// New User Check
if s.InStr("NewUserCheck") = 1 then
NewUserCheck(s)
end if
// Post Full Update From Client
if s.InStr("PostUpdate") = 1 then
ProcessMyDistroUpdateFromClient(s)
end if
// Reset Password
if s.InStr("Reset") = 1 then
end if
// Get Full Update From Server Without MyDistro
// Only needed on initial grab, before account is created
if s.InStr("GetUpdateWithoutMyDistro") = 1 then
GetFullUpdateWithoutMyDistro
end if
// Get Full Update From Server
if s.InStr("GetUpdate") = 1 then
GetFullUpdate(s)
end if
// Get Time Update From Server
if s.InStr("GetTime") = 1 then
GetTimeUpdate
end if
End Sub
#tag EndMethod
#tag Method, Flags = &h1
Protected Sub ProcessMyDistroUpdateFromClient(s as string)
'// Post Full Update From Client
'if s.InStr("PostUpdate") = 1 then
'ProcessMyDistroUpdateFromClient(s)
'end if
dim thexml as string
thexml = s.NthField(kCommSeparator,2)
dim xdoc as XmlDocument
dim node as XmlNode
xdoc = new XmlDocument
xdoc.LoadXml(thexml)
dim theIndex as integer
dim newDistro as Distro
theIndex = GetDistroIndexFromMMOEmail(xdoc.Child(1).GetAttribute("MMOEmail"))
if theIndex = -1 then // Doesn't exist. Create it.
newDistro = new Distro
newDistro.Name = xdoc.Child(1).GetAttribute("Name")
newDistro.Version = val(xdoc.Child(1).GetAttribute("Version"))
newDistro.LoadInPackagesFromList(xdoc.Child(1).GetAttribute("Packages"))
newDistro.ReleasedDate = new date
newDistro.ReleasedDate.TotalSeconds = xdoc.Child(1).GetAttribute("ReleasedDate").Val
newDistro.ReleasedVer = xdoc.Child(1).GetAttribute("ReleasedVer").Val
newDistro.ReleasedBugs = xdoc.Child(1).GetAttribute("ReleasedBugs").Val
newDistro.MMOEmail = xdoc.Child(1).GetAttribute("MMOEmail")
newDistro.MMOPass = xdoc.Child(1).GetAttribute("MMOPass")
newDistro.LoadInPackagesFromList(xdoc.Child(1).GetAttribute("Packages"))
newDistro.LoadInWorkersPaidFromList(xdoc.Child(1).GetAttribute("WorkersPaid"))
newDistro.LoadInWorkersVolunteersFromList(xdoc.Child(1).GetAttribute("WorkersVolunteer"))
OtherDistros.Append newDistro
else // Update it
OtherDistros(theIndex).Name = xdoc.Child(1).GetAttribute("Name")
OtherDistros(theIndex).Version = val(xdoc.Child(1).GetAttribute("Version"))
OtherDistros(theIndex).LoadInPackagesFromList(xdoc.Child(1).GetAttribute("Packages"))
OtherDistros(theIndex).ReleasedDate = new date
OtherDistros(theIndex).ReleasedDate.TotalSeconds = xdoc.Child(1).GetAttribute("ReleasedDate").Val
OtherDistros(theIndex).ReleasedVer = xdoc.Child(1).GetAttribute("ReleasedVer").Val
OtherDistros(theIndex).ReleasedBugs = xdoc.Child(1).GetAttribute("ReleasedBugs").Val
OtherDistros(theIndex).MMOEmail = xdoc.Child(1).GetAttribute("MMOEmail")
OtherDistros(theIndex).MMOPass = xdoc.Child(1).GetAttribute("MMOPass")
OtherDistros(theIndex).LoadInPackagesFromList(xdoc.Child(1).GetAttribute("Packages"))
OtherDistros(theIndex).LoadInWorkersPaidFromList(xdoc.Child(1).GetAttribute("WorkersPaid"))
OtherDistros(theIndex).LoadInWorkersVolunteersFromList(xdoc.Child(1).GetAttribute("WorkersVolunteer"))
end if
End Sub
#tag EndMethod
#tag Method, Flags = &h1
Protected Sub ResetPassword(s as string)
dim EmailAddy as string
dim Password as string
EmailAddy = s.NthField(kCommSeparator,2)
End Sub
#tag EndMethod
#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="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