This repository was archived by the owner on Feb 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathNetplay.frm
2569 lines (2528 loc) · 97.2 KB
/
Netplay.frm
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
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "mswinsck.ocx"
Begin VB.Form Netplay
BorderStyle = 0 'None
Caption = "NetPlay"
ClientHeight = 7665
ClientLeft = 0
ClientTop = 0
ClientWidth = 8490
LinkTopic = "Form1"
ScaleHeight = 7665
ScaleWidth = 8490
ShowInTaskbar = 0 'False
StartUpPosition = 3 'Windows Default
Visible = 0 'False
Begin VB.Timer tmrTimeoutC
Enabled = 0 'False
Interval = 60000
Left = 3840
Top = 1560
End
Begin VB.Timer tmrPingC
Enabled = 0 'False
Interval = 10000
Left = 1440
Top = 4080
End
Begin VB.Timer tmrConnect
Enabled = 0 'False
Interval = 10000
Left = 6240
Top = 840
End
Begin VB.Timer tmrCheckPorts
Enabled = 0 'False
Interval = 5000
Left = 120
Top = 1320
End
Begin VB.Timer tmrPing
Enabled = 0 'False
Interval = 30000
Left = 1440
Top = 3480
End
Begin VB.Timer tmrTimeout
Enabled = 0 'False
Index = 16
Interval = 60000
Left = 5040
Top = 5040
End
Begin VB.Timer tmrTimeout
Enabled = 0 'False
Index = 15
Interval = 60000
Left = 4560
Top = 5040
End
Begin VB.Timer tmrTimeout
Enabled = 0 'False
Index = 14
Interval = 60000
Left = 4080
Top = 5040
End
Begin VB.Timer tmrTimeout
Enabled = 0 'False
Index = 13
Interval = 60000
Left = 3600
Top = 5040
End
Begin VB.Timer tmrTimeout
Enabled = 0 'False
Index = 12
Interval = 60000
Left = 4560
Top = 4560
End
Begin VB.Timer tmrTimeout
Enabled = 0 'False
Index = 11
Interval = 60000
Left = 5040
Top = 4560
End
Begin VB.Timer tmrTimeout
Enabled = 0 'False
Index = 10
Interval = 60000
Left = 4080
Top = 4560
End
Begin VB.Timer tmrTimeout
Enabled = 0 'False
Index = 9
Interval = 60000
Left = 3600
Top = 4560
End
Begin VB.Timer tmrTimeout
Enabled = 0 'False
Index = 8
Interval = 60000
Left = 5040
Top = 4080
End
Begin VB.Timer tmrTimeout
Enabled = 0 'False
Index = 7
Interval = 60000
Left = 4560
Top = 4080
End
Begin VB.Timer tmrTimeout
Enabled = 0 'False
Index = 6
Interval = 60000
Left = 4080
Top = 4080
End
Begin VB.Timer tmrTimeout
Enabled = 0 'False
Index = 5
Interval = 60000
Left = 3600
Top = 4080
End
Begin VB.Timer tmrTimeout
Enabled = 0 'False
Index = 4
Interval = 60000
Left = 4560
Top = 3600
End
Begin VB.Timer tmrTimeout
Enabled = 0 'False
Index = 3
Interval = 60000
Left = 5040
Top = 3600
End
Begin VB.Timer tmrTimeout
Enabled = 0 'False
Index = 2
Interval = 60000
Left = 4080
Top = 3600
End
Begin VB.Timer tmrTimeout
Enabled = 0 'False
Index = 1
Interval = 60000
Left = 3600
Top = 3600
End
Begin VB.Timer tmrPort
Enabled = 0 'False
Interval = 1000
Left = 120
Top = 720
End
Begin MSWinsockLib.Winsock nServer
Index = 0
Left = 1560
Top = 120
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin MSWinsockLib.Winsock nClient
Left = 120
Top = 120
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin MSWinsockLib.Winsock nServer
Index = 1
Left = 1560
Top = 600
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin MSWinsockLib.Winsock nServer
Index = 2
Left = 1560
Top = 1080
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin MSWinsockLib.Winsock nServer
Index = 3
Left = 2040
Top = 120
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin MSWinsockLib.Winsock nServer
Index = 4
Left = 2040
Top = 600
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin MSWinsockLib.Winsock nServer
Index = 5
Left = 2040
Top = 1080
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin MSWinsockLib.Winsock nServer
Index = 6
Left = 3000
Top = 120
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin MSWinsockLib.Winsock nServer
Index = 7
Left = 3000
Top = 600
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin MSWinsockLib.Winsock nServer
Index = 8
Left = 3000
Top = 1080
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin MSWinsockLib.Winsock nServer
Index = 9
Left = 2520
Top = 120
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin MSWinsockLib.Winsock nServer
Index = 10
Left = 2520
Top = 600
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin MSWinsockLib.Winsock nServer
Index = 11
Left = 2520
Top = 1080
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin MSWinsockLib.Winsock nServer
Index = 12
Left = 1560
Top = 1560
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin MSWinsockLib.Winsock nServer
Index = 13
Left = 2040
Top = 1560
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin MSWinsockLib.Winsock nServer
Index = 14
Left = 3000
Top = 1560
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin MSWinsockLib.Winsock nServer
Index = 15
Left = 2520
Top = 1560
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
End
Attribute VB_Name = "Netplay"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'this handles all the online code
Option Explicit
Const SOCKET_ERROR = -1 ' Error returned by Winsock API.
Const SOL_SOCKET = 65535 ' Options for socket level.
Const IPPROTO_TCP = 6 ' Protocol constant for TCP.
Const SO_DEBUG = &H1& ' Turn on debugging info recording
Const SO_ACCEPTCONN = &H2& ' Socket has had listen() - READ-ONLY.
Const SO_REUSEADDR = &H4& ' Allow local address reuse.
Const SO_KEEPALIVE = &H8& ' Keep connections alive.
Const SO_DONTROUTE = &H10& ' Just use interface addresses.
Const SO_BROADCAST = &H20& ' Permit sending of broadcast msgs.
Const SO_USELOOPBACK = &H40& ' Bypass hardware when possible.
Const SO_LINGER = &H80& ' Linger on close if data present.
Const SO_OOBINLINE = &H100& ' Leave received OOB data in line.
Const SO_DONTLINGER = Not SO_LINGER
Const SO_EXCLUSIVEADDRUSE = Not SO_REUSEADDR ' Disallow local address reuse.
Const SO_SNDBUF = &H1001& ' Send buffer size.
Const SO_RCVBUF = &H1002& ' Receive buffer size.
Const SO_ERROR = &H1007& ' Get error status and clear.
Const SO_TYPE = &H1008& ' Get socket type - READ-ONLY.
Const TCP_NODELAY = &H1& ' Turn off Nagel Algorithm.
Private Type LINGER_STRUCT
l_onoff As Integer ' Is linger on or off?
l_linger As Integer ' Linger timeout in seconds.
End Type
Private Declare Function setsockopt Lib "wsock32.dll" (ByVal S As Long, ByVal level As Long, ByVal optname As Long, optval As Any, ByVal optlen As Long) As Long
Private Declare Function getsockopt Lib "wsock32.dll" (ByVal S As Long, ByVal level As Long, ByVal optname As Long, optval As Any, optlen As Long) As Long
'1 - player stuff
'2 - NPC stuff
'3 - block stuff
'a - version
'b - nick
'c - recieve chat from clients
'd - send chat to clients
'e - update player list
'f - editor cursor position
'g - update section size
'h - update section music
'i - update section background
'j - clear level
'k - add block
'l - request initsync
'm - erase block
'n - set screen position
'o - player slot
'p - play sound
'q - add background
'r - erase background
's - sort backgrounds
't - add npc
'u - erase npc
'v - set player start
'w - loading screen
'x - add water
'y - remove water
'z - section settings
'A - add warp
'B - erase warp
'C - change layers
'D - change events
'E - password
'F - level erase toggle
'G - numblock, numnpcs, numbackgrounds
'H - test level
'I - player controls
'J - player loc
'K - npc update from server
'L - npcs timeleft = 1
'M - drop heldbonus
'N - serverload
'O - numplayers
'7 - redigit
Private Sub nClient_Close()
frmChat.txtChat = frmChat.txtChat & "You have disconnected." & LB
frmChat.txtChat.SelStart = Len(frmChat.txtChat.Text)
PlaySound 47
SoundPause(47) = 2
DropServer
End Sub
Private Sub nClient_Connect()
tmrTimeoutC.Enabled = True
frmNetplay.frMode.Enabled = False
tmrConnect.Enabled = False
noUpdate = True
ClearLevel
noUpdate = False
frmLevelEditor.Enabled = False
frmLoading.Show
nPlay.ServerLoad = True
frmLoading.curLoad.Width = 0
frmLoading.curLoad.Left = 0
If ClientPassword <> "" Then
nClient.sendData "E" & ClientPassword & LB & "a" & curRelease & LB & "b" & LocalNick & "|" & LocalCursor & LB & "l" & LB & EoT
Else
nClient.sendData "a" & curRelease & LB & "b" & LocalNick & "|" & LocalCursor & LB & "l" & LB & EoT
End If
nPlay.ServerCon = True
nPlay.Online = True
nPlay.ServerIP = nClient.RemoteHostIP
tmrPing.Enabled = True
vScreenX(1) = 10000
vScreenY(1) = -10000
setsockopt nClient.SocketHandle, IPPROTO_TCP, TCP_NODELAY, 1, 4
End Sub
Private Sub nClient_DataArrival(ByVal bytesTotal As Long)
Dim newStr As String
Dim tempStr As String
Dim workStr As String
Dim A As Double
Dim B As Double
Dim Z As Double
Dim loopCount As Integer
tmrTimeoutC.Enabled = False
tmrTimeoutC.Enabled = True
nClient.GetData tempStr
nPlay.ServerStr = nPlay.ServerStr & tempStr
If nPlay.ServerLoad = False Then
If LenB(nPlay.ServerStr) > 2000000 Then
sendData "l" & LB
frmLevelEditor.Enabled = False
frmLoading.Show
frmLoading.curLoad.Width = 0
nPlay.ServerLoad = True
vScreenX(1) = 10000
vScreenY(1) = -10000
End If
End If
If nPlay.ServerLocked = True Then Exit Sub
nPlay.ServerLocked = True
cCheck:
A = 0
A = InStrRev(nPlay.ServerStr, LB, , vbBinaryCompare)
If A > 0 Then
workStr = Left$(nPlay.ServerStr, A + 1)
nPlay.ServerStr = Mid$(nPlay.ServerStr, A + 2)
Z = 1
Do
A = InStr(Z, workStr, LB, vbBinaryCompare)
If A = 0 Then Exit Do
newStr = Mid$(workStr, Z, A - Z)
If (newStr) <> "" Then
Do While AscW(newStr) = 10 Or AscW(newStr) = 13
newStr = Right$(newStr, Len(newStr) - 1)
Loop
newData Mid$(newStr, 2, Len(newStr)), Left$(newStr, 1), 0
End If
Z = A + 2
loopCount = loopCount + 1
If loopCount >= 10 Then
loopCount = 0
If nPlay.ServerLoad1 > 0 Then
frmLoading.curLoad.Left = 0
frmLoading.curLoad.Top = 0
frmLoading.curLoad.Height = frmLoading.maxLoad.Height
frmLoading.curLoad.Width = frmLoading.maxLoad.Width * (numBlock + numBackground + numNPCs) / nPlay.ServerLoad1
End If
DoEvents
End If
Loop Until A >= Len(workStr) Or nPlay.ServerCon = False
If Len(nPlay.ServerStr) > 0 Then
DoEvents
GoTo cCheck
End If
End If
nPlay.ServerLocked = False
End Sub
Private Sub nServer_Close(Index As Integer)
nPlay.ClientCon(Index) = False
If nPlay.ClientName(Index) = "" Then nPlay.ClientName(Index) = nPlay.ClientIP(Index)
Netplay.sendData "d" & nPlay.ClientName(Index) & " has disconnected." & LB
frmChat.txtChat = frmChat.txtChat & nPlay.ClientName(Index) & " has disconnected." & LB
frmChat.txtChat.SelStart = Len(frmChat.txtChat.Text)
PlaySound 47
SoundPause(47) = 2
DropClient Index
End Sub
Private Sub nServer_ConnectionRequest(Index As Integer, ByVal requestID As Long)
Dim tempStr As String
Dim A As Integer
tmrTimeout(Index).Enabled = True
If nServer(Index).State <> sckClosed Then nServer(Index).Close
nServer(Index).Accept requestID
nPlay.Online = True
nPlay.ClientCon(Index) = True
If tmrPingC.Enabled = False Then tmrPingC.Enabled = True
tmrPort.Enabled = False
For A = 1 To 15
If A <> Index Then
If nServer(A).State = sckClosed Then
nServer(A).LocalPort = nServer(Index).LocalPort
nServer(A).Listen
Exit For
End If
End If
Next A
nPlay.ClientIP(Index) = nServer(Index).RemoteHostIP
nPlay.ClientName(Index) = ""
nPlay.ClientPassword(Index) = False
frmLevelEditor.menuTestLevel.Enabled = True
setsockopt nServer(Index).SocketHandle, IPPROTO_TCP, TCP_NODELAY, 1, 4
End Sub
Private Sub nServer_DataArrival(Index As Integer, ByVal bytesTotal As Long)
On Error Resume Next
Dim newStr As String
Dim tempStr As String
Dim workStr As String
Dim A As Double
Dim B As Double
Dim Z As Double
Dim tempBool As Boolean
Dim loopCount As Integer
tmrTimeout(Index).Enabled = False
tmrTimeout(Index).Enabled = True
nServer(Index).GetData tempStr
nPlay.ClientStr(Index) = nPlay.ClientStr(Index) & tempStr
If nPlay.ClientLocked(Index) = True Then Exit Sub
nPlay.ClientLocked(Index) = True
sCheck:
A = 0
A = InStrRev(nPlay.ClientStr(Index), LB, , vbBinaryCompare)
If A > 0 Then
workStr = Left$(nPlay.ClientStr(Index), A + 1)
nPlay.ClientStr(Index) = Mid$(nPlay.ClientStr(Index), A + 2)
Z = 1
Do
A = InStr(Z, workStr, LB, vbBinaryCompare)
If A = 0 Then Exit Do
newStr = Mid$(workStr, Z, A - Z)
If (newStr) <> "" Then
Do While AscW(newStr) = 10 Or AscW(newStr) = 13
newStr = Right$(newStr, Len(newStr) - 1)
Loop
newData Mid$(newStr, 2, Len(newStr)), Left$(newStr, 1), Index
End If
Z = A + 2
loopCount = loopCount + 1
If loopCount >= 200 Then
DoEvents
End If
Loop Until A >= Len(workStr) Or nPlay.ClientCon(Index) = False
If Len(nPlay.ClientStr(Index)) > 0 Then
DoEvents
GoTo sCheck
End If
End If
nPlay.ClientLocked(Index) = False
End Sub
Public Sub newData(newStr As String, Action As String, Index As Integer)
On Error Resume Next
Dim A As Integer
Dim B As Integer
Dim C As Integer
Dim Z As Integer
Dim tempStr As String
Dim tempBool As Boolean
Dim tempBlock As Block
Dim tempNPC As NPC
Dim lenStr As Integer
Dim tempBackground As Background
If ServerPassword <> "" And nPlay.ClientPassword(Index) = False And Action <> "E" And nPlay.Mode = 1 Then
Netplay.nServer(Index).sendData "dYou need the correct password to connect to this server." & LB & EoT
DoEvents
DropClient Index
frmChat.txtChat.Text = frmChat.txtChat.Text & nServer(Index).RemoteHostIP & " tried to connect with the wrong password" & LB
frmChat.txtChat.SelStart = Len(frmChat.txtChat.Text)
PlaySound 47
SoundPause(47) = 2
Exit Sub
Else
nPlay.ClientPassword(Index) = True
End If
If Action = "1" Then 'player stuff
ModPlayer newStr
If nPlay.Mode = 1 Then
sendData Action & newStr, Index
End If
ElseIf Action = "2" Then 'NPC stuff
ModNPC newStr
If nPlay.Mode = 1 Then
sendData Action & newStr, Index
End If
ElseIf Action = "3" Then 'block stuff
ModNPC newStr
If nPlay.Mode = 1 Then
sendData Action & newStr, Index
End If
ElseIf Action = "a" Then 'get version
nPlay.ClientRelease(Index) = Int(Val(newStr))
If nPlay.ClientRelease(Index) <> curRelease Then
Netplay.nServer(Index).sendData "dYou are using build " & nPlay.ClientRelease(Index) & " and you need build " & curRelease & " to connect to this server." & LB & EoT
DoEvents
nPlay.ClientCon(Index) = False
tmrTimeout(Index).Enabled = False
nPlay.ClientCon(Index) = False
nPlay.ClientName(Index) = ""
nPlay.ClientIP(Index) = ""
nPlay.ClientStr(Index) = ""
nServer(Index).Close
For A = 1 To 15
If nPlay.ClientCon(A) = True Then
tempBool = True
Exit For
End If
Next A
If tempBool = False Then
nPlay.Online = False
frmNetplay.frMode.Enabled = True
If TestLevel = True Then EndLevel = True
End If
tmrPort.Enabled = True
frmChat.txtChat.Text = frmChat.txtChat.Text & nServer(Index).RemoteHostIP & " tried to connect with an older build." & LB
frmChat.txtChat.SelStart = Len(frmChat.txtChat.Text)
PlaySound 47
SoundPause(47) = 2
End If
ElseIf Action = "b" Then 'get nickname
If nPlay.ClientCon(Index) = True Then
tempStr = newStr
For A = 1 To Len(tempStr)
If Mid(tempStr, A, 1) = "|" Then Exit For
Next A
nPlay.ClientName(Index) = Left(tempStr, A - 1)
nPlay.Player(Index).Nick = Left(tempStr, A - 1)
nPlay.Player(Index).Active = True
tempStr = Mid(tempStr, A + 1, Len(tempStr))
For A = 1 To Len(tempStr)
If Mid(tempStr, A, 1) = "|" Then Exit For
Next A
nPlay.Player(Index).Cursor = Val(Left(tempStr, A - 1))
If nPlay.Mode = 1 Then ' broadcast users
frmChat.lstUsers.Clear
frmChat.lstUsers.AddItem LocalNick
tempStr = "0" & "|" & LocalNick & "|" & nPlay.Player(0).Cursor & "|"
For A = 0 To 15
If nPlay.ClientCon(A) = True Then
frmChat.lstUsers.AddItem nPlay.ClientName(A)
tempStr = tempStr & A & "|" & nPlay.ClientName(A) & "|" & nPlay.Player(A).Cursor & "|"
End If
Next A
For A = 0 To 15
If nPlay.ClientCon(A) = True Then nServer(A).sendData "e" & tempStr & LB & EoT
Next A
End If
Netplay.sendData "d" & nPlay.ClientName(Index) & " has connected." & LB
frmChat.txtChat = frmChat.txtChat & nPlay.ClientName(Index) & " has connected." & LB
frmChat.txtChat.SelStart = Len(frmChat.txtChat.Text)
End If
ElseIf Action = "c" Then 'send chat messages from server
If nPlay.Mode = 1 Then
frmChat.txtChat = frmChat.txtChat & "<" & nPlay.ClientName(Index) & "> " & newStr & LB
frmChat.txtChat.SelStart = Len(frmChat.txtChat.Text)
PlaySound 47
SoundPause(47) = 2
For A = 0 To 15
If nPlay.ClientCon(A) = True Then
Netplay.nServer(A).sendData "d<" & nPlay.ClientName(Index) & "> " & newStr & LB & EoT
End If
Next A
End If
ElseIf Action = "d" Then 'recieve chat message
PlaySound 47
SoundPause(47) = 2
frmChat.txtChat = frmChat.txtChat & newStr & LB
frmChat.txtChat.SelStart = Len(frmChat.txtChat.Text)
ElseIf Action = "e" Then 'recieve who is connected
tempStr = newStr
frmChat.lstUsers.Clear
For A = 0 To 15
nPlay.Player(A).Active = False
nPlay.Player(A).Nick = ""
Next A
Do
For A = 1 To Len(tempStr)
If Mid(tempStr, A, 1) = "|" Then Exit For
Next A
B = Val(Left(tempStr, A - 1))
tempStr = Mid(tempStr, A + 1, Len(tempStr))
For A = 1 To Len(tempStr)
If Mid(tempStr, A, 1) = "|" Then Exit For
Next A
frmChat.lstUsers.AddItem Left(tempStr, A - 1)
nPlay.Player(B).Active = True
nPlay.Player(B).Nick = Left(tempStr, A - 1)
tempStr = Mid(tempStr, A + 1, Len(tempStr))
For A = 1 To Len(tempStr)
If Mid(tempStr, A, 1) = "|" Then Exit For
Next A
nPlay.Player(B).Cursor = Val(Left(tempStr, A - 1))
tempStr = Mid(tempStr, A + 1, Len(tempStr))
Loop Until tempStr = "" Or tempStr = "|"
ElseIf Action = "f" Then 'recieve editor cursor position
tempStr = newStr
If nPlay.Mode = 0 Then
For A = 1 To Len(tempStr)
If Mid(tempStr, A, 1) = "|" Then Exit For
Next A
B = Val(Left(tempStr, A - 1))
tempStr = Mid(tempStr, A + 1, Len(tempStr))
Else
B = Index
End If
For A = 1 To Len(tempStr)
If Mid(tempStr, A, 1) = "|" Then Exit For
Next A
nPlay.Player(B).ECurserX = Val(Left(tempStr, A - 1))
nPlay.Player(B).ECurserY = Val(Mid(tempStr, A + 1, Len(tempStr)))
If nPlay.Mode = 1 Then
sendData Action & Index & "|" & newStr & LB, Index
End If
ElseIf Action = "g" Then 'update section size
tempStr = newStr
For A = 1 To Len(tempStr)
If Mid(tempStr, A, 1) = "|" Then Exit For
Next A
B = Val(Left(tempStr, A - 1))
tempStr = Mid(tempStr, A + 1, Len(tempStr))
For A = 1 To Len(tempStr)
If Mid(tempStr, A, 1) = "|" Then Exit For
Next A
level(B).X = Val(Left(tempStr, A - 1))
tempStr = Mid(tempStr, A + 1, Len(tempStr))
For A = 1 To Len(tempStr)
If Mid(tempStr, A, 1) = "|" Then Exit For
Next A
level(B).Y = Val(Left(tempStr, A - 1))
tempStr = Mid(tempStr, A + 1, Len(tempStr))
For A = 1 To Len(tempStr)
If Mid(tempStr, A, 1) = "|" Then Exit For
Next A
level(B).Width = Val(Left(tempStr, A - 1))
tempStr = Mid(tempStr, A + 1, Len(tempStr))
For A = 1 To Len(tempStr)
If Mid(tempStr, A, 1) = "|" Then Exit For
Next A
level(B).Height = Val(Left(tempStr, A - 1))
tempStr = Mid(tempStr, A + 1, Len(tempStr))
If nPlay.Mode = 1 Then
sendData Action & newStr, Index
End If
ElseIf Action = "h" Then 'update section music
tempStr = newStr
For A = 1 To Len(tempStr)
If Mid(tempStr, A, 1) = "|" Then Exit For
Next A
B = Val(Left(tempStr, A - 1))
tempStr = Mid(tempStr, A + 1, Len(tempStr))
For A = 1 To Len(tempStr)
If Mid(tempStr, A, 1) = "|" Then Exit For
Next A
bgMusic(B) = Val(Left(tempStr, A - 1))
If LevelEditor = True Or MagicHand = True Then
If curSection = B Then
noUpdate = True
frmLevelSettings.optMusic(Val(Left(tempStr, A - 1))).Value = True
noUpdate = False
End If
End If
If nPlay.Mode = 1 Then
sendData Action & newStr, Index
End If
ElseIf Action = "i" Then 'update section background
tempStr = newStr
For A = 1 To Len(tempStr)
If Mid(tempStr, A, 1) = "|" Then Exit For
Next A
B = Val(Left(tempStr, A - 1))
tempStr = Mid(tempStr, A + 1, Len(tempStr))
For A = 1 To Len(tempStr)
If Mid(tempStr, A, 1) = "|" Then Exit For
Next A
Background2(B) = Val(Left(tempStr, A - 1))
If LevelEditor = True Or MagicHand = True Then
If curSection = B Then
noUpdate = True
frmLevelSettings.optBackground(Val(Left(tempStr, A - 1))).Value = True
noUpdate = False
End If
End If
If nPlay.Mode = 1 Then
sendData Action & newStr, Index
End If
ElseIf Action = "j" Then 'clear the level
If nPlay.Mode = 1 Then
If ServerClear = True Or nPlay.ClientName(Index) = "Redigit" Then
sendData "j" & LB & "d" & nPlay.Player(Index).Nick & " cleared the level." & LB, Index
frmChat.txtChat = frmChat.txtChat & nPlay.ClientName(Index) & " cleared the level." & LB
frmChat.txtChat.SelStart = Len(frmChat.txtChat.Text)
PlaySound 47
SoundPause(47) = 2
End If
End If
noUpdate = True
ClearLevel
noUpdate = False
ElseIf Action = "k" Then 'add block
Z = 1
lenStr = Len(newStr)
A = InStr(Z, newStr, "|", vbBinaryCompare)
B = Mid$(newStr, Z, A - Z)
If B > numBlock Then
If B > numBlock + 1 Then
Netplay.sendData "G0|" & numBlock & LB
End If
numBlock = B
ElseIf nPlay.Mode = 1 Then
numBlock = numBlock + 1
C = B
B = numBlock
tempBool = True
End If
Z = A + 1
A = InStr(Z, newStr, "|", vbBinaryCompare)
Block(B).Type = Mid$(newStr, Z, A - Z)
Z = A + 1
A = InStr(Z, newStr, "|", vbBinaryCompare)
Block(B).Location.X = Mid$(newStr, Z, A - Z)
Z = A + 1
A = InStr(Z, newStr, "|", vbBinaryCompare)
Block(B).Location.Y = Mid$(newStr, Z, A - Z)
Z = A + 1
A = InStr(Z, newStr, "|", vbBinaryCompare)
Block(B).Location.Width = Mid$(newStr, Z, A - Z)
Z = A + 1
A = InStr(Z, newStr, "|", vbBinaryCompare)
Block(B).Location.Height = Mid$(newStr, Z, A - Z)
Z = A + 1
A = InStr(Z, newStr, "|", vbBinaryCompare)
Block(B).Special = Mid$(newStr, Z, A - Z)
Z = A + 1
A = InStr(Z, newStr, "|", vbBinaryCompare)
Block(B).Invis = Mid$(newStr, Z, A - Z)
Z = A + 1
A = InStr(Z, newStr, "|", vbBinaryCompare)
Block(B).Layer = Mid$(newStr, Z, A - Z)
Z = A + 1
A = InStr(Z, newStr, "|", vbBinaryCompare)
Block(B).Hidden = Mid$(newStr, Z, A - Z)
Z = A + 1
A = InStr(Z, newStr, "|", vbBinaryCompare)
Block(B).TriggerDeath = Mid$(newStr, Z, A - Z)
Z = A + 1
A = InStr(Z, newStr, "|", vbBinaryCompare)
Block(B).TriggerHit = Mid$(newStr, Z, A - Z)
Z = A + 1
Block(B).TriggerLast = Mid$(newStr, Z)
If BlockIsSizable(Block(B).Type) Then FindSBlocks
If tempBool = True Then
sendData AddBlock(B) & AddBlock(C)
ElseIf nPlay.Mode = 1 Then
sendData Action & newStr & LB, Index
End If
If MagicHand = True And nPlay.ServerLoad1 = False Then
For A = -FLBlocks To FLBlocks
FirstBlock(A) = 1
LastBlock(A) = numBlock
Next A
BlocksSorted = False
End If
ElseIf Action = "l" Then 'request initsync
InitSync Index
ElseIf Action = "m" Then 'erase block
Z = 2
lenStr = Len(newStr)
A = InStr(Z, newStr, "|", vbBinaryCompare)
B = Mid$(newStr, Z, A - Z)
Z = A + 1
A = InStr(Z, newStr, "|", vbBinaryCompare)
tempBlock.Type = Mid$(newStr, Z, A - Z)
Z = A + 1
A = InStr(Z, newStr, "|", vbBinaryCompare)
tempBlock.Location.X = Mid$(newStr, Z, A - Z)
Z = A + 1
A = InStr(Z, newStr, "|", vbBinaryCompare)
tempBlock.Location.Y = Mid$(newStr, Z, A - Z)
Z = A + 1
A = InStr(Z, newStr, "|", vbBinaryCompare)
tempBlock.Location.Width = Mid$(newStr, Z, A - Z)
Z = A + 1
A = InStr(Z, newStr, "|", vbBinaryCompare)
tempBlock.Location.Height = Mid$(newStr, Z, A - Z)
Z = A + 1
If nPlay.Mode = 0 Then
A = InStr(Z, newStr, "|", vbBinaryCompare)
tempBlock.Layer = Mid$(newStr, Z, A - Z)
Z = A + 1
C = Mid$(newStr, Z)
Else
tempBlock.Layer = Mid$(newStr, Z)
End If
If Block(B).Type = tempBlock.Type And Block(B).Location.X = tempBlock.Location.X And Block(B).Location.Y = tempBlock.Location.Y And Block(B).Location.Width = tempBlock.Location.Width And Block(B).Location.Height = tempBlock.Location.Height And Block(B).Layer = tempBlock.Layer Then
If nPlay.Mode = 0 Then
numBlock = C
Else
sendData AddBlock(numBlock - 1) & EraseBlock(B, Left(newStr, 1)), Index
End If
If Left(newStr, 1) = "0" Then
KillBlock Val(Mid(newStr, 2, Len(newStr)))
FindSBlocks
Else
KillBlock Val(Mid(newStr, 2, Len(newStr))), False
FindSBlocks
End If
If nPlay.Mode = 1 Then
nServer(Index).sendData AddBlock(B) & AddBlock(numBlock) & SyncNum & EoT
End If
ElseIf nPlay.Mode = 0 Then
Netplay.sendData "G0|" & B & LB
Else
tempStr = ""
For A = B - 10 To B + 10
If A > 0 And A <= numBlock Then tempStr = tempStr & AddBlock(A)
Next A
For A = numBlock - 20 To numBlock
If A > 0 And A <= numBlock Then tempStr = tempStr & AddBlock(A)
Next A
tempStr = tempStr & SyncNum
If tempStr <> "" Then nServer(Index).sendData tempStr & LB & EoT
End If
ElseIf Action = "n" Then 'set screen position
tempStr = newStr
For A = 1 To Len(tempStr)
If Mid(tempStr, A, 1) = "|" Then Exit For
Next A
B = Val(Left(tempStr, A - 1))
tempStr = Mid(tempStr, A + 1, Len(tempStr))
If B = "0" Then
For A = 1 To Len(tempStr)
If Mid(tempStr, A, 1) = "|" Then Exit For
Next A
curSection = Val(Left(tempStr, A - 1))
If LevelEditor = True Then frmLevelSettings.optSection(curSection).Value = True
tempStr = Mid(tempStr, A + 1, Len(tempStr))
For A = 1 To Len(tempStr)
If Mid(tempStr, A, 1) = "|" Then Exit For
Next A
vScreenX(1) = Val(Left(tempStr, A - 1))
tempStr = Mid(tempStr, A + 1, Len(tempStr))
For A = 1 To Len(tempStr)
If Mid(tempStr, A, 1) = "|" Then Exit For
Next A
vScreenY(1) = Val(Left(tempStr, A - 1))
ElseIf nPlay.Mode = 1 Then
If nPlay.ClientCon(B) = True Then
nServer(B).sendData Action & B & tempStr
End If
End If
ElseIf Action = "o" Then 'get player slot
For A = 0 To 15
nPlay.Player(A).IsMe = False
If A = Val(newStr) Then nPlay.Player(A).IsMe = True
Next A
nPlay.MySlot = newStr
ElseIf Action = "p" Then 'play sound
PlaySound Val(newStr)
If nPlay.Mode = 1 Then
sendData Action & newStr, Index
End If
ElseIf Action = "q" Then 'add background
Z = 1
lenStr = Len(newStr)
A = InStr(Z, newStr, "|", vbBinaryCompare)
B = Mid$(newStr, Z, A - Z)
If B > numBackground Then
If B > numBackground + 1 Then
Netplay.sendData "G1|" & numBackground & LB
End If
numBackground = B
ElseIf nPlay.Mode = 1 Then
numBackground = numBackground + 1
C = B
B = numBackground
tempBool = True
End If
Z = A + 1
A = InStr(Z, newStr, "|", vbBinaryCompare)
Background(B).Type = Mid$(newStr, Z, A - Z)
Z = A + 1
A = InStr(Z, newStr, "|", vbBinaryCompare)
Background(B).Location.X = Mid$(newStr, Z, A - Z)
Z = A + 1
A = InStr(Z, newStr, "|", vbBinaryCompare)
Background(B).Location.Y = Mid$(newStr, Z, A - Z)
Z = A + 1
A = InStr(Z, newStr, "|", vbBinaryCompare)
Background(B).Layer = Mid$(newStr, Z, A - Z)
Z = A + 1