void vlog2file(int prepend_time, char *filename, char *format, va_list args) { FILE *fp; time_t lt; char buf[40]; lt = time(NULL); *buf = '\0'; if ((fp = fopen(filename, "ab")) == NULL) { fprintf(stderr, "Unable to open %s!\n", filename); if (prepend_time) fprintf(stderr, "%.16s: ", ctime(<)); vfprintf(stderr, format, args); } else { if (prepend_time) { #ifndef WIN32 format_time(buf, 32, "%c", localtime(<)); #else format_time(buf, 32, "%c", uw32localtime(<)); #endif fprintf(fp, "%.32s: ", buf); } vfprintf(fp, format, args); fprintf(fp, "\n"); fclose(fp); } }
const char * mfn_ftime(MFUNARGS) { time_t lt; struct tm *tm; if (argc == 3) { lt = atol(argv[2]); } else { time(<); } if (argc > 1 && *argv[1]) { int offval = atoi(argv[1]); if (offval < 25 && offval > -25) { lt += 3600 * offval; } else { lt -= offval; } lt += get_tz_offset(); } #ifndef WIN32 tm = localtime(<); #else tm = uw32localtime(<); #endif format_time(buf, BUFFER_LEN - 1, argv[0], tm); return buf; }
const char * CrT_timestr(time_t when) { static char buf[20]; struct tm *da_time; #ifndef WIN32 da_time = localtime(&when); #else da_time = uw32localtime(&when); #endif snprintf(buf, sizeof(buf), "%02d%02d%02d%02d", da_time->tm_mday, da_time->tm_hour, da_time->tm_min, da_time->tm_sec); return buf; }
void interp_err(dbref player, dbref program, struct inst *pc, struct inst *arg, int atop, dbref origprog, const char *msg1, const char *msg2) { char buf[BUFFER_LEN]; char buf2[BUFFER_LEN]; char tbuf[40]; int errcount; time_t lt; err++; if (OWNER(origprog) == OWNER(player)) { strcpyn(buf, sizeof(buf), "\033[1;31;40mProgram Error. Your program just got the following error.\033[0m"); } else { snprintf(buf, sizeof(buf), "\033[1;31;40mProgrammer Error. Please tell %s what you typed, and the following message.\033[0m", NAME(OWNER(origprog))); } notify_nolisten(player, buf, 1); snprintf(buf, sizeof(buf), "\033[1m%s(#%d), line %d; %s: %s\033[0m", NAME(program), program, pc ? pc->line : -1, msg1, msg2); notify_nolisten(player, buf, 1); lt = time(NULL); #ifndef WIN32 format_time(tbuf, 32, "%c", localtime(<)); #else format_time(tbuf, 32, "%c", uw32localtime(<)); #endif strip_ansi(buf2, buf); errcount = get_property_value(origprog, ".debug/errcount"); errcount++; add_property(origprog, ".debug/errcount", NULL, errcount); add_property(origprog, ".debug/lasterr", buf2, 0); add_property(origprog, ".debug/lastcrash", NULL, (int)lt); add_property(origprog, ".debug/lastcrashtime", tbuf, 0); if (origprog != program) { errcount = get_property_value(program, ".debug/errcount"); errcount++; add_property(program, ".debug/errcount", NULL, errcount); add_property(program, ".debug/lasterr", buf2, 0); add_property(program, ".debug/lastcrash", NULL, (int)lt); add_property(program, ".debug/lastcrashtime", tbuf, 0); } }
const char * mfn_date(MFUNARGS) { time_t lt; struct tm *tm; lt = time((time_t*) NULL); if (argc == 1) { lt += (3600 * atoi(argv[0])); lt += get_tz_offset(); } #ifndef WIN32 tm = localtime(<); #else tm = uw32localtime(<); #endif format_time(buf, BUFFER_LEN - 1, "%D", tm); return buf; }
void log_user(dbref player, dbref program, char *logmessage) { char logformat[BUFFER_LEN]; char buf[40]; time_t lt = 0; int len = 0; *buf='\0'; *logformat='\0'; lt=time(NULL); #ifndef WIN32 format_time(buf, 32, "%c", localtime(<)); #else format_time(buf, 32, "%c", uw32localtime(<)); #endif snprintf(logformat,BUFFER_LEN,"%s(#%d) [%s(#%d)] at %.32s: ", NAME(player), player, NAME(program), program, buf); len = BUFFER_LEN - strlen(logformat)-1; strncat (logformat, logmessage, len); strip_evil_characters(logformat); log2file(USER_LOG,"%s",logformat); }