Added possibility to log without attached player (#3260)
Fixes #2268 Thanks to @Akkarinage
This commit is contained in:
parent
ce9cbd2e65
commit
3faf700443
@ -16,6 +16,7 @@
|
|||||||
#include "itemdb.hpp"
|
#include "itemdb.hpp"
|
||||||
#include "map.hpp"
|
#include "map.hpp"
|
||||||
#include "mob.hpp"
|
#include "mob.hpp"
|
||||||
|
#include "npc.hpp"
|
||||||
#include "pc.hpp"
|
#include "pc.hpp"
|
||||||
#include "pet.hpp"
|
#include "pet.hpp"
|
||||||
|
|
||||||
@ -375,6 +376,42 @@ void log_atcommand(struct map_session_data* sd, const char* message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// logs messages passed to script command 'logmes'
|
||||||
|
void log_npc( struct npc_data* nd, const char* message ){
|
||||||
|
nullpo_retv(nd);
|
||||||
|
|
||||||
|
if( !log_config.npc )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if( log_config.sql_logs )
|
||||||
|
{
|
||||||
|
SqlStmt* stmt;
|
||||||
|
stmt = SqlStmt_Malloc(logmysql_handle);
|
||||||
|
if( SQL_SUCCESS != SqlStmt_Prepare(stmt, LOG_QUERY " INTO `%s` (`npc_date`, `char_name`, `map`, `mes`) VALUES (NOW(), ?, '%s', ?)", log_config.log_npc, map_mapid2mapname(nd->bl.m) )
|
||||||
|
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, nd->name, strnlen(nd->name, NAME_LENGTH))
|
||||||
|
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, 255))
|
||||||
|
|| SQL_SUCCESS != SqlStmt_Execute(stmt) )
|
||||||
|
{
|
||||||
|
SqlStmt_ShowDebug(stmt);
|
||||||
|
SqlStmt_Free(stmt);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SqlStmt_Free(stmt);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char timestring[255];
|
||||||
|
time_t curtime;
|
||||||
|
FILE* logfp;
|
||||||
|
|
||||||
|
if( ( logfp = fopen(log_config.log_npc, "a") ) == NULL )
|
||||||
|
return;
|
||||||
|
time(&curtime);
|
||||||
|
strftime(timestring, sizeof(timestring), log_timestamp_format, localtime(&curtime));
|
||||||
|
fprintf(logfp, "%s - %s: %s\n", timestring, nd->name, message);
|
||||||
|
fclose(logfp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// logs messages passed to script command 'logmes'
|
/// logs messages passed to script command 'logmes'
|
||||||
void log_npc(struct map_session_data* sd, const char* message)
|
void log_npc(struct map_session_data* sd, const char* message)
|
||||||
|
@ -72,6 +72,7 @@ void log_pick_pc(struct map_session_data* sd, e_log_pick_type type, int amount,
|
|||||||
void log_pick_mob(struct mob_data* md, e_log_pick_type type, int amount, struct item* itm);
|
void log_pick_mob(struct mob_data* md, e_log_pick_type type, int amount, struct item* itm);
|
||||||
void log_zeny(struct map_session_data* sd, e_log_pick_type type, struct map_session_data* src_sd, int amount);
|
void log_zeny(struct map_session_data* sd, e_log_pick_type type, struct map_session_data* src_sd, int amount);
|
||||||
void log_cash( struct map_session_data* sd, e_log_pick_type type, e_log_cash_type cash_type, int amount );
|
void log_cash( struct map_session_data* sd, e_log_pick_type type, e_log_cash_type cash_type, int amount );
|
||||||
|
void log_npc( struct npc_data* nd, const char* message );
|
||||||
void log_npc(struct map_session_data* sd, const char *message);
|
void log_npc(struct map_session_data* sd, const char *message);
|
||||||
void log_chat(e_log_chat_type type, int type_id, int src_charid, int src_accid, const char* map, int x, int y, const char* dst_charname, const char* message);
|
void log_chat(e_log_chat_type type, int type_id, int src_charid, int src_accid, const char* map, int x, int y, const char* dst_charname, const char* message);
|
||||||
void log_atcommand(struct map_session_data* sd, const char* message);
|
void log_atcommand(struct map_session_data* sd, const char* message);
|
||||||
|
@ -15231,13 +15231,22 @@ BUILDIN_FUNC(mapid2name)
|
|||||||
BUILDIN_FUNC(logmes)
|
BUILDIN_FUNC(logmes)
|
||||||
{
|
{
|
||||||
const char *str;
|
const char *str;
|
||||||
TBL_PC* sd;
|
struct map_session_data* sd = map_id2sd(st->rid);
|
||||||
|
|
||||||
if( !script_rid2sd(sd) )
|
|
||||||
return SCRIPT_CMD_FAILURE;
|
|
||||||
|
|
||||||
str = script_getstr(st,2);
|
str = script_getstr(st,2);
|
||||||
|
if( sd ){
|
||||||
log_npc(sd,str);
|
log_npc(sd,str);
|
||||||
|
}else{
|
||||||
|
struct npc_data* nd = map_id2nd(st->oid);
|
||||||
|
|
||||||
|
if( !nd ){
|
||||||
|
ShowError( "buildin_logmes: Invalid usage without player or npc.\n" );
|
||||||
|
return SCRIPT_CMD_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_npc(nd,str);
|
||||||
|
}
|
||||||
|
|
||||||
return SCRIPT_CMD_SUCCESS;
|
return SCRIPT_CMD_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user