本文整理汇总了C++中safestrnlen函数的典型用法代码示例。如果您正苦于以下问题:C++ safestrnlen函数的具体用法?C++ safestrnlen怎么用?C++ safestrnlen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了safestrnlen函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: log_chat
int log_chat(const char* type, int type_id, int src_charid, int src_accid, const char* map, int x, int y, const char* dst_charname, const char* message)
{
// Log CHAT (Global, Whisper, Party, Guild, Main chat)
// LOGGING FILTERS [Lupus]
// =============================================================
// 0 = Don't log at all
// 1 = Log EVERYTHING!
// Advanced Filter Bits: ||
// 02 - Log Global messages
// 04 - Log Whisper messages
// 08 - Log Party messages
// 16 - Log Guild messages
// 32 - Log Main chat messages
// 64 - Don't log anything when WOE is on
//Check ON/OFF
if(log_config.chat <= 0)
return 0; //Deactivated
#ifndef TXT_ONLY
if(log_config.sql_logs > 0)
{
SqlStmt* stmt;
if (strlen(message) > CHAT_SIZE) {
if (battle_config.error_log)
ShowError("log chat: Received message too long from type %d (%d:%d)!\n", type_id, src_accid, src_charid);
return 0;
}
stmt = SqlStmt_Malloc(logmysql_handle);
if( SQL_SUCCESS != SqlStmt_Prepare(stmt, "INSERT DELAYED INTO `%s` (`time`, `type`, `type_id`, `src_charid`, `src_accountid`, `src_map`, `src_map_x`, `src_map_y`, `dst_charname`, `message`) VALUES (NOW(), '%s', '%d', '%d', '%d', '%s', '%d', '%d', ?, ?)", log_config.log_chat_db, type, type_id, src_charid, src_accid, map, x, y)
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, (char*)dst_charname, safestrnlen(dst_charname, NAME_LENGTH))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, CHAT_SIZE))
|| SQL_SUCCESS != SqlStmt_Execute(stmt) )
{
SqlStmt_ShowDebug(stmt);
SqlStmt_Free(stmt);
return 0;
}
SqlStmt_Free(stmt);
}
else
#endif
{
FILE* logfp;
if((logfp = fopen(log_config.log_chat, "a+")) == NULL)
return 0;
time(&curtime);
strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime));
fprintf(logfp, "%s - %s,%d,%d,%d,%s,%d,%d,%s,%s\n", timestring, type, type_id, src_charid, src_accid, map, x, y, dst_charname, message);
fclose(logfp);
}
return 1;
}
开发者ID:milky-milk,项目名称:ro-server-repos,代码行数:56,代码来源:log.c
示例2: log_chat_sub_sql
void log_chat_sub_sql(e_log_chat_type type, int type_id, int src_charid, int src_accid, const char *mapname, int x, int y, const char* dst_charname, const char* message) {
SqlStmt* stmt;
stmt = SQL->StmtMalloc(logs->mysql_handle);
if( SQL_SUCCESS != SQL->StmtPrepare(stmt, LOG_QUERY " INTO `%s` (`time`, `type`, `type_id`, `src_charid`, `src_accountid`, `src_map`, `src_map_x`, `src_map_y`, `dst_charname`, `message`) VALUES (NOW(), '%c', '%d', '%d', '%d', '%s', '%d', '%d', ?, ?)", logs->config.log_chat, logs->chattype2char(type), type_id, src_charid, src_accid, mapname, x, y)
|| SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_STRING, (char*)dst_charname, safestrnlen(dst_charname, NAME_LENGTH))
|| SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, CHAT_SIZE_MAX))
|| SQL_SUCCESS != SQL->StmtExecute(stmt)
) {
SqlStmt_ShowDebug(stmt);
SQL->StmtFree(stmt);
return;
}
SQL->StmtFree(stmt);
}
开发者ID:kerbiii,项目名称:Hercules,代码行数:15,代码来源:log.c
示例3: log_chat
/// logs chat
void log_chat(e_log_chat_type type, int type_id, int src_charid, int src_accid, const char* mapname, int x, int y, const char* dst_charname, const char* message)
{
if( ( log_config.chat&type ) == 0 )
{// disabled
return;
}
if( log_config.log_chat_woe_disable && ( agit_flag || agit2_flag ) )
{// no chat logging during woe
return;
}
if( log_config.sql_logs ) {
#ifdef BETA_THREAD_TEST
char entry[512];
int e_length = 0;
e_length = sprintf(entry, LOG_QUERY " INTO `%s` (`time`, `type`, `type_id`, `src_charid`, `src_accountid`, `src_map`, `src_map_x`, `src_map_y`, `dst_charname`, `message`) VALUES (NOW(), '%c', '%d', '%d', '%d', '%s', '%d', '%d', '%s', '%s')", log_config.log_chat, log_chattype2char(type), type_id, src_charid, src_accid, mapname, x, y, dst_charname, message );
queryThread_log(entry,e_length);
#else
SqlStmt* stmt;
stmt = SqlStmt_Malloc(logmysql_handle);
if( SQL_SUCCESS != SqlStmt_Prepare(stmt, LOG_QUERY " INTO `%s` (`time`, `type`, `type_id`, `src_charid`, `src_accountid`, `src_map`, `src_map_x`, `src_map_y`, `dst_charname`, `message`) VALUES (NOW(), '%c', '%d', '%d', '%d', '%s', '%d', '%d', ?, ?)", log_config.log_chat, log_chattype2char(type), type_id, src_charid, src_accid, mapname, x, y)
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, (char*)dst_charname, safestrnlen(dst_charname, NAME_LENGTH))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, CHAT_SIZE_MAX))
|| SQL_SUCCESS != SqlStmt_Execute(stmt) )
{
SqlStmt_ShowDebug(stmt);
SqlStmt_Free(stmt);
return;
}
SqlStmt_Free(stmt);
#endif
}
else
{
char timestring[255];
time_t curtime;
FILE* logfp;
if( ( logfp = fopen(log_config.log_chat, "a") ) == NULL )
return;
time(&curtime);
strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime));
fprintf(logfp, "%s - %c,%d,%d,%d,%s,%d,%d,%s,%s\n", timestring, log_chattype2char(type), type_id, src_charid, src_accid, mapname, x, y, dst_charname, message);
fclose(logfp);
}
}
开发者ID:Insswer,项目名称:rathena,代码行数:49,代码来源:log.c
示例4: mapindex_getmapname_ext
/// Retrieves the map name from 'string' (adding .gat extension if not already present).
/// Result gets placed either into 'buf' or in a static local buffer.
const char* mapindex_getmapname_ext(const char* string, char* output)
{
static char buf[MAP_NAME_LENGTH_EXT];
char* dest = (output != NULL) ? output : buf;
size_t len;
strcpy(buf,string);
sscanf(string,"%*[^#]%*[#]%s",buf);
len = safestrnlen(buf, MAP_NAME_LENGTH);
if (len == MAP_NAME_LENGTH) {
ShowWarning("(mapindex_normalize_name) Map name '%*s' is too long!\n", 2*MAP_NAME_LENGTH, buf);
len--;
}
safestrncpy(dest, buf, len+1);
if (len < 4 || stricmp(&dest[len-4], ".gat") != 0) {
strcpy(&dest[len], ".gat");
len += 4; // add .gat extension
}
memset(&dest[len], '\0', MAP_NAME_LENGTH_EXT-len);
return dest;
}
开发者ID:akrus,项目名称:Hercules,代码行数:29,代码来源:mapindex.c
示例5: log_npc_sub_sql
void log_npc_sub_sql(struct map_session_data *sd, const char *message) {
SqlStmt* stmt;
stmt = SQL->StmtMalloc(logs->mysql_handle);
if( SQL_SUCCESS != SQL->StmtPrepare(stmt, LOG_QUERY " INTO `%s` (`npc_date`, `account_id`, `char_id`, `char_name`, `map`, `mes`) VALUES (NOW(), '%d', '%d', ?, '%s', ?)", logs->config.log_npc, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex) )
|| SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_STRING, sd->status.name, strnlen(sd->status.name, NAME_LENGTH))
|| SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, 255))
|| SQL_SUCCESS != SQL->StmtExecute(stmt) )
{
SqlStmt_ShowDebug(stmt);
SQL->StmtFree(stmt);
return;
}
SQL->StmtFree(stmt);
}
开发者ID:kerbiii,项目名称:Hercules,代码行数:14,代码来源:log.c
示例6: Sql_EscapeStringLen
// Search for the party according to its name
struct party_data *search_partyname(char *str) {
char esc_name[NAME_LENGTH*2+1];
char *data;
struct party_data *p = NULL;
Sql_EscapeStringLen(sql_handle, esc_name, str, safestrnlen(str, NAME_LENGTH));
if(SQL_ERROR == Sql_Query(sql_handle, "SELECT `party_id` FROM `%s` WHERE `name`='%s'", party_db, esc_name))
Sql_ShowDebug(sql_handle);
else if(SQL_SUCCESS == Sql_NextRow(sql_handle)) {
Sql_GetData(sql_handle, 0, &data, NULL);
p = inter_party_fromsql(atoi(data));
}
Sql_FreeResult(sql_handle);
return p;
}
开发者ID:Chocolate31,项目名称:eamod,代码行数:17,代码来源:int_party.c
示例7: inter_party_search_partyname
// Search for the party according to its name
struct party_data* inter_party_search_partyname(const char *const str)
{
char esc_name[NAME_LENGTH*2+1];
char* data;
struct party_data* p = NULL;
SQL->EscapeStringLen(inter->sql_handle, esc_name, str, safestrnlen(str, NAME_LENGTH));
if( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `party_id` FROM `%s` WHERE `name`='%s'", party_db, esc_name) )
Sql_ShowDebug(inter->sql_handle);
else if( SQL_SUCCESS == SQL->NextRow(inter->sql_handle) ) {
SQL->GetData(inter->sql_handle, 0, &data, NULL);
p = inter_party->fromsql(atoi(data));
}
SQL->FreeResult(inter->sql_handle);
return p;
}
开发者ID:Mateuus,项目名称:Cronus,代码行数:18,代码来源:int_party.c
示例8: log_atcommand
/// logs used atcommands
void log_atcommand(struct map_session_data* sd, const char* message)
{
nullpo_retv(sd);
if( !log_config.commands ||
!pc_should_log_commands(sd) )
return;
if( log_config.sql_logs )
{
#ifdef BETA_THREAD_TEST
char entry[512];
int e_length = 0;
e_length = sprintf(entry, LOG_QUERY " INTO `%s` (`atcommand_date`, `account_id`, `char_id`, `char_name`, `map`, `command`) VALUES (NOW(), '%d', '%d', '%s', '%s', '%s')", log_config.log_gm, sd->status.account_id, sd->status.char_id, sd->status.name ,mapindex_id2name(sd->mapindex), message);
queryThread_log(entry,e_length);
#else
SqlStmt* stmt;
stmt = SqlStmt_Malloc(logmysql_handle);
if( SQL_SUCCESS != SqlStmt_Prepare(stmt, LOG_QUERY " INTO `%s` (`atcommand_date`, `account_id`, `char_id`, `char_name`, `map`, `command`) VALUES (NOW(), '%d', '%d', ?, '%s', ?)", log_config.log_gm, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex) )
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, sd->status.name, strnlen(sd->status.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);
#endif
}
else
{
char timestring[255];
time_t curtime;
FILE* logfp;
if( ( logfp = fopen(log_config.log_gm, "a") ) == NULL )
return;
time(&curtime);
strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime));
fprintf(logfp, "%s - %s[%d]: %s\n", timestring, sd->status.name, sd->status.account_id, message);
fclose(logfp);
}
}
开发者ID:Insswer,项目名称:rathena,代码行数:46,代码来源:log.c
示例9: log_atcommand
int log_atcommand(struct map_session_data* sd, const char* message)
{
if(!log_config.enable_logs)
return 0;
nullpo_retr(0, sd);
#ifndef TXT_ONLY
if(log_config.sql_logs > 0)
{
SqlStmt* stmt;
if (strlen(message) > CHAT_SIZE) {
if (battle_config.error_log)
ShowError("log atcommand: Received message too long from player %s (%d:%d)!\n", sd->status.name, sd->status.account_id, sd->status.char_id);
return 0;
}
stmt = SqlStmt_Malloc(logmysql_handle);
if( SQL_SUCCESS != SqlStmt_Prepare(stmt, "INSERT DELAYED INTO `%s` (`atcommand_date`, `account_id`, `char_id`, `char_name`, `map`, `command`) VALUES (NOW(), '%d', '%d', ?, '%s', ?)", log_config.log_gm_db, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex) )
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, sd->status.name, strnlen(sd->status.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 0;
}
SqlStmt_Free(stmt);
}
else
#endif
{
FILE* logfp;
if((logfp = fopen(log_config.log_gm, "a+")) == NULL)
return 0;
time(&curtime);
strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime));
fprintf(logfp, "%s - %s[%d]: %s\n", timestring, sd->status.name, sd->status.account_id, message);
fclose(logfp);
}
return 1;
}
开发者ID:milky-milk,项目名称:ro-server-repos,代码行数:44,代码来源:log.c
示例10: script_save_mapreg
/// Saves permanent variables to database
static void script_save_mapreg(void)
{
DBIterator* iter;
DBData *data;
DBKey key;
iter = db_iterator(mapreg_db);
for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) )
{
int num = (key.i & 0x00ffffff);
int i = (key.i & 0xff000000) >> 24;
const char* name = get_str(num);
if( name[1] == '@' )
continue;
if( SQL_ERROR == Sql_Query(mmysql_handle, "UPDATE `%s` SET `value`='%d' WHERE `varname`='%s' AND `index`='%d'", mapreg_table, db_data2i(data), name, i) )
Sql_ShowDebug(mmysql_handle);
}
dbi_destroy(iter);
iter = db_iterator(mapregstr_db);
for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) )
{
int num = (key.i & 0x00ffffff);
int i = (key.i & 0xff000000) >> 24;
const char* name = get_str(num);
char tmp_str2[2*255+1];
if( name[1] == '@' )
continue;
Sql_EscapeStringLen(mmysql_handle, tmp_str2, db_data2ptr(data), safestrnlen(db_data2ptr(data), 255));
if( SQL_ERROR == Sql_Query(mmysql_handle, "UPDATE `%s` SET `value`='%s' WHERE `varname`='%s' AND `index`='%d'", mapreg_table, tmp_str2, name, i) )
Sql_ShowDebug(mmysql_handle);
}
dbi_destroy(iter);
mapreg_dirty = false;
}
开发者ID:Chocolate31,项目名称:eamod,代码行数:41,代码来源:mapreg.c
示例11: log_atcommand
/// logs used GM commands
void log_atcommand(struct map_session_data* sd, int cmdlvl, const char* message)
{
nullpo_retv(sd);
if( cmdlvl < log_config.gm )
return;
#ifndef TXT_ONLY
if( log_config.sql_logs )
{
SqlStmt* stmt;
stmt = SqlStmt_Malloc(logmysql_handle);
if( SQL_SUCCESS != SqlStmt_Prepare(stmt, "INSERT DELAYED INTO `%s` (`atcommand_date`, `account_id`, `char_id`, `char_name`, `map`, `command`) VALUES (NOW(), '%d', '%d', ?, '%s', ?)", log_config.log_gm, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex) )
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, sd->status.name, strnlen(sd->status.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
#endif
{
char timestring[255];
time_t curtime;
FILE* logfp;
if( ( logfp = fopen(log_config.log_gm, "a") ) == NULL )
return;
time(&curtime);
strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime));
fprintf(logfp, "%s - %s[%d]: %s\n", timestring, sd->status.name, sd->status.account_id, message);
fclose(logfp);
}
}
开发者ID:Nihadm89,项目名称:server,代码行数:40,代码来源:log.c
示例12: log_npc
int log_npc(struct map_session_data* sd, const char* message)
{
if(!log_config.enable_logs)
return 0;
nullpo_ret(sd);
if( log_config.sql_logs )
{
SqlStmt* stmt;
stmt = SqlStmt_Malloc(logmysql_handle);
if( SQL_SUCCESS != SqlStmt_Prepare(stmt, "INSERT DELAYED INTO `%s` (`npc_date`, `account_id`, `char_id`, `char_name`, `map`, `mes`) VALUES (NOW(), '%d', '%d', ?, '%s', ?)", log_config.log_npc_db, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex) )
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, sd->status.name, strnlen(sd->status.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 0;
}
SqlStmt_Free(stmt);
}
else
{
FILE* logfp;
if((logfp = fopen(log_config.log_npc, "a+")) == NULL)
return 0;
time(&curtime);
strftime(timestring, 254, "%m/%d/%Y %H:%M:%S", localtime(&curtime));
fprintf(logfp, "%s - %s[%d]: %s\n", timestring, sd->status.name, sd->status.account_id, message);
fclose(logfp);
}
return 1;
}
开发者ID:Anubiros,项目名称:adhara-project,代码行数:35,代码来源:log.c
注:本文中的safestrnlen函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论