-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.c
1858 lines (1492 loc) · 39.4 KB
/
common.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
/*
Copyright (C) 1996-1997 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
$Id: common.c,v 1.108 2007-10-13 15:36:55 cokeman1982 Exp $
*/
#include "common.h"
#ifdef _WIN32
#include <direct.h>
#include <shlobj.h>
#include <errno.h>
#else
#include <stdio.h>
#include <unistd.h>
#endif
#include "quakedef.h"
#include "utils.h"
#include "gl_model.h"
#include "teamplay.h"
#include "crc.h"
#include "stats_grid.h"
#include "tp_triggers.h"
#include "fs.h"
typedef struct commandline_option_s {
const char* name;
int position;
} commandline_option_t;
#define CMDLINE_DEF(x, str) { str, 0 }
static commandline_option_t commandline_parameters[num_cmdline_params] = {
#include "cmdline_params_ids.h"
};
#undef CMDLINE_DEF
const char* Cmd_CommandLineParamName(cmdline_param_id id)
{
return commandline_parameters[id].name;
}
void Draw_BeginDisc (void);
void Draw_EndDisc (void);
#define MAX_NUM_ARGVS 50
usercmd_t nullcmd; // guaranteed to be zero
static char *largv[MAX_NUM_ARGVS + 1];
cvar_t developer = {"developer", "0"};
cvar_t host_mapname = {"mapname", "", CVAR_ROM};
qbool com_serveractive = false;
/*
All of Quake's data access is through a hierarchic file system, but the contents of the file system can be transparently merged from several sources.
The "base directory" is the path to the directory holding the quake.exe and all game directories. The sys_* files pass this to host_init in quakeparms_t->basedir. This can be overridden with the "-basedir" command line parm to allow code debugging in a different directory. The base directory is
only used during filesystem initialization.
The "game directory" is the first tree on the search path and directory that all generated files (savegames, screenshots, demos, config files) will be saved to. This can be overridden with the "-game" command line parameter. The game directory can never be changed while quake is executing. This is a precacution against having a malicious server instruct clients to write files over areas they shouldn't.
*/
//============================================================================
void COM_StoreOriginalCmdline (int argc, char **argv)
{
char buf[4096]; // enough?
int i;
buf[0] = 0;
strlcat (buf, " ", sizeof (buf));
for (i=0; i < argc; i++)
strlcat (buf, argv[i], sizeof (buf));
com_args_original = Q_strdup (buf);
}
//============================================================================
const char *COM_SkipPath (const char *pathname)
{
const char *last;
const char *p;
last = p = pathname;
while (*p)
{
if (*p == '/' || *p == '\\')
last = p + 1;
p++;
}
return last;
}
//============================================================================
char *COM_SkipPathWritable (char *pathname)
{
char *last;
char *p;
last = p = pathname;
while (*p)
{
if (*p == '/' || *p == '\\')
last = p + 1;
p++;
}
return last;
}
//
// Makes a path fit in a specified sized string "c:\quake\bla\bla\bla" => "c:\quake...la\bla"
//
char *COM_FitPath(char *dest, int destination_size, char *src, int size_to_fit)
{
if (!src)
{
return dest;
}
if (size_to_fit > destination_size)
{
size_to_fit = destination_size;
}
if (strlen(src) <= size_to_fit)
{
// Entire path fits in the destination.
strlcpy(dest, src, destination_size);
}
else
{
#define DOT_SIZE 3
#define MIN_LEFT_SIZE 3
int right_size = 0;
int left_size = 0;
int temp = 0;
char *right_dir = COM_SkipPathWritable(src);
// Get the size of the right-most part of the path (filename/directory).
right_size = strlen (right_dir);
// Try to fit the dir/filename if possible.
temp = right_size + DOT_SIZE + MIN_LEFT_SIZE;
right_size = (temp > size_to_fit) ? abs(right_size - (temp - size_to_fit)) : right_size;
// Let the left have the rest.
left_size = size_to_fit - right_size - DOT_SIZE;
// Only let the left have 35% of the total size.
left_size = min (left_size, Q_rint(0.35 * size_to_fit));
// Get the final right size.
right_size = size_to_fit - left_size - DOT_SIZE - 1;
// Make sure we don't have negative values,
// because then our safety checks won't work.
left_size = max (0, left_size);
right_size = max (0, right_size);
if (left_size < destination_size)
{
strlcpy (dest, src, destination_size);
strlcpy (dest + left_size, "...", destination_size);
if (left_size + DOT_SIZE + right_size < destination_size)
{
strlcpy (dest + left_size + DOT_SIZE, src + strlen(src) - right_size, right_size + 1);
}
}
}
return dest;
}
void COM_StripExtension (const char *in, char *out, int out_size)
{
char *dot;
if (in != out)
strlcpy (out, in, out_size);
dot = strrchr (out, '.');
if (dot) {
*dot = 0;
}
}
char *COM_FileExtension (const char *in)
{
static char exten[8];
int i;
if (!(in = strrchr(in, '.')))
return "";
in++;
for (i = 0 ; i < 7 && *in ; i++,in++)
exten[i] = *in;
exten[i] = 0;
return exten;
}
//
// Extract file name without extension, to be used for hunk tags (up to 32 characters, including trailing zero)
//
void COM_FileBase (const char *in, char *out)
{
const char *start, *end;
int length;
if (!(end = strrchr(in, '.')))
end = in + strlen(in);
if (!(start = strrchr(in, '/')))
start = in;
else
start += 1;
length = end - start;
if (length < 0)
strcpy (out, "?empty filename?");
else if (length == 0)
out[0] = 0;
else {
if (length > 31)
length = 31;
memcpy (out, start, length);
out[length] = 0;
}
}
//
// If path doesn't have a .EXT, append extension (extension should include the .)
//
void COM_DefaultExtension (char *path, char *extension)
{
char *src;
src = path + strlen(path) - 1;
while (*src != '/' && src != path) {
if (*src == '.')
return; // it has an extension
src--;
}
strlcat (path, extension, MAX_OSPATH);
}
// If path doesn't have an extension or has a different extension, append(!) specified extension
// Extension should include the .
// path buffer supposed to be MAX_OSPATH size
void COM_ForceExtension (char *path, char *extension)
{
char *src;
src = path + strlen(path) - strlen(extension);
if (src >= path && !strcmp(src, extension))
return;
strlcat (path, extension, MAX_OSPATH);
}
// If path doesn't have an extension or has a different extension, append(!) specified extension
// a bit extended version of COM_ForceExtension(), we suply size of path, so append safe, sure if u provide right path size
void COM_ForceExtensionEx (char *path, char *extension, size_t path_size)
{
char *src;
if (path_size < 1 || path_size <= strlen (extension)) // too small buffer, can't even theoreticaly append extension
Sys_Error("COM_ForceExtensionEx: internall error"); // this is looks like a bug, be fatal then
src = path + strlen (path) - strlen (extension);
if (src >= path && !strcmp (src, extension))
return; // seems we alredy have this extension
strlcat (path, extension, path_size);
src = path + strlen (path) - strlen (extension);
if (src >= path && !strcmp (src, extension))
return; // seems we succeed
Com_Printf ("Failed to force extension %s for %s\n", extension, path); // its good to know about failure
}
//
// Get the path of a temporary directory.
// Returns length of the path or negative value if error.
//
int COM_GetTempDir(char *buf, int bufsize)
{
int returnval = 0;
#ifdef WIN32
returnval = GetTempPath (bufsize, buf);
if (returnval > bufsize || returnval == 0) {
return -1;
}
#else // UNIX
char *tmp;
if (!(tmp = getenv ("TMPDIR")))
tmp = P_tmpdir; // defined at <stdio.h>
returnval = strlen (tmp);
if (returnval > bufsize || returnval == 0) {
return -1;
}
strlcpy (buf, tmp, bufsize);
#endif // WIN32
return returnval;
}
qbool COM_WriteToUniqueTempFileVFS(char* path, int path_buffer_size, const char* ext, vfsfile_t* input)
{
size_t bytes = VFS_GETLEN(input);
byte* buffer = Q_malloc(bytes);
vfserrno_t err;
qbool result;
if (!buffer) {
return false;
}
VFS_READ(input, buffer, (int)bytes, &err);
VFS_SEEK(input, 0, SEEK_SET);
result = COM_WriteToUniqueTempFile(path, path_buffer_size, ext, buffer, bytes);
Q_free(buffer);
return result;
}
//
// Get a unique temp filename.
// Returns negative value on failure.
//
qbool COM_WriteToUniqueTempFile(char *path, int path_buffer_size, const char* ext, const byte* buffer, size_t bytes)
{
char temp_path[MAX_OSPATH];
if (ext == NULL) {
ext = "";
}
// Get the path to temporary directory
if (COM_GetTempDir(temp_path, sizeof(temp_path)) < 0) {
return false;
}
#ifdef _WIN32
{
GUID guid;
char* dot = "";
dot = (ext[0] && ext[0] != '.' ? "." : "");
if (path_buffer_size < MAX_PATH) {
return false;
}
if (CoCreateGuid(&guid) == S_OK) {
if (path_buffer_size > snprintf(path, path_buffer_size, "%s\\%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X%s%s", temp_path, guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7], dot, ext)) {
FS_WriteFile_2(path, buffer, (int)bytes);
return true;
}
}
return false;
}
#else
{
int fd = 0;
strlcat(path, "/ezquakeXXXXXX", path_buffer_size);
if (ext[0]) {
int ext_len = 0;
if (ext[0] != '.') {
strlcat(path, ".", path_buffer_size);
strlcat(path, ext, path_buffer_size);
ext_len = strlen(ext) + 1;
}
else {
strlcat(path, ext, path_buffer_size);
ext_len = strlen(ext);
}
fd = mkstemps(path, ext_len);
}
else {
fd = mkstemp(path);
}
if (fd < 0) {
return false;
}
write(fd, buffer, bytes);
close(fd);
return true;
}
#endif
}
qbool COM_FileExists (char *path)
{
FILE *fexists = NULL;
// Try opening the file to see if it exists.
fexists = fopen(path, "rb");
// The file exists.
if (fexists)
{
// Make sure the file is closed.
fclose (fexists);
return true;
}
return false;
}
char com_token[MAX_COM_TOKEN];
static int com_argc;
static char **com_argv;
char *com_args_original;
com_tokentype_t com_tokentype;
//Parse a token out of a string
const char* COM_ParseEx(const char *data, qbool curlybraces)
{
unsigned char c;
int len;
int quotes;
len = 0;
com_token[0] = 0;
if (!data) {
return NULL;
}
// skip whitespace
while (true) {
while ((c = *data) == ' ' || c == '\t' || c == '\r' || c == '\n') {
data++;
}
if (c == 0) {
return NULL; // end of file;
}
// skip // comments
if (c == '/' && data[1] == '/') {
while (*data && *data != '\n') {
data++;
}
}
else {
break;
}
}
// handle quoted strings specially
if (c == '\"' || (c == '{' && curlybraces) ) {
if (c == '{') {
quotes = 1;
}
else {
quotes = -1;
}
data++;
while (1) {
c = *data;
data++;
if (quotes < 0) {
if (c == '\"') {
quotes++;
}
}
else {
if (c == '}' && curlybraces) {
quotes--;
}
else if (c == '{' && curlybraces) {
quotes++;
}
}
if (!quotes || !c) {
com_token[len] = 0;
return c ? data : data - 1;
}
com_token[len] = c;
len++;
if (len >= sizeof(com_token) - 1) {
return NULL; // quoted section too long
}
}
}
// parse a regular word
do {
com_token[len] = c;
data++;
len++;
if (len >= sizeof(com_token) - 1) {
break;
}
c = *data;
} while (c && c != ' ' && c != '\t' && c != '\n' && c != '\r');
com_token[len] = 0;
return data;
}
const char* COM_Parse(const char* data)
{
return COM_ParseEx(data, false);
}
#define DEFAULT_PUNCTUATION "(,{})(\':;=!><&|+"
char *COM_ParseToken (const char *data, const char *punctuation)
{
int c;
int len;
if (!punctuation)
punctuation = DEFAULT_PUNCTUATION;
len = 0;
com_token[0] = 0;
if (!data)
{
com_tokentype = TTP_UNKNOWN;
return NULL;
}
// skip whitespace
skipwhite:
while ((c = *(unsigned char *) data) <= ' ')
{
if (c == 0)
{
com_tokentype = TTP_UNKNOWN;
return NULL; // end of file;
}
data++;
}
// skip // comments
if (c == '/')
{
if (data[1] == '/')
{
while (*data && *data != '\n')
data++;
goto skipwhite;
}
else if (data[1] == '*')
{
data += 2;
while (*data && (*data != '*' || data[1] != '/'))
data++;
data += 2;
goto skipwhite;
}
}
// handle quoted strings specially
if (c == '\"')
{
com_tokentype = TTP_STRING;
data++;
while (1)
{
if (len >= MAX_COM_TOKEN - 1)
{
com_token[len] = '\0';
return (char*) data;
}
c = *data++;
if (c=='\"' || !c)
{
com_token[len] = 0;
return (char*) data;
}
com_token[len] = c;
len++;
}
}
com_tokentype = TTP_UNKNOWN;
// parse single characters
if (strchr (punctuation, c))
{
com_token[len] = c;
len++;
com_token[len] = 0;
return (char*) (data + 1);
}
// parse a regular word
do
{
if (len >= MAX_COM_TOKEN - 1)
break;
com_token[len] = c;
data++;
len++;
c = *data;
if (strchr (punctuation, c))
break;
} while (c > 32);
com_token[len] = 0;
return (char*) data;
}
//Adds the given string at the end of the current argument list
void COM_AddParm (char *parm)
{
if (com_argc >= MAX_NUM_ARGVS)
return;
largv[com_argc++] = parm;
}
//Returns the position (1 to argc-1) in the program's argument list
//where the given parameter appears, or 0 if not present
int COM_FindParm(const char* parm)
{
int i;
for (i = 1; i < com_argc; i++) {
if (!strcmp(parm, com_argv[i])) {
return i;
}
}
return 0;
}
int COM_CheckParm(cmdline_param_id id)
{
if (id < 0 || id >= num_cmdline_params) {
return 0;
}
return commandline_parameters[id].position;
}
//Tei: added cos -data feature use it.
int COM_CheckParmOffset(cmdline_param_id id, int offset)
{
int i;
const char* parm;
if (id < 0 || id >= num_cmdline_params) {
return 0;
}
parm = commandline_parameters[id].name;
for (i = offset; i < com_argc; i++) {
// NEXTSTEP sometimes clears appkit vars.
if (!com_argv[i]) {
continue;
}
if (!strcmp(parm, com_argv[i])) {
return i;
}
}
return 0;
}
//qbism// 1999-12-23 Multiple "-data" parameters by Maddes end
int COM_Argc (void)
{
return com_argc;
}
char *COM_Argv(int arg)
{
if (arg < 0 || arg >= com_argc) {
return "";
}
return com_argv[arg];
}
void COM_ClearArgv(int arg)
{
if (arg < 0 || arg >= com_argc) {
return;
}
com_argv[arg] = "";
}
void COM_InitArgv(int argc, char **argv)
{
int id;
int i;
for (i = 0, com_argc = 0; com_argc < MAX_NUM_ARGVS - 1 && i < argc; ++i) {
if (argv[i]) {
// follow qw urls if they are our argument without a +qwurl command
if (!strncmp(argv[i], "qw://", 5) && (i == 0 || strncmp(argv[i - 1], "+qwurl", 6)) && com_argc < MAX_NUM_ARGVS - 1) {
largv[com_argc++] = "+qwurl";
largv[com_argc++] = argv[i];
}
else {
largv[com_argc++] = argv[i];
}
}
else {
largv[com_argc++] = "";
}
}
largv[com_argc] = "";
com_argv = largv;
for (id = 0; id < num_cmdline_params; ++id) {
commandline_parameters[id].position = COM_FindParm(commandline_parameters[id].name);
}
}
void COM_Init(void)
{
Cvar_SetCurrentGroup(CVAR_GROUP_NO_GROUP);
Cvar_Register(&developer);
Cvar_Register(&host_mapname);
Cvar_ResetCurrentGroup();
}
//does a varargs printf into a temp buffer, so I don't need to have varargs versions of all text functions.
char *va(const char *format, ...)
{
va_list argptr;
static char string[32][2048];
static int idx = 0;
idx++;
if (idx == 32) {
idx = 0;
}
va_start (argptr, format);
vsnprintf (string[idx], sizeof(string[idx]), format, argptr);
va_end (argptr);
return string[idx];
}
// equals to consecutive calls of strtok(s, " ") that assign values to array
int COM_GetFloatTokens(const char *s, float *fl_array, int fl_array_size)
{
int i;
if (!s || !*s) return 0;
for(i = 0; *s && i < fl_array_size; i++)
{
fl_array[i] = atof(s);
while(*s && *s != ' ') s++; // skips the number
while(*s && *s == ' ') s++; // skips the spaces
}
return i;
}
/*
=====================================================================
INFO STRINGS
=====================================================================
*/
//Searches the string for the given key and returns the associated value, or an empty string.
char *Info_ValueForKey (char *s, char *key) {
char pkey[512];
static char value[4][512]; // use two buffers so compares work without stomping on each other
static int valueindex;
char *o;
valueindex = (valueindex + 1) % 4;
if (*s == '\\')
s++;
while (1) {
o = pkey;
while (*s != '\\') {
if (!*s)
return "";
*o++ = *s++;
}
*o = 0;
s++;
o = value[valueindex];
while (*s != '\\' && *s) {
if (!*s)
return "";
*o++ = *s++;
}
*o = 0;
if (!strcmp (key, pkey) )
return value[valueindex];
if (!*s)
return "";
s++;
}
}
void Info_RemoveKey (char *s, char *key) {
char *start, pkey[512], value[512], *o;
if (strchr (key, '\\')) {
Com_Printf ("Can't use a key with a \\\n");
return;
}
while (1) {
start = s;
if (*s == '\\')
s++;
o = pkey;
while (*s != '\\') {
if (!*s)
return;
*o++ = *s++;
}
*o = 0;
s++;
o = value;
while (*s != '\\' && *s) {
if (!*s)
return;
*o++ = *s++;
}
*o = 0;
if (!strcmp (key, pkey) ) {
Q_strcpy (start, s); // remove this part
return;
}
if (!*s)
return;
}
}
void Info_RemovePrefixedKeys (char *start, char prefix) {
char *s, pkey[512], value[512], *o;
s = start;
while (1) {
if (*s == '\\')
s++;
o = pkey;
while (*s != '\\') {
if (!*s)
return;
*o++ = *s++;
}
*o = 0;
s++;
o = value;
while (*s != '\\' && *s) {
if (!*s)
return;
*o++ = *s++;
}
*o = 0;
if (pkey[0] == prefix) {
Info_RemoveKey (start, pkey);
s = start;
}
if (!*s)
return;
}
}
void Info_SetValueForStarKeyEx (char *s, char *key, char *value, int maxsize, qbool max_info_key_check)
{
char new[1024], *v;
int c;
#ifndef CLIENTONLY
// extern cvar_t sv_highchars;
#endif
if (strchr (key, '\\') || strchr (value, '\\') ) {
Com_Printf ("Can't use keys or values with a \\\n");
return;
}
if (strchr (key, '\"') || strchr (value, '\"') ) {
Com_Printf ("Can't use keys or values with a \"\n");
return;
}
if (max_info_key_check)
{
if (strlen(key) >= MAX_INFO_KEY || strlen(value) >= MAX_INFO_KEY)
{
Com_Printf ("Keys and values must be < %i characters.\n", MAX_INFO_KEY);
return;
}
}
// this next line is kinda trippy
if (*(v = Info_ValueForKey(s, key))) {
// key exists, make sure we have enough room for new value, if we don't,
// don't change it!
if ((int) (strlen(value) - strlen(v) + strlen(s)) >= maxsize) {
Com_Printf ("Info string length exceeded\n");
return;
}
}
Info_RemoveKey (s, key);
if (!value || !strlen(value))
return;
snprintf (new, sizeof (new), "\\%s\\%s", key, value);
if ((int) (strlen(new) + strlen(s)) >= maxsize) {
Com_Printf ("Info string length exceeded\n");
return;
}
// only copy ascii values
s += strlen(s);
v = new;
#ifndef CLIENTONLY
// if (!sv_highchars.value) {
// while (*v) {
// c = (unsigned char)*v++;
// if (c == ('\\'|128))
// continue;
// c &= 127;
// if (c >= 32)
// *s++ = c;