diff options
-rw-r--r-- | src/map/atcommand.c | 68 | ||||
-rw-r--r-- | src/map/atcommand.h | 2 | ||||
-rw-r--r-- | src/map/clif.c | 10 | ||||
-rw-r--r-- | src/map/map.c | 4 |
4 files changed, 82 insertions, 2 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 136617f..4dca224 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -4,6 +4,11 @@ #include <string.h> #include <ctype.h> #include <math.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <time.h> +#include <unistd.h> #include "socket.h" #include "timer.h" @@ -213,6 +218,8 @@ ATCOMMAND_FUNC(unmute); // [Valaris] ATCOMMAND_FUNC(char_wipe); // [Fate] ATCOMMAND_FUNC(set_magic); // [Fate] ATCOMMAND_FUNC(magic_info); // [Fate] +ATCOMMAND_FUNC(log); // [Fate] +ATCOMMAND_FUNC(tee); // [Fate] #ifndef TXT_ONLY ATCOMMAND_FUNC(checkmail); // [Valaris] @@ -460,6 +467,10 @@ static AtCommandInfo atcommand_info[] = { { AtCommand_UnMute, "@charwipe", 60, atcommand_char_wipe }, // [Fate] { AtCommand_SetMagic, "@setmagic", 99, atcommand_set_magic }, // [Fate] { AtCommand_MagicInfo, "@magicinfo", 60, atcommand_magic_info }, // [Fate] + { AtCommand_Log, "@log", 60, atcommand_log }, // [Fate] + { AtCommand_Log, "@l", 60, atcommand_log }, // [Fate] + { AtCommand_Tee, "@tee", 60, atcommand_tee }, // [Fate] + { AtCommand_Tee, "@t", 60, atcommand_tee }, // [Fate] #ifndef TXT_ONLY // sql-only commands { AtCommand_CheckMail, "@checkmail", 1, atcommand_listmail }, // [Valaris] @@ -619,6 +630,39 @@ int get_atcommand_level(const AtCommandType type) { return 100; // 100: command can not be used } + +/*======================================== + * At-command logging + */ + +char *gm_logfile_name = NULL; +static FILE *gm_logfile = NULL; + +static void +log_atcommand(struct map_session_data *sd, const char *message) +{ + if (!gm_logfile && gm_logfile_name) { + gm_logfile = fopen(gm_logfile_name, "a"); + if (!gm_logfile) { + perror("GM log file"); + gm_logfile_name = NULL; + } + } + + if (gm_logfile && pc_isGM(sd)) { + time_t time_v; + struct tm ctime; + time(&time_v); + gmtime_r(&time_v, &ctime); + + fprintf(gm_logfile, "[%04d-%02d-%02d %02d:%02d:%02d] %s\n", + ctime.tm_year + 1900, ctime.tm_mon, ctime.tm_mday, + ctime.tm_hour, ctime.tm_min, ctime.tm_sec, + message); + fflush(gm_logfile); + } +} + /*========================================== *is_atcommand @コマンドに存在するかどうか確認する *------------------------------------------ @@ -668,7 +712,9 @@ is_atcommand(const int fd, struct map_session_data* sd, const char* message, int // Command can not be executed sprintf(output, msg_table[154], command); // %s failed. clif_displaymessage(fd, output); - } + } else { + log_atcommand(sd, message); + } } return info.type; @@ -7951,3 +7997,23 @@ atcommand_set_magic(const int fd, struct map_session_data* sd, return -1; } + + +int +atcommand_log(const int fd, struct map_session_data* sd, + const char* command, const char* message) +{ + return 0; // only used for (implicit) logging +} + +int +atcommand_tee(const int fd, struct map_session_data* sd, + const char* command, const char* message) +{ + char *data = malloc(strlen(message) + 28); + strcpy(data, sd->status.name); + strcat(data, " : "); + strcat(data, message); + clif_message(&sd->bl, data); + return 0; +} diff --git a/src/map/atcommand.h b/src/map/atcommand.h index 4651d39..76593cc 100644 --- a/src/map/atcommand.h +++ b/src/map/atcommand.h @@ -211,6 +211,8 @@ enum AtCommandType { AtCommand_SetMagic, AtCommand_MagicInfo, + AtCommand_Log, + AtCommand_Tee, // end AtCommand_Unknown, AtCommand_MAX diff --git a/src/map/clif.c b/src/map/clif.c index 426ee53..2858e50 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -7501,6 +7501,7 @@ void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) { } } + /*========================================== * *------------------------------------------ @@ -7632,7 +7633,14 @@ void clif_parse_GlobalMessage(int fd, struct map_session_data *sd) { // S 008c < int clif_message(struct block_list *bl, char* msg) { unsigned short msg_len = strlen(msg) + 1; - unsigned char buf[256]; + static int buf_len = -1; + static unsigned char *buf = NULL; + + if (buf_len < msg_len) { + if (buf) + free(buf); + buf = malloc(buf_len = (msg_len + 16)); + } nullpo_retr(0, bl); diff --git a/src/map/map.c b/src/map/map.c index 30b9d78..3db293c 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -1648,6 +1648,8 @@ int map_delmap(char *mapname) { return 0; } +extern char *gm_logfile_name; + /*========================================== * 設定ファイルを読み込む *------------------------------------------ @@ -1715,6 +1717,8 @@ int map_config_read(char *cfgName) { strcpy(help_txt, w2); } else if (strcmpi(w1, "mapreg_txt") == 0) { strcpy(mapreg_txt, w2); + } else if (strcmpi(w1, "gm_log") == 0) { + gm_logfile_name = strdup(w2); } else if (strcmpi(w1, "import") == 0) { map_config_read(w2); } |