//Load achievements for a character int mapif_achievement_fromsql(int char_id, struct s_achievement ad[]) { int i; struct s_achievement tmp_ad; SqlStmt * stmt; stmt = SqlStmt_Malloc(sql_handle); if( stmt == NULL ) { SqlStmt_ShowDebug(stmt); return 0; } memset(&tmp_ad,0,sizeof(tmp_ad)); if( SQL_ERROR == SqlStmt_Prepare(stmt, "SELECT `id`, `completed`, `count1`, `count2`, `count3`, `count4`, `count5` FROM `%s` WHERE `char_id` = ? LIMIT %d", achievement_db, ACHIEVEMENT_MAX) || SQL_ERROR == SqlStmt_BindParam(stmt, 0, SQLDT_INT, &char_id, 0) || SQL_ERROR == SqlStmt_Execute(stmt) || SQL_ERROR == SqlStmt_BindColumn(stmt, 0, SQLDT_INT, &tmp_ad.id, 0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 1, SQLDT_CHAR, &tmp_ad.completed, 0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 2, SQLDT_INT, &tmp_ad.count[0], 0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 3, SQLDT_INT, &tmp_ad.count[1], 0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 4, SQLDT_INT, &tmp_ad.count[2], 0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 5, SQLDT_INT, &tmp_ad.count[3], 0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 6, SQLDT_INT, &tmp_ad.count[4], 0, NULL, NULL) ) SqlStmt_ShowDebug(stmt); for( i = 0; i < ACHIEVEMENT_MAX && SQL_SUCCESS == SqlStmt_NextRow(stmt); ++i ) memcpy(&ad[i], &tmp_ad, sizeof(tmp_ad)); SqlStmt_Free(stmt); return i; }
//Load entire questlog for a character int mapif_quests_fromsql(int char_id, struct quest questlog[]) { int i; struct quest tmp_quest; SqlStmt * stmt; stmt = SqlStmt_Malloc(sql_handle); if( stmt == NULL ) { SqlStmt_ShowDebug(stmt); return 0; } memset(&tmp_quest, 0, sizeof(struct quest)); if( SQL_ERROR == SqlStmt_Prepare(stmt, "SELECT `quest_id`, `state`, `time`, `count1`, `count2`, `count3` FROM `%s` WHERE `char_id`=? LIMIT %d", quest_db, MAX_QUEST_DB) || SQL_ERROR == SqlStmt_BindParam(stmt, 0, SQLDT_INT, &char_id, 0) || SQL_ERROR == SqlStmt_Execute(stmt) || SQL_ERROR == SqlStmt_BindColumn(stmt, 0, SQLDT_INT, &tmp_quest.quest_id, 0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 1, SQLDT_INT, &tmp_quest.state, 0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 2, SQLDT_UINT, &tmp_quest.time, 0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 3, SQLDT_INT, &tmp_quest.count[0], 0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 4, SQLDT_INT, &tmp_quest.count[1], 0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 5, SQLDT_INT, &tmp_quest.count[2], 0, NULL, NULL) ) SqlStmt_ShowDebug(stmt); for( i = 0; i < MAX_QUEST_DB && SQL_SUCCESS == SqlStmt_NextRow(stmt); ++i ) memcpy(&questlog[i], &tmp_quest, sizeof(tmp_quest)); SqlStmt_Free(stmt); return i; }
/** * 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; }
/** * Loads the entire questlog 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 quest *mapif_quests_fromsql(uint32 char_id, int *count) { struct quest *questlog = NULL; struct quest tmp_quest; SqlStmt *stmt; if( !count ) return NULL; stmt = SqlStmt_Malloc(sql_handle); if( stmt == NULL ) { SqlStmt_ShowDebug(stmt); *count = 0; return NULL; } memset(&tmp_quest, 0, sizeof(struct quest)); if( SQL_ERROR == SqlStmt_Prepare(stmt, "SELECT `quest_id`, `state`, `time`, `count1`, `count2`, `count3` FROM `%s` WHERE `char_id`=? ", schema_config.quest_db) || SQL_ERROR == SqlStmt_BindParam(stmt, 0, SQLDT_INT, &char_id, 0) || SQL_ERROR == SqlStmt_Execute(stmt) || SQL_ERROR == SqlStmt_BindColumn(stmt, 0, SQLDT_INT, &tmp_quest.quest_id, 0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 1, SQLDT_INT, &tmp_quest.state, 0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 2, SQLDT_UINT, &tmp_quest.time, 0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 3, SQLDT_INT, &tmp_quest.count[0], 0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 4, SQLDT_INT, &tmp_quest.count[1], 0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 5, SQLDT_INT, &tmp_quest.count[2], 0, NULL, NULL) ) { SqlStmt_ShowDebug(stmt); SqlStmt_Free(stmt); *count = 0; return NULL; } *count = (int)SqlStmt_NumRows(stmt); if( *count > 0 ) { int i = 0; questlog = (struct quest *)aCalloc(*count, sizeof(struct quest)); while( SQL_SUCCESS == SqlStmt_NextRow(stmt) ) { if( i >= *count ) //Sanity check, should never happen break; memcpy(&questlog[i++], &tmp_quest, sizeof(tmp_quest)); } if( i < *count ) { //Should never happen. Compact array *count = i; questlog = (struct quest *)aRealloc(questlog, sizeof(struct quest) * i); } } SqlStmt_Free(stmt); return questlog; }
int chlogif_parse_ackchangesex(int fd, struct char_session_data* sd) { if (RFIFOREST(fd) < 7) return 0; else { unsigned char buf[7]; int acc = RFIFOL(fd,2); int sex = RFIFOB(fd,6); RFIFOSKIP(fd,7); if (acc > 0) { // TODO: Is this even possible? unsigned char i; int char_id = 0, class_ = 0, guild_id = 0; DBMap* auth_db = char_get_authdb(); struct auth_node* node = (struct auth_node*)idb_get(auth_db, acc); SqlStmt *stmt; if (node != NULL) node->sex = sex; // get characters stmt = SqlStmt_Malloc(sql_handle); if (SQL_ERROR == SqlStmt_Prepare(stmt, "SELECT `char_id`, `class`, `guild_id` FROM `%s` WHERE `account_id` = '%d'", schema_config.char_db, acc) || SqlStmt_Execute(stmt)) { SqlStmt_ShowDebug(stmt); SqlStmt_Free(stmt); } SqlStmt_BindColumn(stmt, 0, SQLDT_INT, &char_id, 0, NULL, NULL); SqlStmt_BindColumn(stmt, 1, SQLDT_SHORT, &class_, 0, NULL, NULL); SqlStmt_BindColumn(stmt, 2, SQLDT_INT, &guild_id, 0, NULL, NULL); for (i = 0; i < MAX_CHARS && SQL_SUCCESS == SqlStmt_NextRow(stmt); ++i) { chlogif_parse_change_sex_sub(sex, acc, char_id, class_, guild_id); } SqlStmt_Free(stmt); } // notify all mapservers about this change WBUFW(buf,0) = 0x2b0d; WBUFL(buf,2) = acc; WBUFB(buf,6) = sex; chmapif_sendall(buf, 7); } return 1; }
/// Loads permanent variables from database static void script_load_mapreg(void) { /* 0 1 2 +-------------------------+ | varname | index | value | +-------------------------+ */ SqlStmt* stmt = SqlStmt_Malloc(mmysql_handle); char varname[32+1]; int index; char value[255+1]; uint32 length; if ( SQL_ERROR == SqlStmt_Prepare(stmt, "SELECT `varname`, `index`, `value` FROM `%s`", mapreg_table) || SQL_ERROR == SqlStmt_Execute(stmt) ) { SqlStmt_ShowDebug(stmt); SqlStmt_Free(stmt); return; } SqlStmt_BindColumn(stmt, 0, SQLDT_STRING, &varname[0], sizeof(varname), &length, NULL); SqlStmt_BindColumn(stmt, 1, SQLDT_INT, &index, 0, NULL, NULL); SqlStmt_BindColumn(stmt, 2, SQLDT_STRING, &value[0], sizeof(value), NULL, NULL); while ( SQL_SUCCESS == SqlStmt_NextRow(stmt) ) { int s = add_str(varname); int i = index; if( varname[length-1] == '$' ) idb_put(mapregstr_db, (i<<24)|s, aStrdup(value)); else { idb_put(mapreg_db, (i<<24)|s, (void *)atoi(value)); if( !strcmp(varname, "$Region") && i > 0 && i < MAX_REGIONS ) region[i].guild_id = atoi(value); // Regional Control } } SqlStmt_Free(stmt); mapreg_dirty = false; }
static bool harmony_iterate_groups_adminlevel(int group_id, int level, const char* name) { int account_id; if (level < current_groupscan_minlevel) return true; ShowInfo("Registering group %d..\n", group_id); if (SQL_SUCCESS != SqlStmt_BindParam(admin_stmt, 0, SQLDT_INT, (void*)&group_id, sizeof(group_id)) || SQL_SUCCESS != SqlStmt_Execute(admin_stmt)) { ShowError("Fetching GM accounts from group %d failed.\n", group_id); Sql_ShowDebug(mmysql_handle); return true; } SqlStmt_BindColumn(admin_stmt, 0, SQLDT_INT, &account_id, 0, NULL, NULL); while (SQL_SUCCESS == SqlStmt_NextRow(admin_stmt)) { harm_funcs->zone_register_admin(account_id, false); } return true; }
/** * 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); } #undef CHECK_REMOVE //Update player's view if( j ) { StringBuf buf2; StringBuf_Init(&buf2); StringBuf_Printf(&buf2, "UPDATE `%s` SET %s WHERE `char_id`='%d'", char_db, StringBuf_Value(&buf), char_id); if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) || SQL_ERROR == SqlStmt_Execute(stmt) ) { SqlStmt_ShowDebug(stmt); SqlStmt_Free(stmt); StringBuf_Destroy(&buf); StringBuf_Destroy(&buf2); mapif_itembound_ack(fd, account_id, guild_id); return 1; } StringBuf_Destroy(&buf2); } StringBuf_Destroy(&buf); SqlStmt_Free(stmt); unset_session_flag(account_id, 1); return 0; }
//------------------------------------------------ //Guild bound items pull for offline characters [Akinari] //------------------------------------------------ int mapif_parse_itembound_retrieve(int fd) { StringBuf buf; SqlStmt* stmt; struct item item; int j, i=0, s; bool found=false; struct item items[MAX_INVENTORY]; int char_id = RFIFOL(fd,2); int aid = RFIFOL(fd,6); int guild_id = RFIFOW(fd,10); StringBuf_Init(&buf); 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'",inventory_db,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); mapif_itembound_ack(fd,aid,guild_id); return 1; } SqlStmt_BindColumn(stmt, 0, SQLDT_INT, &item.id, 0, NULL, NULL); SqlStmt_BindColumn(stmt, 1, SQLDT_SHORT, &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); while( SQL_SUCCESS == SqlStmt_NextRow(stmt) ) { if(item.bound == 2) { memcpy(&items[i],&item,sizeof(struct item)); i++; } } Sql_FreeResult(sql_handle); if(!i) { //No items found - No need to continue StringBuf_Destroy(&buf); SqlStmt_Free(stmt); mapif_itembound_ack(fd,aid,guild_id); return 0; } //First we delete the character's items StringBuf_Clear(&buf); StringBuf_Printf(&buf, "DELETE FROM `%s` WHERE",inventory_db); for(j=0; j<i; j++) { if( found ) StringBuf_AppendStr(&buf, " OR"); else found = true; StringBuf_Printf(&buf, " `id`=%d",items[j].id); } 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,aid,guild_id); return 1; } //Now let's update the guild storage with those deleted items found = false; StringBuf_Clear(&buf); StringBuf_Printf(&buf, "INSERT INTO `%s` (`guild_id`, `nameid`, `amount`, `identify`, `refine`, `attribute`, `expire_time`, `bound`", guild_storage_db); for( j = 0; j < MAX_SLOTS; ++j ) StringBuf_Printf(&buf, ", `card%d`", j); StringBuf_AppendStr(&buf, ") VALUES "); for( j = 0; j < i; ++j ) { if( found ) StringBuf_AppendStr(&buf, ","); else found = true; StringBuf_Printf(&buf, "('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d'", guild_id, items[j].nameid, items[j].amount, items[j].identify, items[j].refine, items[j].attribute, items[j].expire_time, items[j].bound); for( s = 0; s < MAX_SLOTS; ++s ) StringBuf_Printf(&buf, ", '%d'", items[j].card[s]); StringBuf_AppendStr(&buf, ")"); } 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,aid,guild_id); return 1; } StringBuf_Destroy(&buf); SqlStmt_Free(stmt); //Finally reload storage and tell map we're done mapif_load_guild_storage(fd,aid,guild_id,0); mapif_itembound_ack(fd,aid,guild_id); return 0; }
void harmony_action_request_global(int task, int id, intptr data) { switch (task) { case HARMTASK_LOGIN_ACTION: chrif_harmony_request((uint8*)data, id); break; case HARMTASK_GET_FD: { TBL_PC *sd = BL_CAST(BL_PC, map_id2bl(id)); *(int32*)data = (sd ? sd->fd : 0); } break; case HARMTASK_SET_LOG_METHOD: log_method = id; break; case HARMTASK_INIT_GROUPS: if (chrif_isconnected()) harmony_register_groups(); else { // Register groups as soon as the char server is available again if (tid_group_register != INVALID_TIMER) _athena_delete_timer(tid_group_register, harmony_group_register_timer); tid_group_register = _athena_add_timer_interval(_athena_gettick()+1000, harmony_group_register_timer, 0, 0, 500); } break; case HARMTASK_RESOLVE_GROUP: #if HARMSW == HARMSW_RATHENA_GROUP *(int32*)data = pc_group_id2level(id); #else *(int32*)data = id; #endif break; case HARMTASK_PACKET: clif_send((const uint8*)data, id, NULL, ALL_CLIENT); break; case HARMTASK_GET_ADMINS: { #if HARMSW == HARMSW_RATHENA_GROUP // Iterate groups and register each group individually current_groupscan_minlevel = id; pc_group_iterate(harmony_iterate_groups_adminlevel); #else // int account_id; int level = id; if (SQL_SUCCESS != SqlStmt_BindParam(admin_stmt, 0, SQLDT_INT, (void*)&level, sizeof(level)) || SQL_SUCCESS != SqlStmt_Execute(admin_stmt)) { ShowError("Fetching GM accounts failed.\n"); Sql_ShowDebug(mmysql_handle); break; } SqlStmt_BindColumn(admin_stmt, 0, SQLDT_INT, &account_id, 0, NULL, NULL); while (SQL_SUCCESS == SqlStmt_NextRow(admin_stmt)) { harm_funcs->zone_register_admin(account_id, false); } #endif break; } case HARMTASK_IS_CHAR_CONNECTED: *(int*)data = chrif_isconnected(); break; default: ShowError("Harmony requested unknown action! (Global; ID=%d)\n", task); ShowError("This indicates that you are running an incompatible version.\n"); break; } }
int classdb_read(const char *classdb_file) { struct class_data *db = NULL; int i, cls=0; int x; StringBuf buf; SqlStmt* stmt; struct class_data c; memset(&c,0,sizeof(c)); stmt=SqlStmt_Malloc(sql_handle); if(stmt == NULL) { SqlStmt_ShowDebug(stmt); return 0; } StringBuf_Init(&buf); StringBuf_AppendStr(&buf,"SELECT `PthId`, `PthType`, `PthChat`, `PthIcon`"); for (i = 0; i < 16; i++) StringBuf_Printf(&buf, ", `PthMark%d`", i); StringBuf_AppendStr(&buf, " FROM `Paths`"); //CALLOC(cdata[atoi(str[1])],struct class_data,1); if(SQL_ERROR == SqlStmt_Prepare(stmt,StringBuf_Value(&buf)) || SQL_ERROR == SqlStmt_Execute(stmt) || SQL_ERROR == SqlStmt_BindColumn(stmt, 0, SQLDT_INT, &c.id,0,NULL,NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 1, SQLDT_INT, &c.path, 0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 2, SQLDT_INT, &c.chat, 0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 3, SQLDT_INT, &c.icon, 0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 4, SQLDT_STRING, &c.rank0, sizeof(c.rank0), NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 5, SQLDT_STRING, &c.rank1, sizeof(c.rank1), NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 6, SQLDT_STRING, &c.rank2, sizeof(c.rank2), NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 7, SQLDT_STRING, &c.rank3, sizeof(c.rank3), NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 8, SQLDT_STRING, &c.rank4, sizeof(c.rank4), NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 9, SQLDT_STRING, &c.rank5, sizeof(c.rank5), NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 10, SQLDT_STRING, &c.rank6, sizeof(c.rank6), NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 11, SQLDT_STRING, &c.rank7, sizeof(c.rank7), NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 12, SQLDT_STRING, &c.rank8, sizeof(c.rank8), NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 13, SQLDT_STRING, &c.rank9, sizeof(c.rank9), NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 14, SQLDT_STRING, &c.rank10, sizeof(c.rank10), NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 15, SQLDT_STRING, &c.rank11, sizeof(c.rank11), NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 16, SQLDT_STRING, &c.rank12, sizeof(c.rank12), NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 17, SQLDT_STRING, &c.rank13, sizeof(c.rank13), NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 18, SQLDT_STRING, &c.rank14, sizeof(c.rank14), NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 19, SQLDT_STRING, &c.rank15, sizeof(c.rank15), NULL, NULL) ) { SqlStmt_ShowDebug(stmt); SqlStmt_Free(stmt); StringBuf_Destroy(&buf); return 0; } //sql_request("SELECT * FROM classdb"); cls=SqlStmt_NumRows(stmt); for(i=0;i<cls && SQL_SUCCESS == SqlStmt_NextRow(stmt);i++) { db = classdb_search(c.id); memcpy(db,&c,sizeof(c)); } SqlStmt_Free(stmt); StringBuf_Destroy(&buf); printf("Class db read done. %d classes loaded!\n", cls); return 0; }
int createdb_read(const char *createdb_file) { FILE *fp; struct creation_data *db; int i, itm=0,x,id,count; SqlStmt* stmt=NULL; struct creation_data data; StringBuf buf; stmt=SqlStmt_Malloc(sql_handle); if(stmt == NULL) { SqlStmt_ShowDebug(stmt); return 0; } StringBuf_Init(&buf); StringBuf_AppendStr(&buf,"SELECT `id`,`item_created`,`item_count`,`success_rate`, `item_failed`, `item_failcount`, `item_failrate`"); for(x=1;x<11;x++) StringBuf_Printf(&buf,",`item%d`",x); for(x=1;x<11;x++) StringBuf_Printf(&buf,",`amount%d`",x); StringBuf_AppendStr(&buf," FROM `Createdb`"); memset(&data,0,sizeof(data)); if(SQL_ERROR == SqlStmt_Prepare(stmt,StringBuf_Value(&buf)) || SQL_ERROR == SqlStmt_Execute(stmt) || SQL_ERROR == SqlStmt_BindColumn(stmt, 0, SQLDT_INT, &id,0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 1, SQLDT_INT, &data.item_created,0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 2, SQLDT_INT, &data.amount,0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 3, SQLDT_INT, &data.success_rate,0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 4, SQLDT_INT, &data.item_failed,0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 5, SQLDT_INT, &data.item_failcount,0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 6, SQLDT_INT, &data.item_failrate,0, NULL, NULL) ) { SqlStmt_ShowDebug(stmt); SqlStmt_Free(stmt); StringBuf_Destroy(&buf); return 0; } for(x=0;x<10;x++) { SqlStmt_BindColumn(stmt, x+7, SQLDT_INT, &data.item[x], 0,NULL, NULL); SqlStmt_BindColumn(stmt, x+17, SQLDT_INT, &data.item_count[x],0,NULL,NULL); } for(itm=0;SQL_SUCCESS == SqlStmt_NextRow(stmt);itm++) { db = createdb_search(id); db->item_created=data.item_created; db->amount=data.amount; db->success_rate=data.success_rate; db->item_failed=data.item_failed; db->item_failcount=data.item_failcount; db->item_failrate=data.item_failrate; db->count=0; for(x=0;x<10;x++) { db->item[x]=data.item[x]; db->item_count[x]=data.item_count[x]; if(db->item[x]>0) db->count++; } } SqlStmt_Free(stmt); StringBuf_Destroy(&buf); printf("Creation db read done. %u creations loaded!\n", itm); return 0; }