-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.bb
2178 lines (1919 loc) · 68.7 KB
/
server.bb
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
;---------------------------------------------------------;
;------------------- SERVER INITIALIZE -------------------
Const GAME_SOLO%=0
Const GAME_SERVER%=1
Const GAME_CLIENT%=2
Const PLAYER_CLASSD%=0
Const PLAYER_MENTAL%=1
Const PLAYER_REDMIST%=2
Const PLAYER_EYEKILLER%=3
Const RIGHTS_ADMIN%=0
Const RIGHTS_MONSTER%=1
Const RIGHTS_CLASSD%=2
Const RIGHTS_HOST%=3
Const SERVER_MESSAGE_DISCONNECT% = 100000
Const SERVER_MESSAGE_KICK% = 100001
Global AUTO_DISCONNECT_TIME = Int(GetINIInt("options.ini","multiplayer","autodisconnect time")) * 1000
Global SCARE_COOLDOWN = Int(GetINIInt("options.ini","multiplayer","scare cooldown")) * 60
Global MessageSendToServer$ = ""
Global flooramount = 210
Dim FloorActions(flooramount)
Dim FloorTimer(flooramount)
Global isFlying% = False
Global UpdateTimer = 0
;Global ChatLogFile
Dim HorrorSFX(9)
Global ID = 0
Const UDP_FREQUENCY = 20
Global name$ = GetINIString("options.ini","multiplayer","name")
Global Client_HighPacketLose = False
Global Server%,Stream%,PlayState%,IncomingStream%,PlayerCount%,PlayerID%,UDPSend%,LastMsgID%,SentMsgID%
Global PlayerName$,ServerAddress$
ServerAddress$ = GetINIString("options.ini","multiplayer","ip")
Global SentChatMsg$,SentChatMsgID%
Global TypedChatMsg$,ChatOpen%
Global AdminSpyChat% = 0
Global RecvChatID%
Global MsgCount = 0
Global PlayingAs%
Global SpookTimer%,SpookCooldown%,SpookCount%,VisibilityTimer%,LastRecvSpook%,LastSentSpook%
Global AnimStandTime = 301
LastMsgID = 0
Global MoveForw%,MoveBack%,MoveLeft%,MoveRight%,MoveShift%
Global DirListShift%
Global DirList%[60]
Global DirListAngle#[60]
Global MemX#[60]
Global MemY#[60]
Global MemZ#[60]
Type ChatMessage
Field Txt$
Field R%,G%,B%
Field ID%
Field Timer%
Field SendTo%[32]
Field Sender%
End Type
PlayerCount = 0
PlayerID = 0
PlayState = GAME_SOLO
UDPSend = 0
PlayerName$ = GetINIString("options.ini","multiplayer","name")
Global Rights% = RIGHTS_CLASSD
Global Act% = 0
Type Player
Field IP%,Port%,Pivot%
Field FallSpeed#
Field MLeft%,MRight%,MForw%,MBack%,MClick1%,MClick2%,MShift%
Field Name$
Field DirList%[60]
Field DirListAngle#[60]
Field DirsToRead%
Field LastMsgTime%,LastClientMsg%
Field TexturePath$
Field LoadedTexture%
Field LastChatMsgID%
Field LastRecvChatMsg%
Field Connected%
Field PlayingAs%
Field SpookCount%
Field SpookCooldown%
Field VisibilityTimer%
Field VisibleTimer%
Field LastSpookSent%
Field IsVisible%
Field KillTimer%
Field Stamina#
Field Rights%
Field Act%
Field InView%
Field IsFlying%
Field Red%
Field Green%
Field Blue%
End Type
Dim Players.Player(60)
Dim FloorEntities%(1)
Global PlayerMesh = LoadAnimMesh("GFX\npc\mental.b3d")
Global PlayerTex = LoadTexture("GFX\npc\player.jpg")
; --------------------- SERVER INITIALIZE END ---------------------
Function ConnectToServer%(Addr$="")
Server% = CreateUDPStream() ;create a UDP stream with any free port
Local waitForCo% = MilliSecs()+10000
TempStr$ = ""
xcenter = GraphicsWidth()/2
ycenter = GraphicsHeight()/2
ticks = 0
If (Not Server) Then
PlayState = GAME_SOLO
Else
WriteLine Server,"connected" +GAME_VERSION
WriteByte Server,0
WriteLine Server,PlayerName
CountHostIPs(Addr) ;get host ips from server
SendUDPMsg(Server,HostIP(1),8730)
Stream = RecvUDPMsg(Server)
Local prevSendTime% = MilliSecs()
While Not Stream
SetBuffer BackBuffer()
Stream = RecvUDPMsg(Server)
Cls
Color 255,255,255
Text xcenter,ycenter,"Trying to connect to the server...",True
Color 30,30,30
If(Button(xcenter-30,ycenter+40,60,25,"Cancel",False)) Then Return
Flip
Delay 100
ticks = ticks + 1
If MilliSecs()>prevSendTime+3000 Then
WriteLine Server,"connected" +GAME_VERSION
WriteByte Server,0
WriteLine Server,PlayerName
SendUDPMsg(Server,HostIP(1),8730)
prevSendTime% = MilliSecs()
EndIf
Wend
Color 255,255,255
Cls
Text xcenter,ycenter,"Joining...",True
Color 30,30,30
If(Button(xcenter-30,ycenter+40,60,25,"Cancel",False)) Then Return
Flip
PlayState=GAME_CLIENT ;let the game know you're a client
Players(0)=New Player
Players(0)\IP = UDPMsgIP(Server)
Players(0)\Port = UDPMsgPort(Server) ;save the server's information
Players(0)\LastMsgTime = MilliSecs()
MapString = ReadLine(Server)
ID = ReadByte(Server)
If MapString = "KICK" Or Mid(MapString,1,7) = "version" Then
PlayState = GAME_SOLO
CloseUDPStream(Server)
Delete Players(0)
Cls
While Not Button(xcenter-30,ycenter+40,60,25,"Back",False)
Color 255,255,255
If Mid(MapString,1,7) = "version" Then
Text xcenter,ycenter,"The server runs on version " + Mid(MapString,8,Len(MapString)-7)+ "."
ElseIf MapString = "KICK" Then
Text xcenter,ycenter,"You have been kicked from the server."
EndIf
Color 30,30,30
Flip
Delay 100
Wend
Return
EndIf
SCARE_COOLDOWN = ReadInt(Server)
ticks = 0
Local map$ = "0"
While map <> "1"
WriteLine Server,"map" +MapString
WriteByte Server,0
WriteLine Server,PlayerName
SendUDPMsg(Server,Players(0)\IP,Players(0)\Port)
Color 255,255,255
Text xcenter,ycenter,"Joining...",True
Color 30,30,30
If(Button(xcenter-30,ycenter+40,60,25,"Cancel",False)) Then Return
Flip
Delay 200
ticks = ticks + 1
getconn = RecvUDPMsg(Server)
map$ = ReadLine(Server)
DebugLog map$
If map <> "1" Then MapString = map
If ticks > 10 And map = "0" Then
CloseUDPStream(Server)
Cls
Color 30,30,30
While Not Button(xcenter-30,ycenter+40,60,25,"Back",False)
Color 255,255,255
Text xcenter,ycenter,"Connection lost.",True
Color 30,30,30
Flip
Delay 100
Wend
Return
EndIf
If ticks > 50 Then
CloseUDPStream(Server)
Cls
Color 30,30,30
While Not Button(xcenter-30,ycenter+40,60,25,"Back",False)
Color 255,255,255
Text xcenter,ycenter,"Could not join due to high packet lose.",True
Color 30,30,30
Flip
Delay 100
Wend
Return
EndIf
Wend
EndIf
End Function
Function LoadMap()
;The First Area rooms
map0 = LoadMesh("GFX\map0.x") ; First room. The player must proceed to the 6xt floor to begin
;GetMentalRoomMesh(map0)
map = LoadMesh("GFX\map.x") ; Default staircase hallway. You will cross through many of these; 087-B-1 may appear at those
map1 = LoadMesh("GFX\map1.x") ; Room with an window where 087-B-2 may appear
map2 = LoadMesh("GFX\map2.x") ; Room where 087-B-2 may appear
map3 = LoadMesh("GFX\map3.x") ; Big room with an stair leading to the lower floor
map4 = LoadMesh("GFX\map4.x")
map5 = LoadMesh("GFX\map5.x")
map6 = LoadMesh("GFX\map6.x") ; Room with 3 hallways leading to the same place
map7 = LoadMesh("GFX\map7.x") ; Small room with column
map8 = LoadMesh("GFX\map8.x") ; Big room with pit in center
map9 = LoadMesh("GFX\map9.x") ; Hallway with many turns
map10 = LoadMesh("GFX\map10.x") ; Hallway with many turns
map11 = LoadMesh("GFX\map11.x") ; ACT_WAIT
map12 = LoadMesh("GFX\map12.x") ; Big room with many pits
map13 = LoadMesh("GFX\map13.x") ; Long hallway, also ACT_BEHIND
map14 = LoadMesh("GFX\map14.x") ; Hallway with window
map15 = LoadMesh("GFX\map15.x") ; Hallway with upstairs and downstairs
map16 = LoadMesh("GFX\map16.x") ; ACT_BIGSTAIRSROOM
map17 = LoadMesh("GFX\map17.x") ; ACT_BLUR
map18 = LoadMesh("GFX\map18.x") ; Maze
map19 = LoadMesh("GFX\map19.x") ; Room with window
map20 = LoadMesh("GFX\map20.x") ; Room with broken wall
map21 = LoadMesh("GFX\map21.x") ; Room with broken wall 2
map22 = LoadMesh("GFX\map22.x") ; ACT_173_2
map23 = LoadMesh("GFX\map23.x") ; Unknown Event
map24 = LoadMesh("GFX\ending.x")
map26 = LoadMesh("GFX\map26.x") ; ACT_RUN_2, ACT_RUN_3
map27 = LoadMesh("GFX\map27.x") ; Hallway with window
map28 = LoadMesh("GFX\map28.x") ; Cross
map_maze = LoadMesh("GFX\act_maze.x") ; ACT_MAZE
elevator = LoadMesh("GFX\elevator.x") ; ACT_WAIT
mapending = LoadMesh("GFX\mapending.x")
mapnothing = LoadMesh("GFX\mapnothing.x")
map_transition = LoadMesh("GFX\map_a1_transition.x")
map_elevator = LoadMesh("GFX\map_elevator.x")
map_elevator_end = LoadMesh("GFX\map_elevator_end.x")
;Create door
door = CreateCube()
ScaleEntity(door, 0.5,1,0.5)
EntityType door, hit_map
PositionEntity(door, -3.5, -1, -0.5)
doortexture = LoadTexture("GFX\map\door.jpg")
EntityTexture(door, doortexture)
label = CreateCube()
ScaleEntity(label, 0.35,0.35,0.35)
EntityType label, hit_map
PositionEntity(label, 0.34, -0.7, -1.49)
labeltexture = LoadTexture("GFX\map\label.jpg")
EntityTexture(label, labeltexture)
SetFont signfont
Firstfloor = 0
For i = Firstfloor To Len(MapString)/2
Select Mid(MapString,i*2+1, 2)
Case "00":
CreateFloor(map0,i)
Case "99":
CreateFloor(map,i)
Case "01":
CreateFloor(map1,i)
Case "02":
CreateFloor(map2,i)
Case "03":
CreateFloor(map3,i)
Case "04":
CreateFloor(map4,i)
Case "05":
CreateFloor(map5,i)
Case "06":
CreateFloor(map6,i)
Case "07":
CreateFloor(map7,i)
Case "08":
CreateFloor(map8,i)
Case "09":
CreateFloor(map9,i)
Case "10":
CreateFloor(map10,i)
Case "11":
CreateFloor(map11,i)
Case "12":
CreateFloor(map12,i)
Case "13":
CreateFloor(map13,i)
Case "14":
CreateFloor(map14,i)
Case "15":
CreateFloor(map15,i)
Case "16":
CreateFloor(map16,i)
Case "17":
CreateFloor(map17,i)
Case "18":
CreateFloor(map18,i)
Case "19":
CreateFloor(map19,i)
Case "20":
CreateFloor(map20,i)
Case "21":
CreateFloor(map21,i)
Case "23"
CreateFloor(map23,i)
Case "26":
CreateFloor(map26,i)
Case "27":
CreateFloor(map27,i)
Case "28":
CreateFloor(map28,i)
Case "22":
CreateFloor(map22,i)
Case "85":
CreateFloor(map_elevator_end,i)
Case "84":
CreateFloor(map_transition,i)
Case "83":
CreateFloor(mapnothing,i)
Case "82":
CreateFloor(mapending,i)
Case "81":
CreateFloor(map_maze,i)
Case "80":
CreateFloor(elevator,i)
Default:
CreateFloor(map,i)
End Select
Next
For i = 0 To flooramount-1
flooractions(i) = 0
floortimer(i) = 0
Next
SetFont signfont
SetBuffer BackBuffer()
FreeEntity map0
FreeEntity map
FreeEntity map1
FreeEntity map2
FreeEntity map3
FreeEntity map4
FreeEntity map5
FreeEntity map6
FreeEntity map7
FreeEntity map8
FreeEntity map9
FreeEntity map10
FreeEntity map11
FreeEntity map12
FreeEntity map13
FreeEntity map14
FreeEntity map15
FreeEntity map16
FreeEntity map17
FreeEntity map18
FreeEntity map19
FreeEntity map20
FreeEntity map21
FreeEntity map22
FreeEntity map23
FreeEntity map24
FreeEntity map26
FreeEntity map27
FreeEntity map28
FreeEntity map_maze
FreeEntity mapending
FreeEntity elevator
FreeEntity mapnothing
FreeEntity map_transition
FreeEntity map_elevator
FreeEntity map_elevator_end
End Function
Function JoinServer%(Addr$="")
LoadMap()
Local waitForCo% = MilliSecs()+10000
TempStr$ = ""
ticks = 0
If (Not Server) Then
PlayState = GAME_SOLO
Else
PlayState=GAME_CLIENT ;let the game know you're a client
Rights = RIGHTS_CLASSD
CurrEnemy = Null
;collider = CreatePivot() ;reset erased objects
PlayerTex = LoadTexture("GFX\npc\player.jpg")
For j=0 To 31
If Players(j)=Null Then Players(j)=New Player : Players(j)\Connected = False
Local TmpMesh = LoadAnimMesh("GFX\npc\mental.b3d")
EntityTexture TmpMesh,PlayerTex
Players(j)\Pivot = CreatePivot()
PositionEntity Players(j)\Pivot,-200.5,ColliderDefaultY#,-0.5
EntityRadius Players(j)\Pivot, ColliderXRadius#,ColliderYRadius#
EntityParent TmpMesh,Players(j)\Pivot
ScaleEntity TmpMesh, 0.15,0.15,0.15
PositionEntity TmpMesh,-200.5,-0.5,True
EntityAlpha GetChild(Players(j)\Pivot,1),0.0
EntityType Players(j)\Pivot,hit_friendly
Next
PositionEntity collider,-2.5, ColliderDefaultY#, -0.5
EntityType collider, hit_friendly
EndIf
UpdateLights()
End Function
Function SendToServer(tempstr$="")
If PlayState <> GAME_SERVER Then
WriteLine Server,tempstr
WriteByte(Server,ID)
SendUDPMsg(Server,Players(0)\IP,Players(0)\Port)
EndIf
End Function
Function SendToPlayers(tempid)
;WriteInt(Server,tempid)
For i = 1 To 31
If Players(i) <> Null Then
WriteInt(Server,tempid)
SendUDPMsg(Server,Players(i)\IP,Players(i)\Port)
EndIf
Next
End Function
Function Button%(x,y,width,height,txt$, disabled%=False)
Local Pushed = False
Local ClrR = ColorRed()
Local ClrG = ColorGreen()
Local ClrB = ColorBlue()
If Not disabled Then
If MouseX() > x And MouseX() < x+width Then
If MouseY() > y And MouseY() < y+height Then
If MouseDown(1) Then
Pushed = True
Color ClrR*0.6, ClrG*0.6, ClrB*0.6
Else
Color min(ClrR*1.4,255),min(ClrG*1.4,255),min(ClrB*1.4,255)
EndIf
EndIf
EndIf
EndIf
If Pushed Then
Rect x,y,width,height
Color 133,130,125
Rect x+1,y+1,width-1,height-1,False
Color 10,10,10
Rect x,y,width,height,False
Color 250,250,250
Line x,y+height-1,x+width-1,y+height-1
Line x+width-1,y,x+width-1,y+height-1
Else
Rect x,y,width,height
Color 133,130,125
Rect x,y,width-1,height-1,False
Color 250,250,250
Rect x,y,width,height,False
Color 10,10,10
Line x,y+height-1,x+width-1,y+height-1
Line x+width-1,y,x+width-1,y+height-1
EndIf
Color 255,255,255
If disabled Then Color 70,70,70
Text x+width/2, y+height/2-1, txt, True, True
Color 0,0,0
If Pushed And MouseHit1 Then
PlaySound ButtonSFX
Return True
EndIf
End Function
Function RectBox(x,y,width,height)
Local ClrR = ColorRed()
Local ClrG = ColorGreen()
Local ClrB = ColorBlue()
Rect x,y,width,height
Color 133,130,125
Rect x,y,width-1,height-1,False
Color 250,250,250
Rect x,y,width,height,False
Color 10,10,10
Line x,y+height-1,x+width-1,y+height-1
Line x+width-1,y,x+width-1,y+height-1
Color 0,0,0
End Function
Function UpdateServer()
If Players(0)\IP = 1 Then
PlayState=GAME_SERVER ;let the game know you're a server
Server% = CreateUDPStream(8730) ;create a UDP stream with a specific port
Players(0)=New Player
Players(0)\IP=0 ;there is no IP for this "client"
Players(0)\Port=0 ;there is no port for this "client"
Players(0)\Pivot=collider ;player 1 is yourself
Players(0)\Name = PlayerName ;this is the host's name
Players(0)\LastMsgTime = MilliSecs() ;this sets a timer to detect if the connection with the server is still established
Players(0)\Connected = True
Players(0)\Rights = RIGHTS_HOST
Players(0)\Act = ACT_FLASH
Players(0)\VisibilityTimer = 0
Players(0)\SpookCount = 3
Players(0)\Red = 255
Players(0)\Green = 255
Players(0)\Blue = 255
EntityType collider, hit_friendly
PlayerCount=PlayerCount+1
PlayingAs = PLAYER_CLASSD
Rights = RIGHTS_HOST
SpookCount = 3
VisibilityTimer = 0
SpookCooldown = 90
SpookTimer = 0
UpdateLights()
EndIf
Local getconn%
MouseHit1 = MouseHit(1)
MouseHit2 = MouseHit(2)
If KeyHit(57) And PlayingAs <> PLAYER_CLASSD Then
isFlying = Not isFlying
SendToServer("fly")
If isFlying Then
EntityType collider,hit_map
Else
EntityType collider,hit_invisible
EndIf
EndIf
Local isForw%,posx#,posy#,posz#,pyaw#,isFloor% ;isBack%,isLeft%,isRight%,
If PlayState<>GAME_SOLO Then
If (MilliSecs()>=UDPSend) Then
UDPSend=MilliSecs()+UDP_FREQUENCY
EndIf
EndIf
;Scare
If MouseHit2 And SpookCount > 0 And VisibilityTimer < 0 And PlayingAs <> PLAYER_CLASSD Then
AddChatMsg("You will be able to scare in " + ((SCARE_COOLDOWN+VisibilityTimer)/60)+ " seconds.",150,50,50,ID,False)
MouseHit2 = False
EndIf
If MouseHit2 And SpookCount <= 0 And VisibilityTimer < 0 And PlayingAs <> PLAYER_CLASSD Then
For i=0 To 31
If Players(i)<>Null And i<>ID Then
If Players(i)\KillTimer<=0 And Players(i)\PlayingAs = PLAYER_CLASSD Then
Local dist# = Distance2(EntityX(Players(i)\Pivot), EntityY(Players(i)\Pivot), EntityZ(Players(i)\Pivot))
If (Act = ACT_RUN And dist < 3.0) Or (Act = ACT_WALK And dist < 2.0) Or (Act = ACT_173 And dist < 4.0) Or (Act = ACT_BEHIND And dist < 2.0) Or (Act = ACT_DARKNESS And dist < 3.0) Then
AddChatMsg("You are too close to a Class D.",150,50,50,ID,False)
MouseHit2 = False
i = 32
EndIf
If (Act = ACT_BEHIND And dist > 2.0) Then
For j=(PlayState=GAME_SERVER) To 31
If Players(j)<>Null And j <> ID Then
If Players(j)\PlayingAs=PLAYER_CLASSD And Players(j)\Connected Then
vXa# = EntityX(collider)-EntityX(Players(j)\Pivot)
vZa# = EntityZ(collider)-EntityZ(Players(j)\Pivot)
vLena# = Sqr((vXa*vXa)+(vZa*vZa))
vYawa# = VectorYaw(vXa/vLena,0.0,vZa/vLena)-EntityYaw(Players(j)\Pivot)
While vYawa<-180.0
vYawa=vYawa+360.0
Wend
While vYawa>=180.0
vYawa=vYawa-360.0
Wend
currfloor = (-EntityY(Players(j)\Pivot)-0.3)/2+0.1
If Abs(PlayerFloor-currfloor) <= 1 And Abs(vYawa)<45 And EntityVisible(collider,Players(j)\Pivot) Then
AddChatMsg("You can't appear when someone is looking at you.",150,50,50,ID,False)
j = 32
i = 32
MouseHit2 = False
EndIf
EndIf
EndIf
Next
EndIf
EndIf
EndIf
Next
EndIf
; _______
If PlayingAs <> PLAYER_CLASSD Then
Stamina = STAMINA_MAX
EndIf
If Act = ACT_FLASH And VisibilityTimer > 0 Then
CanMove = False
EndIf
If PlayState=GAME_SERVER Then
Players(0)\PlayingAs = PlayingAs
Select Players(0)\PlayingAs
Case PLAYER_CLASSD
Players(0)\Red = 255
Players(0)\Green = 255
Players(0)\Blue = 0
Case PLAYER_MENTAL
Players(0)\Red = 255
Players(0)\Green = 100
Players(0)\Blue = 100
Case PLAYER_REDMIST
Players(0)\Red = 255
Players(0)\Green = 100
Players(0)\Blue = 100
Case PLAYER_EYEKILLER
Players(0)\Red = 255
Players(0)\Green = 100
Players(0)\Blue = 100
End Select
Local messagesToSend%
getconn = RecvUDPMsg(Server) ;AcceptTCPStream(Server)
While getconn ;The server has received a message from a client
messagesToSend = 0
TempRead$ = ReadLine(Server)
PlayerID% = ReadByte(Server)
TempID%=Int(TempRead)
;Receive act change by a monster
If Mid(TempRead,1,3)="act" Then
temp = Mid(TempRead,4,2)
Players(PlayerID)\Act = temp
If temp = 0 Then
Players(PlayerID)\PlayingAs = PLAYER_CLASSD
EntityTexture GetChild(Players(PlayerID)\Pivot,1),LoadTexture("GFX\npc\player.jpg")
EntityType Players(PlayerID)\Pivot,hit_friendly
ElseIf temp = ACT_FLASH Or temp = ACT_WALK Or temp = ACT_RUN Or temp = ACT_DARKNESS Then
Players(PlayerID)\PlayingAs = PLAYER_MENTAL
EntityTexture GetChild(Players(PlayerID)\Pivot,1),mental3
EntityType Players(PlayerID)\Pivot,hit_invisible
ElseIf temp = ACT_173 Or temp = ACT_FLASH_2 Or temp = ACT_BEHIND
EntityTexture GetChild(Players(PlayerID)\Pivot,1),tex1732
EntityType Players(PlayerID)\Pivot,hit_invisible
Players(PlayerID)\PlayingAs = PLAYER_REDMIST
ElseIf temp = ACT_BLUR Then
EntityTexture GetChild(Players(PlayerID)\Pivot,1),eyekiller
EntityType Players(PlayerID)\Pivot,hit_invisible
Players(PlayerID)\PlayingAs = PLAYER_EYEKILLER
EndIf
EndIf
;Receive rights change by an admin
If Mid(TempRead,1,12)="rights_admin" Then
temp = Mid(TempRead,13,2)
Players(temp)\Rights = RIGHTS_ADMIN
EndIf
If Mid(TempRead,1,14)="rights_monster" Then
temp = Mid(TempRead,15,2)
Players(temp)\Rights = RIGHTS_MONSTER
EndIf
If Mid(TempRead,1,13)="rights_classd" Then
temp = Mid(TempRead,14,2)
Players(temp)\Rights = RIGHTS_CLASSD
Players(temp)\PlayingAs = PLAYER_CLASSD
EntityTexture GetChild(Players(PlayerID)\Pivot,1),LoadTexture("GFX\npc\player.jpg")
EntityType Players(PlayerID)\Pivot,hit_friendly
EndIf
If Mid(TempRead,1,4)="kick" Then
temp = Mid(TempRead,5,2)
WriteInt Server,SERVER_MESSAGE_KICK ;kick the player
SendUDPMsg Server,Players(temp)\IP,Players(temp)\Port ;tell the client to disconnect
FreeEntity GetChild(Players(temp)\Pivot,1)
FreeEntity Players(temp)\Pivot
PlayerCount=PlayerCount-1
AddChatMsg(Players(temp)\Name+ " has been kicked by " + Players(PlayerID)\Name+ ".",255,0,0,PlayerID,True)
Players(temp)=Null
Delete Players(temp)
EndIf
If Mid(TempRead,1,8)="teleport" Then
temp = Mid(Tempread,9,2)
PositionEntity(Players(PlayerID)\Pivot, EntityX(Players(temp)\Pivot),EntityY(Players(temp)\Pivot),EntityZ(Players(temp)\Pivot))
ResetEntity Players(PlayerID)\Pivot
EndIf
If Mid(TempRead,1,4)="chat" Then
AddChatMsg(Players(PlayerID)\Name + ": " + Mid(tempread, 5, Len(tempread)-4),Players(PlayerID)\Red,Players(PlayerID)\Green,Players(PlayerID)\Blue,PlayerID,True)
EndIf
If TempRead = "fly" Then
Players(PlayerID)\IsFlying = Not Players(PlayerID)\IsFlying
EndIf
If Mid(TempRead,1,3) = "map" Then
If Mid(TempRead,4,Len(TempRead)-3) = MapString Then
WriteLine(Server, "1")
Else
WriteLine(Server, MapString)
EndIf
SendUDPMsg Server,getconn,UDPMsgPort(Server)
EndIf
If TempRead=("connected" + GAME_VERSION) Then ;the player connected and started generating the map
For giveID=1 To 32
If Players(giveID)<>Null Then
If (Players(giveID)\IP = getconn) And (Players(giveID)\Port = UDPMsgPort(Server)) Then
If Players(giveID)\Connected Then giveID = -1
Exit
EndIf
EndIf
Next
If giveID>-1 Then
For giveID=1 To 32
If giveID >=32 Then giveID = -1 : Exit
If (Players(giveID)=Null) Then Exit
Next
EndIf
If Players(giveID)=Null Then
Local PlayerTex = LoadTexture("GFX\npc\player.jpg")
Players(giveID)=New Player
Players(giveID)\IP=getconn
Players(giveID)\Port=UDPMsgPort(Server)
Players(giveID)\Pivot=CreatePivot()
Players(giveID)\Stamina=STAMINA_MAX
Players(giveID)\Rights=RIGHTS_CLASSD
Players(giveID)\Act = ACT_FLASH
Players(giveID)\VisibilityTimer=0
Players(giveID)\SpookCount = 3
Players(giveID)\isFlying = False
Players(giveID)\Red = 255
Players(giveID)\Green = 255
Players(giveID)\Blue = 0
Local tempMesh = LoadAnimMesh("GFX\npc\mental.b3d")
ScaleEntity tempMesh, 0.15,0.15,0.15
PositionEntity tempMesh,0.0,ColliderDefaultY#,0.0,True
EntityParent tempMesh,Players(giveID)\Pivot
EntityTexture tempMesh,PlayerTex
PositionEntity Players(giveID)\Pivot,-2.5, ColliderDefaultY#, -0.5,True
EntityRadius Players(giveID)\Pivot, ColliderXRadius#,ColliderYRadius#
EntityType Players(giveID)\Pivot,hit_friendly
Players(giveID)\PlayingAs = PLAYER_CLASSD
Select Players(giveID)\PlayingAs
Case PLAYER_CLASSD
EntityTexture GetChild(Players(giveID)\Pivot,1),PlayerTex
EntityType Players(giveID)\Pivot, hit_friendly
Case PLAYER_MENTAL
EntityTexture GetChild(Players(giveID)\Pivot,1),mental
EntityType Players(giveID)\Pivot, hit_invisible;monster
Case PLAYER_REDMIST
EntityTexture GetChild(Players(giveID)\Pivot,1),tex173
EntityType Players(giveID)\Pivot, hit_invisible;monster
Case PLAYER_EYEKILLER
EntityTexture GetChild(Players(giveID)\Pivot,1),eyekiller
EntityType Players(giveID)\Pivot, hit_invisible;monster
End Select
Players(giveID)\LastMsgTime=MilliSecs()
Players(giveID)\Name = ReadLine(Server)
WriteLine(Server,MapString) ;give the player the server's map arrangement
WriteByte(Server,giveID) ;give the player their ID
WriteInt(Server, SCARE_COOLDOWN)
SendUDPMsg Server,getconn,UDPMsgPort(Server) ;give the message to the player
PlayerCount=PlayerCount+1
Else ;server is full
WriteLine Server,"KICK" ;kick the player
SendUDPMsg Server,getconn,UDPMsgPort(Server) ;tell the client to disconnect
EndIf
ElseIf Mid(TempRead,1,9)="connected" Then ;client has got another version of the game
WriteLine(Server,"version" +GAME_VERSION)
WriteByte(Server,giveID)
SendUDPMsg(Server,getconn,UDPMsgPort(Server))
Else If TempRead="disconnect" Then ;player has "cleanly" disconnected
TempID%=PlayerID
If Players(TempID)<>Null Then ;this player exists: remove it
If Players(TempID)\IP = getconn And Players(TempID)\Port = UDPMsgPort(Server) Then
FreeEntity GetChild(Players(TempID)\Pivot,1)
FreeEntity Players(TempID)\Pivot
PlayerCount=PlayerCount-1
AddChatMsg(Players(TempID)\Name+ " has disconnected.",255,255,0,TempID,True)
Players(TempID)=Null
Delete Players(TempID)
EndIf
EndIf
Else
If Players(TempID)<>Null Then ;player exists
If Players(TempID)\IP = getconn Then
If Players(TempID)\Connected = False Then
AddChatMsg(Players(TempID)\Name+ " has joined the server.",255,255,0,TempID,True)
EndIf
Players(TempID)\Connected = True
Local newMsg%=ReadInt(Server)
If Players(TempID)\LastClientMsg<newMsg Then
Players(TempID)\LastMsgTime=MilliSecs()
For j%=0 To 59
Players(TempID)\DirList[j] = ReadByte(Server)
Players(TempID)\DirListAngle[j] = ReadFloat(Server)
Next
Players(TempID)\DirsToRead=max(Players(TempID)\DirsToRead+(newMsg-Players(TempID)\LastClientMsg),0)
;pyaw# = ReadFloat(Server)
;RotateEntity Players(TempID)\Pivot,0.0,pyaw,0.0,True
Players(TempID)\LastClientMsg=newMsg
Local chatID% = ReadInt(Server)
Local chatMsg$ = ReadLine(Server)
If chatID>Players(TempID)\LastChatMsgID Then
Players(TempID)\LastChatMsgID = chatID
If Len(chatMsg)>0 Then
If Players(TempID)\PlayingAs=PLAYER_CLASSD Then
AddChatMsg(Players(TempID)\Name+ ": " +chatMsg,50,70,255,TempID,False)
Else
AddChatMsg(Players(TempID)\Name+ ": " +chatMsg,150,0,0,TempID,True)
EndIf
EndIf
EndIf
Players(TempID)\LastRecvChatMsg = ReadInt(Server)
EndIf
EndIf
EndIf
EndIf
getconn = RecvUDPMsg(Server)
Wend
SpookCooldown=max(SpookCooldown-1,0)
VisibilityTimer=max(VisibilityTimer-1,-10000)
For i=1 To 31
isFloor=False
If (Players(i)<>Null) Then
If Players(i)\Connected Then
Select Players(i)\PlayingAs
Case PLAYER_CLASSD
Players(i)\Red = 255
Players(i)\Green = 255
Players(i)\Blue = 0
Case PLAYER_MENTAL
Players(i)\Red = 255
Players(i)\Green = 100
Players(i)\Blue = 100
Case PLAYER_REDMIST
Players(i)\Red = 255
Players(i)\Green = 100
Players(i)\Blue = 100
Case PLAYER_EYEKILLER
Players(i)\Red = 255
Players(i)\Green = 100
Players(i)\Blue = 100
End Select
WriteInt(Server,SentMsgID)
For j=0 To 31
If (Players(j)<>Null) Then
WriteByte(Server,j+1)
WriteInt(Server,Players(j)\LastClientMsg)
If Players(j)\Pivot<>collider Then
WriteByte(Server,(Players(j)\MForw)+(Players(j)\MBack*2)+(Players(j)\MLeft*4)+(Players(j)\MRight*8)+(Players(j)\MShift*16))
WriteByte(Server,Players(j)\PlayingAs)
WriteByte(Server,Players(j)\Rights)
WriteByte(Server,(Players(j)\KillTimer)>0)
WriteInt(Server,Players(j)\VisibilityTimer)
WriteInt(Server,Players(j)\SpookCount)
WriteByte(Server,Players(j)\Act)
WriteLine(Server,Players(j)\Name)
WriteLine(Server,Players(j)\IsFlying)
WriteFloat(Server,EntityX(Players(j)\Pivot,True))
WriteFloat(Server,EntityY(Players(j)\Pivot,True))
WriteFloat(Server,EntityZ(Players(j)\Pivot,True))
WriteFloat(Server,EntityYaw(Players(j)\Pivot,True))
Else
WriteByte(Server,MoveForw+(MoveBack*2)+(MoveLeft*4)+(MoveRight*8)+(MoveShift*16))
WriteByte(Server,PlayingAs)
WriteByte(Server,Rights)
WriteByte(Server,KillTimer>0)
WriteInt(Server,VisibilityTimer)
WriteInt(Server,SpookCount)
WriteByte(Server,Act)
WriteLine(Server,PlayerName)
WriteLine(Server,IsFlying)
WriteFloat(Server,EntityX(collider,True))
WriteFloat(Server,EntityY(collider,True))
WriteFloat(Server,EntityZ(collider,True))
WriteFloat(Server,EntityYaw(collider,True))
EndIf
;WriteLine(Server,Players(j)\TexturePath)
Else
WriteByte(Server,0)
EndIf
Next
WriteInt(Server,Players(i)\LastSpookSent)
Local cm.ChatMessage
For cm = Each ChatMessage
If cm\ID>Players(i)\LastRecvChatMsg And cm\SendTo[i] Then messagesToSend=messagesToSend+1
Next
WriteByte(Server,messagesToSend)
For cm = Each ChatMessage
If cm\ID>Players(i)\LastRecvChatMsg And cm\SendTo[i] Then
WriteInt(Server,cm\ID)
WriteLine(Server,cm\Txt)
WriteByte(Server,cm\R)
WriteByte(Server,cm\G)
WriteByte(Server,cm\B)
EndIf
Next
SendUDPMsg Server,Players(i)\IP,Players(i)\Port
EndIf
pyaw = EntityYaw(Players(i)\Pivot,True)
If Players(i)\KillTimer<=0 Then
Local animmed% = Players(i)\DirList[0]<>0
Players(i)\DirsToRead = min(59,Players(i)\DirsToRead)
While Players(i)\DirsToRead>0
isForw = Players(i)\DirList[Players(i)\DirsToRead]
Players(i)\DirsToRead=Players(i)\DirsToRead-1