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