]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/gamelog.qc
Merge branch 'master' into Mario/q3_speaker_fix
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / gamelog.qc
1 #include "gamelog.qh"
2
3 #include <server/autocvars.qh>
4 #include <server/miscfunctions.qh>
5
6 string GameLog_ProcessIP(string s)
7 {
8         if(!autocvar_sv_eventlog_ipv6_delimiter)
9                 return s;
10         return strreplace(":", "_", s);
11 }
12
13 void GameLogEcho(string s)
14 {
15         if (autocvar_sv_eventlog_files)
16         {
17                 if (!logfile_open)
18                 {
19                         logfile_open = true;
20                         int matches = autocvar_sv_eventlog_files_counter + 1;
21                         cvar_set("sv_eventlog_files_counter", itos(matches));
22                         string fn = ftos(matches);
23                         if (strlen(fn) < 8)
24                                 fn = strcat(substring("00000000", 0, 8 - strlen(fn)), fn);
25                         fn = strcat(autocvar_sv_eventlog_files_nameprefix, fn, autocvar_sv_eventlog_files_namesuffix);
26                         logfile = fopen(fn, FILE_APPEND);
27                         fputs(logfile, ":logversion:3\n");
28                 }
29                 if (logfile >= 0)
30                 {
31                         if (autocvar_sv_eventlog_files_timestamps)
32                                 fputs(logfile, strcat(":time:", strftime(true, "%Y-%m-%d %H:%M:%S", "\n", s, "\n")));
33                         else
34                                 fputs(logfile, strcat(s, "\n"));
35                 }
36         }
37         if (autocvar_sv_eventlog_console)
38         {
39                 dedicated_print(strcat(s, "\n"));
40         }
41 }
42
43 void GameLogInit()
44 {
45         logfile_open = false;
46         // will be opened later
47 }
48
49 void GameLogClose()
50 {
51         if (logfile_open && logfile >= 0)
52         {
53                 fclose(logfile);
54                 logfile = -1;
55         }
56 }