123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- #define BUILDING_OPENDOORS
- #include <stdio.h>
- #include <time.h>
- #include "OpenDoor.h"
- #include "ODCore.h"
- #include "ODGen.h"
- #include "ODInEx.h"
- #include "ODKrnl.h"
- static FILE *logfile_pointer;
- static BOOL ODLogWriteStandardMsg(INT nLogfileMessage);
- static void ODLogClose(INT nReason);
- ODAPIDEF void ODCALL ODLogEnable(void)
- {
-
- od_log_open();
- }
- ODAPIDEF BOOL ODCALL od_log_open()
- {
- time_t nUnixTime;
- struct tm *ptmTimeRecord;
-
- TRACE(TRACE_API, "od_log_open()");
-
- if(!bODInitialized) od_init();
-
- if(od_control.od_logfile_disable) return(TRUE);
-
- if((logfile_pointer=fopen(od_control.od_logfile_name, "a")) == NULL)
- {
- return(FALSE);
- }
-
- nUnixTime = time(NULL);
- ptmTimeRecord = localtime(&nUnixTime);
-
- fprintf(logfile_pointer, "\n---------- %s %02d %s %02d, %s\n",
- od_control.od_day[ptmTimeRecord->tm_wday],
- ptmTimeRecord->tm_mday,
- od_control.od_month[ptmTimeRecord->tm_mon],
- ptmTimeRecord->tm_year,
- od_program_name);
-
- sprintf(szODWorkString, (char *)od_control.od_logfile_messages[11],
- od_control.user_name);
- od_log_write(szODWorkString);
-
-
- pfLogWrite = ODLogWriteStandardMsg;
- pfLogClose = ODLogClose;
- return(TRUE);
- }
- static BOOL ODLogWriteStandardMsg(INT nLogfileMessage)
- {
- if(nLogfileMessage < 0 || nLogfileMessage > 11)
- {
- return(FALSE);
- }
- od_log_write((char *)od_control.od_logfile_messages[nLogfileMessage]);
- if(nLogfileMessage == 8)
- {
- sprintf(szODWorkString, od_control.od_logfile_messages[12],
- od_control.user_reasonforchat);
- szODWorkString[67] = '\0';
- od_log_write(szODWorkString);
- }
- return(TRUE);
- }
- ODAPIDEF BOOL ODCALL od_log_write(char *pszMessage)
- {
- char *pszFormat;
- time_t nUnixTime;
- struct tm *ptmTimeRecord;
-
- if(!bODInitialized) od_init();
- OD_API_ENTRY();
-
- if(od_control.od_logfile_disable)
- {
- OD_API_EXIT();
- return(TRUE);
- }
-
- if(logfile_pointer==NULL)
- {
- if(!od_log_open())
- {
- OD_API_EXIT();
- return(FALSE);
- }
- }
-
- nUnixTime=time(NULL);
- ptmTimeRecord=localtime(&nUnixTime);
-
- if(ptmTimeRecord->tm_hour<10)
- {
- pszFormat=(char *)"> %1.1d:%02d:%02d %s\n";
- }
- else
- {
- pszFormat=(char *)"> %2.2d:%02d:%02d %s\n";
- }
-
- fprintf(logfile_pointer, pszFormat, ptmTimeRecord->tm_hour,
- ptmTimeRecord->tm_min, ptmTimeRecord->tm_sec, pszMessage);
- OD_API_EXIT();
- return(TRUE);
- }
- static void ODLogClose(INT nReason)
- {
-
- if(od_control.od_logfile_disable) return;
-
- if(logfile_pointer==NULL) return;
- if(bPreOrExit)
- {
- od_log_write((char *)od_control.od_logfile_messages[13]);
- }
- else if(btExitReason<=5 && btExitReason>=1)
- {
- od_log_write((char *)od_control.od_logfile_messages[btExitReason-1]);
- }
- else
- {
- sprintf(szODWorkString,(char *)od_control.od_logfile_messages[5],nReason);
- od_log_write(szODWorkString);
- }
-
- fclose(logfile_pointer);
-
- pfLogWrite = NULL;
- pfLogClose = NULL;
- logfile_pointer = NULL;
- }
|