-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD_CLISRV.C
1739 lines (1510 loc) · 50.4 KB
/
D_CLISRV.C
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
// d_clisrv.c :
// DOOM Network game communication and protocol,
// all OS independend parts.
#include "doomdef.h"
#include "command.h"
#include "i_net.h"
#include "i_system.h"
#include "d_net.h"
#include "d_netcmd.h"
#include "d_clisrv.h"
#include "d_main.h"
#include "g_game.h"
#include "hu_stuff.h"
#include "keys.h"
#include "doomstat.h"
#include "m_argv.h"
#include "m_menu.h"
#include "console.h"
#include "d_netfil.h"
#define DEBUGFILE
#ifdef DEBUGFILE
#define DEBFILE(msg) { if(debugfile) fprintf(debugfile,msg) }
#else
#define DEBFILE(msg)
#endif
//
// NETWORKING
//
// gametic is the tic about to (or currently being) run
// maketic is the tic that hasn't had control made for it yet
// server:
// nettics is the tic for eatch node
// firsttictosend is the lowest value of nettics
// client:
// neededtic is the tic needed by the client for run the game
// firsttictosend is used to optimize a condition
// normaly maketic>=gametic>0,
// 1=disable MAXLAG support
#define MAXLAG 1
#define PREDICTIONQUEUE BACKUPTICS
#define PREDICTIONMASK (PREDICTIONQUEUE-1)
// more precise version number to compare in network
#define SUBVERSION 4
#if MAXLAG>BACKUPTICS
Error maxlag > backuptics
#endif
extern doomdata_t* netbuffer; // points inside doomcom
extern doomcom_t* doomcom;
boolean server; // true or false but !server=client
byte serverplayer;
ULONG session;
// server specific vars
byte playernode[MAXPLAYERS];
ULONG cl_maketic[MAXNETNODES];
byte nodetoplayer[MAXNETNODES];
byte playerpernode[MAXNETNODES]; // used specialy for scplitscreen
boolean nodeingame[MAXNETNODES]; // set false as nodes leave game
ULONG nettics[MAXNETNODES]; // what tic the client have received
ULONG supposedtics[MAXNETNODES];// nettics prevision for smaller packet
ULONG firstticstosend; // min of the nettics
boolean dedicated; // dedicate server
short consistancy[BACKUPTICS];
ULONG maketic;
boolean acceptnewnode;
// client specific
#ifdef CLIENTPREDICTION
ticcmd_t localcmds[PREDICTIONQUEUE];
ULONG localgametic;
#else
ticcmd_t localcmds;
#endif
boolean cl_packetmissed;
boolean drone;
// here it is for the secondary local player (splitscreen)
ticcmd_t localcmds2;
byte localtextcmd[MAXTEXTCMD];
byte localtextcmd2[MAXTEXTCMD]; // splitscreen
char servernode; // the number of the server node
ULONG neededtic;
// engine
ticcmd_t netcmds[BACKUPTICS][MAXPLAYERS];
byte textcmds[BACKUPTICS][MAXPLAYERS][MAXTEXTCMD];
consvar_t cv_playdemospeed = {"playdemospeed","0",0,CV_Unsigned};
void D_Cleartic(int tic);
extern int viewangleoffset;
// some software don't support largest packet
// (original sersetup, not exactely, but the probabylity of sending a packet
// of 512 octet is like 0.1)
USHORT software_MAXPACKETLENGHT;
int ExpandTics (int low)
{
int delta;
delta = low - (maketic&0xff);
if (delta >= -64 && delta <= 64)
return (maketic&~0xff) + low;
if (delta > 64)
return (maketic&~0xff) - 256 + low;
if (delta < -64)
return (maketic&~0xff) + 256 + low;
#ifdef PARANOIA
I_Error ("ExpandTics: strange value %i at maketic %i",low,maketic);
#endif
return 0;
}
// -----------------------------------------------------------------
// Some extra data function for handle textcmd buffer
// -----------------------------------------------------------------
void (*listnetxcmd[MAXNETXCMD])(char **p,int playernum);
void RegisterNetXCmd(netxcmd_t id,void (*cmd_f) (char **p,int playernum))
{
#ifdef PARANOIA
if(id>=MAXNETXCMD)
I_Error("command id %d too big",id);
if(listnetxcmd[id]!=0)
I_Error("Command id %d already used",id);
#endif
listnetxcmd[id]=cmd_f;
}
void SendNetXCmd(byte id,void *param,int nparam)
{
if(demoplayback)
return;
if(localtextcmd[0]+1+nparam>MAXTEXTCMD)
{
#ifdef PARANOIA
I_Error("No more place in the buffer for netcmd %d\n",id);
#else
CONS_Printf("\2Net Command fail\n");
#endif
return;
}
localtextcmd[0]++;
localtextcmd[localtextcmd[0]]=id;
if(param && nparam)
{
memcpy(&localtextcmd[localtextcmd[0]+1],param,nparam);
localtextcmd[0]+=nparam;
}
}
// splitscreen player
void SendNetXCmd2(byte id,void *param,int nparam)
{
if(demoplayback)
return;
if(localtextcmd2[0]+1+nparam>MAXTEXTCMD)
{
#ifdef PARANOIA
I_Error("No more place in the buffer for netcmd %d\n",id);
#else
CONS_Printf("\2Net Command fail\n");
#endif
return;
}
localtextcmd2[0]++;
localtextcmd2[localtextcmd2[0]]=id;
if(param && nparam)
{
memcpy(&localtextcmd2[localtextcmd2[0]+1],param,nparam);
localtextcmd2[0]+=nparam;
}
}
void ExtraDataTicker(void)
{
int i,tic,time;
byte *curpos,*bufferend;
tic=gametic % BACKUPTICS;
for(i=0;i<MAXPLAYERS;i++)
if(playeringame[i])
{
curpos=(byte *)&(textcmds[tic][i]);
bufferend=&curpos[curpos[0]+1];
curpos++;
while(curpos<bufferend)
{
if(*curpos < MAXNETXCMD && listnetxcmd[*curpos])
{
byte id=*curpos;
curpos++;
if(debugfile)
{
fprintf(debugfile,"executing x_cmd %d ply %d",id,i);
time=I_GetTime();
}
(listnetxcmd[id])((char **)&curpos,i);
if(debugfile)
fprintf(debugfile," done\n");
}
else
I_Error("Got unknow net command [%d]=%d (max %d)\n"
,curpos-(byte *)&(textcmds[tic][i])
,*curpos,textcmds[tic][i][0]);
}
}
}
// -----------------------------------------------------------------
// end of extra data function
// -----------------------------------------------------------------
// -----------------------------------------------------------------
// extra data function for lmps
// -----------------------------------------------------------------
// desciption of extradate byte of LEGACY 1.12 not the same of the 1.20
// 1.20 don't have the extradata bits fields but a byte for eatch command
// see XD_xxx in d_netcmd.h
//
// if extradatabit is set, after the ziped tic you find this :
//
// type | description
// ---------+--------------
// byte | size of the extradata
// byte | the extradata (xd) bits : see XD_...
// with this byte you know what parameter folow
// if(xd & XDNAMEANDCOLOR)
// byte | color
// char[MAXPLAYERNAME] | name of the player
// endif
// if(xd & XD_WEAPON_PREF)
// byte | original weapon switch : boolean, true if use the old
// | weapon switch methode
// char[NUMWEAPONS] | the weapon switch priority
// byte | autoaim : true if use the old autoaim system
// endif
boolean AddLmpExtradata(byte **demo_point,int playernum)
{
int tic;
tic=gametic % BACKUPTICS;
if(textcmds[tic][playernum][0]==0)
return false;
memcpy(*demo_point,textcmds[tic][playernum],textcmds[tic][playernum][0]+1);
*demo_point += textcmds[tic][playernum][0]+1;
return true;
}
extern netxcmd_t NameAndColorCmd,WeaponPrefCmd;
void ReadLmpExtraData(byte **demo_pointer,int playernum)
{
unsigned char nextra,ex;
if(!demo_pointer)
{
textcmds[gametic%BACKUPTICS][playernum][0]=0;
return;
}
nextra=**demo_pointer;
if(demoversion==112) // support old demos v1.12
{
int size=0;
char *p=*demo_pointer+1; // skip nextra
textcmds[gametic%BACKUPTICS][playernum][0]=0;
ex=*p++;
if(ex & 1)
{
size=textcmds[gametic%BACKUPTICS][playernum][0];
textcmds[gametic%BACKUPTICS][playernum][size+1]=XD_NAMEANDCOLOR;
memcpy(&textcmds[gametic%BACKUPTICS][playernum][size+2],
p,
MAXPLAYERNAME+1);
p+=MAXPLAYERNAME+1;
textcmds[gametic%BACKUPTICS][playernum][0]+=MAXPLAYERNAME+1+1;
}
if(ex & 2)
{
size=textcmds[gametic%BACKUPTICS][playernum][0];
textcmds[gametic%BACKUPTICS][playernum][size+1]=XD_WEAPONPREF;
memcpy(&textcmds[gametic%BACKUPTICS][playernum][size+2],
p,
NUMWEAPONS+2);
p+=NUMWEAPONS+2;
textcmds[gametic%BACKUPTICS][playernum][0]+=NUMWEAPONS+2+1;
}
nextra--;
}
else
memcpy(textcmds[gametic%BACKUPTICS][playernum],*demo_pointer,nextra+1);
// increment demo pointer
*demo_pointer +=nextra+1;
}
// -----------------------------------------------------------------
// extra data function for lmps
// -----------------------------------------------------------------
//
// CheckAbort
//
int CheckAbort (void)
{
ULONG stoptic;
stoptic = I_GetTime () + TICRATE/4; // wait 0.25 sec
while (I_GetTime() < stoptic)
I_StartTic ();
stoptic = I_GetKey();
if (stoptic==KEY_ESCAPE)
I_Error ("Network game synchronization aborted.");
return stoptic;
}
//
// SendPlayerConfig
//
// send a special packet for declare how many player in local
// used only in arbitratrenetstart()
void SendPlayerConfig(byte mode)
{
netbuffer->packettype=PLAYERCFG;
if (drone)
netbuffer->u.clientcfg.localplayers=0;
else
if (cv_splitscreen.value)
netbuffer->u.clientcfg.localplayers=2;
else
netbuffer->u.clientcfg.localplayers=1;
netbuffer->u.clientcfg.version = VERSION;
netbuffer->u.clientcfg.subversion = SUBVERSION;
netbuffer->u.clientcfg.mode = mode;
doomcom->datalength = sizeof(clientconfig_pak);
HSendPacket(servernode,false,0);
}
void SendServerConfig(char start,boolean notimecheck)
{
int i,playermask=0;
char wadfilename[MAX_WADPATH];
netbuffer->packettype=SERVERCFG;
for(i=0;i<MAXPLAYERS;i++)
if(playeringame[i])
playermask|=1<<i;
netbuffer->u.servercfg.version = VERSION;
netbuffer->u.servercfg.subversion = SUBVERSION;
netbuffer->u.servercfg.session = session;
netbuffer->u.servercfg.serverplayer = serverplayer;
netbuffer->u.servercfg.start = start;
netbuffer->u.servercfg.totalplayernum = doomcom->numplayers;
netbuffer->u.servercfg.playerdetected = playermask;
i=0;
while(wadfiles[i])
{
strcpy(wadfilename,wadfiles[i]->filename);
nameonly(wadfilename);
// 8.3 no lfn to fix
memcpy(netbuffer->u.servercfg.fileneeded[i].name,wadfilename,SFN);
if(notimecheck)
netbuffer->u.servercfg.fileneeded[i].timestamp = 0;
else
netbuffer->u.servercfg.fileneeded[i].timestamp = wadfiles[i]->timestamp;
i++;
}
netbuffer->u.servercfg.fileneedednum=i;
doomcom->datalength = (int)&( ((doomdata_t *)0)->u.servercfg.fileneeded[i]);
// missing : (wads), and new parameters like solidecorps
//sizeof(serverconfig_pak);
// the last with ack
for(i=0;i<doomcom->numnodes;i++)
{
netbuffer->u.servercfg.playernum = nodetoplayer[i];
HSendPacket(i,start,0);
}
}
boolean CL_CheckFiles(boolean notimecheck)
{
int i,j,found;
char wadfilename[MAX_WADPATH];
// the first is the iwad (the main wad file)
strcpy(wadfilename,wadfiles[0]->filename);
nameonly(wadfilename);
if( strnicmp(wadfilename,netbuffer->u.servercfg.fileneeded[0].name,SFN)!=0)
I_Error("You must use the same IWAD file (main wad file)");
for (i=1;i<netbuffer->u.servercfg.fileneedednum;i++)
{
if(devparm) CONS_Printf("searching for %s",netbuffer->u.servercfg.fileneeded[i].name);
// check for allready loaded file
j=1;
found=false;
while(wadfiles[j])
{
strcpy(wadfilename,wadfiles[j]->filename);
nameonly(wadfilename);
if( strnicmp(wadfilename,netbuffer->u.servercfg.fileneeded[i].name,SFN)==0 &&
(notimecheck || wadfiles[j]->timestamp==netbuffer->u.servercfg.fileneeded[i].timestamp || netbuffer->u.servercfg.fileneeded[i].timestamp==0))
{
if(devparm) CONS_Printf(" already loaded\n");
found = true;
break;
}
j++;
}
if(found)
continue;
// load at runtime now
memcpy(wadfilename,netbuffer->u.servercfg.fileneeded[i].name,SFN);
wadfilename[SFN]=0;
if(notimecheck)
j = recsearch(wadfilename,0);
else
j = recsearch(wadfilename,netbuffer->u.servercfg.fileneeded[i].timestamp);
if(j==1)
{
P_AddWadFile(wadfilename);
if(devparm) CONS_Printf(" loaded at runtime\n");
}
else
if(j==2)
{
CONS_Printf("\2File %s found but with differant date\n",wadfilename);
return false; // not found
}
else // j==0
{
CONS_Printf("\2File %s not found\n",wadfilename);
return false; // not found
}
}
return true;
}
// add a player via a node
void SV_AddPlayer(int node,int playernumber)
{
int j;
nodetoplayer[node]=doomcom->numplayers;
// insert in player table
for(j=0;j<playernumber;j++)
{
if(!playeringame[doomcom->numplayers])
{
playeringame[doomcom->numplayers]=true;
playernode[doomcom->numplayers]=node;
CONS_Printf("Player %d is in the game (node %d)\n"
,doomcom->numplayers,node);
doomcom->numplayers++;
}
}
}
typedef enum {
cl_searching,
cl_ready,
cl_notthefiles
} cl_mode_t;
//
// D_ArbitrateNetStart
//
// send player and game config too
void D_ArbitrateNetStart (void)
{
int i;
char start=0;
int ontime=0;
byte cl_mode=cl_searching;
boolean onetime[MAXNETNODES];
boolean notimecheck = M_CheckParm("-notime");
// servernode can be -1 : the client wait a packet from the server to know
// where the server is (dos protocol)
// 32 : le client send a broadcast message and then the server reply
// 0->31 : le client know where the serser is
// for the moment doomcom->numnode is the number of node waited and this don't quit
// until there is no numnodes nodes
if(server)
{
CONS_Printf("Waiting %d nodes...\n",doomcom->numnodes);
noackret=1;
for(i=0;i<MAXNETNODES;i++) onetime[i]=false;
}
else
if(servernode<0 || servernode>MAXNETNODES)
CONS_Printf("Searching the server...\n");
else
CONS_Printf("Contacting the server...\n");
do {
CheckAbort ();
AckTicker();
// server send there config before to be sure to have to player number 0
// this hack because HGetPacket get first local packet then remote packet
if(server && !dedicated)
SendPlayerConfig (cl_ready);
for(i = 10 ; i>0 ; --i)
if( HGetPacket() )
{
if( !server && netbuffer->packettype==SERVERCFG )
{
//
// Client Part
//
// got server config packet
int j;
if( servernode==-1 || servernode>=MAXNETNODES)
servernode=doomcom->remotenode;
nodeingame[(byte)servernode]=true;
if( VERSION != netbuffer->u.servercfg.version &&
SUBVERSION != netbuffer->u.clientcfg.subversion)
I_Error ("Different DOOM versions cannot play a net game!");
session = netbuffer->u.servercfg.session;
serverplayer = netbuffer->u.servercfg.serverplayer;
doomcom->numplayers = netbuffer->u.servercfg.totalplayernum;
if (serverplayer>0)
playernode[serverplayer]=servernode;
if( ontime==0 )
{
ontime=1;
if( CL_CheckFiles(notimecheck) || M_CheckParm("-nofiles") )
cl_mode=cl_ready;
else
cl_mode=cl_notthefiles;
CONS_Printf("Found, waiting Start message...\n");
}
start = netbuffer->u.servercfg.start;
if( netbuffer->u.servercfg.playernum == 0xff )
I_Error("Maximum of player reached\n");
consoleplayer = netbuffer->u.servercfg.playernum;
playernode[consoleplayer]=0;
if( consoleplayer & DRONE )
{
if(!drone)
I_Error("Outch I'am not DRONE\n");
else
consoleplayer &= ~DRONE;
}
for(j=0;j<MAXPLAYERS;j++)
playeringame[j]=(netbuffer->u.servercfg.playerdetected & (1<<j))!=0;
}
if(server && netbuffer->packettype==PLAYERCFG
&& !nodeingame[doomcom->remotenode]
&& netbuffer->u.clientcfg.version==VERSION
&& netbuffer->u.clientcfg.subversion==SUBVERSION) // new node
{
int playernumber=netbuffer->u.clientcfg.localplayers;
//
// Server Part
//
switch(netbuffer->u.clientcfg.mode) {
case cl_searching :
break;
case cl_notthefiles:
if( !onetime[doomcom->remotenode] )
{
CONS_Printf("\2node %d can't join (don't have all the files)\n",doomcom->remotenode);
onetime[doomcom->remotenode]=true;
}
break;
case cl_ready:
if (doomcom->numplayers+playernumber>=MAXPLAYERS)
nodetoplayer[doomcom->remotenode]=0xff; // too much player, refuse joining
else
{
nodeingame[doomcom->remotenode]=true;
playerpernode[doomcom->remotenode]=playernumber;
if (!playernumber) //drone
nodetoplayer[doomcom->remotenode]=0 | DRONE;
else
SV_AddPlayer(doomcom->remotenode,playernumber);
} // players<32
break;
} // switch
} // server
} // if getpacket
// the last is sended with ack
if(server && !start)
{
int i,nodecount=0;
for(i=0;i<MAXNETNODES;i++)
if(nodeingame[i])
nodecount++;
start=(nodecount==doomcom->numnodes);
SendServerConfig(start,notimecheck);
}
// client to server, send also the ack
if(servernode!=-1 && !server)
SendPlayerConfig (cl_mode);
} while (!(
(!server && start)
||(server && AllAckReceived() && start )
)
);
CONS_Printf ("player %i of %i (%i nodes)\n",
consoleplayer+1, doomcom->numplayers, doomcom->numnodes);
#ifdef DEBUGFILE
if(debugfile)
fprintf(debugfile,"Synchronisation Finished, player %i of %i (%i nodes)\n",
consoleplayer+1, doomcom->numplayers, doomcom->numnodes);
#endif
noackret=0;
consoleplayer&= ~DRONE;
displayplayer = consoleplayer;
if( cv_splitscreen.value )
{
secondarydisplayplayer=consoleplayer+1;
multiplayer=1;
}
D_SendPlayerConfig();
// while(HGetPacket());
}
void D_Cleartic(int tic)
{
int i;
for(i=0;i<MAXPLAYERS;i++)
textcmds[tic%BACKUPTICS][i][0]=0;
}
void ExecuteExitCmd(char **cp,int playernum)
{
if(!demoplayback)
{
if( server )
nodeingame[playernode[playernum]] = false;
I_NetFreeNodenum(playernode[playernum]);
}
playeringame[playernum] = false;
CONS_Printf("\2%s left the game\n",player_names[playernum]);
// if (demorecording)
// G_CheckDemoStatus ();
}
void StartTitle (void)
{
int i;
if (demorecording)
G_CheckDemoStatus ();
// reset client/server code
server=true;
firstticstosend=maketic;
localtextcmd[maketic]=0;
localtextcmd2[maketic]=0;
cl_packetmissed=false;
session=0;
D_CloseConnection(); // netgame=false
servernode=0;
for(i=1;i<MAXNETNODES;i++)
nodeingame[i]=0;
nodeingame[0]=true;
// reset game engine
for(i=0;i<BACKUPTICS;i++)
D_Cleartic(i);
CV_SetValue(&cv_deathmatch,0);
CV_SetValue(&cv_splitscreen,0);
CV_SetValue(&cv_respawnmonsters,0);
for(i=1;i<MAXPLAYERS;i++)
playeringame[i] = 0;
playeringame[0]=true;
doomcom->numplayers=1;
nomonsters = false;
consoleplayer=displayplayer=secondarydisplayplayer=0;
D_StartTitle ();
}
void ExecuteQuitCmd(char **cp,int playernum)
{
M_StartMessage("Server have Shutdown\n\nPress Esc",NULL,true);
StartTitle();
}
void Command_GetPlayerNum(void)
{
int i;
for(i=0;i<MAXPLAYERS;i++)
if(playeringame[i])
if(serverplayer==i)
CONS_Printf("\2num:%2d node:%2d %s\n",i,playernode[i],player_names[i]);
else
CONS_Printf("num:%2d node:%2d %s\n",i,playernode[i],player_names[i]);
}
int nametonum(char *name)
{
int playernum,i;
if( strcmp(name,"0")==0 )
return 0;
else
{
playernum=atoi(name);
if(playernum==0)
{
for(i=0;i<MAXPLAYERS;i++)
if(playeringame[i] && strcmp(player_names[i],name)==0)
return i;
CONS_Printf("there is no player named\"%s\"\n",name);
return -1;
}
}
return playernum;
}
void Command_Kick(void)
{
char buf[3];
if (COM_Argc() != 2)
{
CONS_Printf ("kick <playername> or <playernum> : kick a player\n");
return;
}
if(server)
{
buf[0]=nametonum(COM_Argv(1));
if(buf[0]==-1)
return;
buf[1]=1; // message 1 : "go away"
SendNetXCmd(XD_KICK,&buf,2);
}
else
CONS_Printf("You are not the server\n");
}
void Got_KickCmd(char **p,int playernum)
{
int pnum=*(*p)++;
CONS_Printf("%s have been kicked ",player_names[pnum]);
switch(*(*p)++)
{
case 1: CONS_Printf("(Go away)\n");
break;
case 2: CONS_Printf("(Consistancy failure)\n");
break;
}
if(pnum==consoleplayer)
{
StartTitle();
M_StartMessage("You have been kicked by the server\n",NULL,false);
}
else
ExecuteExitCmd(NULL,pnum);
}
CV_PossibleValue_t maxplayers_cons_t[]={{1,"MIN"},{32,"MAX"},{0,NULL}};
consvar_t cv_allownewplayer = {"sv_allownewplayer","1",0,CV_OnOff};
consvar_t cv_maxplayers = {"sv_maxplayers","32",CV_NETVAR,maxplayers_cons_t,NULL,32};
//
// D_CheckNetGame
// Works out player numbers among the net participants
//
void D_ClientServerInit (void)
{
int i;
for (i=0 ; i<MAXNETNODES ; i++)
{
nodeingame[i] = false;
nodetoplayer[i]=0; // not realy but what else ?
nettics[i]=0;
supposedtics[i]=0;
cl_maketic[i]=0;
}
for (i=0 ; i<MAXPLAYERS ; i++)
{
playeringame[i]=false;
playernode[i]=-1;
}
maketic=0;
gametic=0;
neededtic=0;
cl_packetmissed=false;
#ifdef CLIENTPREDICTION
localgametic = 0;
#endif
localtextcmd[0]=0;
localtextcmd2[0]=0;
for(i=0;i<BACKUPTICS;i++)
D_Cleartic(i);
session=0;
consoleplayer = doomcom->consoleplayer;
playernode[consoleplayer]=0;
viewangleoffset=0;
if(M_CheckParm("-left"))
{
drone = true;
viewangleoffset = ANG90;
}
if(M_CheckParm("-right"))
{
drone = true;
viewangleoffset = -ANG90;
}
if(M_CheckParm("-dedicated"))
{
dedicated=true;
nodeingame[0]=true;
serverplayer=-1;
}
else
serverplayer=consoleplayer;
if(server)
servernode=0;
else
if( servernode>=0 && servernode<MAXNETNODES)
nodeingame[(byte)servernode]=true;
RegisterNetXCmd(XD_EXIT,ExecuteExitCmd);
RegisterNetXCmd(XD_QUIT,ExecuteQuitCmd);
COM_AddCommand("getplayernum",Command_GetPlayerNum);
COM_AddCommand("kick",Command_Kick);
#ifdef JOININGAME
CV_RegisterVar (&cv_allownewplayer);
CV_RegisterVar (&cv_maxplayers);
#endif
RegisterNetXCmd(XD_KICK,Got_KickCmd);
doomcom->numplayers=0;
cv_allownewplayer.value=1;
D_ArbitrateNetStart ();
cv_allownewplayer.value=0;
#ifdef DEBUGFILE
if(debugfile)
fprintf(debugfile,"\n-=-=-=-=-=-=-= Game Begin =-=-=-=-=-=-=-\n\n");
#endif
// while(CheckAbort()!=KEY_ENTER);
}
void SendAllTics (void);
void SendClientCmd (void);
void GetPackets (void);
//
// D_QuitNetGame
// Called before quitting to leave a net game
// without hanging the other players
//
void D_QuitNetGame (void)
{
if (!netgame || demoplayback)
return;
#ifdef DEBUGFILE
if (debugfile)
{
fprintf(debugfile,"===========================================================================\n"
" Quiting Game, closing connection\n"
"===========================================================================\n");
}
#endif
if(server)
{
D_Cleartic(maketic); // clear textcmds
textcmds[maketic % BACKUPTICS][0][0]=1;
textcmds[maketic % BACKUPTICS][0][1]=XD_QUIT;
maketic++;
SendAllTics();
}
else
{
SendNetXCmd(XD_EXIT,NULL,0);
if(cv_splitscreen.value)
SendNetXCmd2(XD_EXIT,NULL,0);
SendClientCmd();
}
// wait the ackreturn with timout of 5 Sec
if( netgame )
{
ULONG timout=I_GetTime()+5*TICRATE;
ULONG tictac=I_GetTime();
HGetPacket();
while(timout>I_GetTime() && !AllAckReceived())
{
while(tictac==I_GetTime()) ;
tictac=I_GetTime();
HGetPacket();
AckTicker();
}
}
if (I_NetShutdown)
I_NetShutdown();
#ifdef DEBUGFILE
if (debugfile)
{
fprintf(debugfile,"===========================================================================\n"
" Log finish\n"
"===========================================================================\n");
fclose (debugfile);
}
#endif
}
// used at txtcmds received to check packetsize bound
int TotalTextCmdPerTic(int tic)
{
int i,total=1; // num of textcmds per tic
tic %= BACKUPTICS;
for(i=0;i<MAXPLAYERS;i++)
if( textcmds[tic][i][0] )
total += (textcmds[tic][i][0] + 2); // size and playernum
return total;
}
//
// GetPackets
//
void GetPackets (void)
{
int netconsole;
ULONG realend,realstart;
int p=maketic%BACKUPTICS;
byte *pak,*txtpak,numtxtpak;
int node;
while ( HGetPacket() )