diff options
-rw-r--r-- | src/astar.h | 7 | ||||
-rw-r--r-- | src/gui/char_select.cpp | 14 | ||||
-rw-r--r-- | src/gui/char_server.cpp | 5 | ||||
-rw-r--r-- | src/gui/login.cpp | 14 | ||||
-rw-r--r-- | src/log.cpp | 184 | ||||
-rw-r--r-- | src/log.h | 11 | ||||
-rw-r--r-- | src/net/protocol.cpp | 5 |
7 files changed, 68 insertions, 172 deletions
diff --git a/src/astar.h b/src/astar.h index 4a9fa045..e5cc3809 100644 --- a/src/astar.h +++ b/src/astar.h @@ -1,9 +1,10 @@ +#ifndef _ASTAR_H +#define _ASTAR_H + #ifdef WIN32 #pragma warning (disable:4312) #endif -#include <allegro.h> - #include "map.h" #include "being.h" @@ -22,4 +23,4 @@ void RenderScreen (bool stepByStep=false); PATH_NODE *find_path(int pathfinderID,int startingX, int startingY, int targetX, int targetY); void ReadPath(int pathfinderID); - +#endif diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 76a2d01d..1a109836 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -144,10 +144,11 @@ void server_char_select() { WFIFOSET(3); while((in_size<3)||(out_size>0))flush(); - log_hex("Char_Select_Packet", "Packet_ID", RFIFOW(0)); - log_int("Char_Select_Packet", "Packet_length", get_length(RFIFOW(0))); - log_int("Char_Select_Packet", "Packet_in_size", RFIFOW(2)); - log_int("Char_Select_Packet", "In_size", in_size); + log("CharSelect", "Packet ID: %x, Length: %d, Packet_in_size %d", + RFIFOW(0), + get_length(RFIFOW(0)), + RFIFOW(2)); + log("CharSelect", "In_size: %d", in_size); if(RFIFOW(0)==0x0071) { while(in_size<28)flush(); @@ -158,9 +159,8 @@ void server_char_select() { map_port = RFIFOW(26); state = GAME; - log("Player", "map", map_name); - log("Char_Select_packet", "server_address", iptostring(map_address)); - log_int("Char_Select_packet", "server_port", map_port); + log("CharSelect", "Map: %s", map_name); + log("CharSelect", "Server: %s:%d", iptostring(map_address), map_port); RFIFOSKIP(28); close_session(); } else if(RFIFOW(0)==0x006c) { diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp index a90c3d90..7217abd8 100644 --- a/src/gui/char_server.cpp +++ b/src/gui/char_server.cpp @@ -118,9 +118,8 @@ void server_char_server() { } state = CHAR_SELECT; - log("Player", "name", char_info->name); - log_hex("Char_Server_Packet", "Packet_ID", RFIFOW(0)); - log_int("Char_Server_Packet", "Packet_length", RFIFOW(2)); + log("CharServer", "Player: %s (Packet ID: %x, Length: %d", + char_info->name, RFIFOW(0), RFIFOW(2)); RFIFOSKIP(RFIFOW(2)); diff --git a/src/gui/login.cpp b/src/gui/login.cpp index 6e619757..342ea3dd 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -62,7 +62,7 @@ DIALOG login_dialog[] = { if(!username)strcpy(username, "player\0"); set_config_string("login", "username", username); } else set_config_string("login", "username", "player\0"); - log("Player", "username", username); + log("Network", "Username is %s", username); gui_exit = shutdown_dialog(player); if((gui_exit==5)||(key[KEY_ENTER])) { if(username[0]=='\0') { @@ -101,8 +101,8 @@ void server_login() { WFIFOSET(55); while((in_size<23)||(out_size>0))flush(); - log_hex("Login_Packet", "Packet_ID", RFIFOW(0)); - log_int("Login_Packet", "Packet_length", get_packet_length(RFIFOW(0))); + log("Network", "Packet ID: %x", RFIFOW(0)); + log("Network", "Packet length: %d", get_packet_length(RFIFOW(0))); if(RFIFOW(0)==0x0069) { while(in_size<RFIFOW(2))flush(); @@ -119,10 +119,10 @@ void server_login() { server_info[i].port = RFIFOW(47+32*i+4); state = CHAR_SERVER; } - log("Login_Packet", "server_address", iptostring(server_info[0].address)); - log("Login_Packet", "server_name", server_info[0].name); - log_int("Login_Packet", "server_users", server_info[0].online_users); - log_int("Login_Packet", "server_port", server_info[0].port); + log("Network", "Server: %s (%s:%d)", server_info[0].name, + iptostring(server_info[0].address), + server_info[0].port); + log("Network", "Users: %d", server_info[0].online_users); RFIFOSKIP(RFIFOW(2)); } else if(RFIFOW(0)==0x006a) { switch(RFIFOB(2)) { diff --git a/src/log.cpp b/src/log.cpp index f9c42cf7..3fac29e4 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -22,168 +22,68 @@ #include "log.h" int warning_n; // Keep warning number +FILE* logfile; + #define LOG_FILE "./docs/tmw.log" -#define LOG_VERSION "0.3" -void init_log() { -#ifdef WIN32 - remove(LOG_FILE); -#else - unlink(LOG_FILE); -#endif - push_config_state(); - set_config_file(LOG_FILE); -#ifdef WIN32 // for the moment i cant find a valuable unix function for _strdate // Sull - char date[9]; - set_config_string("Core", "date", _strdate(date)); -#endif - set_config_string("Core", "log_version", LOG_VERSION); - set_config_string("Core", "Allegro_ID", allegro_id); - switch(os_type) { - case OSTYPE_UNKNOWN: - set_config_string("Core", "Os", "unknown, or regular MSDOS"); - break; - case OSTYPE_WIN3: - set_config_string("Core", "Os", "Windows 3.1 or earlier"); - break; - case OSTYPE_WIN95: - set_config_string("Core", "Os", "Windows 95"); - break; - case OSTYPE_WIN98: - set_config_string("Core", "Os", "Windows 98"); - break; - case OSTYPE_WINME: - set_config_string("Core", "Os", "Windows ME"); - break; - case OSTYPE_WINNT: - set_config_string("Core", "Os", "Windows NT"); - break; - case OSTYPE_WIN2000: - set_config_string("Core", "Os", "Windows 2000"); - break; - case OSTYPE_WINXP: - set_config_string("Core", "Os", "Windows XP"); - break; - case OSTYPE_OS2: - set_config_string("Core", "Os", "OS/2"); - break; - case OSTYPE_WARP: - set_config_string("Core", "Os", "OS/2 Warp 3"); - break; - case OSTYPE_DOSEMU: - set_config_string("Core", "Os", "Linux DOSEMU"); - break; - case OSTYPE_OPENDOS: - set_config_string("Core", "Os", "Caldera OpenDOS"); - break; - case OSTYPE_LINUX: - set_config_string("Core", "Os", "Linux"); - break; - case OSTYPE_SUNOS: - set_config_string("Core", "Os", "SunOS/Solaris"); - break; - case OSTYPE_FREEBSD: - set_config_string("Core", "Os", "FreeBSD"); - break; - case OSTYPE_NETBSD: - set_config_string("Core", "Os", "NetBSD"); - break; - case OSTYPE_IRIX: - set_config_string("Core", "Os", "IRIX"); - break; - case OSTYPE_QNX: - set_config_string("Core", "Os", "QNX"); - break; - case OSTYPE_UNIX: - set_config_string("Core", "Os", "Unknown Unix variant"); - break; - case OSTYPE_BEOS: - set_config_string("Core", "Os", "BeOS"); - break; - case OSTYPE_MACOS: - set_config_string("Core", "Os", "MacOS"); - break; - default: - set_config_string("Core", "Os", "Unknown"); - break; - } - set_config_int("Core", "Os_version", os_version); - set_config_int("Core", "Os_revision", os_revision); - if(os_multitasking)set_config_string("Core", "Multitasking", "TRUE"); - else set_config_string("Core", "Multitasking", "FALSE"); - - set_config_string("Core", "CPU_Vendor", cpu_vendor); - switch(cpu_family) { - case 3: - set_config_string("Core", "CPU_Family", "386"); - break; - case 4: - set_config_string("Core", "CPU_Family", "486"); - break; - case 5: - set_config_string("Core", "CPU_Family", "Pentium"); - break; - case 6: - set_config_string("Core", "CPU_Family", "Pentium II/III/PRO/Athlon"); - break; - case 15: - set_config_string("Core", "CPU_Family", "Pentium IV"); - break; - default: - set_config_string("Core", "CPU_Family", "Unknown"); - set_config_int("Core", "CPU_Family_ID", cpu_family); - break; - } - - set_config_int("Core", "CPU_model", cpu_model); - - set_config_int("Core", "CPU_capabilities", cpu_capabilities); - pop_config_state(); - - warning_n = 0; -} -void log(const char *log_section, const char *log_name, const char *log_text) { - push_config_state(); - set_config_file(LOG_FILE); - set_config_string(log_section, log_name, log_text); - pop_config_state(); +void init_log() { + logfile = fopen(LOG_FILE, "w"); + if (!logfile) { + printf("Warning: error while opening log file.\n"); + } + warning_n = 0; } -void log_hex(const char *log_section, const char *log_name, const short log_value) { - push_config_state(); - set_config_file(LOG_FILE); - set_config_hex(log_section, log_name, log_value); - pop_config_state(); -} +void log(const char *category, const char *log_text, ...) { + if (logfile) { + char* buf = new char[1024]; + + va_list ap; + va_start(ap, log_text); + vsprintf(buf, log_text, ap); + va_end(ap); + + time_t t; + time(&t); -void log_int(const char *log_section, const char *log_name, const int log_value) { - push_config_state(); - set_config_file(LOG_FILE); - set_config_int(log_section, log_name, log_value); - pop_config_state(); + fprintf( + logfile, + "[%s%d:%s%d:%s%d] %s: %s\n", + (((t / 60) / 60) % 24 < 10) ? "0" : "", + (int)(((t / 60) / 60) % 24), + ((t / 60) % 60 < 10) ? "0" : "", + (int)((t / 60) % 60), + (t % 60 < 10) ? "0" : "", + (int)(t % 60), + category, buf + ); + fflush(logfile); + + delete[] buf; + } } + void error(const char *error_text) { - log("Error", "Last_error", error_text); + log("Error", error_text); + #ifdef WIN32 - MessageBox(NULL, error_text, "Error", MB_ICONERROR|MB_OK); + MessageBox(NULL, error_text, "Error", MB_ICONERROR|MB_OK); #else - printf("Error: %s", error_text); + printf("Error: %s", error_text); #endif - exit(1); + exit(1); } void warning(const char *warning_text) { - char warning_name[40]; - sprintf(warning_name, "warning_%i", warning_n); - log("Error", warning_name, warning_text); + log("Warning", warning_text); } void status(const char *status_text) { #ifdef DEBUG - log("Status", "last_function", status_text); + log("Status", status_text); #endif } @@ -26,16 +26,13 @@ #ifndef _LOG_H #define _LOG_H -#include <allegro.h> -#ifdef WIN32 -#include <winalleg.h> -#endif +#include <stdlib.h> #include <stdio.h> +#include <stdarg.h> +#include <time.h> void init_log(); -void log(const char *log_section, const char *log_name, const char *log_text); -void log_hex(const char *log_section, const char *log_name, const short log_value); -void log_int(const char *log_section, const char *log_name, const int log_value); +void log(const char *category, const char *log_text, ...); void error(const char *error_text); void warning(const char *warning_text); void status(const char *status_text); diff --git a/src/net/protocol.cpp b/src/net/protocol.cpp index 98530a4d..e1c1af9a 100644 --- a/src/net/protocol.cpp +++ b/src/net/protocol.cpp @@ -184,10 +184,9 @@ void map_start() { while(in_size<11)flush(); x = get_x(RFIFOP(6)); y = get_y(RFIFOP(6)); - log_int("Player", "x", x); - log_int("Player", "y", y); //direction = get_direction(RFIFOP(6)); - log_int("Player", "direction", direction); + log("Protocol", "Player position: (%d, %d), Direction: %d", + x, y, direction); RFIFOSKIP(11); } else if(0x0081) { warning("Map server D/C"); |