-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneral.bas
429 lines (385 loc) · 16.3 KB
/
general.bas
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
Attribute VB_Name = "general"
Option Explicit
Public Channel(1 To 10) As New frmChannel
Public ChannelName(1 To 10) As String
Public ChannelTopic(1 To 10) As String
Public Query(1 To 100) As New frmQuery
Public QueryName(1 To 100) As String
Public RealName As String
Public email As String
Public NickName As String
Public word(1 To 10) As String
Public connected As Boolean
Public Sub CheckLine(strLine As String)
Dim i As Integer
Dim oneline As String
Static RestLine As String
strLine = RestLine & strLine
For i = 1 To Len(strLine)
If Mid(strLine, i, 1) = Chr(13) Or Mid(strLine, i, 1) = Chr(10) Then
oneline = Mid(strLine, 1, i - 1)
Call CheckWord(oneline)
strLine = Mid(strLine, i + 1)
i = 1
End If
Next i
RestLine = strLine
End Sub
Public Sub CheckWord(strWord As String)
Dim i As Integer
Dim x As Integer
'check for carriage return in front of line and delete
If Mid(strWord, 1, 1) = Chr(13) Or Mid(strWord, 1, 1) = Chr(10) Then
strWord = Mid(strWord, 2)
End If
frmStatus.txtStatus.SelText = "ONELINE: " & strWord & vbCrLf
x = 0
For i = 1 To 10
word(i) = ""
Next i
For i = 1 To Len(strWord)
If Mid(strWord, i, 1) = Chr(32) Then
x = x + 1
If x > 10 Then
Exit For
End If
word(x) = Trim(Mid(strWord, 1, i - 1))
strWord = LTrim(Mid(strWord, i + 1))
i = 1
If IsNumeric(word(2)) = True And x = 3 Then
Call numeric(word(1), word(2), word(3), strWord)
Exit Sub
End If
End If
Next i
Dim parms As String
For i = 4 To 10
parms = parms & " " & word(i)
Next i
parms = RTrim(LTrim(parms & " " & strWord))
Call command(word(1), word(2), word(3), parms)
'frmStatus.txtStatus.SelText = "WORD 2: " & word(2) & " " & word(3) & vbCrLf
'frmStatus.txtStatus.SelText = "PARMS: " & PARMS & vbCrLf
End Sub
Public Sub numeric(server As String, num As String, NickName As String, strLine As String)
On Error GoTo NumericError
frmStatus.txtStatus.SelText = num & " " & strLine & vbCrLf
Dim i As Integer
Dim x As Integer
Dim ix As Integer
'used for "322" to seperate info from PARMS
Dim mItem As Variant
Dim xChannelName As String
Dim xUsers As String
Dim xTopic As String
Static ChannelCount As Integer 'count channels on server
Select Case num
'MOTD 372 375 376 378
Case "372"
frmMOTD.txtMOTD.SelText = strLine & vbCrLf
DoEvents
Case "378"
frmMOTD.txtMOTD.SelText = strLine & vbCrLf
DoEvents
Case "376"
frmMOTD.Show
'NAMES 353
Case "353"
'channame(3) = first name in list
'channame(1) = channel name
Dim ChanName(1 To 100) As String
'seperate names
For i = 1 To Len(strLine)
If Mid(strLine, i, 1) = Chr(32) Then
x = x + 1
ChanName(x) = Trim(Mid(strLine, 1, i - 1))
strLine = LTrim(Mid(strLine, i + 1))
If x = 3 Then
ChanName(3) = Mid(ChanName(3), 2)
'clear name list box in channel and refresh
For ix = 1 To 10
If LCase(ChannelName(ix)) = LCase(ChanName(2)) And x > 2 Then
Channel(ix).lstNames.Clear
End If
Next ix
End If
'add name to channel listbox
For ix = 1 To 10
If LCase(ChannelName(ix)) = LCase(ChanName(2)) And x > 2 Then
Channel(ix).lstNames.AddItem ChanName(x)
End If
Next ix
i = 0
End If
Next i
'get last name in 353
x = x + 1
ChanName(x) = strLine
'321 Start List
'322 list channels #channel #users :topic
'323 end list
Case "321"
ChannelCount = 0
Case "322"
ChannelCount = ChannelCount + 1
frmChannels.Caption = "Cabral Channel List [" & ChannelCount & "]"
'Tree View Control
'frmChannels.ChannelView.Nodes.Add = strLine
'seperate CHANNEL USERS :TOPIC
x = 0
For i = 1 To Len(strLine)
If Mid(strLine, i, 1) = Chr(32) Then
x = x + 1
Select Case x
Case 1
xChannelName = Mid(strLine, 1, i - 1)
Case 2
xUsers = Mid(strLine, 1, i - 1)
Case 3
xTopic = Mid(strLine, 1)
Exit For
End Select
strLine = Mid(strLine, i + 1)
i = 0
End If
Next i
'put in listview control (lvxChan control)
If Len(xChannelName) > 1 Then
Set frmChannels.lvwChan.SmallIcons = mdiMain.imgChannel
If Int(xUsers) > 10 Then
Set mItem = frmChannels.lvwChan.ListItems.Add(, , xChannelName, , 1)
Else
Set mItem = frmChannels.lvwChan.ListItems.Add(, , xChannelName, , 2)
End If
mItem.SubItems(1) = xUsers
mItem.SubItems(2) = Mid(xTopic, 2)
End If
DoEvents
Case "323"
frmChannels.Show
End Select
NumericError:
If Err.Number <> 0 Then
MsgBox "Please copy and send the following message to cabral@n-link.com" & vbCrLf & vbCrLf & "Server: " & server & vbCrLf & "Numeric: " & num & vbCrLf & "Nickname: " & NickName & vbCrLf & "String: " & strLine, vbOKOnly, "Bug Found"
'Resume Next
End If
End Sub
Public Sub command(Username As String, command As String, target As String, parms As String)
Dim i As Integer
Dim x As Integer
Dim found As Boolean
'chop off the ":" in front of all parameters
If Left(parms, 1) = ":" Then
parms = Mid(parms, 2)
End If
frmStatus.txtStatus.SelText = command & " " & parms & vbCrLf & "TARGET: " & target & vbCrLf
'break down usrename
Dim UserEmail
For i = 1 To Len(Username)
If Mid(Username, i, 1) = "!" Then
UserEmail = Mid(Username, i + 1)
Username = Mid(Username, 1, i - 1)
If Left(Username, 1) = ":" Then
Username = Mid(Username, 2)
End If
End If
Next i
'this SELECT CASE is for anything that's not a 'command'
Select Case UCase(Username)
Case "PING"
mdiMain.tcp.SendData "PONG " & parms & vbCrLf
frmStatus.txtStatus.SelColor = RGB(0, 140, 0)
frmStatus.txtStatus.SelText = "*** PONG " & parms & vbCrLf
'status window shows server name
frmStatus.Caption = "Cabral Status: " & parms
'mdiMain shows [server name]
mdiMain.Caption = "Cabral IRC [" & parms & "]"
frmStatus.txtStatus.SelColor = vbBlack
End Select
Select Case UCase(command)
Case "JOIN"
For i = 1 To 10
'if you join channel then load channel window
If ChannelName(i) = "" Then
If LCase(Username) = LCase(NickName) Then
Load Channel(i)
ChannelName(i) = LCase(parms)
Channel(i).Caption = parms
Exit For
End If
End If
'other users join channel
'update nick list box
If LCase(ChannelName(i)) = LCase(parms) Then
Channel(i).lstNames.AddItem Username
'show in channel that user joined channel
Channel(i).txtText.SelColor = RGB(0, 140, 0)
Channel(i).txtText.SelText = "*** " & Username & " has joined " & parms & vbCrLf
Channel(i).txtText.SelColor = vbBlack
End If
Next i
Case "PART"
For i = 1 To 10
'if you leave then unload channel window
If ChannelName(i) = LCase(parms) Then
If LCase(Username) = LCase(NickName) Then
Unload Channel(i)
ChannelName(i) = ""
Exit For
End If
End If
'other users leave channel
'update nick list box
If LCase(ChannelName(i)) = LCase(parms) And parms <> "" Then
'cycle through names and remove if found
For x = 0 To Channel(i).lstNames.ListCount - 1
If Channel(i).lstNames.ListIndex Then
If LCase(Channel(i).lstNames.List(x)) = LCase(Username) Or LCase(Channel(i).lstNames.List(x)) = LCase("@" & Username) Then
Channel(i).lstNames.RemoveItem (x)
'show in channel that user left channel
Channel(i).txtText.SelColor = RGB(0, 140, 0)
Channel(i).txtText.SelText = "*** " & Username & " has left " & parms & vbCrLf
Channel(i).txtText.SelColor = vbBlack
'Exit For
End If
End If
Next x
End If
Next i
Case "PRIVMSG"
If Left(target, 1) = "#" Then
For i = 1 To 10
If ChannelName(i) = LCase(target) Then
'if it's a channel action
If LCase(Left(parms, 7)) = LCase("ACTION") Then
Channel(i).txtText.SelColor = RGB(140, 0, 140)
Channel(i).txtText.SelText = "* "
Channel(i).txtText.SelBold = True
Channel(i).txtText.SelText = Username
Channel(i).txtText.SelBold = False
Channel(i).txtText.SelText = " " & Mid(parms, 8) & vbCrLf
Channel(i).txtText.SelColor = vbBlack
Else
Channel(i).txtText.SelText = "<"
Channel(i).txtText.SelBold = True
Channel(i).txtText.SelText = Username
Channel(i).txtText.SelBold = False
Channel(i).txtText.SelText = "> " & parms & vbCrLf
End If
Else
'if exited channel before PART msg then show channel text in status
'bottom line echos 10 times in status (fix)
'frmStatus.txtStatus.SelText = target & ": <" & Username & "> " & parms & vbCrLf
End If
Next i
Else
found = False
For i = 1 To 100
If LCase(Username) = LCase(QueryName(i)) Then
found = True
Exit For
End If
Next i
If found = False Then
For i = 1 To 100
If QueryName(i) = "" Then
'load query window
Load Query(i)
Query(i).Caption = Username
QueryName(i) = Username
Exit For
End If
Next i
End If
For i = 1 To 100
If LCase(QueryName(i)) = LCase(Username) Then
Query(i).txtQuery.SelText = "<"
Query(i).txtQuery.SelBold = True
Query(i).txtQuery.SelColor = vbRed
Query(i).txtQuery.SelText = Username
Query(i).txtQuery.SelBold = False
Query(i).txtQuery.SelColor = vbBlack
Query(i).txtQuery.SelText = "> " & parms & vbCrLf
End If
Next i
End If
Case "NICK"
'Update your nickname variable
If LCase(Username) = LCase(NickName) Then
NickName = parms
End If
Case "NOTICE"
'channel notice
If Left(target, 1) = "#" Then
For i = 1 To 10
'cycle through channel names and if found a match then
'writing to channel window
If LCase(target) = LCase(ChannelName(i)) Then
Channel(i).txtText.SelColor = RGB(140, 0, 0)
Channel(i).txtText.SelText = target
Channel(i).txtText.SelColor = vbBlack
Channel(i).txtText.SelText = ": <"
Channel(i).txtText.SelBold = True
Channel(i).txtText.SelText = Username
Channel(i).txtText.SelBold = False
Channel(i).txtText.SelText = "> " & parms & vbCrLf
Else
'show channel NOTICE to status window
End If
Next i
Else
'personal NOTICE to you
'query window for username not found yet
found = False
'loop to find an already open query window
For i = 1 To 100
If LCase(QueryName(i)) = LCase(Username) Then
found = True
End If
Next i
'create query window if not already loaded
If found = False Then
For i = 1 To 100
If QueryName(i) = "" Then
'load query window
Load Query(i)
Query(i).Caption = Username
QueryName(i) = Username
Exit For
End If
Next i
End If
'finally show NOTICE in query window
For i = 1 To 100
If LCase(QueryName(i)) = LCase(Username) Then
Query(i).txtQuery.SelColor = RGB(140, 0, 0)
Query(i).txtQuery.SelBold = True
Query(i).txtQuery.SelText = "NOTICE"
Query(i).txtQuery.SelBold = False
Query(i).txtQuery.SelColor = vbBlack
Query(i).txtQuery.SelText = ": " & parms & vbCrLf
End If
Next i
End If
Case "QUIT"
'cycle through each window since the QUIT message
'tells you no channel or anything
For i = 1 To 10
'if channel exsists (should have name)
If ChannelName(i) <> "" Then
'cycle through each listbox on each channel window
For x = 0 To Channel(i).lstNames.ListCount - 1
'if QUIT name matches lstnames(name) then remove
If LCase(Channel(i).lstNames.List(x)) = LCase(Username) Or LCase(Channel(i).lstNames.List(x)) = LCase("@" & Username) Then
'remove from list box for certain window
Channel(i).lstNames.RemoveItem (x)
'Display quit in channel
Channel(i).txtText.SelColor = RGB(0, 0, 140)
Channel(i).txtText.SelText = "*** " & Username & " has QUIT (" & parms & ")" & vbCrLf
Channel(i).txtText.SelColor = vbBlack
End If
Next x
End If
Next i
End Select
End Sub