2 * $Logfile: /Freespace2/code/Network/multi_log.cpp $
7 * Header file to support multiplayer logging functions
10 * Revision 1.2 2002/05/07 03:16:47 theoddone33
11 * The Great Newline Fix
13 * Revision 1.1.1.1 2002/05/03 03:28:10 root
17 * 8 8/17/99 2:24p Dave
18 * Fixed wacky squad color stuff.
20 * 7 6/07/99 9:51p Dave
21 * Consolidated all multiplayer ports into one.
23 * 6 4/27/99 2:59p Dave
24 * Potential fix for reliable socket connection problem.
26 * 5 4/09/99 2:21p Dave
27 * Multiplayer beta stuff. CD checking.
29 * 4 1/24/99 11:37p Dave
30 * First full rev of beam weapons. Very customizable. Removed some bogus
31 * Int3()'s in low level net code.
33 * 3 11/19/98 4:19p Dave
34 * Put IPX sockets back in psnet. Consolidated all multiplayer config
37 * 2 10/07/98 10:53a Dave
40 * 1 10/07/98 10:50a Dave
42 * 3 8/21/98 1:14p Dave
43 * Put in log system hooks in useful places.
45 * 2 8/20/98 5:31p Dave
46 * Put in handy multiplayer logfile system. Now need to put in useful
47 * applications of it all over the code.
49 * 1 8/20/98 2:00p Dave
57 #include "multi_log.h"
58 #include "multi_options.h"
62 // ----------------------------------------------------------------------------------------------------
63 // MULTI LOGFILE DEFINES/VARS
66 // max length for a line of the logfile
67 #define MAX_LOGFILE_LINE_LEN 256
69 // name of the multiplayer logfile
70 #define MULTI_LOGFILE_NAME "multi.log"
72 // echo all ml_printf's to the debug window
73 #define MULTI_LOGFILE_ECHO_TO_DEBUG
75 // how often we'll write an update to the logfile (in seconds)
76 #define MULTI_LOGFILE_UPDATE_TIME 2520 // every 42 minutes
79 CFILE *Multi_log_out = NULL;
81 // time when the logfile was opened
82 int Multi_log_open_systime = -1;
84 // time when we last updated the logfile
85 int Multi_log_update_systime = -1;
87 // ----------------------------------------------------------------------------------------------------
88 // MULTI LOGFILE FUNCTIONS
91 // write the standard header to the logfile
92 void multi_log_write_header()
99 strftime(str, 1024, "Freespace Multi Log - Opened %a, %b %d, %Y at %I:%M%p\n----\n----\n----\n\n", localtime(&timer));
103 // write the standard shutdown trailer
104 void multi_log_write_trailer()
111 strftime(str, 1024, "\n\n----\n----\n----\nFreespace Multi Log - Closing on %a, %b %d, %Y at %I:%M%p", localtime(&timer));
115 // write out some info about stuff
116 void multi_log_write_update()
118 int diff = (int)difftime(time(NULL), Multi_log_open_systime);
119 int hours, mins, seconds;
121 // figure out some time values
123 mins = (diff - (hours * 3600)) / 60;
124 seconds = (diff - (hours * 3600) - (mins * 60));
127 ml_printf("Server has been active for %d hours, %d minutes, and %d seconds", hours, mins, seconds);
130 // initialize the multi logfile
131 void multi_log_init()
133 // attempt to open the file
134 Multi_log_out = cfopen(MULTI_LOGFILE_NAME, "wt", CFILE_NORMAL, CF_TYPE_DATA);
136 // if we successfully opened the file, write the header
137 if(Multi_log_out != NULL){
138 multi_log_write_header();
140 // initialize our timer info
141 Multi_log_open_systime = time(NULL);
142 Multi_log_update_systime = Multi_log_open_systime;
144 nprintf(("Network","Error opening %s for writing!!\n",MULTI_LOGFILE_NAME));
148 // close down the multi logfile
149 void multi_log_close()
151 // if we have a valid file, write a trailer and close
152 if(Multi_log_out != NULL){
153 multi_log_write_trailer();
155 cfclose(Multi_log_out);
156 Multi_log_out = NULL;
160 // give some processing time to the logfile system so it can check up on stuff
161 void multi_log_process()
163 // if we don't have a valid logfile, do nothing
164 if(Multi_log_out == NULL){
168 // check to see if we've been active a long enough time, and
169 if(time(NULL) - Multi_log_update_systime > MULTI_LOGFILE_UPDATE_TIME){
171 multi_log_write_update();
173 Multi_log_update_systime = time(NULL);
177 // printf function itself called by the ml_printf macro
178 void ml_printf(char *format, ...)
180 char tmp[MAX_LOGFILE_LINE_LEN*4];
183 // if we don't have a valid logfile do nothing
184 if(Multi_log_out == NULL){
189 va_start(args, format);
190 vsprintf(tmp, format, args);
197 // string print function
198 void ml_string(char *string, int add_time)
200 char tmp[MAX_LOGFILE_LINE_LEN*4];
204 // if we don't have a valid logfile do nothing
205 if(Multi_log_out == NULL){
209 // if the passed string is NULL, do nothing
214 // maybe add the time
218 strftime(time_str, 128, "%m/%d %H:%M:%S~ ", localtime(&timer));
219 strcpy(tmp, time_str);
226 // now print it to the logfile if necessary
227 cfputs(tmp, Multi_log_out);
228 cflush(Multi_log_out);
230 #if defined(MULTI_LOGFILE_ECHO_TO_DEBUG)
231 // nprintf(("Network","%s\n",tmp));
232 mprintf(("ML %s", tmp));