-
Notifications
You must be signed in to change notification settings - Fork 16
/
modOtherCode.bas
1917 lines (1523 loc) · 64.2 KB
/
modOtherCode.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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Attribute VB_Name = "modOtherCode"
Option Explicit
Private Const OBJECT_NAME As String = "modOtherCode"
Public Const AZ As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Public Const Num09 As String = "0123456789"
'Read/WriteIni code thanks to ickis
Public Sub WriteINI(ByVal wiSection$, ByVal wiKey As String, ByVal wiValue As String, Optional ByVal wiFile As String = "x")
If (StrComp(wiFile, "x", vbBinaryCompare) = 0) Then
wiFile = GetConfigFilePath()
Else
If (InStr(1, wiFile$, "\", vbBinaryCompare) = 0) Then
wiFile = GetFilePath(wiFile)
End If
End If
WritePrivateProfileString wiSection, wiKey, _
wiValue, wiFile
End Sub
Public Function ReadCfg$(ByVal riSection$, ByVal riKey$)
Dim sRiBuffer As String
Dim sRiValue As String
Dim sRiLong As String
Dim riFile As String
riFile = GetConfigFilePath()
If (Dir(riFile) <> vbNullString) Then
sRiBuffer = String(255, vbNull)
sRiLong = GetPrivateProfileString(riSection, riKey, Chr$(1), _
sRiBuffer, 255, riFile)
If (Left$(sRiBuffer, 1) <> Chr$(1)) Then
sRiValue = Left$(sRiBuffer, sRiLong)
ReadCfg = sRiValue
End If
Else
ReadCfg = ""
End If
End Function
Public Function ReadINI$(ByVal riSection$, ByVal riKey$, ByVal riFile$)
Dim sRiBuffer As String
Dim sRiValue As String
Dim sRiLong As String
If (InStr(1, riFile$, "\", vbBinaryCompare) = 0) Then
riFile$ = GetFilePath(riFile)
End If
If (Dir(riFile$) <> vbNullString) Then
sRiBuffer = String(255, vbNull)
sRiLong = GetPrivateProfileString(riSection, riKey, Chr$(1), _
sRiBuffer, 255, riFile)
If (Left$(sRiBuffer, 1) <> Chr(1)) Then
sRiValue = Left$(sRiBuffer, sRiLong)
ReadINI = sRiValue
End If
Else
ReadINI = ""
End If
End Function
'// http://www.vbforums.com/showpost.php?p=2909252
Public Sub InsertionSort(ByRef pvarArray As Variant)
Dim i As Long
Dim j As Long
Dim iMin As Long
Dim iMax As Long
Dim varSwap As Variant
iMin = LBound(pvarArray) + 1
iMax = UBound(pvarArray)
For i = iMin To iMax
varSwap = pvarArray(i)
For j = i To iMin Step -1
If varSwap < pvarArray(j - 1) Then pvarArray(j) = pvarArray(j - 1) Else Exit For
Next j
pvarArray(j) = varSwap
Next i
End Sub
Public Function GetTimeStamp(Optional DateTime As Date) As String
If (DateDiff("s", DateTime, "00:00:00 12/30/1899") = 0) Then
DateTime = Now
End If
Select Case (BotVars.TSSetting)
Case 0
GetTimeStamp = _
" [" & Format(DateTime, "HH:MM:SS AM/PM") & "] "
Case 1
GetTimeStamp = _
" [" & Format(DateTime, "HH:MM:SS") & "] "
Case 2
GetTimeStamp = _
" [" & Format(DateTime, "HH:MM:SS") & "." & Right$("000" & GetCurrentMS, 3) & "] "
Case 3
GetTimeStamp = vbNullString
Case Else
GetTimeStamp = _
" [" & Format(DateTime, "HH:MM:SS AM/PM") & "] "
End Select
End Function
Public Function GetVerByte(Product As String, Optional ByVal UseHardcode As Integer) As Long
Dim Key As String
Key = GetProductKey(Product)
If ((Config.GetVersionByte(Key) = -1) Or _
(UseHardcode = 1)) Then
GetVerByte = GetProductInfo(Product).VersionByte
Else
GetVerByte = Config.GetVersionByte(Key)
End If
End Function
Public Function GetGamePath(ByVal Client As String) As String
' [override] XXHashes= functionality replaced by checkrevision.ini -> [CRev_XX] Path=
' removed ~Ribose/2010-08-12
Dim CRevINIPath As String
Dim Key As String
Dim Path As String
Dim sep1 As String
Dim sep2 As String
' Moved CheckRevision.ini to profile directory instead of install directory. -Pyro, 2016-03-21
'CRevINIPath = GetFilePath(FILE_CREV_INI, StringFormat("{0}\", App.Path))
CRevINIPath = GetFilePath(FILE_CREV_INI)
Key = GetProductKey(Client)
Path = ReadINI$(StringFormat("CRev_{0}", Key), "Path", CRevINIPath)
sep1 = vbNullString
sep2 = vbNullString
If (InStr(1, Path, ":\") = 0) Then
If (Left$(Path, 1) <> "\") Then sep1 = "\"
If (Right$(Path, 1) <> "\") Then sep2 = "\"
Path = StringFormat("{0}{1}{2}{3}", App.Path, sep1, Path, sep2)
End If
GetGamePath = Path
End Function
Function MKL(Value As Long) As String
Dim Result As String * 4
Call CopyMemory(ByVal Result, Value, 4)
MKL = Result
End Function
Function MKI(Value As Integer) As String
Dim Result As String * 2
Call CopyMemory(ByVal Result, Value, 2)
MKI = Result
End Function
Public Function CheckPath(ByVal sPath As String) As Long
If (LenB(Dir$(sPath)) = 0) Then
frmChat.AddChat g_Color.ErrorMessageText, "[HASHES] " & _
Mid$(sPath, InStrRev(sPath, "\") + 1) & " is missing."
CheckPath = 1
End If
End Function
Public Function Ban(ByVal Inpt As String, SpeakerAccess As Integer, Optional Kick As Integer) As String
On Error GoTo ERROR_HANDLER
Static LastBan As String
Dim Username As String
Dim CleanedUsername As String
Dim i As Integer
Dim pos As Integer
If (LenB(Inpt) > 0) Then
If (Kick > 2) Then
LastBan = vbNullString
Exit Function
End If
If (g_Channel.Self.IsOperator) Then
If (InStr(1, Inpt, Space$(1), vbBinaryCompare) <> 0) Then
Username = LCase$(Left$(Inpt, InStr(1, Inpt, Space(1), _
vbBinaryCompare) - 1))
Else
Username = LCase$(Inpt)
End If
If (LenB(Username) > 0) Then
LastBan = LCase$(Username)
'CleanedUsername = StripRealm(CleanedUsername)
CleanedUsername = StripInvalidNameChars(Username)
If (SpeakerAccess < 200) Then
If ((GetSafelist(CleanedUsername)) Or (GetSafelist(Username))) Then
Ban = "Error: That user is safelisted."
Exit Function
End If
End If
If (Database.GetUserAccess(Username).Rank >= SpeakerAccess) Then
Ban = "Error: You do not have sufficient access to do that."
Exit Function
End If
pos = g_Channel.GetUserIndex(Username)
If (pos > 0) Then
If (g_Channel.Users(pos).IsOperator) Then
Ban = "Error: You cannot ban a channel operator."
Exit Function
End If
End If
If (Kick = 0) Then
Call frmChat.AddQ("/ban " & Inpt)
Else
Call frmChat.AddQ("/kick " & Inpt)
End If
End If
Else
Ban = "Error: The bot does not have ops."
End If
End If
Exit Function
ERROR_HANDLER:
frmChat.AddChat g_Color.ErrorMessageText, "Error (#" & Err.Number & "): " & Err.Description & " in Ban()."
Exit Function
End Function
' This function created in response to http://www.stealthbot.net/forum/index.php?showtopic=20550
Public Function StripInvalidNameChars(ByVal Username As String) As String
Dim Allowed(14) As Integer
Dim i As Integer
Dim j As Integer
Dim thisChar As Integer
Dim NewUsername As String
Dim ThisCharOK As Boolean
If (LenB(Username) > 0) Then
NewUsername = Username
Allowed(0) = Asc("`")
Allowed(1) = Asc("[")
Allowed(2) = Asc("]")
Allowed(3) = Asc("{")
Allowed(4) = Asc("}")
Allowed(5) = Asc("_")
Allowed(6) = Asc("-")
Allowed(7) = Asc("@")
Allowed(8) = Asc("^")
Allowed(9) = Asc(".")
Allowed(10) = Asc("+")
Allowed(11) = Asc("=")
Allowed(12) = Asc("~")
Allowed(13) = Asc("|")
Allowed(14) = Asc("*")
For i = 1 To Len(Username)
thisChar = Asc(Mid$(Username, i, 1))
ThisCharOK = False
If (Not (IsAlpha(thisChar))) Then
If (Not (IsNumber(thisChar))) Then
For j = 0 To UBound(Allowed)
If (thisChar = Allowed(j)) Then
ThisCharOK = True
End If
Next j
If (Not (ThisCharOK)) Then
NewUsername = Replace(NewUsername, Chr(thisChar), vbNullString)
End If
End If
End If
Next i
StripInvalidNameChars = NewUsername
End If
End Function
'// Utility Function for joining strings
'// EXAMPLE
'// StringFormat("This is an {1} of its {0}.", "use", "example") '// OUTPUT: This is an example of its use.
'// 08/14/2009 JSM - Created
Public Function StringFormatA(ByVal Source As String, params() As Variant) As String
On Error GoTo ERROR_HANDLER:
Dim retVal As String
Dim i As Integer
retVal = Source
For i = LBound(params) To UBound(params)
retVal = Replace(retVal, "{" & i & "}", CStr(params(i)))
Next i
StringFormatA = retVal
Exit Function
ERROR_HANDLER:
Call frmChat.AddChat(vbRed, "Error: " & Err.Description & " in StringFormatA().")
StringFormatA = vbNullString
End Function
'// Utility Function for joining strings
'// EXAMPLE
'// StringFormat("This is an {1} of its {0}.", "use", "example") '// OUTPUT: This is an example of its use.
'// 08/14/2009 JSM - Created
Public Function StringFormat(ByVal Source As String, ParamArray params() As Variant) As String
On Error GoTo ERROR_HANDLER:
Dim retVal As String
Dim i As Integer
retVal = Source
For i = LBound(params) To UBound(params)
retVal = Replace(retVal, "{" & i & "}", CStr(params(i)))
Next i
StringFormat = retVal
Exit Function
ERROR_HANDLER:
Call frmChat.AddChat(vbRed, "Error: " & Err.Description & " in StringFormat().")
StringFormat = vbNullString
End Function
Public Function StripAccountNumber(ByVal Username As String) As String
Dim numpos As Integer
Dim atpos As Integer
numpos = InStr(1, Username, "#", vbBinaryCompare)
If numpos > 0 Then
atpos = InStr(numpos + 1, Username, Config.GatewayDelimiter, vbBinaryCompare)
If atpos > 0 Then
StripAccountNumber = Left$(Username, numpos - 1) & Mid$(Username, atpos)
Else
StripAccountNumber = Left$(Username, numpos - 1)
End If
Else
StripAccountNumber = Username
End If
End Function
Public Function StripRealm(ByVal Username As String) As String
If (InStr(1, Username, Config.GatewayDelimiter, vbBinaryCompare) > 0) Then
Username = Replace(Username, Config.GatewayDelimiter & "USWest", vbNullString, 1)
Username = Replace(Username, Config.GatewayDelimiter & "USEast", vbNullString, 1)
Username = Replace(Username, Config.GatewayDelimiter & "Asia", vbNullString, 1)
Username = Replace(Username, Config.GatewayDelimiter & "Euruope", vbNullString, 1)
Username = Replace(Username, Config.GatewayDelimiter & "Beta", vbNullString, 1)
Username = Replace(Username, Config.GatewayDelimiter & "Lordaeron", vbNullString, 1)
Username = Replace(Username, Config.GatewayDelimiter & "Azeroth", vbNullString, 1)
Username = Replace(Username, Config.GatewayDelimiter & "Kalimdor", vbNullString, 1)
Username = Replace(Username, Config.GatewayDelimiter & "Northrend", vbNullString, 1)
Username = Replace(Username, Config.GatewayDelimiter & "Westfall", vbNullString, 1)
Username = Replace(Username, Config.GatewayDelimiter & "Blizzard", vbNullString, 1)
End If
StripRealm = Username
End Function
Public Sub bnetSend(ByVal Message As String, Optional ByVal Tag As String = vbNullString, Optional ByVal _
ID As Double = 0)
Dim pBuf As clsDataBuffer
On Error GoTo ERROR_HANDLER
If (frmChat.sckBNet.State = sckConnected) Then
Set pBuf = New clsDataBuffer
With pBuf
If (Config.UseUTF8) Then
.InsertNTString Message, UTF8
Else
.InsertNTString Message
End If
.SendPacket SID_CHATCOMMAND
.Clear
If (Tag = "request_receipt") Then
g_request_receipt = True
.SendPacket SID_FRIENDSLIST
End If
End With
Set pBuf = Nothing
End If
If (Left$(Message, 1) <> "/") Then
If (g_Channel.IsSilent) Then
frmChat.AddChat g_Color.Carats, "<", g_Color.TalkBotUsername, GetCurrentUsername, _
g_Color.Carats, "> ", g_Color.WhisperText, Message
Else
frmChat.AddChat g_Color.Carats, "<", g_Color.TalkBotUsername, GetCurrentUsername, _
g_Color.Carats, "> ", g_Color.TalkNormalText, Message
End If
End If
On Error Resume Next
RunInAll "Event_MessageSent", ID, Message, Tag
Exit Sub
ERROR_HANDLER:
Call frmChat.AddChat(vbRed, "Error: " & Err.Description & " in bnetSend().")
Exit Sub
End Sub
Public Function Voting(ByVal Mode1 As Byte, Optional Mode2 As Byte, Optional Username As String) As String
On Error GoTo ERROR_HANDLER:
Static Voted() As String
Static VotesYes As Integer
Static VotesNo As Integer
Static VoteMode As Byte
Static Target As String
Dim i As Integer
Select Case (Mode1)
Case BVT_VOTE_ADD
For i = LBound(Voted) To UBound(Voted)
If (StrComp(Voted(i), LCase$(Username), vbTextCompare) = 0) Then
Exit Function
End If
Next i
Select Case (Mode2)
Case BVT_VOTE_ADDYES
VotesYes = VotesYes + 1
Case BVT_VOTE_ADDNO
VotesNo = VotesNo + 1
End Select
Voted(UBound(Voted)) = _
LCase$(Username)
ReDim Preserve Voted(0 To UBound(Voted) + 1)
Case BVT_VOTE_START
VotesYes = 0
VotesNo = 0
ReDim Voted(0)
VoteMode = Mode2
Target = Username
Voting = "Vote started. Type YES or NO to vote. Your vote will " & _
"only be counted once."
Case BVT_VOTE_END
If (Mode2 = BVT_VOTE_CANCEL) Then
Voting = "Vote canceled. Final results: [" & VotesYes & "] YES, " & _
"[" & VotesNo & "] NO. "
Else
Select Case (VoteMode)
Case BVT_VOTE_STD
Voting = "Final results: [" & VotesYes & "] YES, [" & VotesNo & "] NO. "
If VotesYes > VotesNo Then
Voting = Voting & "YES wins, with " & _
Format(VotesYes / (VotesYes + VotesNo), "percent") & " of the vote."
ElseIf (VotesYes < VotesNo) Then
Voting = Voting & "NO wins, with " & _
Format(VotesNo / (VotesYes + VotesNo), "percent") & " of the vote."
Else
Voting = Voting & "The vote was a draw."
End If
Case BVT_VOTE_BAN
If (VotesYes > VotesNo) Then
Voting = Ban(Target & " Banned by vote", VoteInitiator.Rank)
Else
Voting = "Ban vote failed."
End If
Case BVT_VOTE_KICK
If (VotesYes > VotesNo) Then
Voting = Ban(Target & " Kicked by vote", VoteInitiator.Rank, 1)
Else
Voting = "Kick vote failed."
End If
End Select
End If
VoteDuration = -1
VotesYes = 0
VotesNo = 0
VoteMode = 0
Target = vbNullString
ReDim Voted(0)
Case BVT_VOTE_TALLY
Voting = "Current results: [" & VotesYes & "] YES, [" & VotesNo & "] NO; " & _
VoteDuration & " seconds remain."
If (VotesYes > VotesNo) Then
Voting = Voting & " YES leads, with " & _
Format(VotesYes / (VotesYes + VotesNo), "percent") & " of the vote."
ElseIf (VotesYes < VotesNo) Then
Voting = Voting & _
" NO leads, with " & Format(VotesNo / (VotesYes + VotesNo), "percent") & _
" of the vote."
Else
Voting = Voting & " The vote is a draw."
End If
End Select
Exit Function
ERROR_HANDLER:
Call frmChat.AddChat(g_Color.ErrorMessageText, _
StringFormat("Error: #{0}: {1} in {2}.Voting()", Err.Number, Err.Description, OBJECT_NAME))
End Function
Public Sub RequestSystemKeys(Optional ByVal eType As enuServerRequestHandlerType = reqInternal, Optional oCommand As clsCommandObj)
Dim aKeys(3) As String
aKeys(0) = "System\Account Created"
aKeys(1) = "System\Last Logon"
aKeys(2) = "System\Last Logoff"
aKeys(3) = "System\Time Logged"
RequestUserData BotVars.Username, aKeys, eType, oCommand
End Sub
'// parses a system time and returns in the format:
'// mm/dd/yy, hh:mm:ss
'//
Public Function SystemTimeToString(ByRef st As SYSTEMTIME) As String
Dim buf As String
With st
buf = buf & .wMonth & "/"
buf = buf & .wDay & "/"
buf = buf & .wYear & ", "
buf = buf & IIf(.wHour > 9, .wHour, "0" & .wHour) & ":"
buf = buf & IIf(.wMinute > 9, .wMinute, "0" & .wMinute) & ":"
buf = buf & IIf(.wSecond > 9, .wSecond, "0" & .wSecond)
End With
SystemTimeToString = buf
End Function
Public Function GetCurrentMS() As String
Dim st As SYSTEMTIME
GetLocalTime st
GetCurrentMS = Right$("000" & st.wMilliseconds, 3)
End Function
Public Function ZeroOffset(ByVal lInpt As Long, ByVal lDigits As Long) As String
Dim sOut As String
sOut = Hex(lInpt)
ZeroOffset = Right$(String(lDigits, "0") & sOut, lDigits)
End Function
Public Function ZeroOffsetEx(ByVal lInpt As Long, ByVal lDigits As Long) As String
ZeroOffsetEx = Right$(String(lDigits, "0") & lInpt, lDigits)
End Function
Public Function CheckBlock(ByVal Username As String) As Boolean
Dim s As String
Dim i As Integer
For i = 0 To UBound(g_Blocklist)
If Len(g_Blocklist(i)) > 0 Then
If (PrepareCheck(Username) Like PrepareCheck(g_Blocklist(i))) Then
CheckBlock = True
Exit Function
End If
End If
Next i
End Function
Public Function CheckMsg(ByVal Msg As String, Optional ByVal Username As String, Optional ByVal Ping As _
Long) As Boolean
Dim i As Integer
Msg = PrepareCheck(Msg)
For i = 0 To UBound(gFilters)
If (Len(gFilters(i)) > 0) Then
If (InStr(1, gFilters(i), "%", vbBinaryCompare) > 0) Then
Msg = PrepareCheck(DoReplacements(gFilters(i), Username, Ping))
End If
If (Msg Like "*" & PrepareCheck(gFilters(i)) & "*") Then
CheckMsg = True
Exit Function
End If
End If
Next i
End Function
Public Sub UpdateProfile()
Dim s As String
s = MediaPlayer.TrackName
If (s = vbNullString) Then
SetProfile "", ":[ ProfileAmp ]:" & vbCrLf & MediaPlayer.Name & " is not currently playing " & _
vbCrLf & "Last updated " & Time & ", " & Format(Date, "d-MM-yyyy") & vbCrLf & _
CVERSION & " - http://www.stealthbot.net"
Else
SetProfile "", ":[ ProfileAmp ]:" & vbCrLf & MediaPlayer.Name & " is currently playing: " & _
vbCrLf & s & vbCrLf & "Last updated " & Time & ", " & Format(Date, "d-MM-yyyy") & _
vbCrLf & CVERSION & " - http://www.stealthbot.net"
End If
End Sub
Public Function FlashWindow() As Boolean
Dim pfwi As FLASHWINFO
'Me.WindowState = vbMinimized
With pfwi
.cbSize = 20
.dwFlags = FLASHW_ALL Or 12
.dwTimeout = 0
.hWnd = frmChat.hWnd
.uCount = 0
End With
FlashWindow = FlashWindowEx(pfwi)
End Function
Public Sub ReadyInet()
frmChat.Inet.Cancel
End Sub
Public Function HTMLToRGBColor(ByVal s As String) As Long
HTMLToRGBColor = RGB(Val("&H" & Mid$(s, 1, 2)), Val("&H" & Mid$(s, 3, 2)), _
Val("&H" & Mid$(s, 5, 2)))
End Function
Public Function StrictIsNumeric(ByVal sCheck As String, Optional AllowNegatives As Boolean = False) As Boolean
Dim i As Long
StrictIsNumeric = True
If (Len(sCheck) > 0) Then
For i = 1 To Len(sCheck)
If ((Asc(Mid$(sCheck, i, 1)) = 45)) Then
If ((Not AllowNegatives) Or (i > 1)) Then
StrictIsNumeric = False
Exit Function
End If
ElseIf (Not ((Asc(Mid$(sCheck, i, 1)) >= 48) And _
(Asc(Mid$(sCheck, i, 1)) <= 57))) Then
StrictIsNumeric = False
Exit Function
End If
Next i
Else
StrictIsNumeric = False
End If
End Function
Public Sub GetCountryData(ByRef CountryAbbrev As String, ByRef CountryName As String, ByRef sCountryCode As String)
Const LOCALE_USER_DEFAULT As Long = &H400
Const LOCALE_ICOUNTRY As Long = &H5 'Country Code
Const LOCALE_SABBREVCTRYNAME As Long = &H7 'abbreviated country name
Const LOCALE_SENGCOUNTRY As Long = &H1002 'English name of country
Dim sBuf As String
sBuf = String$(256, 0)
Call GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVCTRYNAME, sBuf, Len(sBuf))
CountryAbbrev = KillNull(sBuf)
sBuf = String$(256, 0)
Call GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SENGCOUNTRY, sBuf, Len(sBuf))
CountryName = KillNull(sBuf)
sBuf = String$(256, 0)
Call GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ICOUNTRY, sBuf, Len(sBuf))
sCountryCode = KillNull(sBuf)
End Sub
Public Sub SetNagelStatus(ByVal lSocketHandle As Long, ByVal bEnabled As Boolean)
If (lSocketHandle > 0) Then
If (bEnabled) Then
Call SetSockOpt(lSocketHandle, IPPROTO_TCP, TCP_NODELAY, NAGLE_OFF, NAGLE_OPTLEN)
Else
Call SetSockOpt(lSocketHandle, IPPROTO_TCP, TCP_NODELAY, NAGLE_ON, NAGLE_OPTLEN)
End If
End If
End Sub
Public Sub EnableSO_KEEPALIVE(ByVal lSocketHandle As Long)
Call SetSockOpt(lSocketHandle, IPPROTO_TCP, SO_KEEPALIVE, True, 4) 'thanks Eric
End Sub
Public Function ProductCodeToFullName(ByVal pCode As String) As String
ProductCodeToFullName = GetProductInfo(pCode).FullName
End Function
' Assumes that sIn has Length >=1
Public Function PercentActualUppercase(ByVal sIn As String) As Double
Dim UppercaseChars As Integer
Dim i As Integer
sIn = Replace$(sIn, Space(1), vbNullString)
If (Len(sIn) > 0) Then
For i = 1 To Len(sIn)
If (IsAlpha(Asc(Mid$(sIn, i, 1)))) Then
If (IsUppercase(Asc(Mid$(sIn, i, 1)))) Then
UppercaseChars = (UppercaseChars + 1)
End If
End If
Next i
PercentActualUppercase = _
CDbl(100 * (UppercaseChars / Len(sIn)))
End If
End Function
Public Function MyUCase(ByVal sIn As String) As String
Dim i As Integer
Dim CurrentByte As Byte
If (LenB(sIn) > 0) Then
For i = 1 To Len(sIn)
CurrentByte = Asc(Mid$(sIn, i, 1))
If (IsAlpha(CurrentByte)) Then
If (Not (IsUppercase(CurrentByte))) Then
Mid$(sIn, i, 1) = _
Chr(CurrentByte - 32)
End If
End If
Next i
End If
MyUCase = sIn
End Function
Public Function IsAlpha(ByVal bCharValue As Byte) As Boolean
IsAlpha = ((bCharValue >= 65 And bCharValue <= 90) Or _
(bCharValue >= 97 And bCharValue <= 122))
End Function
Public Function IsNumber(ByVal bCharValue As Byte) As Boolean
IsNumber = ((bCharValue >= 48 And bCharValue <= 57))
End Function
Public Function IsUppercase(ByVal bCharValue As Byte) As Boolean
IsUppercase = (bCharValue >= 65 And bCharValue <= 90)
End Function
Public Function VBHexToHTMLHex(ByVal sIn As String) As String
sIn = Left$((sIn) & "000000", 6)
VBHexToHTMLHex = Mid$(sIn, 5, 2) & Mid$(sIn, 3, 2) & _
Mid$(sIn, 1, 2)
End Function
'//10-15-2009 - Hdx - Updated url to new address
Public Sub GetW3LadderProfile(ByVal sPlayer As String, ByVal eType As enuWebProfileTypes, ByVal Gateway As String)
Const W3LadderURLFormat As String = "http://{0}.battle.net/war3/ladder/{1}-player-profile.aspx?Gateway={2}&PlayerName={3}"
Dim W3LadderURL As String
Dim W3WebProfileType As String
Dim W3Domain As String
W3Domain = "classic"
If (LenB(sPlayer) > 0) Then
W3WebProfileType = IIf(eType = W3XP, PRODUCT_W3XP, PRODUCT_WAR3)
Select Case Gateway
Case "Kalimdor": W3Domain = "asialadders"
Case "Azeroth", "Lordaeron", "Northrend": W3Domain = "classic"
Case Else: Exit Sub
End Select
W3LadderURL = StringFormat(W3LadderURLFormat, W3Domain, LCase$(W3WebProfileType), Gateway, NameWithoutRealm(sPlayer, 1))
ShellOpenURL W3LadderURL, sPlayer & "'s " & UCase$(W3WebProfileType) & " ladder profile on " & Gateway
End If
End Sub
Public Sub DoLastSeen(ByVal Username As String)
Dim i As Integer
Dim found As Boolean
If (colLastSeen.Count > 0) Then
For i = 1 To colLastSeen.Count
If (StrComp(colLastSeen.Item(i), Username, _
vbTextCompare) = 0) Then
found = True
Exit For
End If
Next i
End If
If (Not (found)) Then
colLastSeen.Add Username
If (colLastSeen.Count > 15) Then
Call colLastSeen.Remove(1)
End If
End If
End Sub
Public Sub SetTitle(ByVal sTitle As String)
frmChat.Caption = "[" & sTitle & "]" & " - " & CVERSION
End Sub
Public Function NameWithoutRealm(ByVal Username As String, Optional ByVal Strict As Byte = 0) As String
If ((frmChat.ClanHandler.IsW3) And (Strict = 0)) Then
NameWithoutRealm = Username
Else
If (InStr(1, Username, Config.GatewayDelimiter, vbBinaryCompare) > 0) Then
NameWithoutRealm = Left$(Username, InStr(1, Username, Config.GatewayDelimiter) - 1)
Else
NameWithoutRealm = Username
End If
End If
End Function
Public Function GetCurrentUsername() As String
GetCurrentUsername = ConvertUsername(CurrentUsername)
End Function
Public Function GetUserNamespace(Optional ByVal Username As String) As String
If (LenB(Username) = 0) Then
GetUserNamespace = BotVars.Gateway
Else
If (InStr(1, Username, Config.GatewayDelimiter, vbBinaryCompare) > 0) Then
GetUserNamespace = Mid$(Username, InStr(1, Username, Config.GatewayDelimiter, _
vbBinaryCompare) + 1)
Else
GetUserNamespace = BotVars.Gateway
End If
End If
End Function
Public Function GetConfigFilePath() As String
Static FilePath As String
If (LenB(FilePath) = 0) Then
If ((LenB(ConfigOverride) > 0)) Then
FilePath = ConfigOverride
Else
FilePath = StringFormat("{0}Config.ini", GetProfilePath())
End If
End If
If (InStr(1, FilePath, "\", vbBinaryCompare) = 0) Then
FilePath = StringFormat("{0}\{1}", CurDir$(), FilePath)
End If
GetConfigFilePath = FilePath
End Function
Public Function GetFilePath(ByVal FileName As String, Optional DefaultPath As String = vbNullString) As String
Dim s As String
If (InStr(FileName, "\") = 0) Then
If (LenB(DefaultPath) = 0) Then
GetFilePath = StringFormat("{0}{1}", GetProfilePath(), FileName)
Else
GetFilePath = StringFormat("{0}{1}", DefaultPath, FileName)
End If
s = Config.GetFilePath(FileName)
If (LenB(s) > 0) Then
If (LenB(Dir$(s))) Then
GetFilePath = s
End If
End If
Else
GetFilePath = FileName
End If
End Function
Public Function GetFolderPath(ByVal sFolderName As String) As String
On Error GoTo ERROR_HANDLER:
Dim sPath As String
sPath = GetFilePath(sFolderName)
If (Not Right$(sPath, 1) = "\") Then sPath = sPath & "\"
GetFolderPath = sPath
Exit Function
ERROR_HANDLER:
frmChat.AddChat g_Color.ErrorMessageText, StringFormat("Error #{0}: {1} in {2}.{3}()", Err.Number, Err.Description, "modOtherCode", "GetFolderPath")
End Function
'Public Function OKToDoAutocompletion(ByRef sText As String, ByVal KeyAscii As Integer) As Boolean
' If BotVars.NoAutocompletion Then
' OKToDoAutocompletion = False
' Else
' If (InStr(sText, " ") = 0) And KeyAscii <> 32 Then ' one word only
' OKToDoAutocompletion = True
' Else ' > 1 words
' If StrComp(Left$(sText, 1), "/") = 0 And KeyAscii <> 32 Then ' left character is a /
'
' If InStr(InStr(sText, " ") + 1, sText, " ") = 0 Then ' only two words
' If StrComp(Left$(sText, 3), "/m ") = 0 Or _
' StrComp(Left$(sText, 3), "/w ") = 0 Then
'
' OKToDoAutocompletion = True
' Else
' OKToDoAutocompletion = False
' End If
' Else ' more than two words
' OKToDoAutocompletion = False
' End If
' Else
' OKToDoAutocompletion = False
' End If
' End If
' End If
'End Function
' ProfileIndex param should only be used when changing profiles as a SET
' - colProfiles MUST be instantiated in order to call with a ProfileIndex > 0!
Public Function GetProfilePath(Optional ByVal ProfileIndex As Integer) As String
Static LastPath As String
Dim s As String
' If ProfileIndex > 0 Then
' If ProfileIndex <= colProfiles.Count Then
' s = colProfiles.Item(ProfileIndex)
' 'check for path\
' If Right$(s, 1) <> "\" Then
' s = s & "\"
' End If
'
' GetProfilePath = s
' Else
' If LenB(LastPath) > 0 Then
' GetProfilePath = LastPath
' Else
' GetProfilePath = App.Path & "\"
' End If
' End If
' Else
If LenB(LastPath) > 0 Then
GetProfilePath = LastPath
Else
GetProfilePath = StringFormat("{0}\", CurDir$())
End If
' End If
LastPath = GetProfilePath
End Function
Public Sub OpenReadme()
ShellOpenURL "http://www.stealthbot.net/wiki/Main_Page", "the StealthBot Wiki"