2 * $Logfile: /Freespace2/code/Network/multi_log.cpp $
7 * Header file to support multiplayer logging functions
10 * Revision 1.1 2002/05/03 03:28:10 root
14 * 8 8/17/99 2:24p Dave
15 * Fixed wacky squad color stuff.
17 * 7 6/07/99 9:51p Dave
18 * Consolidated all multiplayer ports into one.
20 * 6 4/27/99 2:59p Dave
21 * Potential fix for reliable socket connection problem.
23 * 5 4/09/99 2:21p Dave
24 * Multiplayer beta stuff. CD checking.
26 * 4 1/24/99 11:37p Dave
27 * First full rev of beam weapons. Very customizable. Removed some bogus
28 * Int3()'s in low level net code.
30 * 3 11/19/98 4:19p Dave
31 * Put IPX sockets back in psnet. Consolidated all multiplayer config
34 * 2 10/07/98 10:53a Dave
37 * 1 10/07/98 10:50a Dave
39 * 3 8/21/98 1:14p Dave
40 * Put in log system hooks in useful places.
42 * 2 8/20/98 5:31p Dave
43 * Put in handy multiplayer logfile system. Now need to put in useful
44 * applications of it all over the code.
46 * 1 8/20/98 2:00p Dave
54 #include "multi_log.h"
55 #include "multi_options.h"
59 // ----------------------------------------------------------------------------------------------------
60 // MULTI LOGFILE DEFINES/VARS
63 // max length for a line of the logfile
64 #define MAX_LOGFILE_LINE_LEN 256
66 // name of the multiplayer logfile
67 #define MULTI_LOGFILE_NAME "multi.log"
69 // echo all ml_printf's to the debug window
70 #define MULTI_LOGFILE_ECHO_TO_DEBUG
72 // how often we'll write an update to the logfile (in seconds)
73 #define MULTI_LOGFILE_UPDATE_TIME 2520 // every 42 minutes
76 CFILE *Multi_log_out = NULL;
78 // time when the logfile was opened
79 int Multi_log_open_systime = -1;
81 // time when we last updated the logfile
82 int Multi_log_update_systime = -1;
84 // ----------------------------------------------------------------------------------------------------
85 // MULTI LOGFILE FUNCTIONS
88 // write the standard header to the logfile
89 void multi_log_write_header()
96 strftime(str, 1024, "Freespace Multi Log - Opened %a, %b %d, %Y at %I:%M%p\n----\n----\n----\n\n", localtime(&timer));
100 // write the standard shutdown trailer
101 void multi_log_write_trailer()
108 strftime(str, 1024, "\n\n----\n----\n----\nFreespace Multi Log - Closing on %a, %b %d, %Y at %I:%M%p", localtime(&timer));
112 // write out some info about stuff
113 void multi_log_write_update()
115 int diff = (int)difftime(time(NULL), Multi_log_open_systime);
116 int hours, mins, seconds;
118 // figure out some time values
120 mins = (diff - (hours * 3600)) / 60;
121 seconds = (diff - (hours * 3600) - (mins * 60));
124 ml_printf("Server has been active for %d hours, %d minutes, and %d seconds", hours, mins, seconds);
127 // initialize the multi logfile
128 void multi_log_init()
130 // attempt to open the file
131 Multi_log_out = cfopen(MULTI_LOGFILE_NAME, "wt", CFILE_NORMAL, CF_TYPE_DATA);
133 // if we successfully opened the file, write the header
134 if(Multi_log_out != NULL){
135 multi_log_write_header();
137 // initialize our timer info
138 Multi_log_open_systime = time(NULL);
139 Multi_log_update_systime = Multi_log_open_systime;
141 nprintf(("Network","Error opening %s for writing!!\n",MULTI_LOGFILE_NAME));
145 // close down the multi logfile
146 void multi_log_close()
148 // if we have a valid file, write a trailer and close
149 if(Multi_log_out != NULL){
150 multi_log_write_trailer();
152 cfclose(Multi_log_out);
153 Multi_log_out = NULL;
157 // give some processing time to the logfile system so it can check up on stuff
158 void multi_log_process()
160 // if we don't have a valid logfile, do nothing
161 if(Multi_log_out == NULL){
165 // check to see if we've been active a long enough time, and
166 if(time(NULL) - Multi_log_update_systime > MULTI_LOGFILE_UPDATE_TIME){
168 multi_log_write_update();
170 Multi_log_update_systime = time(NULL);
174 // printf function itself called by the ml_printf macro
175 void ml_printf(char *format, ...)
177 char tmp[MAX_LOGFILE_LINE_LEN*4];
180 // if we don't have a valid logfile do nothing
181 if(Multi_log_out == NULL){
186 va_start(args, format);
187 vsprintf(tmp, format, args);
194 // string print function
195 void ml_string(char *string, int add_time)
197 char tmp[MAX_LOGFILE_LINE_LEN*4];
201 // if we don't have a valid logfile do nothing
202 if(Multi_log_out == NULL){
206 // if the passed string is NULL, do nothing
211 // maybe add the time
215 strftime(time_str, 128, "%m/%d %H:%M:%S~ ", localtime(&timer));
216 strcpy(tmp, time_str);
223 // now print it to the logfile if necessary
224 cfputs(tmp, Multi_log_out);
225 cflush(Multi_log_out);
227 #if defined(MULTI_LOGFILE_ECHO_TO_DEBUG)
228 // nprintf(("Network","%s\n",tmp));
229 mprintf(("ML %s", tmp));