-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.h
1252 lines (1068 loc) · 43 KB
/
player.h
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
struct tRotation {
u_long X;
u_long Y;
u_long Z;
};
struct tPosition {
u_long X;
u_long Y;
u_long Z;
};
struct tPlayer {
u_long ID; // het nummer verkregen tijdens joinen
u_long TimeID; // de ID in CMR04_Times
u_long MemberID; // de ID in CMR04_Members
u_char isBOT; // 0=human, 1=bot //not used
u_long IP; // IP nummer als een long
struct in_addr AddrIn; // adres als struct addr_in
u_int PortNr;
u_char Nick[16]; // 15 chars + trailing x00
u_char Country;
u_char Car;
u_char CarType;
u_char Gearbox;
u_char Damage;
u_char ConnectionSpeed;
u_long Ping;
u_long Ready; // 0=not ready yet, 1=ready
u_short ChatLine;
u_short LastCMD; // het laatst ontvangen commando
short PacketLen; // lengte van pakketje in Packet.
int State; // de vooruitgang in het spel
// ring-buffer / roterende buffer
short PtrBufferRead;// index in de array Packet[PtrBufferRead][BUFFSZ]
short PtrBufferWrite; // index in de array Packet[PtrBufferWrite][BUFFSZ]
//
short BufferedPackets; // het aantal buffer dat momenteel een packet bevat.
short BufferLen[MAXBUFF]; // het aantal bytes in elke buffer (in gebruik)
u_short BufferCMD[MAXBUFF]; // het commando dat hoort bij het packet in de buffer
int BufferCountdown[MAXBUFF];// aftellen hoeveel keer nog opnieuw te verzenden
u_char Packet[MAXBUFF][BUFFSZ];// het(/de) opnieuw te versturen pakketje(s).
struct tRotation Rotation; //obsolete??!!
struct tPosition Position; // " "
long PosCount; // aantal posities opgenomen
u_char PosRec[BLOB_LEN]; /// // de opgenomen posities (LastPos records) van een hele race..
u_long LastPosRecSent[MAXPLAYERS]; // de index van de laatst verstuurde PosRec naar (per) player
u_char PosSplitSent[4]; // intermediate van host aan speler verzonden
u_char LastPos[27]; // het laatste in-game Position-packet..
// Position-packet naar andere spelers al verzonden? lijst
u_char PosSent[MAXPLAYERS]; // 0=niet verzonden naar anderen, 1=al verzonden
u_long PosReceived; // >0==al een positie-packet ontvangen van deze speler, 0==nog niets ontvangen..
//test
u_char LastPosBuf[MAXLASTPOS][27]; // De MAXLASTPOS laatste in-game Position-packet..[0]==laatst ontvangen (jongste packet), [PosReceived]==oudste packet in buffer..
u_long LastPosSentTime[MAXPLAYERS];// de timestamp van de laatst verzonden positie naar een speler..
///test
u_char NickC6D6; // D6=nick opgegeven met een D6-81, anders met een C6-81
u_char ReceivedC60E; // 0==nog geen c6-0e ontvangen, <>0==wel
// laatste keer sinds ready onthouden
u_long LastTimeReady;
u_char ReadyWarning;
// NO-CUTS
float LastPosX; // de vorige 3D positie X-coördinaat
float LastPosY; // de vorige 3D positie Y-coördinaat
float LastPosZ; // de vorige 3D positie Z-coördinaat
// 2 timestamps uit het ontvangen packet..
u_long Ping1;
u_long Ping2;
u_long PingCount;
u_long LastTimeValue;
u_long AvgPing; // gemiddelde ping
u_char StartNr; // het PlayerNr geldig tijdens de race (verandert dan niet)
u_char StartPlayerNr; // het PlayerNr op het moment van race-start (verandert dan niet meer)
u_char hasFinished; // 0=niet gefinished, anders gefinished als #hasFinished
u_char hasRetired; // 0=niet retired, 1=retired
u_char hasQuit; // 0=niet ge-quit, 1=quitted
// race-tijden en splits..
u_char SplitsDone; // teller hoeveel splits er zijn gepasseerd.
u_long SplitTime[4]; // 4 split-tijden (3 splits + finish)
u_long StartTime; // timestamp in de eerste ontvangen Pos-packet van deze client (na racestart C6-04)
u_long RaceTime; // eind- / totaal-tijd
u_char PercToSplit0;
u_char Percentage; // percentage gereden [0..100] %
// huidige vote waarden..
u_char VoteStage; // een track prefereren..
u_long VoteKick; // een speler (met deze ID) wegcijferen..
u_char VoteGhost; // de host-bot rijdt het record van deze klasse (4WD,2WD,GB,Bonus)
};
struct tPlayer *ptr_players;
// Een lijst met de player-indexen..allemaal "leeg" nog..
short PlayerIndex[8] = { -1,-1,-1,-1,-1,-1,-1,-1 };
// speler eigenschappen opvragen..
u_char* getIP( short PlayerNr );
u_long getID( short PlayerNr );
u_long getMemberID( short PlayerNr );
u_int getPortNr( short PlayerNr );
u_char *getNick( short PlayerNr );
u_char getCountry( short PlayerNr );
u_char getCar( short PlayerNr );
u_char getCarType( short PlayerNr );
u_char getGearbox( short PlayerNr );
u_char getConnectionSpeed( short PlayerNr );
u_long getPing( short PlayerNr );
u_long getPingCount( short PlayerNr );
u_long getAvgPing( short PlayerNr );
u_long getReady( short PlayerNr );
u_short getChatLine( short PlayerNr );
u_short getLastCMD( short PlayerNr );
u_long getSplitTime( short PlayerNr, u_char SplitNr ); //0..3
u_long getRaceTime( short PlayerNr );
u_char getSplitsDone( short PlayerNr );
u_char getPercToSplit0( short PlayerNr );
u_char getStartNr( short PlayerNr );
u_char getStartPlayerNr( short PlayerNr );
u_char getFinished( short PlayerNr );
u_char getRetired( short PlayerNr );
u_char getQuit( short PlayerNr );
u_char getVoteStage( short PlayerNr );
u_long getVoteKick( short PlayerNr );
u_char getVoteGhost( short PlayerNr );
struct tRotation getRotation( short PlayerNr );
struct tPosition getPosition( short PlayerNr );
float getLastPosX( short PlayerNr );
float getLastPosY( short PlayerNr );
float getLastPosZ( short PlayerNr );
// speler eigenschappen veranderen..
void changeID( short PlayerNr, u_long aID );
void changeMemberID( short PlayerNr, u_long aMemberID );
void changePortNr( short PlayerNr, u_int aPortNr );
void changeNick( short PlayerNr, u_char *aNickname );
void changeCountry( short PlayerNr, u_char aCountry );
void changeCar( short PlayerNr, u_char aCar );
void changeCarType( short PlayerNr, u_char aCarType );
void changeGearbox( short PlayerNr, u_char aGearbox );
void changeConnectionSpeed( short PlayerNr, u_char aConnectionSpeed );
void changePing( short PlayerNr, u_long aPing );
void changePingCount( short PlayerNr, u_long aPingCount );
void changeAvgPing( short PlayerNr, u_long aPing );
void changeReady( short PlayerNr, u_long aReady );
void changeChatLine( short PlayerNr, u_short aChatLine );
void increaseChatLine( short PlayerNr );
void increaseChatLines();
void changeLastCMD( short PlayerNr, u_short CMD );
void changeSplitTime( short PlayerNr, u_char SplitNr, u_long aSplitTime );
void changeRaceTime( short PlayerNr, u_long aRaceTime );
void changeSplitsDone( short PlayerNr, u_char aSplitsDone );
void increaseSplitsDone( short PlayerNr );
void changePercToSplit0( short PlayerNr, u_char BCD );
void changeStartNr( short PlayerNr, u_char aStartNr );
void changeStartPlayerNr( short PlayerNr, u_char aStartPlayerNr );
void changeFinished( short PlayerNr, u_char aFinished );
void changeRetired( short PlayerNr, u_char aRetired );
void changeQuit( short PlayerNr, u_char aQuit );
void changeVoteStage( short PlayerNr, u_char aVoteStage );
void changeVoteKick( short PlayerNr, u_long aVoteKick );
void changeVoteGhost( short PlayerNr, u_char aVoteGhost );
void changePosition( short PlayerNr, u_long aX, u_long aY, u_long aZ );
void changeRotation( short PlayerNr, u_long aX, u_long aY, u_long aZ );
void changeState( short PlayerNr, int aState );
void changeLastPosX( short PlayerNr, float aLastPosX );
void changeLastPosY( short PlayerNr, float aLastPosY );
void changeLastPosZ( short PlayerNr, float aLastPosZ );
// de positie-buffer vullen en aanschuiven..
void AddLastPos( short PlayerNr );
// de index in de buffer teruggeven, van de positie waarvan de tijd <= aan de opgegeven timestamp..
// resultaat == -1 als er geen geldige positie/tijd is gevonden..
int GetLastPos( short PlayerNr, u_long aTimeStamp );
// spelers zoeken/toevoegen/verwijderen..
short FindPlayer(u_long aIP, u_int aPortNr);
short AddPlayer(struct in_addr aIP, u_int aPortNr);
short DeletePlayer(short PlayerNr);
void ClearPlayer(short SlotNr);
// De speler-IP opvragen als een string
//
u_char* getIP( short PlayerNr ) {
if (PlayerNr<1 || PlayerNr>=NumPlayers) return "";
return inet_ntoa(ptr_players[PlayerIndex[PlayerNr]].AddrIn);
}
// De speler-ID opvragen
//
u_long getID(short PlayerNr) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0;
return ptr_players[PlayerIndex[PlayerNr]].ID;
}
// De speler-MemberID opvragen
//
u_long getMemberID( short PlayerNr ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0;
return ptr_players[PlayerIndex[PlayerNr]].MemberID;
}
// De speler-PortNr opvragen
//
u_int getPortNr( short PlayerNr ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0;
return ptr_players[PlayerIndex[PlayerNr]].PortNr;
}
// De speler-naam opvragen
//
u_char *getNick(short PlayerNr) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return "";
return &ptr_players[PlayerIndex[PlayerNr]].Nick;
}
// Het speler-land opvragen
//
u_char getCountry(short PlayerNr) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0;
return ptr_players[PlayerIndex[PlayerNr]].Country;
}
// De speler-auto opvragen
//
u_char getCar(short PlayerNr) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0;
return ptr_players[PlayerIndex[PlayerNr]].Car;
}
// Het speler-auto-type opvragen
//
u_char getCarType(short PlayerNr) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0;
return ptr_players[PlayerIndex[PlayerNr]].CarType;
}
// De speler-transmissie opvragen
//
u_char getGearbox(short PlayerNr) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0;
return ptr_players[PlayerIndex[PlayerNr]].Gearbox;
}
// De speler-connectionspeed opvragen
//
u_char getConnectionSpeed( short PlayerNr ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0;
return ptr_players[PlayerIndex[PlayerNr]].ConnectionSpeed;
}
// De speler-ping opvragen
//
u_long getPing(short PlayerNr) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0x00000000;
return ptr_players[PlayerIndex[PlayerNr]].Ping;
}
// De speler-pingcount opvragen
//
u_long getPingCount(short PlayerNr) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0x00000000;
return ptr_players[PlayerIndex[PlayerNr]].PingCount;
}
// De speler gemiddelde ping opvragen
//
u_long getAvgPing(short PlayerNr) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0x00000000;
return ptr_players[PlayerIndex[PlayerNr]].AvgPing;
}
// De speler-ready-status opvragen
//
u_long getReady(short PlayerNr) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0x00000000; //niet klaar..
return ptr_players[PlayerIndex[PlayerNr]].Ready;
}
// De speler-ChatLine opvragen
//
u_short getChatLine(short PlayerNr) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0;
return ptr_players[PlayerIndex[PlayerNr]].ChatLine;
}
// De speler-LastCMD opvragen
//
u_short getLastCMD( short PlayerNr ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0;
return ptr_players[PlayerIndex[PlayerNr]].LastCMD;
}
// Een speler's split-tijd opvragen
//
u_long getSplitTime( short PlayerNr, u_char SplitNr ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers || SplitNr<0 || SplitNr >3) return 0;
return ptr_players[PlayerIndex[PlayerNr]].SplitTime[SplitNr];
}
// De speler's actuele race-tijd opvragen
//
u_long getRaceTime( short PlayerNr ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0;
return ptr_players[PlayerIndex[PlayerNr]].RaceTime;
}
// Het speler's aantal gepasseerde splits opvragen
//
u_char getSplitsDone( short PlayerNr ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0;
return ptr_players[PlayerIndex[PlayerNr]].SplitsDone;
}
// De speler's percentage tot aan de volgende split opvragen
//
u_char getPercToSplit0( short PlayerNr ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0;
return ptr_players[PlayerIndex[PlayerNr]].PercToSplit0;
}
// speler Start-nummer opvragen (PlayerNr tijdens de race)
//
u_char getStartNr( short PlayerNr ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0xFF; //ongeldig
return ptr_players[PlayerIndex[PlayerNr]].StartNr;
}
// speler Start-playerNummer opvragen (PlayerNr bij start-race)
//
u_char getStartPlayerNr( short PlayerNr ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0xFF; //ongeldig
return ptr_players[PlayerIndex[PlayerNr]].StartPlayerNr;
}
// speler-Finished opvragen
//
u_char getFinished( short PlayerNr ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 1;
return ptr_players[PlayerIndex[PlayerNr]].hasFinished;
}
// speler-hasRetired opvragen
//
u_char getRetired( short PlayerNr ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 1;
return ptr_players[PlayerIndex[PlayerNr]].hasRetired;
}
// speler-hasQuit opvragen
//
u_char getQuit( short PlayerNr ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 1;
return ptr_players[PlayerIndex[PlayerNr]].hasQuit;
}
// De speler-VoteStage opvragen
//
u_char getVoteStage( short PlayerNr ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0;
return ptr_players[PlayerIndex[PlayerNr]].VoteStage;
}
// De speler-VoteKick opvragen
//
u_long getVoteKick( short PlayerNr ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0;
return ptr_players[PlayerIndex[PlayerNr]].VoteKick;
}
// De speler-VoteRecordGhost opvragen
//
u_char getVoteGhost( short PlayerNr ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 1;
return ptr_players[PlayerIndex[PlayerNr]].VoteGhost;
}
// De speler-Rotatie opvragen
//
struct tRotation getRotation(short PlayerNr) {
// if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0;
return ptr_players[PlayerIndex[PlayerNr]].Rotation;
}
// De speler-Positie opvragen
//
struct tPosition getPosition(short PlayerNr) {
// if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0;
return ptr_players[PlayerIndex[PlayerNr]].Position;
}
int getState( short PlayerNr ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0;
return ptr_players[PlayerIndex[PlayerNr]].State;
}
// de laatste positie X-coord opvragen
float getLastPosX( short PlayerNr ) {
if (PlayerNr>=8) return ptr_players[PlayerNr].LastPosX;
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0.0f;
return ptr_players[PlayerIndex[PlayerNr]].LastPosX;
}
// de laatste positie Y-coord opvragen
float getLastPosY( short PlayerNr ) {
if (PlayerNr>=8) return ptr_players[PlayerNr].LastPosY;
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0.0f;
return ptr_players[PlayerIndex[PlayerNr]].LastPosY;
}
// de laatste positie Z-coord opvragen
float getLastPosZ( short PlayerNr ) {
if (PlayerNr>=8) return ptr_players[PlayerNr].LastPosZ;
if (PlayerNr<0 || PlayerNr>=NumPlayers) return 0.0f;
return ptr_players[PlayerIndex[PlayerNr]].LastPosZ;
}
// De speler-ID veranderen
//
void changeID(short PlayerNr, u_long aID) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].ID = aID;
}
// De speler-MemberID veranderen
//
void changeMemberID( short PlayerNr, u_long aMemberID ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].MemberID = aMemberID;
}
void changePortNr( short PlayerNr, u_int aPortNr ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].PortNr = aPortNr;
}
// De speler-naam veranderen
//
void changeNick(short PlayerNr, u_char *aNickname) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
strcpy(ptr_players[PlayerIndex[PlayerNr]].Nick, aNickname);
}
// Het speler-land veranderen
//
void changeCountry(short PlayerNr, u_char aCountry) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].Country = aCountry;
}
// De speler-auto veranderen
//
void changeCar(short PlayerNr, u_char aCar) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].Car = aCar;
}
// De speler-auto-type veranderen
//
void changeCarType(short PlayerNr, u_char aCarType) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].CarType = aCarType;
// de host-ghost instellen voor dezelfde klasse
ptr_players[PlayerIndex[PlayerNr]].VoteGhost = aCarType;
}
// De speler-transmissie veranderen
//
void changeGearbox(short PlayerNr, u_char aGearbox) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].Gearbox = aGearbox;
}
// De speler-connectionspeed veranderen
//
void changeConnectionSpeed( short PlayerNr, u_char aConnectionSpeed ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].ConnectionSpeed = aConnectionSpeed;
}
// De speler-Ping veranderen
//
void changePing(short PlayerNr, u_long aPing) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].Ping = aPing;
if ( ptr_players[PlayerIndex[PlayerNr]].PingCount == 2 ) {
changeAvgPing( PlayerNr, aPing );
}
// de gemiddelde ping
if ( aPing < 10000 ) {
ptr_players[PlayerIndex[PlayerNr]].PingCount++;
u_long PingCnt;
PingCnt = ptr_players[PlayerIndex[PlayerNr]].PingCount;
float mpA, mpB;
mpA = ( (PingCnt - 1) / PingCnt );
mpB = ( 1/ PingCnt );
//a = (getAvgPing(PlayerNr) * (( (ptr_players[PlayerIndex[PlayerNr]].PingCount-1) / ptr_players[PlayerIndex[PlayerNr]].PingCount )) + (aPing / ptr_players[PlayerIndex[PlayerNr]].PingCount));// /ptr_players[PlayerIndex[PlayerNr]].PingCount) * ;
//b = (aPing / ptr_players[PlayerIndex[PlayerNr]].PingCount);
//changeAvgPing( PlayerNr, (u_long ) ( (mpA * getAvgPing(PlayerNr) ) + ( mpB * aPing ) ) );
//changeAvgPing( PlayerNr, (u_long ) (a + b) );
//changeAvgPing( PlayerNr, (u_long ) (getAvgPing(PlayerNr) * (( (ptr_players[PlayerIndex[PlayerNr]].PingCount-1) / ptr_players[PlayerIndex[PlayerNr]].PingCount )) + (aPing / ptr_players[PlayerIndex[PlayerNr]].PingCount)) );
//changeAvgPing( PlayerNr, (u_long ) ( (( (PingCnt - 1) / PingCnt ) * getAvgPing(PlayerNr) ) + ( ( 1/ PingCnt ) * aPing ) ) );
changeAvgPing( PlayerNr, ( 0.8 * getAvgPing(PlayerNr) + 0.2 * aPing ) );
}
}
// De speler-PingCount veranderen
//
void changePingCount(short PlayerNr, u_long aPingCount) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].PingCount = aPingCount;
}
// De speler-Gemiddelde Ping veranderen
//
void changeAvgPing(short PlayerNr, u_long aPing) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].AvgPing = aPing;
}
// De speler-ChatLine veranderen
//
void changeChatLine(short PlayerNr, u_short aChatLine) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].ChatLine = aChatLine;
// ptr_players[PlayerIndex[PlayerNr]].LastCMD = aChatLine-1; //laatste waarde onthouden..
}
// De speler-ChatLine verhogen
//
void increaseChatLine(short PlayerNr) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].ChatLine++;
}
void increaseChatLines() {
int i=0;
for (i=0;i<NumPlayers;i++) {
ptr_players[PlayerIndex[i]].ChatLine++;
}
}
// De speler-LastCMD veranderen
//
void changeLastCMD( short PlayerNr, u_short CMD ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].LastCMD = CMD;
}
// Een speler's Split-tijd veranderen
//
void changeSplitTime( short PlayerNr, u_char SplitNr, u_long aSplitTime ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers || SplitNr<0 || SplitNr >3) return;
ptr_players[PlayerIndex[PlayerNr]].SplitTime[SplitNr] = aSplitTime;
}
// De speler's actuele race-tijd veranderen
//
void changeRaceTime( short PlayerNr, u_long aRaceTime ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].RaceTime = aRaceTime;
}
// Het speler's aantal gepasseerde splits veranderen
//
void changeSplitsDone( short PlayerNr, u_char aSplitsDone ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].SplitsDone = aSplitsDone;
}
void increaseSplitsDone( short PlayerNr ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].SplitsDone++;
}
// De speler's percentage tot aan de volgende split veranderen
// de opgegeven waarde voor argument BCD is een "Binary Coded Decimal"
void changePercToSplit0( short PlayerNr, u_char BCD ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].PercToSplit0 = (BCD >> 4)*10 + (BCD & 0x0F);
}
// Het speler StartNr waarde veranderen
//
void changeStartNr( short PlayerNr, u_char aStartNr ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].StartNr = aStartNr;
}
// Het speler StartPlayerNr waarde veranderen
//
void changeStartPlayerNr( short PlayerNr, u_char aStartPlayerNr ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[aStartPlayerNr]].StartPlayerNr = aStartPlayerNr;
}
// De speler-Finished waarde veranderen
//
void changeFinished( short PlayerNr, u_char aFinished ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].hasFinished = aFinished;
}
// De speler-hasRetired waarde veranderen
//
void changeRetired( short PlayerNr, u_char aRetired ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].hasRetired = aRetired;
}
// De speler-hasQuit waarde veranderen
//
void changeQuit( short PlayerNr, u_char aQuit ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].hasQuit = aQuit;
}
// De speler-VoteStage veranderen
//
void changeVoteStage( short PlayerNr, u_char aVoteStage ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].VoteStage = aVoteStage;
}
// De speler-VoteKick veranderen
//
void changeVoteKick( short PlayerNr, u_long aVoteKick ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].VoteKick = aVoteKick;
}
// De speler-VoteGhost veranderen
//
void changeVoteGhost( short PlayerNr, u_char aVoteGhost ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
// if ( aVoteGhost==0 ) aVoteGhost = 1;
ptr_players[PlayerIndex[PlayerNr]].VoteGhost = aVoteGhost;
}
// De speler-Ready-status veranderen
//
void changeReady(short PlayerNr, u_long aReady) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].Ready = aReady;
}
// De speler-rotatie veranderen
//
void changeRotation(short PlayerNr, u_long aX, u_long aY, u_long aZ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].Rotation.X = aX;
ptr_players[PlayerIndex[PlayerNr]].Rotation.Y = aY;
ptr_players[PlayerIndex[PlayerNr]].Rotation.Z = aZ;
}
// De speler-positie veranderen
//
void changePosition(short PlayerNr, u_long aX, u_long aY, u_long aZ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].Position.X = aX;
ptr_players[PlayerIndex[PlayerNr]].Position.Y = aY;
ptr_players[PlayerIndex[PlayerNr]].Position.Z = aZ;
}
// De speler-State veranderen
//
void changeState( short PlayerNr, int aState ) {
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].State = aState;
}
// LastPos X-coord instellen
void changeLastPosX( short PlayerNr, float aLastPosX ) {
if (PlayerNr>=8) ptr_players[PlayerNr].LastPosX = aLastPosX;
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].LastPosX = aLastPosX;
}
// LastPos Y-coord instellen
void changeLastPosY( short PlayerNr, float aLastPosY ) {
if (PlayerNr>=8) ptr_players[PlayerNr].LastPosX = aLastPosY;
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].LastPosY = aLastPosY;
}
// LastPos Z-coord instellen
void changeLastPosZ( short PlayerNr, float aLastPosZ ) {
if (PlayerNr>=8) ptr_players[PlayerNr].LastPosX = aLastPosZ;
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
ptr_players[PlayerIndex[PlayerNr]].LastPosZ = aLastPosZ;
}
// LastPosBuffer vullen..
void AddLastPos( short PlayerNr ) {
int i;
if (PlayerNr<0 || PlayerNr>=NumPlayers) return;
// eerst alle posities in de buffer opschuiven..de laatste zal verdwijnen uit de array..
for ( i=MAXLASTPOS-1 - 1; i>=0; i-- ) {
memcpy( &ptr_players[PlayerIndex[PlayerNr]].LastPosBuf[i+1], &ptr_players[PlayerIndex[PlayerNr]].LastPosBuf[i], 27);
}
// de laatst ontvangen positie komt op array-index 0
memcpy( &ptr_players[PlayerIndex[PlayerNr]].LastPosBuf[0], &ptr_players[PlayerIndex[PlayerNr]].LastPos, 27);
}
// de index in de buffer teruggeven, van de positie waarvan de tijd >= aan de opgegeven timestamp..
// resultaat == -1 als er geen geldige positie/tijd is gevonden..
int GetLastPos( short PlayerNr, u_long aTimeStamp ) {
int Result = -1;
int i;
int N;
u_long Time, TimeB;
u_long diffA, diffB;
if (PlayerNr<0 || PlayerNr>=NumPlayers) return Result;
N = ptr_players[PlayerIndex[PlayerNr]].PosReceived;
// heeft de speler al (tenminste 1) posities verzonden??
if ( N == 0 ) return Result;
// alle positie in de buffer doorlopen van deze speler..
if (N>MAXLASTPOS) N = MAXLASTPOS;
// zoek de eerste tijd die <= aTimeStamp..
for ( i=0; i<N; i++ ) {
// de RaceTime uit LastPos lezen..
Time = ptr_players[PlayerIndex[PlayerNr]].LastPosBuf[i][2];
Time += (ptr_players[PlayerIndex[PlayerNr]].LastPosBuf[i][3] << 8);
Time += (ptr_players[PlayerIndex[PlayerNr]].LastPosBuf[i][4] << 16);
Time += (ptr_players[PlayerIndex[PlayerNr]].LastPosBuf[i][5] << 24);
//
if ( Time <= aTimeStamp ) {
Result = i;
/*
// dichtstbijzijnde timestamp zoeken (ze vliegen door de lucht !! woot woot)
if ( i>0 ) {
diffA = aTimeStamp - Time;
TimeB = ptr_players[PlayerIndex[PlayerNr]].LastPosBuf[i-1][2];
TimeB += ptr_players[PlayerIndex[PlayerNr]].LastPosBuf[i-1][3] << 8;
TimeB += ptr_players[PlayerIndex[PlayerNr]].LastPosBuf[i-1][4] << 16;
TimeB += ptr_players[PlayerIndex[PlayerNr]].LastPosBuf[i-1][5] << 24;
diffB = TimeB - aTimeStamp;
if ( diffB < diffA ) Result = i-1;
}
*/
break;
}
}
/*
// zoek de eerste tijd die >= aTimeStamp..
for ( i=N-1; i>=0; i-- ) {
// de RaceTime uit LastPos lezen..
Time = ptr_players[PlayerIndex[PlayerNr]].LastPosBuf[i][2];
Time += ptr_players[PlayerIndex[PlayerNr]].LastPosBuf[i][3] << 8;
Time += ptr_players[PlayerIndex[PlayerNr]].LastPosBuf[i][4] << 16;
Time += ptr_players[PlayerIndex[PlayerNr]].LastPosBuf[i][5] << 24;
//
if ( Time >= aTimeStamp ) {
Result = i;
break;
}
}
*/
return Result;
}
int GetLastPosRec( u_long aTimeStamp, u_char aPlayer, u_char ForPlayer ) {
int Result;// = ptr_players[0].PosReceived;
int i;
int N;
u_long Time;
N = BLOB_LEN/27-1;
Result = ptr_players[aPlayer].LastPosRecSent[ForPlayer];
// heeft de speler al (tenminste 1) posities verzonden??
if ( N == 0 ) return Result;
// alle positie in de buffer doorlopen van deze speler..
if (N>MAXLASTPOS) N = MAXLASTPOS;
// zoek de eerste tijd die <= aTimeStamp..
for ( i=Result; i<18000; i++ ) {//search forward..
// check this out..changed: 2008mei15
if ( i>=ptr_players[aPlayer].PosCount ) return Result; //extrapolate player
// de RaceTime uit LastPos lezen..
Time = ptr_players[aPlayer].PosRec[i*27+2];
Time += ( ptr_players[aPlayer].PosRec[i*27+3] << 8 );
Time += ( ptr_players[aPlayer].PosRec[i*27+4] << 16 );
Time += ( ptr_players[aPlayer].PosRec[i*27+5] << 24 );
//Time = (u_long *)ptr_players[aPlayer].PosRec+i*27+2;
//
if ( Time >= aTimeStamp ) {
Result = i;
// onthouden waar we zijn gebleven..
ptr_players[aPlayer].LastPosRecSent[ForPlayer] = i; //interpolate player
break;
}
}
return Result;
}
// Zoek de speler op met de opgegeven IP en PortNr.
// resulteer het speler-nummer (PlayerNr met waarden vanaf 0. -1 = ongeldig/mislukt)
//
short FindPlayer(u_long aIP, u_int aPortNr) {
short PlayerNr=-1;
int i=1;
for ( i=1 ; i<NumPlayers ; i++ ) {
if ( ptr_players[PlayerIndex[i]].PortNr == aPortNr ) {
if ( ptr_players[PlayerIndex[i]].IP == aIP ) {
PlayerNr = i;
break;
}
}
}
return PlayerNr;
}
// Een speler toevoegen.
// resulteer het speler-nummer (PlayerNr met waarden vanaf 0. -1 = ongeldig/mislukt)
//
short AddPlayer(struct in_addr aIP, u_int aPortNr) {
short PlayerNr=-1;
int i=0;
int j=0;
u_char isOK;
char *Country;
if ( GlobalConfigMode == 1 ) {
PlayerNr = NumPlayers++; //NumPlayers achteraf ophogen..
i = PlayerNr;
PlayerIndex[PlayerNr] = i;
// de gegevens overnemen naar dit record..
ptr_players[i].Car = 1;
ptr_players[i].AddrIn = aIP;
ptr_players[i].IP = htonl(aIP.s_addr);
ptr_players[i].PortNr = aPortNr;
ptr_players[i].ChatLine = 2;
ptr_players[i].LastCMD = 0x0000; //ptr_players[i].ChatLine-1;
ptr_players[i].RaceTime = 0x00000000; //tijd in ms.
for (j=0; j<4; j++) ptr_players[i].SplitTime[j] = 0;
ptr_players[i].SplitsDone = 0;
ptr_players[i].PercToSplit0 = 0x00; // BCD coded (Binary Coded Decimal), 0x00=0%, 0x09=9%, 0x10=10% etc..
ptr_players[i].VoteStage = 0; // geen vote voor een stage..
ptr_players[i].VoteKick = 0; // geen vote tegen een speler met deze ID..
ptr_players[i].VoteGhost = 1; // 4WD ghost
ptr_players[i].StartNr = 0xFF; // ongeldig startnummer..
ptr_players[i].hasFinished = 0x00; // nog niet gefinisht..
ptr_players[i].hasRetired = 0x00; // nog niet retired..
ptr_players[i].hasQuit = 0x00; // nog niet ge-quit..
ptr_players[i].State = -1; //<geen speler>
ptr_players[i].Ping = 0x00000020;
ptr_players[i].PingCount = 0x00000001;
ptr_players[i].AvgPing = 0x00000020;
ptr_players[i].BufferedPackets = 0; // nog geen enkel pakketje reeds gebufferd (tbv ACK/resent)
ptr_players[i].PtrBufferRead = 3;
ptr_players[i].PtrBufferWrite = 2; // MAXBUFF-1; //roterende buffer
ptr_players[i].PosCount = 0;
ptr_players[i].LastTimeReady = minisec();
ptr_players[i].ReadyWarning = 0;
//PosRec;
for (j=0;j<4;j++) ptr_players[i].PosSplitSent[j] = 0; //1 == intermediate[j] verzonden naar speler
for (j=0;j<MAXBUFF;j++) {
ptr_players[i].BufferLen[j] = -1; // de buffer markeren als zijnde niet in gebruik..
ptr_players[i].BufferCountdown[j] = 0;
}
// laatst ontvangen Position-packet al verstuurd aan spelers? reset
for (j=0; j < MAXPLAYERS; j++ ) { // MaxPlayers
ptr_players[i].PosSent[j] = 1; //als "al verzonden" instellen naar andere speler(j)
//test
ptr_players[i].LastPosSentTime[j] = 0x00000000;
ptr_players[i].LastPosRecSent[j] = 0;
///test
}
if ( ++GlobalJoinCount > 255 ) GlobalJoinCount = 1; /// 20080504 ivm player 0
//--test of andere spelers dit nummer al gebruiken
isOK = 0;
while ( isOK==0 ) {
isOK = 1;
for ( j=1; j<NumPlayers; j++ ) {
if ( ptr_players[PlayerIndex[j]].ID == GlobalJoinCount ) {
if ( ++GlobalJoinCount > 255 ) GlobalJoinCount = 1; /// 20080504 ivm player 0
isOK = 0;
}
}
}
//--
ptr_players[i].ID = GlobalJoinCount; // het totaal joins ophogen..
return PlayerNr;
}
// zoek de eerste vrije entry in de array ptr_players
for ( i=1; i < MaxPlayers; i++ ) {
//if (ptr_players[i].IP==0 && ptr_players[i].PortNr==0) {
if (ptr_players[i].PortNr==0) {//empty slot
PlayerNr = NumPlayers++; //NumPlayers achteraf ophogen..
PlayerIndex[PlayerNr] = i;
// Nick instellen voor naamloos ( of geen naampakket sturen.. )
strcpy( &ptr_players[i].Nick, "Anonymous\0" );
// de gegevens overnemen naar dit record..
ptr_players[i].AddrIn = aIP;
ptr_players[i].IP = htonl(aIP.s_addr);
ptr_players[i].PortNr = aPortNr;
ptr_players[i].ConnectionSpeed = 0x00;
ptr_players[i].ChatLine = 2;
ptr_players[i].LastCMD = 0x0000; //ptr_players[i].ChatLine-1;
ptr_players[i].Country = 0;
ptr_players[i].Car = 1;
ptr_players[i].CarType = 0x00;
ptr_players[i].Gearbox = 0;
ptr_players[i].RaceTime = 0x00000000; //tijd in ms.
for (j=0; j<4; j++) ptr_players[i].SplitTime[j] = 0;
ptr_players[i].SplitsDone = 0;
ptr_players[i].PercToSplit0 = 0x00; // BCD coded (Binary Coded Decimal), 0x00=0%, 0x09=9%, 0x10=10% etc..
ptr_players[i].Percentage = 0x00; //start..finish == 0..100 %
ptr_players[i].VoteStage = 0; // geen vote voor een stage..
ptr_players[i].VoteKick = 0; // geen vote tegen een speler met deze ID..
ptr_players[i].VoteGhost = 0; // host-ghost record laten zien van deze klasse
ptr_players[i].StartNr = 0xFF; // ongeldig startnummer..
ptr_players[i].StartPlayerNr = 0xFF; // ongeldig startnummer..
ptr_players[i].Ready = 0x00000000;
ptr_players[i].hasFinished = 0x00; // nog niet gefinisht..
ptr_players[i].hasRetired = 0x00; // nog niet retired..
ptr_players[i].hasQuit = 0x00; // nog niet ge-quit..
ptr_players[i].State = -1; //<geen speler>
ptr_players[i].Ping = 0x00000020;
ptr_players[i].Ping1 = 0x00000000;
ptr_players[i].Ping2 = 0x00000000;
ptr_players[i].PingCount = 0x00000001;
ptr_players[i].AvgPing = 0x00000020;
ptr_players[i].PacketLen = 0;
ptr_players[i].BufferedPackets = 0; // nog geen enkel pakketje reeds gebufferd (tbv ACK/resent)
ptr_players[i].PtrBufferRead = 3;
ptr_players[i].PtrBufferWrite = 2; // MAXBUFF-1; //roterende buffer
ptr_players[i].LastTimeReady = minisec();
ptr_players[i].LastTimeValue = 0x00000000;
ptr_players[i].ReadyWarning = 0x00;
ptr_players[i].PosCount = 0;
ptr_players[i].PosReceived = 0x00000000;
ptr_players[i].ReceivedC60E = 0x00; //gridpresent1 al ontvangen?
ptr_players[i].NickC6D6 = 0x00; //gridpresent1 al ontvangen?
// tbv. No-Cuts check..
ptr_players[i].LastPosX = 0.0f;
ptr_players[i].LastPosY = 0.0f;
ptr_players[i].LastPosZ = 0.0f;
//PosRec;