summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFate <fate-tmw@googlemail.com>2008-12-05 21:47:26 -0700
committerFate <fate-tmw@googlemail.com>2008-12-05 21:47:26 -0700
commitb2718e6b40767b0b898ed165de29f1621e974b07 (patch)
tree0989a1e2638b0ed3f079685f7136918a5758eea1
parentcc8781ddac1b0dd6d67182f3e9b553ea163e43b7 (diff)
parenta444f55f1448cfb3b14f9019fd73b684e6a9f322 (diff)
downloadtmwa-b2718e6b40767b0b898ed165de29f1621e974b07.tar.gz
tmwa-b2718e6b40767b0b898ed165de29f1621e974b07.tar.bz2
tmwa-b2718e6b40767b0b898ed165de29f1621e974b07.tar.xz
tmwa-b2718e6b40767b0b898ed165de29f1621e974b07.zip
Merge branch 'master' into exp
-rw-r--r--src/map/atcommand.c68
-rw-r--r--src/map/atcommand.h2
-rw-r--r--src/map/clif.c12
-rw-r--r--src/map/map.c4
-rw-r--r--src/map/script.c4
5 files changed, 85 insertions, 5 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..ab64c2d 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -2583,7 +2583,7 @@ int clif_changestatus(struct block_list *bl,int type,int val)
*/
int clif_changelook(struct block_list *bl,int type,int val)
{
- clif_changelook_towards(bl, type, val, NULL);
+ return clif_changelook_towards(bl, type, val, NULL);
}
int clif_changelook_towards(struct block_list *bl,int type,int val, struct map_session_data *dstsd)
@@ -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);
}
diff --git a/src/map/script.c b/src/map/script.c
index df033f9..4cbeb38 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -1697,10 +1697,10 @@ int buildin_rand(struct script_state *st)
max=tmp;
}
range=max-min+1;
- push_val(st->stack,C_INT,(range <= 0 ? 0 : rand()%range) + min);
+ push_val(st->stack,C_INT,(range <= 0 ? 0 : MRAND(range)) + min);
} else {
range=conv_num(st,& (st->stack->stack_data[st->start+2]));
- push_val(st->stack,C_INT,range <= 0 ? 0 : rand()%range);
+ push_val(st->stack,C_INT,range <= 0 ? 0 : MRAND(range));
}
return 0;
}