-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhost_cmd.c
2590 lines (2198 loc) · 55.2 KB
/
host_cmd.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
/*
* $Header: /H2 Mission Pack/Host_cmd.c 25 4/01/98 4:53p Jmonroe $
*/
#include "quakedef.h"
#include <windows.h>
#include <time.h>
extern cvar_t pausable;
extern cvar_t sv_flypitch;
extern cvar_t sv_walkpitch;
int current_skill;
static double old_time;
void Mod_Print (void);
void SaveGamestate(qboolean ClientsOnly);
int LoadGamestate(char *level, char *startspot, int ClientsMode);
void RestoreClients(void);
// EER1
void R_ClearParticles (void);
UINT info_mask, info_mask2;
#define TESTSAVE
/*
==================
Host_Quit_f
==================
*/
extern void M_Menu_Quit_f (void);
void Host_Quit_f (void)
{
if (key_dest != key_console && cls.state != ca_dedicated)
{
M_Menu_Quit_f ();
return;
}
CL_Disconnect ();
Host_ShutdownServer(false);
Sys_Quit (0);
}
/*
==================
Host_Status_f
==================
*/
void Host_Status_f (void)
{
client_t *client;
int seconds;
int minutes;
int hours = 0;
int j;
void (*print) (char *fmt, ...);
if (cmd_source == src_command)
{
if (!sv.active)
{
Cmd_ForwardToServer ();
return;
}
print = Con_Printf;
}
else
print = SV_ClientPrintf;
print ("host: %s\n", Cvar_VariableString ("hostname"));
print ("version: %4.2f\n", VERSION);
if (tcpipAvailable)
print ("tcp/ip: %s\n", my_tcpip_address);
print ("map: %s\n", sv.name);
print ("players: %i active (%i max)\n\n", net_activeconnections, svs.maxclients);
for (j=0, client = svs.clients ; j<svs.maxclients ; j++, client++)
{
if (!client->active)
continue;
seconds = (int)(net_time - client->netconnection->connecttime);
minutes = seconds / 60;
if (minutes)
{
seconds -= (minutes * 60);
hours = minutes / 60;
if (hours)
minutes -= (hours * 60);
}
else
hours = 0;
print ("#%-2u %-16.16s %3i %2i:%02i:%02i\n", j+1, client->name, (int)client->edict->v.frags, hours, minutes, seconds);
print (" %s\n", client->netconnection->address);
}
}
/*
==================
Host_God_f
Sets client to godmode
==================
*/
void Host_God_f (void)
{
if (cmd_source == src_command)
{
Cmd_ForwardToServer ();
return;
}
if (PR_GLOBAL_STRUCT(deathmatch) || PR_GLOBAL_STRUCT(coop))
return;
sv_player->v.flags = (int)sv_player->v.flags ^ FL_GODMODE;
if (!((int)sv_player->v.flags & FL_GODMODE) )
SV_ClientPrintf ("godmode OFF\n");
else
SV_ClientPrintf ("godmode ON\n");
}
void Host_Notarget_f (void)
{
if (cmd_source == src_command)
{
Cmd_ForwardToServer ();
return;
}
if (PR_GLOBAL_STRUCT(deathmatch) || PR_GLOBAL_STRUCT(coop))
return;
sv_player->v.flags = (int)sv_player->v.flags ^ FL_NOTARGET;
if (!((int)sv_player->v.flags & FL_NOTARGET) )
SV_ClientPrintf ("notarget OFF\n");
else
SV_ClientPrintf ("notarget ON\n");
}
/*
==================
Host_Noclip_f
Sets client to noclip mode
==================
*/
void Host_Noclip_f (void)
{
if (cmd_source == src_command)
{
Cmd_ForwardToServer ();
return;
}
if (PR_GLOBAL_STRUCT(deathmatch) || PR_GLOBAL_STRUCT(coop))
return;
if (sv_player->v.movetype != MOVETYPE_NOCLIP)
{
cl.noclip_anglehack = true;
sv_player->v.movetype = MOVETYPE_NOCLIP;
SV_ClientPrintf ("noclip ON\n");
}
else
{
cl.noclip_anglehack = false;
sv_player->v.movetype = MOVETYPE_WALK;
SV_ClientPrintf ("noclip OFF\n");
}
}
/*
==================
Host_Ping_f
==================
*/
void Host_Ping_f (void)
{
int i, j;
float total;
client_t *client;
if (cmd_source == src_command)
{
Cmd_ForwardToServer ();
return;
}
SV_ClientPrintf ("Client ping times:\n");
for (i=0, client = svs.clients ; i<svs.maxclients ; i++, client++)
{
if (!client->active)
continue;
total = 0;
for (j=0 ; j<NUM_PING_TIMES ; j++)
total+=client->ping_times[j];
total /= NUM_PING_TIMES;
SV_ClientPrintf ("%4i %s\n", (int)(total*1000), client->name);
}
}
/*
===============================================================================
SERVER TRANSITIONS
===============================================================================
*/
/*
======================
Host_Map_f
handle a
map <servername>
command from the console. Active clients are kicked off.
======================
*/
void Host_Map_f (void)
{
int i;
char name[MAX_QPATH];
if (Cmd_Argc()<2) //no map name given
{
Con_Printf ("map <levelname>: start a new server\nCurrently on: %s\n",cl.levelname);
Con_Printf ("%s\n",cls.mapstring);
return;
}
if (cmd_source != src_command)
return;
cls.demonum = -1; // stop demo loop in case this fails
CL_Disconnect ();
Host_ShutdownServer(false);
key_dest = key_game; // remove console or menu
SCR_BeginLoadingPlaque ();
info_mask = 0;
if (!coop.value && deathmatch.value)
info_mask2 = 0x80000000;
else
info_mask2 = 0;
cls.mapstring[0] = 0;
for (i=0 ; i<Cmd_Argc() ; i++)
{
strcat (cls.mapstring, Cmd_Argv(i));
strcat (cls.mapstring, " ");
}
strcat (cls.mapstring, "\n");
svs.serverflags = 0; // haven't completed an episode yet
strcpy (name, Cmd_Argv(1));
SV_SpawnServer (name, NULL);
if (!sv.active)
return;
if (cls.state != ca_dedicated)
{
loading_stage = 2;
strcpy (cls.spawnparms, "");
for (i=2 ; i<Cmd_Argc() ; i++)
{
strcat (cls.spawnparms, Cmd_Argv(i));
strcat (cls.spawnparms, " ");
}
Cmd_ExecuteString ("connect local", src_command);
}
}
/*
==================
Host_Changelevel_f
Goes to a new map, taking all clients along
==================
*/
void Host_Changelevel_f (void)
{
char level[MAX_QPATH];
char _startspot[MAX_QPATH];
char *startspot;
int i;
if (Cmd_Argc() < 2)
{
Con_Printf ("changelevel <levelname> : continue game on a new level\n");
return;
}
if (!sv.active || cls.demoplayback)
{
Con_Printf ("Only the server may changelevel\n");
return;
}
// check for client having map before anything else
sprintf (level, "maps/%s.bsp", Cmd_Argv(1));
if (COM_OpenFile (level, &i, NULL) == -1)
Host_Error ("cannot find map %s", level);
strcpy (level, Cmd_Argv(1));
if (Cmd_Argc() == 2)
startspot = NULL;
else
{
strcpy (_startspot, Cmd_Argv(2));
startspot = _startspot;
}
SV_SaveSpawnparms ();
SV_SpawnServer (level, startspot);
}
/*
==================
Host_Restart_f
Restarts the current server for a dead player
==================
*/
void Host_Restart_f (void)
{
char mapname[MAX_QPATH];
char startspot[MAX_QPATH];
if (cls.demoplayback || !sv.active)
return;
if (cmd_source != src_command)
return;
strcpy (mapname, sv.name); // must copy out, because it gets cleared
strcpy(startspot, sv.startspot);
if (Cmd_Argc() == 2 && strcmpi(Cmd_Argv(1),"restore") == 0)
{
if (LoadGamestate (mapname, startspot, 3))
{
SV_SpawnServer (mapname, startspot);
RestoreClients();
}
}
else
{
// in sv_spawnserver
SV_SpawnServer (mapname, startspot);
}
}
/*
==================
Host_Reconnect_f
This command causes the client to wait for the signon messages again.
This is sent just before a server changes levels
==================
*/
void Host_Reconnect_f (void)
{
R_ClearParticles (); //jfm: for restarts which didn't use to clear parts.
if (oem.value && cl.intermission == 9)
{
CL_Disconnect();
return;
}
SCR_BeginLoadingPlaque ();
cls.signon = 0; // need new connection messages
}
/*
=====================
Host_Connect_f
User command to connect to server
=====================
*/
void Host_Connect_f (void)
{
char name[MAX_QPATH];
cls.demonum = -1; // stop demo loop in case this fails
if (cls.demoplayback)
{
CL_StopPlayback ();
CL_Disconnect ();
}
strcpy (name, Cmd_Argv(1));
CL_EstablishConnection (name);
Host_Reconnect_f ();
}
/*
===============================================================================
LOAD / SAVE GAME
===============================================================================
*/
#define SAVEGAME_VERSION 5
#define ShortTime "%m/%d/%Y %H:%M"
char name[MAX_OSPATH],dest[MAX_OSPATH],tempdir[MAX_OSPATH];
/*
===============
Host_SavegameComment
Writes a SAVEGAME_COMMENT_LENGTH character comment describing the current
===============
*/
void Host_SavegameComment (char *text)
{
int i;
char kills[20];
struct tm *tblock;
time_t TempTime;
for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
text[i] = ' ';
memcpy (text, cl.levelname, strlen(cl.levelname));
// sprintf (kills,"kills:%3i/%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
TempTime = time(NULL);
tblock = localtime(&TempTime);
strftime(kills,sizeof(kills),ShortTime,tblock);
memcpy (text+21, kills, strlen(kills));
// convert space to _ to make stdio happy
for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
if (text[i] == ' ')
text[i] = '_';
text[SAVEGAME_COMMENT_LENGTH] = '\0';
}
/*
===============
Host_Savegame_f
===============
*/
void Host_Savegame_f (void)
{
FILE *f;
int i;
char comment[SAVEGAME_COMMENT_LENGTH+1];
// char name[MAX_OSPATH],dest[MAX_OSPATH],tempdir[MAX_OSPATH];
qboolean error_state = false;
int attempts = 0;
char *message;
if (cmd_source != src_command)
return;
if (!sv.active)
{
Con_Printf ("Not playing a local game.\n");
return;
}
if (cl.intermission)
{
Con_Printf ("Can't save in intermission.\n");
return;
}
#ifndef TESTSAVE
if (svs.maxclients != 1)
{
Con_Printf ("Can't save multiplayer games.\n");
return;
}
#endif
if (Cmd_Argc() != 2)
{
Con_Printf ("save <savename> : save a game\n");
return;
}
if (strstr(Cmd_Argv(1), ".."))
{
Con_Printf ("Relative pathnames are not allowed.\n");
return;
}
for (i=0 ; i<svs.maxclients ; i++)
{
if (svs.clients[i].active && (svs.clients[i].edict->v.health <= 0) )
{
Con_Printf ("Can't savegame with a dead player\n");
return;
}
}
SaveGamestate(false);
retry:
attempts++;
sprintf (name, "%s/%s", com_savedir, Cmd_Argv(1));
Sys_mkdir (name);
CL_RemoveGIPFiles(name);
i = GetTempPath(sizeof(tempdir),tempdir);
if (!i)
{
sprintf(tempdir,"%s\\",com_savedir);
}
sprintf (name, "%sclients.gip",tempdir);
DeleteFile(name);
sprintf (name, "%s*.gip", tempdir);
sprintf (dest, "%s/%s/",com_savedir, Cmd_Argv(1));
Con_Printf ("Saving game to %s...\n", dest);
error_state = CL_CopyFiles(tempdir, name, dest);
sprintf(dest,"%s/%s/info.dat",com_savedir, Cmd_Argv(1));
f = fopen (dest, "w");
if (!f)
{
Con_Printf ("ERROR: couldn't open.\n");
return;
}
fprintf (f, "%i\n", SAVEGAME_VERSION);
Host_SavegameComment (comment);
fprintf (f, "%s\n", comment);
for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
fprintf (f, "%f\n", svs.clients->spawn_parms[i]);
fprintf (f, "%d\n", current_skill);
fprintf (f, "%s\n", sv.name);
fprintf (f, "%f\n", sv.time);
fprintf (f, "%d\n", svs.maxclients);
fprintf (f, "%f\n", deathmatch.value);
fprintf (f, "%f\n", coop.value);
fprintf (f, "%f\n", teamplay.value);
fprintf (f, "%f\n", randomclass.value);
fprintf (f, "%f\n", cl_playerclass.value);
fprintf (f, "%d\n", info_mask);
fprintf (f, "%d\n", info_mask2);
if (ferror(f))
error_state = true;
fclose(f);
if (error_state)
{
if (attempts == 1)
message = "The game could not be saved properly. You may be out of hard drive space! You can ALT-TAB out to try and free up some space. Type 'Y' if you want to try and re-save the game, otherwise 'N' to ignore.";
else
message = "The game could not be saved properly on the previous attempt. You may be out of hard drive space! You can ALT-TAB out to try and free up some space. Type 'Y' if you want to try and re-save the game, otherwise 'N' to ignore.";
key_lastpress = 0;
if (SCR_ModalMessage(message))
{
goto retry;
}
}
}
/*
===============
Host_Loadgame_f
===============
*/
void Host_Loadgame_f (void)
{
FILE *f;
char mapname[MAX_QPATH];
float time, tfloat;
char str[32768];
int i;
edict_t *ent;
int version;
float tempf;
int tempi;
float spawn_parms[NUM_SPAWN_PARMS];
// char name[MAX_OSPATH],dest[MAX_OSPATH],tempdir[MAX_OSPATH];
qboolean error_state = false;
int attempts = 0;
char *message;
if (cmd_source != src_command)
return;
if (Cmd_Argc() != 2)
{
Con_Printf ("load <savename> : load a game\n");
return;
}
cls.demonum = -1; // stop demo loop in case this fails
CL_Disconnect();
CL_RemoveGIPFiles(NULL);
sprintf (name, "%s/%s", com_savedir, Cmd_Argv(1));
Con_Printf ("Loading game from %s...\n", name);
i = GetTempPath(sizeof(tempdir),tempdir);
if (!i)
{
sprintf(tempdir,"%s\\",com_savedir);
}
sprintf(dest,"%s/info.dat",name);
f = fopen (dest, "r");
if (!f)
{
Con_Printf ("ERROR: couldn't open.\n");
return;
}
fscanf (f, "%i\n", &version);
if (version != SAVEGAME_VERSION)
{
fclose (f);
Con_Printf ("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
return;
}
fscanf (f, "%s\n", str);
for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
fscanf (f, "%f\n", &spawn_parms[i]);
// this silliness is so we can load 1.06 save files, which have float skill values
fscanf (f, "%f\n", &tfloat);
current_skill = (int)(tfloat + 0.1);
Cvar_SetValue ("skill", (float)current_skill);
Cvar_SetValue ("deathmatch", 0);
Cvar_SetValue ("coop", 0);
Cvar_SetValue ("teamplay", 0);
Cvar_SetValue ("randomclass", 0);
fscanf (f, "%s\n",mapname);
fscanf (f, "%f\n",&time);
tempi = -1;
fscanf (f, "%d\n",&tempi);
if (tempi >= 1)
svs.maxclients = tempi;
tempf = -1;
fscanf (f, "%f\n",&tempf);
if (tempf >= 0)
Cvar_SetValue ("deathmatch", tempf);
tempf = -1;
fscanf (f, "%f\n",&tempf);
if (tempf >= 0)
Cvar_SetValue ("coop", tempf);
tempf = -1;
fscanf (f, "%f\n",&tempf);
if (tempf >= 0)
Cvar_SetValue ("teamplay", tempf);
tempf = -1;
fscanf (f, "%f\n",&tempf);
if (tempf >= 0)
Cvar_SetValue ("randomclass", tempf);
tempf = -1;
fscanf (f, "%f\n",&tempf);
if (tempf >= 0)
Cvar_SetValue ("cl_playerclass", tempf);
fscanf (f, "%d\n",&info_mask);
fscanf (f, "%d\n",&info_mask2);
fclose (f);
CL_RemoveGIPFiles(tempdir);
retry:
attempts++;
sprintf (name, "%s/%s/*.gip", com_savedir, Cmd_Argv(1));
sprintf (dest, "%s/%s/",com_savedir, Cmd_Argv(1));
strcat(tempdir,"/");
error_state = CL_CopyFiles(dest, name, tempdir);
if (error_state)
{
if (attempts == 1)
message = "The game could not be loaded properly. You may be out of hard drive space! You can ALT-TAB out to try and free up some space. Type 'Y' if you want to try and re-load the game, otherwise 'N' to abort.";
else
message = "The game could not be loaded properly on the previous attempt. You may be out of hard drive space! You can ALT-TAB out to try and free up some space. Type 'Y' if you want to try and re-load the game, otherwise 'N' to abort.";
key_lastpress = 0;
if (SCR_ModalMessage(message))
{
goto retry;
}
else
return;
}
LoadGamestate (mapname, NULL, 2);
SV_SaveSpawnparms ();
ent = EDICT_NUM(1);
Cvar_SetValue ("cl_playerclass", ent->v.playerclass);//this better be the same as above...
// this may be rudundant with the setting in PR_LoadProgs, but not sure so its here too
if (progs->crc == PROGS_V112_CRC)
pr_global_struct->cl_playerclass = ent->v.playerclass;
svs.clients->playerclass = ent->v.playerclass;
sv.paused = true; // pause until all clients connect
sv.loadgame = true;
if (cls.state != ca_dedicated)
{
CL_EstablishConnection ("local");
Host_Reconnect_f ();
}
}
void SaveGamestate(qboolean ClientsOnly)
{
// char name[MAX_OSPATH],tempdir[MAX_OSPATH];
FILE *f;
int i;
char comment[SAVEGAME_COMMENT_LENGTH+1];
edict_t *ent;
int start,end;
qboolean error_state = false;
int attempts = 0;
char *message;
retry:
attempts++;
i = GetTempPath(sizeof(tempdir),tempdir);
if (!i)
{
sprintf(tempdir,"%s\\",com_savedir);
}
if (ClientsOnly)
{
start = 1;
end = svs.maxclients+1;
sprintf (name, "%sclients.gip",tempdir);
}
else
{
start = 1;
end = sv.num_edicts;
sprintf (name, "%s%s.gip", tempdir, sv.name);
// Con_Printf ("Saving game to %s...\n", name);
}
f = fopen (name, "w");
if (!f)
{
Con_Printf ("ERROR: couldn't open.\n");
return;
}
fprintf (f, "%i\n", SAVEGAME_VERSION);
if (!ClientsOnly)
{
Host_SavegameComment (comment);
fprintf (f, "%s\n", comment);
// for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
// fprintf (f, "%f\n", svs.clients->spawn_parms[i]);
fprintf (f, "%f\n", skill.value);
fprintf (f, "%s\n", sv.name);
fprintf (f, "%f\n", sv.time);
// fprintf (f, "%d\n", info_mask);
// fprintf (f, "%d\n", info_mask2);
// write the light styles
for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
{
if (sv.lightstyles[i])
fprintf (f, "%s\n", sv.lightstyles[i]);
else
fprintf (f,"m\n");
}
SV_SaveEffects(f);
fprintf(f,"-1\n");
ED_WriteGlobals (f);
}
else
{
/*fprintf(f, "%d\n", info_mask);
fprintf(f, "%d\n", info_mask2);*/
}
host_client = svs.clients;
// for (i=svs.maxclients+1 ; i<sv.num_edicts ; i++)
// to save the client states
for (i=start ; i<end ; i++)
{
ent = EDICT_NUM(i);
if ((int)ent->v.flags & FL_ARCHIVE_OVERRIDE)
continue;
if (ClientsOnly)
{
if (host_client->active)
{
fprintf (f, "%i\n",i);
ED_Write (f, ent);
//fflush (f); // Baker change (fflush is a major slowdown, let alone running it hundreds of times)
}
host_client++;
}
else
{
fprintf (f, "%i\n",i);
ED_Write (f, ent);
//fflush (f); // Baker change (fflush is a major slowdown, let alone running it hundreds of times)
}
}
if (ferror(f))
{
error_state = true;
}
fclose (f);
if (error_state)
{
if (attempts == 1)
message = "The level could not be saved properly. You may be out of hard drive space! You can ALT-TAB out to try and free up some space. Type 'Y' if you want to try and re-save the level, otherwise 'N' to ignore.";
else
message = "The level could not be saved properly on the previous attempt. You may be out of hard drive space! You can ALT-TAB out to try and free up some space. Type 'Y' if you want to try and re-save the level, otherwise 'N' to ignore.";
key_lastpress = 0;
if (SCR_ModalMessage(message))
{
goto retry;
}
}
}
void RestoreClients(void)
{
int i,j;
edict_t *ent;
double time_diff;
if (LoadGamestate(NULL,NULL,1))
return;
time_diff = sv.time - old_time;
for (i=0,host_client = svs.clients ; i<svs.maxclients ; i++, host_client++)
{
if (host_client->active)
{
ent = host_client->edict;
//ent->v.colormap = NUM_FOR_EDICT(ent);
ent->v.team = (host_client->colors & 15) + 1;
ent->v.netname = host_client->name - pr_strings;
ent->v.playerclass = host_client->playerclass;
if (is_progdefs111)
{
// copy spawn parms out of the client_t
for (j = 0; j < NUM_SPAWN_PARMS; j++)
(&pr_global_struct_v111->parm1)[j] = host_client->spawn_parms[j];
// call the spawn function
pr_global_struct_v111->time = sv.time;
pr_global_struct_v111->self = EDICT_TO_PROG(ent);
G_FLOAT(OFS_PARM0) = time_diff;
PR_ExecuteProgram (pr_global_struct_v111->ClientReEnter);
}
else
{
// copy spawn parms out of the client_t
for (j=0 ; j< NUM_SPAWN_PARMS ; j++)
(&pr_global_struct->parm1)[j] = host_client->spawn_parms[j];
// call the spawn function
pr_global_struct->time = sv.time;
pr_global_struct->self = EDICT_TO_PROG(ent);
G_FLOAT(OFS_PARM0) = time_diff;
PR_ExecuteProgram (pr_global_struct->ClientReEnter);
}
}
}
SaveGamestate(true);
}
int LoadGamestate(char *level, char *startspot, int ClientsMode)
{
// char name[MAX_OSPATH],tempdir[MAX_OSPATH];
FILE *f;
char mapname[MAX_QPATH];
float time, sk;
char str[32768], *start;
int i, r;
edict_t *ent;
int entnum;
int version;
// float spawn_parms[NUM_SPAWN_PARMS];
qboolean auto_correct = false;
i = GetTempPath(sizeof(tempdir),tempdir);
if (!i)
{
sprintf(tempdir,"%s\\",com_savedir);
}
if (ClientsMode == 1)
{
sprintf (name, "%sclients.gip",tempdir);
}
else
{
sprintf (name, "%s%s.gip", tempdir, level);
if (ClientsMode != 2 && ClientsMode != 3)
Con_Printf ("Loading game from %s...\n", name);
}
f = fopen (name, "r");
if (!f)
{
if (ClientsMode == 2)
Con_Printf ("ERROR: couldn't open.\n");
return -1;
}
fscanf (f, "%i\n", &version);
if (version != SAVEGAME_VERSION)
{
fclose (f);
Con_Printf ("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
return -1;
}
if (ClientsMode != 1)
{
fscanf (f, "%s\n", str);
// for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
// fscanf (f, "%f\n", &spawn_parms[i]);
fscanf (f, "%f\n", &sk);
Cvar_SetValue ("skill", sk);
fscanf (f, "%s\n", mapname);
fscanf (f, "%f\n", &time);
SV_SpawnServer (mapname, startspot);
if (!sv.active)
{
Con_Printf ("Couldn't load map\n");
return -1;
}