本文整理汇总了C++中StringBuf_AppendStr函数的典型用法代码示例。如果您正苦于以下问题:C++ StringBuf_AppendStr函数的具体用法?C++ StringBuf_AppendStr怎么用?C++ StringBuf_AppendStr使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StringBuf_AppendStr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mapif_achievement_update
/**
* Updates an achievement in a character's achievementlog.
* @param char_id: Character ID
* @param ad: Achievement data
* @return false in case of errors, true otherwise
*/
bool mapif_achievement_update(uint32 char_id, struct achievement* ad)
{
StringBuf buf;
int i;
StringBuf_Init(&buf);
StringBuf_Printf(&buf, "UPDATE `%s` SET ", schema_config.achievement_table);
if( ad->completed ){
StringBuf_Printf(&buf, "`completed` = FROM_UNIXTIME('%u'),", (uint32)ad->completed);
}else{
StringBuf_AppendStr(&buf, "`completed` = NULL,");
}
if( ad->rewarded ){
StringBuf_Printf(&buf, "`rewarded` = FROM_UNIXTIME('%u')", (uint32)ad->rewarded);
}else{
StringBuf_AppendStr(&buf, "`rewarded` = NULL");
}
for (i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; ++i)
StringBuf_Printf(&buf, ", `count%d` = '%d'", i + 1, ad->count[i]);
StringBuf_Printf(&buf, " WHERE `id` = %d AND `char_id` = %u", ad->achievement_id, char_id);
if (SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf))) {
Sql_ShowDebug(sql_handle);
StringBuf_Destroy(&buf);
return false;
}
StringBuf_Destroy(&buf);
return true;
}
示例2: mapif_achievement_add
/**
* Adds an achievement to a character's achievementlog.
* @param char_id: Character ID
* @param ad: Achievement data
* @return false in case of errors, true otherwise
*/
bool mapif_achievement_add(uint32 char_id, struct achievement* ad)
{
StringBuf buf;
int i;
StringBuf_Init(&buf);
StringBuf_Printf(&buf, "INSERT INTO `%s` (`char_id`, `id`, `completed`, `rewarded`", schema_config.achievement_table);
for (i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; ++i)
StringBuf_Printf(&buf, ", `count%d`", i + 1);
StringBuf_AppendStr(&buf, ")");
StringBuf_Printf(&buf, " VALUES ('%u', '%d',", char_id, ad->achievement_id, (uint32)ad->completed, (uint32)ad->rewarded);
if( ad->completed ){
StringBuf_Printf(&buf, "FROM_UNIXTIME('%u'),", (uint32)ad->completed);
}else{
StringBuf_AppendStr(&buf, "NULL,");
}
if( ad->rewarded ){
StringBuf_Printf(&buf, "FROM_UNIXTIME('%u')", (uint32)ad->rewarded);
}else{
StringBuf_AppendStr(&buf, "NULL");
}
for (i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; ++i)
StringBuf_Printf(&buf, ", '%d'", ad->count[i]);
StringBuf_AppendStr(&buf, ")");
if (SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf))) {
Sql_ShowDebug(sql_handle);
StringBuf_Destroy(&buf);
return false;
}
StringBuf_Destroy(&buf);
return true;
}
示例3: memset
/**
* Load achievements for a character.
* @param char_id: Character ID
* @param count: Pointer to return the number of found entries.
* @return Array of found entries. It has *count entries, and it is care of the caller to aFree() it afterwards.
*/
struct achievement *mapif_achievements_fromsql(uint32 char_id, int *count)
{
struct achievement *achievelog = NULL;
struct achievement tmp_achieve;
SqlStmt *stmt;
StringBuf buf;
int i;
if (!count)
return NULL;
memset(&tmp_achieve, 0, sizeof(tmp_achieve));
StringBuf_Init(&buf);
StringBuf_AppendStr(&buf, "SELECT `id`, COALESCE(UNIX_TIMESTAMP(`completed`),0), COALESCE(UNIX_TIMESTAMP(`rewarded`),0)");
for (i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; ++i)
StringBuf_Printf(&buf, ", `count%d`", i + 1);
StringBuf_Printf(&buf, " FROM `%s` WHERE `char_id` = '%u'", schema_config.achievement_table, char_id);
stmt = SqlStmt_Malloc(sql_handle);
if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf))
|| SQL_ERROR == SqlStmt_Execute(stmt) )
{
SqlStmt_ShowDebug(stmt);
SqlStmt_Free(stmt);
StringBuf_Destroy(&buf);
*count = 0;
return NULL;
}
SqlStmt_BindColumn(stmt, 0, SQLDT_INT, &tmp_achieve.achievement_id, 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 1, SQLDT_INT, &tmp_achieve.completed, 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 2, SQLDT_INT, &tmp_achieve.rewarded, 0, NULL, NULL);
for (i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; ++i)
SqlStmt_BindColumn(stmt, 3 + i, SQLDT_INT, &tmp_achieve.count[i], 0, NULL, NULL);
*count = (int)SqlStmt_NumRows(stmt);
if (*count > 0) {
i = 0;
achievelog = (struct achievement *)aCalloc(*count, sizeof(struct achievement));
while (SQL_SUCCESS == SqlStmt_NextRow(stmt)) {
if (i >= *count) // Sanity check, should never happen
break;
memcpy(&achievelog[i++], &tmp_achieve, sizeof(tmp_achieve));
}
if (i < *count) {
// Should never happen. Compact array
*count = i;
achievelog = (struct achievement *)aRealloc(achievelog, sizeof(struct achievement) * i);
}
}
SqlStmt_Free(stmt);
StringBuf_Destroy(&buf);
ShowInfo("achievement load complete from DB - id: %d (total: %d)\n", char_id, *count);
return achievelog;
}
示例4: chmapif_parse_req_saveskillcooldown
//Request to save skill cooldown data
int chmapif_parse_req_saveskillcooldown(int fd){
if( RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2) )
return 0;
else {
int count, aid, cid;
aid = RFIFOL(fd,4);
cid = RFIFOL(fd,8);
count = RFIFOW(fd,12);
if( count > 0 )
{
struct skill_cooldown_data data;
StringBuf buf;
int i;
StringBuf_Init(&buf);
StringBuf_Printf(&buf, "INSERT INTO `%s` (`account_id`, `char_id`, `skill`, `tick`) VALUES ", schema_config.skillcooldown_db);
for( i = 0; i < count; ++i )
{
memcpy(&data,RFIFOP(fd,14+i*sizeof(struct skill_cooldown_data)),sizeof(struct skill_cooldown_data));
if( i > 0 )
StringBuf_AppendStr(&buf, ", ");
StringBuf_Printf(&buf, "('%d','%d','%d','%d')", aid, cid, data.skill_id, data.tick);
}
if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) )
Sql_ShowDebug(sql_handle);
StringBuf_Destroy(&buf);
}
RFIFOSKIP(fd, RFIFOW(fd, 2));
}
return 1;
}
示例5: inter_accreg_tosql
//--------------------------------------------------------
// Save registry to sql
int inter_accreg_tosql(uint32 account_id, uint32 char_id, struct accreg* reg, int type)
{
StringBuf buf;
int i;
if( account_id <= 0 )
return 0;
reg->account_id = account_id;
reg->char_id = char_id;
//`global_reg_value` (`type`, `account_id`, `char_id`, `str`, `value`)
switch( type ) {
case 3: //Char Reg
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `type`=3 AND `char_id`='%d'", schema_config.reg_db, char_id) )
Sql_ShowDebug(sql_handle);
account_id = 0;
break;
case 2: //Account Reg
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `type`=2 AND `account_id`='%d'", schema_config.reg_db, account_id) )
Sql_ShowDebug(sql_handle);
char_id = 0;
break;
case 1: //Account2 Reg
ShowError("inter_accreg_tosql: Char server shouldn't handle type 1 registry values (##). That is the login server's work!\n");
return 0;
default:
ShowError("inter_accreg_tosql: Invalid type %d\n", type);
return 0;
}
if( reg->reg_num <= 0 )
return 0;
StringBuf_Init(&buf);
StringBuf_Printf(&buf, "INSERT INTO `%s` (`type`,`account_id`,`char_id`,`str`,`value`) VALUES ", schema_config.reg_db);
for( i = 0; i < reg->reg_num; ++i ) {
struct global_reg* r = ®->reg[i];
if( r->str[0] != '\0' && r->value[0] != '\0' ) {
char str[32];
char val[256];
if( i > 0 )
StringBuf_AppendStr(&buf, ",");
Sql_EscapeString(sql_handle, str, r->str);
Sql_EscapeString(sql_handle, val, r->value);
StringBuf_Printf(&buf, "('%d','%d','%d','%s','%s')", type, account_id, char_id, str, val);
}
}
if( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) {
Sql_ShowDebug(sql_handle);
}
StringBuf_Destroy(&buf);
return 1;
}
示例6: itemdb_save_serials
void itemdb_save_serials(void)
{
struct item_data *id;
StringBuf buf;
int count = 0, i;
StringBuf_Init(&buf);
StringBuf_Printf(&buf, "REPLACE INTO `item_serials` (`nameid`, `serial`) VALUES ");
for( i = 0; i < ARRAYLENGTH(itemdb_array); i++ )
{
id = itemdb_array[i];
if( id == NULL || itemdb_isstackable2(id) || id->last_serial == 0 || !id->changed )
continue;
if( count )
StringBuf_AppendStr(&buf, ",");
StringBuf_Printf(&buf, "('%d','%u')", id->nameid, id->last_serial);
id->changed = false;
count++;
}
if( count && SQL_ERROR == Sql_QueryStr(mmysql_handle, StringBuf_Value(&buf)) )
Sql_ShowDebug(mmysql_handle);
StringBuf_Destroy(&buf);
return;
}
示例7: auction_create
unsigned int auction_create(struct auction_data *auction)
{
int j;
StringBuf buf;
SqlStmt* stmt;
if( !auction )
return false;
auction->timestamp = time(NULL) + (auction->hours * 3600);
StringBuf_Init(&buf);
StringBuf_Printf(&buf, "INSERT INTO `%s` (`seller_id`,`seller_name`,`buyer_id`,`buyer_name`,`price`,`buynow`,`hours`,`timestamp`,`nameid`,`item_name`,`type`,`refine`,`attribute`,`unique_id`", auction_db);
for( j = 0; j < MAX_SLOTS; j++ )
StringBuf_Printf(&buf, ",`card%d`", j);
StringBuf_Printf(&buf, ") VALUES ('%d',?,'%d',?,'%d','%d','%d','%lu','%d',?,'%d','%d','%d','%"PRIu64"'",
auction->seller_id, auction->buyer_id, auction->price, auction->buynow, auction->hours, (unsigned long)auction->timestamp, auction->item.nameid, auction->type, auction->item.refine, auction->item.attribute, auction->item.unique_id);
for( j = 0; j < MAX_SLOTS; j++ )
StringBuf_Printf(&buf, ",'%d'", auction->item.card[j]);
StringBuf_AppendStr(&buf, ")");
//Unique Non Stackable Item ID
updateLastUid(auction->item.unique_id);
dbUpdateUid(sql_handle);
stmt = SqlStmt_Malloc(sql_handle);
if( SQL_SUCCESS != SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, auction->seller_name, strnlen(auction->seller_name, NAME_LENGTH))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, auction->buyer_name, strnlen(auction->buyer_name, NAME_LENGTH))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 2, SQLDT_STRING, auction->item_name, strnlen(auction->item_name, ITEM_NAME_LENGTH))
|| SQL_SUCCESS != SqlStmt_Execute(stmt) )
{
SqlStmt_ShowDebug(stmt);
auction->auction_id = 0;
}
else
{
struct auction_data *auction_;
unsigned int tick = auction->hours * 3600000;
auction->item.amount = 1;
auction->item.identify = 1;
auction->item.expire_time = 0;
auction->auction_id = (unsigned int)SqlStmt_LastInsertId(stmt);
auction->auction_end_timer = add_timer( gettick() + tick , auction_end_timer, auction->auction_id, 0);
ShowInfo("New Auction %u | time left %u ms | By %s.\n", auction->auction_id, tick, auction->seller_name);
CREATE(auction_, struct auction_data, 1);
memcpy(auction_, auction, sizeof(struct auction_data));
idb_put(auction_db_, auction_->auction_id, auction_);
}
SqlStmt_Free(stmt);
StringBuf_Destroy(&buf);
return auction->auction_id;
}
示例8: mail_loadmessage
/// Retrieves a single message from the database.
/// Returns true if the operation succeeds (or false if it fails).
static bool mail_loadmessage(int mail_id, struct mail_message* msg)
{
int j;
StringBuf buf;
StringBuf_Init(&buf);
StringBuf_AppendStr(&buf, "SELECT `id`,`send_name`,`send_id`,`dest_name`,`dest_id`,`title`,`message`,`time`,`status`,"
"`zeny`,`amount`,`nameid`,`refine`,`attribute`,`identify`, `serial`");
for( j = 0; j < MAX_SLOTS; j++ )
StringBuf_Printf(&buf, ",`card%d`", j);
StringBuf_Printf(&buf, " FROM `%s` WHERE `id` = '%d'", mail_db, mail_id);
if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf))
|| SQL_SUCCESS != Sql_NextRow(sql_handle) )
{
Sql_ShowDebug(sql_handle);
Sql_FreeResult(sql_handle);
StringBuf_Destroy(&buf);
return false;
}
else
{
char* data;
Sql_GetData(sql_handle, 0, &data, NULL); msg->id = atoi(data);
Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(msg->send_name, data, NAME_LENGTH);
Sql_GetData(sql_handle, 2, &data, NULL); msg->send_id = atoi(data);
Sql_GetData(sql_handle, 3, &data, NULL); safestrncpy(msg->dest_name, data, NAME_LENGTH);
Sql_GetData(sql_handle, 4, &data, NULL); msg->dest_id = atoi(data);
Sql_GetData(sql_handle, 5, &data, NULL); safestrncpy(msg->title, data, MAIL_TITLE_LENGTH);
Sql_GetData(sql_handle, 6, &data, NULL); safestrncpy(msg->body, data, MAIL_BODY_LENGTH);
Sql_GetData(sql_handle, 7, &data, NULL); msg->timestamp = atoi(data);
Sql_GetData(sql_handle, 8, &data, NULL); msg->status = (mail_status)atoi(data);
Sql_GetData(sql_handle, 9, &data, NULL); msg->zeny = atoi(data);
Sql_GetData(sql_handle,10, &data, NULL); msg->item.amount = (short)atoi(data);
Sql_GetData(sql_handle,11, &data, NULL); msg->item.nameid = atoi(data);
Sql_GetData(sql_handle,12, &data, NULL); msg->item.refine = atoi(data);
Sql_GetData(sql_handle,13, &data, NULL); msg->item.attribute = atoi(data);
Sql_GetData(sql_handle,14, &data, NULL); msg->item.identify = atoi(data);
Sql_GetData(sql_handle,15, &data, NULL); msg->item.serial = (unsigned int)atol(data);
msg->item.expire_time = 0;
msg->item.bound = 0;
msg->item.favorite = 0;
for( j = 0; j < MAX_SLOTS; j++ )
{
Sql_GetData(sql_handle,16 + j, &data, NULL);
msg->item.card[j] = atoi(data);
}
}
StringBuf_Destroy(&buf);
Sql_FreeResult(sql_handle);
return true;
}
示例9: guild_storage_fromsql
/// Load guild_storage data to mem
int guild_storage_fromsql(int guild_id, struct guild_storage* p)
{
StringBuf buf;
struct item* item;
char* data;
int i;
int j;
memset(p, 0, sizeof(struct guild_storage)); //clean up memory
p->storage_amount = 0;
p->guild_id = guild_id;
// storage {`guild_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`}
StringBuf_Init(&buf);
StringBuf_AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`");
for( j = 0; j < MAX_SLOTS; ++j )
StringBuf_Printf(&buf, ",`card%d`", j);
StringBuf_Printf(&buf, " FROM `%s` WHERE `guild_id`='%d' ORDER BY `nameid`", guild_storage_db, guild_id);
if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) )
Sql_ShowDebug(sql_handle);
StringBuf_Destroy(&buf);
for( i = 0; i < MAX_GUILD_STORAGE && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i )
{
item = &p->items[i];
Sql_GetData(sql_handle, 0, &data, NULL);
item->id = atoi(data);
Sql_GetData(sql_handle, 1, &data, NULL);
item->nameid = atoi(data);
Sql_GetData(sql_handle, 2, &data, NULL);
item->amount = atoi(data);
Sql_GetData(sql_handle, 3, &data, NULL);
item->equip = atoi(data);
Sql_GetData(sql_handle, 4, &data, NULL);
item->identify = atoi(data);
Sql_GetData(sql_handle, 5, &data, NULL);
item->refine = atoi(data);
Sql_GetData(sql_handle, 6, &data, NULL);
item->attribute = atoi(data);
item->expire_time = 0;
for( j = 0; j < MAX_SLOTS; ++j )
{
Sql_GetData(sql_handle, 7+j, &data, NULL);
item->card[j] = atoi(data);
}
}
p->storage_amount = i;
Sql_FreeResult(sql_handle);
ShowInfo("guild storage load complete from DB - id: %d (total: %d)\n", guild_id, p->storage_amount);
return 0;
}
示例10: ext_storage_fromsql
// DB -> storage data conversion
int ext_storage_fromsql(int account_id, struct extra_storage_data *p)
{
StringBuf buf;
struct item* item;
char* data;
int i;
int j;
memset(p, 0, sizeof(struct extra_storage_data)); //clean up memory
p->storage_amount = 0;
// storage {`account_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`}
StringBuf_Init(&buf);
StringBuf_AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`expire_time`,`unique_id`,`bound`");
for( j = 0; j < MAX_SLOTS; ++j )
StringBuf_Printf(&buf, ",`card%d`", j);
StringBuf_Printf(&buf, " FROM `%s` WHERE `account_id`='%d' ORDER BY `nameid`", rentstorage_db, account_id);
if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) )
Sql_ShowDebug(sql_handle);
StringBuf_Destroy(&buf);
for( i = 0; i < MAX_EXTRA_STORAGE && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i )
{
item = &p->items[i];
Sql_GetData(sql_handle, 0, &data, NULL); item->id = atoi(data);
Sql_GetData(sql_handle, 1, &data, NULL); item->nameid = atoi(data);
Sql_GetData(sql_handle, 2, &data, NULL); item->amount = atoi(data);
Sql_GetData(sql_handle, 3, &data, NULL); item->equip = atoi(data);
Sql_GetData(sql_handle, 4, &data, NULL); item->identify = atoi(data);
Sql_GetData(sql_handle, 5, &data, NULL); item->refine = atoi(data);
Sql_GetData(sql_handle, 6, &data, NULL); item->attribute = atoi(data);
Sql_GetData(sql_handle, 7, &data, NULL); item->expire_time = (unsigned int)atoi(data);
Sql_GetData(sql_handle, 8, &data, NULL); item->unique_id = strtoull(data, NULL, 10);
Sql_GetData(sql_handle, 9, &data, NULL); item->bound = atoi(data);
for( j = 0; j < MAX_SLOTS; ++j )
{
Sql_GetData(sql_handle, 10+j, &data, NULL); item->card[j] = atoi(data);
}
}
p->storage_amount = i;
Sql_FreeResult(sql_handle);
ShowInfo("rentstorage load complete from DB - id: %d (total: %d)\n", account_id, p->storage_amount);
return 1;
}
示例11: SqlStmt_PrepareStr
/// Prepares the statement.
int SqlStmt_PrepareStr(SqlStmt* self, const char* query)
{
if( self == NULL )
return SQL_ERROR;
SqlStmt_FreeResult(self);
StringBuf_Clear(&self->buf);
StringBuf_AppendStr(&self->buf, query);
if( mysql_stmt_prepare(self->stmt, StringBuf_Value(&self->buf), (unsigned long)StringBuf_Length(&self->buf)) )
{
ShowSQL("DB error - %s\n", mysql_stmt_error(self->stmt));
return SQL_ERROR;
}
self->bind_params = false;
return SQL_SUCCESS;
}
示例12: Sql_QueryStr
int32 Sql_QueryStr(Sql_t* self, const char* query)
{
if( self == NULL )
return SQL_ERROR;
Sql_FreeResult(self);
StringBuf_Clear(&self->buf);
StringBuf_AppendStr(&self->buf, query);
if( mysql_real_query(&self->handle, StringBuf_Value(&self->buf), (uint32)StringBuf_Length(&self->buf)) )
{
ShowSQL("DB error - %s\n", mysql_error(&self->handle));
return SQL_ERROR;
}
self->result = mysql_store_result(&self->handle);
if( mysql_errno(&self->handle) != 0 )
{
ShowSQL("DB error - %s\n", mysql_error(&self->handle));
return SQL_ERROR;
}
return SQL_SUCCESS;
}
示例13: mail_savemessage
/// Stores a single message in the database.
/// Returns the message's ID if successful (or 0 if it fails).
int mail_savemessage(struct mail_message *msg)
{
StringBuf buf;
SqlStmt *stmt;
int j;
// build message save query
StringBuf_Init(&buf);
StringBuf_Printf(&buf, "INSERT INTO `%s` (`send_name`, `send_id`, `dest_name`, `dest_id`, `title`, `message`, `time`, `status`, `zeny`, `amount`, `nameid`, `refine`, `attribute`, `identify`, `unique_id`", mail_db);
for(j = 0; j < MAX_SLOTS; j++)
StringBuf_Printf(&buf, ", `card%d`", j);
StringBuf_Printf(&buf, ") VALUES (?, '%d', ?, '%d', ?, ?, '%lu', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%"PRIu64"'",
msg->send_id, msg->dest_id, (unsigned long)msg->timestamp, msg->status, msg->zeny, msg->item.amount, msg->item.nameid, msg->item.refine, msg->item.attribute, msg->item.identify, msg->item.unique_id);
for(j = 0; j < MAX_SLOTS; j++)
StringBuf_Printf(&buf, ", '%d'", msg->item.card[j]);
StringBuf_AppendStr(&buf, ")");
//Unique Non Stackable Item ID
updateLastUid(msg->item.unique_id);
dbUpdateUid(sql_handle);
// prepare and execute query
stmt = SqlStmt_Malloc(sql_handle);
if(SQL_SUCCESS != SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, msg->send_name, strnlen(msg->send_name, NAME_LENGTH))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, msg->dest_name, strnlen(msg->dest_name, NAME_LENGTH))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 2, SQLDT_STRING, msg->title, strnlen(msg->title, MAIL_TITLE_LENGTH))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 3, SQLDT_STRING, msg->body, strnlen(msg->body, MAIL_BODY_LENGTH))
|| SQL_SUCCESS != SqlStmt_Execute(stmt)) {
SqlStmt_ShowDebug(stmt);
msg->id = 0;
} else
msg->id = (int)SqlStmt_LastInsertId(stmt);
SqlStmt_Free(stmt);
StringBuf_Destroy(&buf);
return msg->id;
}
示例14: buyingstore_create
//.........这里部分代码省略.........
{// custom: no vending cells
clif_displaymessage(sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
return 4;
}
weight = sd->weight;
// check item list
for( i = 0; i < count; i++ )
{// itemlist: <name id>.W <amount>.W <price>.L
unsigned short nameid, amount;
int price, idx;
struct item_data* id;
nameid = RBUFW(itemlist,i*8+0);
amount = RBUFW(itemlist,i*8+2);
price = RBUFL(itemlist,i*8+4);
if( ( id = itemdb_exists(nameid) ) == NULL || amount == 0 )
{// invalid input
break;
}
if( price <= 0 || price > BUYINGSTORE_MAX_PRICE )
{// invalid price: unlike vending, items cannot be bought at 0 Zeny
break;
}
if( !id->flag.buyingstore || !itemdb_cantrade_sub(id, pc_get_group_level(sd), pc_get_group_level(sd)) || ( idx = pc_search_inventory(sd, nameid) ) == -1 )
{// restrictions: allowed, no character-bound items and at least one must be owned
break;
}
if( sd->inventory.u.items_inventory[idx].amount + amount > BUYINGSTORE_MAX_AMOUNT )
{// too many items of same kind
break;
}
if( i )
{// duplicate check. as the client does this too, only malicious intent should be caught here
ARR_FIND( 0, i, listidx, sd->buyingstore.items[listidx].nameid == nameid );
if( listidx != i )
{// duplicate
ShowWarning("buyingstore_create: Found duplicate item on buying list (nameid=%hu, amount=%hu, account_id=%d, char_id=%d).\n", nameid, amount, sd->status.account_id, sd->status.char_id);
break;
}
}
weight+= id->weight*amount;
sd->buyingstore.items[i].nameid = nameid;
sd->buyingstore.items[i].amount = amount;
sd->buyingstore.items[i].price = price;
}
if( i != count )
{// invalid item/amount/price
sd->buyingstore.slots = 0;
clif_buyingstore_open_failed(sd, BUYINGSTORE_CREATE, 0);
return 5;
}
if( (sd->max_weight*90)/100 < weight )
{// not able to carry all wanted items without getting overweight (90%)
sd->buyingstore.slots = 0;
clif_buyingstore_open_failed(sd, BUYINGSTORE_CREATE_OVERWEIGHT, weight);
return 7;
}
// success
sd->state.buyingstore = true;
sd->buyer_id = buyingstore_getuid();
sd->buyingstore.zenylimit = zenylimit;
sd->buyingstore.slots = i; // store actual amount of items
safestrncpy(sd->message, storename, sizeof(sd->message));
Sql_EscapeString( mmysql_handle, message_sql, sd->message );
if( Sql_Query( mmysql_handle, "INSERT INTO `%s`(`id`, `account_id`, `char_id`, `sex`, `map`, `x`, `y`, `title`, `limit`, `autotrade`, `body_direction`, `head_direction`, `sit`) "
"VALUES( %d, %d, %d, '%c', '%s', %d, %d, '%s', %d, %d, '%d', '%d', '%d' );",
buyingstores_table, sd->buyer_id, sd->status.account_id, sd->status.char_id, sd->status.sex == 0 ? 'F' : 'M', map[sd->bl.m].name, sd->bl.x, sd->bl.y, message_sql, sd->buyingstore.zenylimit, sd->state.autotrade, at ? at->dir : sd->ud.dir, at ? at->head_dir : sd->head_dir, at ? at->sit : pc_issit(sd) ) != SQL_SUCCESS ){
Sql_ShowDebug(mmysql_handle);
}
StringBuf_Init(&buf);
StringBuf_Printf(&buf, "INSERT INTO `%s`(`buyingstore_id`,`index`,`item_id`,`amount`,`price`) VALUES", buyingstore_items_table);
for (i = 0; i < sd->buyingstore.slots; i++){
StringBuf_Printf(&buf, "(%d,%d,%hu,%d,%d)", sd->buyer_id, i, sd->buyingstore.items[i].nameid, sd->buyingstore.items[i].amount, sd->buyingstore.items[i].price);
if (i < sd->buyingstore.slots-1)
StringBuf_AppendStr(&buf, ",");
}
if (SQL_ERROR == Sql_QueryStr(mmysql_handle, StringBuf_Value(&buf)))
Sql_ShowDebug(mmysql_handle);
StringBuf_Destroy(&buf);
clif_buyingstore_myitemlist(sd);
clif_buyingstore_entry(sd);
idb_put(buyingstore_db, sd->status.char_id, sd);
return 0;
}
示例15: mapif_parse_itembound_retrieve
/**
* ZI 0x3056 <char_id>.L <account_id>.L <guild_id>.W
* Pulls guild bound items for offline characters
* @author [Akinari]
*/
int mapif_parse_itembound_retrieve(int fd)
{
StringBuf buf;
SqlStmt *stmt;
unsigned short i = 0, count = 0;
struct item item, items[MAX_INVENTORY];
int j, guild_id = RFIFOW(fd,10);
uint32 char_id = RFIFOL(fd,2), account_id = RFIFOL(fd,6);
StringBuf_Init(&buf);
//Get bound items from player's inventory
StringBuf_AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `bound`");
for( j = 0; j < MAX_SLOTS; ++j )
StringBuf_Printf(&buf, ", `card%d`", j);
StringBuf_Printf(&buf, " FROM `%s` WHERE `char_id`='%d' AND `bound` = %d", inventory_db, char_id, BOUND_GUILD);
stmt = SqlStmt_Malloc(sql_handle);
if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) ||
SQL_ERROR == SqlStmt_Execute(stmt) )
{
SqlStmt_ShowDebug(stmt);
SqlStmt_Free(stmt);
StringBuf_Destroy(&buf);
mapif_itembound_ack(fd, account_id, guild_id);
return 1;
}
SqlStmt_BindColumn(stmt, 0, SQLDT_INT, &item.id, 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 1, SQLDT_USHORT, &item.nameid, 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 2, SQLDT_SHORT, &item.amount, 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 3, SQLDT_USHORT, &item.equip, 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 4, SQLDT_CHAR, &item.identify, 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 5, SQLDT_CHAR, &item.refine, 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 6, SQLDT_CHAR, &item.attribute, 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 7, SQLDT_UINT, &item.expire_time, 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 8, SQLDT_UINT, &item.bound, 0, NULL, NULL);
for( j = 0; j < MAX_SLOTS; ++j )
SqlStmt_BindColumn(stmt, 9 + j, SQLDT_SHORT, &item.card[j], 0, NULL, NULL);
memset(&items, 0, sizeof(items));
while( SQL_SUCCESS == SqlStmt_NextRow(stmt) )
memcpy(&items[count++], &item, sizeof(struct item));
Sql_FreeResult(sql_handle);
ShowInfo("Found '"CL_WHITE"%d"CL_RESET"' guild bound item(s) from CID = "CL_WHITE"%d"CL_RESET", AID = %d, Guild ID = "CL_WHITE"%d"CL_RESET".\n", count, char_id, account_id, guild_id);
if( !count ) { //No items found - No need to continue
StringBuf_Destroy(&buf);
SqlStmt_Free(stmt);
mapif_itembound_ack(fd, account_id, guild_id);
return 1;
}
set_session_flag(account_id, 1);
//Delete bound items from player's inventory
StringBuf_Clear(&buf);
StringBuf_Printf(&buf, "DELETE FROM `%s` WHERE `bound` = %d", inventory_db, BOUND_GUILD);
if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) ||
SQL_ERROR == SqlStmt_Execute(stmt) )
{
SqlStmt_ShowDebug(stmt);
SqlStmt_Free(stmt);
StringBuf_Destroy(&buf);
mapif_itembound_ack(fd, account_id, guild_id);
return 1;
}
//Send the deleted items to map-server to store them in guild storage [Cydh]
mapif_itembound_store2gstorage(fd, guild_id, items, count);
//Verifies equip bitmasks (see item.equip) and handles the sql statement
#define CHECK_REMOVE(var, mask, token, num) {\
if( (var)&(mask) && !(j&(num)) ) {\
if( j )\
StringBuf_AppendStr(&buf, ",");\
StringBuf_AppendStr(&buf, "`"#token"`='0'");\
j |= (1<<num);\
}\
}
StringBuf_Clear(&buf);
j = 0;
for( i = 0; i < count && i < MAX_INVENTORY; i++ ) {
if( !&items[i] || !items[i].equip )
continue;
//Equips can be at more than one slot at the same time
CHECK_REMOVE(items[i].equip, EQP_HAND_R, weapon, 0);
CHECK_REMOVE(items[i].equip, EQP_HAND_L, shield, 1);
CHECK_REMOVE(items[i].equip, EQP_HEAD_TOP|EQP_COSTUME_HEAD_TOP, head_top, 2);
CHECK_REMOVE(items[i].equip, EQP_HEAD_MID|EQP_COSTUME_HEAD_MID, head_mid, 3);
CHECK_REMOVE(items[i].equip, EQP_HEAD_LOW|EQP_COSTUME_HEAD_LOW, head_bottom, 4);
CHECK_REMOVE(items[i].equip, EQP_GARMENT|EQP_COSTUME_GARMENT, robe, 5);
}
//.........这里部分代码省略.........