]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/gamec/miscfunctions.c
Added logging support for rune match; logging is now called "event log".
[divverent/nexuiz.git] / data / qcsrc / server / gamec / miscfunctions.c
1 string W_Name(float weaponid);
2 float(float index) weapon_translateindextoflag;
3
4 float logfile_open;
5 float logfile;
6
7 void(string s, float check_dangerous) ServerConsoleEcho =
8 {
9         local string ch;
10         localcmd("echo \"");
11         if(check_dangerous)
12         {
13                 while(strlen(s))
14                 {
15                         ch = substring(s, 0, 1);
16                         if(ch != "\"" && ch != "\r" && ch != "\n")
17                                 localcmd(ch);
18                         s = substring(s, 1, strlen(s) - 1);
19                 }
20         }
21         else
22         {
23                 localcmd(s);
24         }
25         localcmd("\"\n");
26 }
27
28 void(string s, float check_dangerous) GameLogEcho =
29 {
30         string fn;
31         float matches;
32
33         if(cvar("sv_eventlog_files"))
34         {
35                 if(!logfile_open)
36                 {
37                         logfile_open = TRUE;
38                         matches = cvar("sv_eventlog_files_counter") + 1;
39                         cvar_set("sv_eventlog_files_counter", ftos(matches));
40                         fn = ftos(matches);
41                         if(strlen(fn) < 8)
42                                 fn = strcat(substring("00000000", 0, 8 - strlen(fn)), fn);
43                         fn = strcat(cvar_string("sv_eventlog_files_nameprefix"), fn, cvar_string("sv_eventlog_files_namesuffix"));
44                         logfile = fopen(fn, FILE_APPEND);
45                         dprint(strcat("\n\n\n\n**********\nlogfile id: ", ftos(logfile), "\n\n\n"));
46                 }
47                 if(logfile >= 0)
48                         fputs(logfile, strcat(s, "\n"));
49         }
50         if(cvar("sv_eventlog_console"))
51         {
52                 ServerConsoleEcho(s, check_dangerous);
53         }
54 }
55
56 void() GameLogInit =
57 {
58         logfile_open = 0;
59         // will be opened later
60 }
61
62 void() GameLogClose =
63 {
64         if(logfile_open && logfile >= 0)
65         {
66                 fclose(logfile);
67                 logfile = -1;
68         }
69 }
70
71 float math_mod(float a, float b)
72 {
73         return a - (floor(a / b) * b);
74 }
75
76 string linewrap(string s, float l)
77 {
78         string t;
79
80         t = "";
81         while(l < strlen(s))
82         {
83                 t = strcat(t, substring(s, 0, l), "\n");
84                 s = substring(s, l+1, strlen(s));
85         }
86         return strcat(t, s);
87 }