-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmodServer.bas
3616 lines (3357 loc) · 154 KB
/
modServer.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 = "modServer"
Option Explicit
'Game Constants
Public Const TitleString = "Odyssey Realms Server"
Public Const MaxUsers = 80
Public Const DownloadSite = "http://www.odysseyclassic.info"
Public Const CurrentClientVer = 5
Public Const PrefixSuffixChance = 40
'Misc Variables
Public BackupCounter As Long
Public Startup As Boolean
Public Word(1 To 50) As String
Public Prefix As String
Public Suffix As String
Public OutdoorLight As Byte
'Sockets
Public ListeningSocket As Long
Sub SaveFlags()
Dim A As Long, St As String
For A = 0 To 255
If World.Flag(A) > 0 Then
St = St + QuadChar$(World.Flag(A))
Else
St = St + QuadChar$(0)
End If
Next A
DataRS.Edit
DataRS!flags = St
DataRS.Update
End Sub
Sub SaveObjects()
Dim A As Long, B As Long, St As String
For A = 1 To MaxMaps
With Map(A)
If .Keep = True Then
For B = 0 To MaxMapObjects
With .Object(B)
If .Object > 0 Then
If .Value >= 0 Then
If Map(A).Tile(.X, .Y).Att = 5 Or Map(A).Tile(.X, .Y).Att2 = 5 Then
St = St + DoubleChar(A) + Chr$(B) + Chr$(.X) + Chr$(.Y) + DoubleChar$(.Object) + QuadChar(.Value) + Chr$(.ItemPrefix) + Chr$(.ItemSuffix)
End If
End If
End If
End With
Next B
End If
End With
Next A
DataRS.Edit
DataRS!ObjectData = St
DataRS.Update
End Sub
Sub SaveBugReports()
Dim A As Long, B As Long, St As String
On Error GoTo ExitSub
For A = 1 To UBound(Bug)
With Bug(A)
BugsRS.Seek "=", A
If .Status > 0 Then
If BugsRS.NoMatch Then
BugsRS.AddNew
Else
BugsRS.Edit
End If
BugsRS!ID = A
BugsRS!PlayerUser = .PlayerUser
BugsRS!PlayerName = .PlayerName
BugsRS!PlayerIP = .PlayerIP
BugsRS!Title = .Title
BugsRS!Description = .Description
BugsRS!Status = .Status
BugsRS!ResolverUser = .ResolverUser
BugsRS!ResolverName = .ResolverName
BugsRS.Update
Else
If Not BugsRS.NoMatch Then BugsRS.Delete
End If
End With
Next A
ExitSub:
End Sub
Sub CheckGuild(Index As Long)
If Guild(Index).Name <> vbNullString Then
If CountGuildMembers(Index) < 1 Then
'Not enough players -- delete guild
DeleteGuild Index, 1
End If
End If
End Sub
Function CheckSum(St As String) As Long
Dim A As Long, B As Long
For A = 1 To Len(St)
B = B + Asc(Mid$(St, A, 1))
Next A
CheckSum = B
End Function
Function CountGuildMembers(Index As Long) As Long
Dim A As Long, B As Long
With Guild(Index)
If .Name <> vbNullString Then
B = 0
For A = 0 To 19
If .Member(A).Name <> vbNullString Then
B = B + 1
End If
Next A
CountGuildMembers = B
End If
End With
End Function
Sub DeleteCharacter()
Dim A As Long, B As Long, St As String
On Error Resume Next
St = UserRS!Name
For A = 1 To MaxGuilds
With Guild(A)
If .Name <> vbNullString Then
For B = 0 To 19
With .Member(B)
If .Name = St Then
.Name = vbNullString
CheckGuild A
End If
End With
Next B
End If
End With
Next A
On Error GoTo 0
End Sub
Sub DeleteAccount()
On Error Resume Next
If UserRS!Class > 0 Then
DeleteCharacter
End If
UserRS.Delete
On Error GoTo 0
End Sub
Sub LoadObjectData(ObjectData As String)
Dim A As Long, NumObjects As Long
NumObjects = Len(ObjectData) / 13 - 1
For A = 0 To NumObjects
With Map(Asc(Mid$(ObjectData, A * 13 + 1, 1)) * 256 + Asc(Mid$(ObjectData, A * 13 + 2, 1))).Object(Asc(Mid$(ObjectData, A * 13 + 3, 1)))
.X = Asc(Mid$(ObjectData, A * 13 + 4, 1))
.Y = Asc(Mid$(ObjectData, A * 13 + 5, 1))
.Object = GetInt(Mid$(ObjectData, A * 13 + 6, 2))
.Value = Asc(Mid$(ObjectData, A * 13 + 8, 1)) * 16777216 + Asc(Mid$(ObjectData, A * 13 + 9, 1)) * 65536 + Asc(Mid$(ObjectData, A * 13 + 10, 1)) * 256& + Asc(Mid$(ObjectData, A * 13 + 11, 1))
.ItemPrefix = Asc(Mid$(ObjectData, A * 13 + 12, 1))
.ItemSuffix = Asc(Mid$(ObjectData, A * 13 + 13, 1))
End With
Next A
End Sub
Function NPCNum(ByVal Name As String) As Long
Name = UCase$(Name)
Dim A As Long
For A = 1 To MaxNPCs
With NPC(A)
If UCase$(.Name) = Name Then
NPCNum = A
Exit Function
End If
End With
Next A
End Function
Function FindInvObject(Index As Long, ObjectNum As Long) As Long
Dim A As Long
With Player(Index)
For A = 1 To 20
If .Inv(A).Object = ObjectNum Then
FindInvObject = A
Exit Function
End If
Next A
End With
End Function
Function FindPlayer(ByVal Name As String) As Long
Name = UCase$(Name)
Dim A As Long
For A = 1 To MaxUsers
With Player(A)
If .InUse = True Then
If UCase$(.Name) = Name Then
FindPlayer = A
Exit Function
End If
End If
End With
Next A
End Function
Function FreeBanNum() As Long
Dim A As Long
For A = 1 To 50
If Ban(A).InUse = False Then
FreeBanNum = A
Exit For
End If
Next A
End Function
Function FreeInvNum(Index As Long) As Long
Dim A As Long
With Player(Index)
For A = 1 To 20
If .Inv(A).Object = 0 Then
FreeInvNum = A
Exit Function
End If
Next A
End With
End Function
Function FreeMapDoorNum(MapNum As Long) As Long
Dim A As Long
With Map(MapNum)
For A = 0 To 9
If .Door(A).Att = 0 Then
FreeMapDoorNum = A
Exit Function
End If
Next A
End With
FreeMapDoorNum = -1
End Function
Function FreeMapObj(MapNum As Long) As Long
Dim A As Long
If MapNum >= 1 Then
With Map(MapNum)
For A = 0 To MaxMapObjects
If .Object(A).Object = 0 Then
.Object(A).Value = 0
.Object(A).ItemPrefix = 0
.Object(A).ItemSuffix = 0
FreeMapObj = A
Exit Function
End If
Next A
End With
End If
FreeMapObj = -1
End Function
Function FreePlayer() As Long
Dim A As Long
For A = 1 To MaxUsers
If Player(A).InUse = False Then
FreePlayer = A
Exit Function
End If
Next A
End Function
Sub GainExp(Index As Long, Exp As Long)
With Player(Index)
If .Level < 80 Then
If CDbl(.Experience) + CDbl(Exp) > 2147483647# Then
.Experience = 2147483647
Else
.Experience = .Experience + Exp
End If
'Floating text
SendToMap .Map, Chr$(112) + Chr$(13) + Chr$(.X) + Chr$(.Y) + CStr(Exp)
If .Experience >= Int(1000 * CLng(.Level) ^ 1.3) Then
If .Level < World.MaxLevel Then
.Level = .Level + 1
.Experience = 0
CalculateStats Index
SendSocket Index, Chr$(59) + Chr$(.MaxHP) + Chr$(.MaxEnergy) + Chr$(.MaxMana)
End If
End If
End If
End With
End Sub
Sub GainEliteExp(Index As Long, Exp As Long)
With Player(Index)
If .Level < World.MaxLevel Then
If CDbl(.Experience) + CDbl(Exp) > 2147483647# Then
.Experience = 2147483647
Else
.Experience = .Experience + Exp
End If
'Floating text
SendToMap .Map, Chr$(112) + Chr$(13) + Chr$(.X) + Chr$(.Y) + CStr(Exp)
If .Experience >= Int(1000 * CLng(.Level) ^ 1.3) Then
If .Level < World.MaxLevel Then
.Level = .Level + 1
.Experience = 0
CalculateStats Index
SendSocket Index, Chr$(59) + Chr$(.MaxHP) + Chr$(.MaxEnergy) + Chr$(.MaxMana)
End If
End If
End If
End With
End Sub
Function GuildNum(ByVal Name As String) As Long
Name = UCase$(Name)
Dim A As Long
For A = 1 To MaxGuilds
With Guild(A)
If UCase$(.Name) = Name Then
GuildNum = A
Exit Function
End If
End With
Next A
End Function
Function IsVacant(MapNum As Long, X As Long, Y As Long) As Boolean
Dim A As Long
If X < 0 Or Y < 0 Or X > 11 Or Y > 11 Then Exit Function
With Map(MapNum)
Select Case .Tile(X, Y).Att
Case 1, 2, 3, 10, 13, 14, 15, 16 'Wall / Warp / Door / No Monsters
Exit Function
Case 19 'Light
If ExamineBit(.Tile(X, Y).AttData(2), 0) Then
Exit Function
End If
Case 20 'Light Dampening
If ExamineBit(.Tile(X, Y).AttData(3), 0) Then
Exit Function
End If
End Select
Select Case .Tile(X, Y).Att2
Case 1, 10, 13, 14, 15, 16
Exit Function
End Select
For A = 0 To MaxMonsters
With .Monster(A)
If .Monster > 0 Then
If .X = X Then
If .Y = Y Then
Exit Function
End If
End If
End If
End With
Next A
For A = 1 To MaxUsers
With Player(A)
If .Map = MapNum Then
If .X = X Then
If .Y = Y Then
If .IsDead = False Then
Exit Function
End If
End If
End If
End If
End With
Next A
End With
IsVacant = True
End Function
Function PlayerIsVacant(MapNum As Long, X As Long, Y As Long) As Boolean
Dim A As Long
With Map(MapNum)
Select Case .Tile(X, Y).Att
Case 1, 2, 3, 13, 14, 15, 16 'Wall / Warp
Exit Function
Case 19 'Light
If ExamineBit(.Tile(X, Y).AttData(2), 0) Then
Exit Function
End If
Case 20 'Light Dampening
If ExamineBit(.Tile(X, Y).AttData(3), 0) Then
Exit Function
End If
End Select
Select Case .Tile(X, Y).Att2
Case 1, 2, 3, 13, 14, 15, 16
Exit Function
End Select
For A = 0 To MaxMonsters
With .Monster(A)
If .Monster > 0 Then
If .X = X Then
If .Y = Y Then
Exit Function
End If
End If
End If
End With
Next A
For A = 1 To MaxUsers
With Player(A)
If .Map = MapNum Then
If .X = X Then
If .Y = Y Then
If Not .Status = 25 Then
If .IsDead = False Then
If .Guild > 0 Then
If Player(A).Guild = 0 Then
If ExamineBit(Map(.Map).flags, 0) = False And ExamineBit(Map(.Map).flags, 6) = False Then
Else
Exit Function
End If
Else
Exit Function
End If
Else
Exit Function
End If
End If
End If
End If
End If
End If
End With
Next A
End With
PlayerIsVacant = True
End Function
Sub JoinGame(Index As Long)
Dim A As Long, St1 As String, Tick As Currency
Tick = getTime()
With Player(Index)
.SpeedHackTimer = Tick - 120000
If .Class = 0 Then
.Mode = modeBanned
Hacker Index, "C.0"
Exit Sub
End If
.Mode = modePlaying
SendAllBut Index, Chr$(6) + Chr$(Index) + DoubleChar$(CLng(.Sprite)) + Chr$(.Status) + Chr$(.Guild) + Chr$(.MaxHP) + .Name
SendToGods Chr$(16) + Chr$(0) + .User + " - " + .IP
If .Access > 0 Then PrintGodSilent .User, " (Joined Game) "
PrintAccount "User: " + .User + " - Name " + .Name + " - IP: " + .IP + " - ID: " + .ComputerID
St1 = DoubleChar(1) + Chr$(24)
A = .Map
If Map(A).BootLocation.Map > 0 Then
'Move player if not allowed to join on this map
.Map = Map(A).BootLocation.Map
.X = Map(A).BootLocation.X
.Y = Map(A).BootLocation.Y
End If
If .Map < 1 Then .Map = 1
If .Map > MaxMaps Then .Map = MaxMaps
If .X > 11 Then .X = 11
If .Y > 11 Then .Y = 11
'Send Player Data
For A = 1 To MaxUsers
If A <> Index Then
With Player(A)
If .Mode = modePlaying Then
St1 = St1 + DoubleChar(7 + Len(.Name)) + Chr$(6) + Chr$(A) + DoubleChar$(CLng(.Sprite)) + Chr$(.Status) + Chr$(.Guild) + Chr$(.MaxHP) + .Name
If Len(St1) > 1024 Then
SendRaw Index, St1
St1 = vbNullString
End If
End If
End With
End If
Next A
'Send Inventory Data
For A = 1 To 20
If .Inv(A).Object > 0 Then
St1 = St1 + DoubleChar$(10) + Chr$(17) + Chr$(A) + DoubleChar$(CLng(.Inv(A).Object)) + QuadChar(.Inv(A).Value) + Chr$(.Inv(A).ItemPrefix) + Chr$(.Inv(A).ItemSuffix)
If Len(St1) > 1024 Then
SendRaw Index, St1
St1 = vbNullString
End If
End If
Next A
If .EquippedObject(6).Object > 0 Then St1 = St1 + DoubleChar(2) + Chr$(19) + Chr$(.EquippedObject(6).Object)
For A = 1 To 5
If .EquippedObject(A).Object > 0 Then
St1 = St1 + DoubleChar(9) + Chr$(115) + DoubleChar$(CLng(.EquippedObject(A).Object)) + QuadChar(.EquippedObject(A).Value) + Chr$(.EquippedObject(A).ItemPrefix) + Chr$(.EquippedObject(A).ItemSuffix)
End If
Next A
If Len(St1) > 0 Then
SendRaw Index, St1
End If
SendSocket Index, Chr$(143) + Chr$(OutdoorLight)
JoinMap Index
Parameter(0) = Index
RunScript "JOINGAME"
CalculateStats Index
'Send Guild Data
If .Guild > 0 Then
St1 = vbNullString
With Guild(.Guild)
For A = 0 To DeclarationCount
With .Declaration(A)
St1 = St1 + DoubleChar(4) + Chr$(71) + Chr$(A) + Chr$(.Guild) + Chr$(.Type)
End With
Next A
If .Bank >= 0 Then
St1 = St1 + DoubleChar(9) + Chr$(152) + QuadChar(.Bank) + QuadChar$(GetGuildUpkeep(CLng(Player(Index).Guild)))
Else
St1 = St1 + DoubleChar(9) + Chr$(74) + QuadChar(Abs(.Bank)) + QuadChar(.DueDate)
End If
If Not .MOTD = "" Then
SendSocket Index, Chr$(56) + Chr$(14) + .Name + " - " + .MOTDCreator + " - " + CStr(CDate(.MOTDDate)) + " - " + .MOTD
Else
SendSocket Index, Chr$(16) + Chr$(43)
End If
End With
If Len(St1) > 0 Then
SendRaw Index, St1
End If
End If
End With
End Sub
Sub JoinMap(Index As Long)
Dim A As Long, MapNum As Long, St1 As String, Tick As Currency
Tick = getTime
With Player(Index)
MapNum = .Map
If Map(MapNum).NumPlayers = 0 And Map(MapNum).ResetTimer > 0 And Tick - Map(MapNum).ResetTimer >= 120000 And ExamineBit(Map(MapNum).Flags2, 2) = 0 Then
ResetMap MapNum
End If
With Map(MapNum)
.NumPlayers = .NumPlayers + 1
End With
St1 = DoubleChar(14) + Chr$(12) + DoubleChar(CLng(MapNum)) + Chr$(.X) + Chr$(.Y) + Chr$(.D) + QuadChar(Map(MapNum).Version) + QuadChar(Map(MapNum).CheckSum)
With Map(MapNum)
For A = 0 To 9
If .Door(A).Att > 0 Then
If Tick - .Door(A).T > 10000 Then
.Tile(.Door(A).X, .Door(A).Y).Att = .Door(A).Att
.Door(A).Att = 0
End If
End If
Next A
End With
'Send Door Data
For A = 0 To 9
With Map(MapNum).Door(A)
If .Att > 0 Then
St1 = St1 + DoubleChar(4) + Chr$(36) + Chr$(A) + Chr$(.X) + Chr$(.Y)
End If
End With
Next A
'Send Player Data
For A = 1 To MaxUsers
If Player(A).Mode = modePlaying And Player(A).Map = MapNum And A <> Index Then
With Player(A)
St1 = St1 + DoubleChar(8) + Chr$(8) + Chr$(A) + Chr$(.X) + Chr$(.Y) + Chr$(.D) + DoubleChar$(CLng(.Sprite)) + Chr$(.Status)
End With
If Len(St1) > 1024 Then
SendRaw Index, St1
St1 = vbNullString
End If
End If
Next A
With Map(MapNum)
'Send Map Monster Data
For A = 0 To MaxMonsters
With .Monster(A)
If .Monster > 0 Then
St1 = St1 + DoubleChar(9) + Chr$(38) + Chr$(A) + DoubleChar$(CLng(.Monster)) + Chr$(.X) + Chr$(.Y) + Chr$(.D) + DoubleChar$(CLng(.HP))
End If
End With
Next A
'Send Map Object Data
For A = 0 To MaxMapObjects
With .Object(A)
If .Object > 0 Then
St1 = St1 + DoubleChar(12) + Chr$(14) + Chr$(A) + DoubleChar$(CLng(.Object)) + Chr$(.X) + Chr$(.Y) + Chr$(.ItemPrefix) + Chr$(.ItemSuffix) + QuadChar(.Value)
End If
If Len(St1) > 1024 Then
SendRaw Index, St1
St1 = vbNullString
End If
End With
Next A
End With
A = Map(MapNum).NPC
If A >= 1 Then
With NPC(A)
If .JoinText <> vbNullString Then
St1 = St1 + DoubleChar(3 + Len(.JoinText)) + Chr$(88) + DoubleChar$(A) + .JoinText
End If
End With
End If
If St1 <> vbNullString Then
SendRaw Index, St1
End If
SendToMapAllBut MapNum, Index, Chr$(8) + Chr$(Index) + Chr$(.X) + Chr$(.Y) + Chr$(.D) + DoubleChar$(CLng(.Sprite)) + Chr$(.Status)
Parameter(0) = Index
RunScript "JOINMAP" + CStr(MapNum)
End With
End Sub
Sub MapWarp(Index As Long)
With Player(Index)
SendSocket Index, Chr$(147) + Chr$(.X) + Chr$(.Y) + Chr$(.D)
SendToMapAllBut .Map, Index, Chr$(8) + Chr$(Index) + Chr$(.X) + Chr$(.Y) + Chr$(.D) + DoubleChar$(CLng(.Sprite)) + Chr$(.Status)
End With
End Sub
Sub LoadMap(MapNum As Long, MapData As String)
Dim A As Long, X As Long, Y As Long
If Len(MapData) = 2677 Then
'Characters 1-30 = Name
'36 = Midi
With Map(MapNum)
.Name = ClipString$(Mid$(MapData, 1, 30))
.CheckSum = CheckSum(MapData)
.Version = Asc(Mid$(MapData, 31, 1)) * 16777216 + Asc(Mid$(MapData, 32, 1)) * 65536 + Asc(Mid$(MapData, 33, 1)) * 256& + Asc(Mid$(MapData, 34, 1))
.NPC = Asc(Mid$(MapData, 35, 1)) * 256 + Asc(Mid$(MapData, 36, 1))
.Midi = Asc(Mid$(MapData, 37, 1))
.ExitUp = Asc(Mid$(MapData, 38, 1)) * 256 + Asc(Mid$(MapData, 39, 1))
.ExitDown = Asc(Mid$(MapData, 40, 1)) * 256 + Asc(Mid$(MapData, 41, 1))
.ExitLeft = Asc(Mid$(MapData, 42, 1)) * 256 + Asc(Mid$(MapData, 43, 1))
.ExitRight = Asc(Mid$(MapData, 44, 1)) * 256 + Asc(Mid$(MapData, 45, 1))
.BootLocation.Map = Asc(Mid$(MapData, 46, 1)) * 256 + Asc(Mid$(MapData, 47, 1))
.BootLocation.X = Asc(Mid$(MapData, 48, 1))
.BootLocation.Y = Asc(Mid$(MapData, 49, 1))
.DeathLocation.Map = Asc(Mid$(MapData, 50, 1)) * 256 + Asc(Mid$(MapData, 51, 1))
.DeathLocation.X = Asc(Mid$(MapData, 52, 1))
.DeathLocation.Y = Asc(Mid$(MapData, 53, 1))
.flags = Asc(Mid$(MapData, 54, 1))
.Flags2 = Asc(Mid$(MapData, 55, 1))
For A = 0 To 9 '56 - 86
.MonsterSpawn(A).Monster = Asc(Mid$(MapData, 56 + A * 3)) * 256 + Asc(Mid$(MapData, 57 + A * 3))
.MonsterSpawn(A).Rate = Asc(Mid$(MapData, 58 + A * 3))
Next A
'86
For Y = 0 To 11
For X = 0 To 11
With .Tile(X, Y)
A = 86 + Y * 216 + X * 18
'1-10 = Tiles
.Ground = Asc(Mid$(MapData, A, 1)) * 256 + Asc(Mid$(MapData, A + 1, 1))
.Ground2 = Asc(Mid$(MapData, A + 2, 1)) * 256 + Asc(Mid$(MapData, A + 3, 1))
.BGTile1 = Asc(Mid$(MapData, A + 4, 1)) * 256 + Asc(Mid$(MapData, A + 5, 1))
.BGTile2 = Asc(Mid$(MapData, A + 6, 1)) * 256 + Asc(Mid$(MapData, A + 7, 1))
.FGTile = Asc(Mid$(MapData, A + 8, 1)) * 256 + Asc(Mid$(MapData, A + 9, 1))
.FGTile2 = Asc(Mid$(MapData, A + 10, 1)) * 256 + Asc(Mid$(MapData, A + 11, 1))
.Att = Asc(Mid$(MapData, A + 12, 1))
.AttData(0) = Asc(Mid$(MapData, A + 13, 1))
.AttData(1) = Asc(Mid$(MapData, A + 14, 1))
.AttData(2) = Asc(Mid$(MapData, A + 15, 1))
.AttData(3) = Asc(Mid$(MapData, A + 16, 1))
.Att2 = Asc(Mid$(MapData, A + 17, 1))
Select Case .Att
Case 5
Map(MapNum).Keep = True
Case 8
If .AttData(2) > 0 Then
Map(MapNum).Hall = .AttData(2)
End If
End Select
Select Case .Att2
Case 5
Map(MapNum).Keep = True
End Select
End With
Next X
Next Y
End With
End If
End Sub
Sub LoadMapOld(MapNum As Long, MapData As String)
Dim A As Long, X As Long, Y As Long
MsgBox Len(MapData)
If Len(MapData) = 2388 Then
'Characters 1-30 = Name
'36 = Midi
With Map(MapNum)
.Name = ClipString$(Mid$(MapData, 1, 30))
.CheckSum = CheckSum(MapData)
.Version = Asc(Mid$(MapData, 31, 1)) * 16777216 + Asc(Mid$(MapData, 32, 1)) * 65536 + Asc(Mid$(MapData, 33, 1)) * 256& + Asc(Mid$(MapData, 34, 1))
.NPC = Asc(Mid$(MapData, 35, 1))
.Midi = Asc(Mid$(MapData, 36, 1))
.ExitUp = Asc(Mid$(MapData, 37, 1)) * 256 + Asc(Mid$(MapData, 38, 1))
.ExitDown = Asc(Mid$(MapData, 39, 1)) * 256 + Asc(Mid$(MapData, 40, 1))
.ExitLeft = Asc(Mid$(MapData, 41, 1)) * 256 + Asc(Mid$(MapData, 42, 1))
.ExitRight = Asc(Mid$(MapData, 43, 1)) * 256 + Asc(Mid$(MapData, 44, 1))
.BootLocation.Map = Asc(Mid$(MapData, 45, 1)) * 256 + Asc(Mid$(MapData, 46, 1))
.BootLocation.X = Asc(Mid$(MapData, 47, 1))
.BootLocation.Y = Asc(Mid$(MapData, 48, 1))
.DeathLocation.Map = Asc(Mid$(MapData, 49, 1)) * 256 + Asc(Mid$(MapData, 50, 1))
.DeathLocation.X = Asc(Mid$(MapData, 51, 1))
.DeathLocation.Y = Asc(Mid$(MapData, 52, 1))
.flags = Asc(Mid$(MapData, 53, 1))
.Flags2 = Asc(Mid$(MapData, 54, 1))
For A = 0 To 9 '55 - 85
.MonsterSpawn(A).Monster = Asc(Mid$(MapData, 55 + A * 3)) * 256 + Asc(Mid$(MapData, 56 + A * 3))
.MonsterSpawn(A).Rate = Asc(Mid$(MapData, 57 + A * 3))
Next A
'86
For Y = 0 To 11
For X = 0 To 11
With .Tile(X, Y)
A = 85 + Y * 192 + X * 16
'1-8 = Tiles
.Ground = Asc(Mid$(MapData, A, 1)) * 256 + Asc(Mid$(MapData, A + 1, 1))
.Ground2 = Asc(Mid$(MapData, A + 2, 1)) * 256 + Asc(Mid$(MapData, A + 3, 1))
.BGTile1 = Asc(Mid$(MapData, A + 4, 1)) * 256 + Asc(Mid$(MapData, A + 5, 1))
.BGTile2 = Asc(Mid$(MapData, A + 6, 1)) * 256 + Asc(Mid$(MapData, A + 7, 1))
.FGTile = Asc(Mid$(MapData, A + 8, 1)) * 256 + Asc(Mid$(MapData, A + 9, 1))
.Att = Asc(Mid$(MapData, A + 10, 1))
.AttData(0) = Asc(Mid$(MapData, A + 11, 1))
.AttData(1) = Asc(Mid$(MapData, A + 12, 1))
.AttData(2) = Asc(Mid$(MapData, A + 13, 1))
.AttData(3) = Asc(Mid$(MapData, A + 14, 1))
.Att2 = Asc(Mid$(MapData, A + 15, 1))
Select Case .Att
Case 5
Map(MapNum).Keep = True
Case 8
If .AttData(2) > 0 Then
Map(MapNum).Hall = .AttData(2)
End If
End Select
Select Case .Att2
Case 5
Map(MapNum).Keep = True
End Select
End With
Next X
Next Y
End With
End If
End Sub
Sub LoadMapOld2008(MapNum As Long, MapData As String)
Dim A As Long, X As Long, Y As Long
If Len(MapData) = 2359 Then
'Characters 1-30 = Name
'36 = Midi
With Map(MapNum)
.Name = ClipString$(Mid$(MapData, 1, 30))
.CheckSum = CheckSum(MapData)
.Version = Asc(Mid$(MapData, 31, 1)) * 16777216 + Asc(Mid$(MapData, 32, 1)) * 65536 + Asc(Mid$(MapData, 33, 1)) * 256& + Asc(Mid$(MapData, 34, 1))
.NPC = Asc(Mid$(MapData, 35, 1))
.Midi = Asc(Mid$(MapData, 36, 1))
.ExitUp = Asc(Mid$(MapData, 37, 1)) * 256 + Asc(Mid$(MapData, 38, 1))
.ExitDown = Asc(Mid$(MapData, 39, 1)) * 256 + Asc(Mid$(MapData, 40, 1))
.ExitLeft = Asc(Mid$(MapData, 41, 1)) * 256 + Asc(Mid$(MapData, 42, 1))
.ExitRight = Asc(Mid$(MapData, 43, 1)) * 256 + Asc(Mid$(MapData, 44, 1))
.BootLocation.Map = Asc(Mid$(MapData, 45, 1)) * 256 + Asc(Mid$(MapData, 46, 1))
.BootLocation.X = Asc(Mid$(MapData, 47, 1))
.BootLocation.Y = Asc(Mid$(MapData, 48, 1))
.flags = Asc(Mid$(MapData, 49, 1))
For A = 0 To 2 '50 - 55
.MonsterSpawn(A).Monster = Asc(Mid$(MapData, 50 + A * 2))
.MonsterSpawn(A).Rate = Asc(Mid$(MapData, 51 + A * 2))
Next A
'56
.Keep = False
For Y = 0 To 11
For X = 0 To 11
With .Tile(X, Y)
A = 56 + Y * 192 + X * 16
'1-8 = Tiles
.Ground = Asc(Mid$(MapData, A, 1)) * 256 + Asc(Mid$(MapData, A + 1, 1))
.Ground2 = Asc(Mid$(MapData, A + 2, 1)) * 256 + Asc(Mid$(MapData, A + 3, 1))
.BGTile1 = Asc(Mid$(MapData, A + 4, 1)) * 256 + Asc(Mid$(MapData, A + 5, 1))
.BGTile2 = Asc(Mid$(MapData, A + 6, 1)) * 256 + Asc(Mid$(MapData, A + 7, 1))
.FGTile = Asc(Mid$(MapData, A + 8, 1)) * 256 + Asc(Mid$(MapData, A + 9, 1))
.FGTile2 = 0
.Att = Asc(Mid$(MapData, A + 10, 1))
.AttData(0) = Asc(Mid$(MapData, A + 11, 1))
.AttData(1) = Asc(Mid$(MapData, A + 12, 1))
.AttData(2) = Asc(Mid$(MapData, A + 13, 1))
.AttData(3) = Asc(Mid$(MapData, A + 14, 1))
.Att2 = Asc(Mid$(MapData, A + 15, 1))
Select Case .Att
Case 5
Map(MapNum).Keep = True
Case 8
If .AttData(2) > 0 Then
Map(MapNum).Hall = .AttData(2)
End If
End Select
Select Case .Att2
Case 5
Map(MapNum).Keep = True
End Select
End With
Next X
Next Y
End With
End If
End Sub
Sub LoadMapOld1997(MapNum As Long, MapData As String)
Dim A As Long, X As Long, Y As Long
If Len(MapData) = 1927 Then
'Characters 1-30 = Name
'36 = Midi
With Map(MapNum)
.CheckSum = CheckSum(MapData)
.Name = ClipString$(Mid$(MapData, 1, 30))
.Version = Asc(Mid$(MapData, 31, 1)) * 16777216 + Asc(Mid$(MapData, 32, 1)) * 65536 + Asc(Mid$(MapData, 33, 1)) * 256& + Asc(Mid$(MapData, 34, 1))
.NPC = Asc(Mid$(MapData, 35, 1))
.Midi = Asc(Mid$(MapData, 36, 1))
.ExitUp = Asc(Mid$(MapData, 37, 1)) * 256 + Asc(Mid$(MapData, 38, 1))
.ExitDown = Asc(Mid$(MapData, 39, 1)) * 256 + Asc(Mid$(MapData, 40, 1))
.ExitLeft = Asc(Mid$(MapData, 41, 1)) * 256 + Asc(Mid$(MapData, 42, 1))
.ExitRight = Asc(Mid$(MapData, 43, 1)) * 256 + Asc(Mid$(MapData, 44, 1))
.BootLocation.Map = Asc(Mid$(MapData, 45, 1)) * 256 + Asc(Mid$(MapData, 46, 1))
.BootLocation.X = Asc(Mid$(MapData, 47, 1))
.BootLocation.Y = Asc(Mid$(MapData, 48, 1))
.flags = Asc(Mid$(MapData, 49, 1))
For A = 0 To 2 '50 - 55
.MonsterSpawn(A).Monster = Asc(Mid$(MapData, 50 + A * 2))
.MonsterSpawn(A).Rate = Asc(Mid$(MapData, 51 + A * 2))
Next A
'56
.Keep = False
For Y = 0 To 11
For X = 0 To 11
With .Tile(X, Y)
A = 56 + Y * 156 + X * 13
'1-8 = Tiles
.Ground = Asc(Mid$(MapData, A, 1)) * 256 + Asc(Mid$(MapData, A + 1, 1))
.Ground2 = 0
.BGTile1 = Asc(Mid$(MapData, A + 2, 1)) * 256 + Asc(Mid$(MapData, A + 3, 1))
.BGTile2 = Asc(Mid$(MapData, A + 4, 1)) * 256 + Asc(Mid$(MapData, A + 5, 1))
.FGTile = Asc(Mid$(MapData, A + 6, 1)) * 256 + Asc(Mid$(MapData, A + 7, 1))
.FGTile2 = 0
.Att = Asc(Mid$(MapData, A + 8, 1))
.AttData(0) = Asc(Mid$(MapData, A + 9, 1))
.AttData(1) = Asc(Mid$(MapData, A + 10, 1))
.AttData(2) = Asc(Mid$(MapData, A + 11, 1))
.AttData(3) = Asc(Mid$(MapData, A + 12, 1))
.Att2 = 0
Select Case .Att
Case 5
Map(MapNum).Keep = True
Case 8
If .AttData(2) > 0 Then
Map(MapNum).Hall = .AttData(2)
End If
End Select
End With
Next X
Next Y
End With
Else
MsgBox Len(MapData)
End If
End Sub
Sub Main()
Randomize
timeBeginPeriod 1
Dim A As Long
Dim St As String
Dim LingerType As LingerType
Startup = True
InitFunctionTable
frmLoading.Show
frmLoading.Refresh
On Error Resume Next
MkDir "log"
MkDir "log/debug"
MkDir "log/god"
MkDir "log/password"
MkDir "log/cheat"
MkDir "log/script"
MkDir "log/account"
MkDir "log/items"
MkDir "log/chat"
MkDir "log/chat/guild"
MkDir "log/chat/god"
MkDir "log/chat/say"
MkDir "log/chat/yell"
MkDir "log/chat/emote"
MkDir "log/chat/broadcast"
MkDir "log/chat/tell"
MkDir "scriptini"
On Error GoTo 0
LoadDatabase
For A = 1 To MaxMaps
ResetMap A
Next A
frmLoading.lblStatus = "Initializing Sockets.."
frmLoading.lblStatus.Refresh
Load frmMain
frmMain.Caption = TitleString + " [0]"
Hook
StartWinsock St
'Listen for connections
With LingerType
.l_onoff = 1
.l_linger = 0
End With
ListeningSocket = ListenForConnect(World.ServerPort, gHW, 1025)
If ListeningSocket = INVALID_SOCKET Then
MsgBox "Unable to create listening socket!", vbOKOnly + vbExclamation, TitleString
EndWinsock
Unhook
End
End If
If setsockopt(ListeningSocket, SOL_SOCKET, SO_LINGER, LingerType, 4) <> 0 Then
MsgBox "Unable to create listening socket!", vbOKOnly + vbExclamation, TitleString
EndWinsock
Unhook
End
End If
If setsockopt(ListeningSocket, IPPROTO_TCP, TCP_NODELAY, 1&, 4) <> 0 Then
MsgBox "Unable to create listening socket!", vbOKOnly + vbExclamation, TitleString
EndWinsock
Unhook
End
End If
Unload frmLoading
frmMain.Show
Startup = False
PrintLog ("Odyssey Realms Server Version B" + CStr(CurrentClientVer) + ".")
PrintLog "Attempting to connect to the Registry..."
ConnectToRegistry
End Sub
Function NewMapMonster(MapNum As Long, MonsterNum As Long) As String
Dim TX As Long, TY As Long, TriesLeft As Long
Dim MonsterType As Long, MonsterFlags As Byte
If Int(MonsterNum / 2) * 2 = MonsterNum Or ExamineBit(Map(MapNum).flags, 4) = True Then
MonsterType = Map(MapNum).MonsterSpawn(Int(MonsterNum / 2)).Monster
If MonsterType > 0 Then
MonsterFlags = Monster(MonsterType).flags
Randomize
TX = Int(Rnd * 12)
TY = Int(Rnd * 12)
TriesLeft = 20
While TriesLeft > 0 And (Map(MapNum).Tile(TX, TY).Att > 0 Or Map(MapNum).Tile(TX, TY).Att2 > 0)