/*========================================== * new auth system [Kevin] *------------------------------------------*/ void chrif_authreq(struct map_session_data *sd) { struct auth_node *auth_data; auth_data=idb_get(auth_db, sd->bl.id); if(auth_data) { if(auth_data->char_dat && auth_data->account_id== sd->bl.id && auth_data->login_id1 == sd->login_id1) { //auth ok pc_authok(sd, auth_data->login_id2, auth_data->connect_until_time, auth_data->char_dat); } else { //auth failed pc_authfail(sd); chrif_char_offline(sd); //Set him offline, the char server likely has it set as online already. } if (auth_data->char_dat) aFree(auth_data->char_dat); idb_remove(auth_db, sd->bl.id); } else { //data from char server has not arrived yet. auth_data = aCalloc(1,sizeof(struct auth_node)); auth_data->sd = sd; auth_data->fd = sd->fd; auth_data->account_id = sd->bl.id; auth_data->login_id1 = sd->login_id1; auth_data->node_created = gettick(); uidb_put(auth_db, sd->bl.id, auth_data); } return; }
/** * Create new item data * @param nameid */ static struct item_data *itemdb_create_item(unsigned short nameid) { struct item_data *id; CREATE(id, struct item_data, 1); memset(id, 0, sizeof(struct item_data)); id->nameid = nameid; id->type = IT_ETC; //Etc item uidb_put(itemdb, nameid, id); return id; }
int setInvalidCount(unsigned int ip) { int c=uidb_get(bf_lockout,ip); if(!c) { timer_insert(10*60*1000,10*60*1000,login_clear_lockout,ip,0); } uidb_put(bf_lockout,ip,c+1); return c+1; }
//character selected, insert into auth db void chrif_authok(int fd) { struct auth_node *auth_data; TBL_PC* sd; //Check if we don't already have player data in our server //(prevents data that is to be saved from being overwritten by //this received status data if this auth is later successful) [Skotlex] if ((sd = map_id2sd(RFIFOL(fd, 4))) != NULL) { struct mmo_charstatus *status = (struct mmo_charstatus *)RFIFOP(fd, 20); //Auth check is because this could be the very same sd that is waiting char-server authorization. if (sd->state.auth && sd->status.char_id == status->char_id) return; } if ((auth_data =uidb_get(auth_db, RFIFOL(fd, 4))) != NULL) { //Is the character already awaiting authorization? if (auth_data->sd) { //First, check to see if the session data still exists (avoid dangling pointers) if(session[auth_data->fd] && session[auth_data->fd]->session_data == auth_data->sd) { if (auth_data->char_dat == NULL && auth_data->account_id == RFIFOL(fd, 4) && auth_data->login_id1 == RFIFOL(fd, 8)) { //Auth Ok pc_authok(auth_data->sd, RFIFOL(fd, 16), RFIFOL(fd, 12), (struct mmo_charstatus*)RFIFOP(fd, 20)); } else { //Auth Failed pc_authfail(auth_data->sd); chrif_char_offline(auth_data->sd); //Set him offline, the char server likely has it set as online already. } } //else: Character no longer exists, just go through. } //Delete the data of this node... if (auth_data->char_dat) aFree (auth_data->char_dat); uidb_remove(auth_db, RFIFOL(fd, 4)); return; } // Awaiting for client to connect. auth_data = (struct auth_node *)aCalloc(1,sizeof(struct auth_node)); auth_data->char_dat = (struct mmo_charstatus *) aCalloc(1,sizeof(struct mmo_charstatus)); auth_data->account_id=RFIFOL(fd, 4); auth_data->login_id1=RFIFOL(fd, 8); auth_data->connect_until_time=RFIFOL(fd, 12); auth_data->login_id2=RFIFOL(fd, 16); memcpy(auth_data->char_dat,RFIFOP(fd, 20),sizeof(struct mmo_charstatus)); auth_data->node_created=gettick(); uidb_put(auth_db, RFIFOL(fd, 4), auth_data); }
struct creation_data* createdb_search(int id) { static struct creation_data *db=NULL; if (db && db->id == id) return db; db = uidb_get(create_db, id); if (db) return db; CALLOC(db, struct creation_data, 1); uidb_put(create_db, id, db); db->id = id; //strcpy(db->name, "??"); return db; }
struct class_data* classdb_search(int id) { static struct class_data *db=NULL; if (db && db->id == id) return db; db = uidb_get(class_db, id); if (db) return db; CALLOC(db, struct class_data, 1); uidb_put(class_db, id, db); db->id = id; db->chat=0; strcpy(db->rank0,"??"); //strcpy(db->rank_name[0], "??"); return db; }
/** * Initializing autotraders from table */ void do_init_buyingstore_autotrade( void ) { if(battle_config.feature_autotrade) { if (Sql_Query(mmysql_handle, "SELECT `id`, `account_id`, `char_id`, `sex`, `title`, `limit`, `body_direction`, `head_direction`, `sit` " "FROM `%s` " "WHERE `autotrade` = 1 AND `limit` > 0 AND (SELECT COUNT(`buyingstore_id`) FROM `%s` WHERE `buyingstore_id` = `id`) > 0 " "ORDER BY `id`;", buyingstores_table, buyingstore_items_table ) != SQL_SUCCESS ) { Sql_ShowDebug(mmysql_handle); return; } if( Sql_NumRows(mmysql_handle) > 0 ) { uint16 items = 0; DBIterator *iter = NULL; struct s_autotrader *at = NULL; // Init each autotrader data while (SQL_SUCCESS == Sql_NextRow(mmysql_handle)) { size_t len; char* data; at = NULL; CREATE(at, struct s_autotrader, 1); Sql_GetData(mmysql_handle, 0, &data, NULL); at->id = atoi(data); Sql_GetData(mmysql_handle, 1, &data, NULL); at->account_id = atoi(data); Sql_GetData(mmysql_handle, 2, &data, NULL); at->char_id = atoi(data); Sql_GetData(mmysql_handle, 3, &data, NULL); at->sex = (data[0] == 'F') ? 0 : 1; Sql_GetData(mmysql_handle, 4, &data, &len); safestrncpy(at->title, data, zmin(len + 1, MESSAGE_SIZE)); Sql_GetData(mmysql_handle, 5, &data, NULL); at->limit = atoi(data); Sql_GetData(mmysql_handle, 6, &data, NULL); at->dir = atoi(data); Sql_GetData(mmysql_handle, 7, &data, NULL); at->head_dir = atoi(data); Sql_GetData(mmysql_handle, 8, &data, NULL); at->sit = atoi(data); at->count = 0; if (battle_config.feature_autotrade_direction >= 0) at->dir = battle_config.feature_autotrade_direction; if (battle_config.feature_autotrade_head_direction >= 0) at->head_dir = battle_config.feature_autotrade_head_direction; if (battle_config.feature_autotrade_sit >= 0) at->sit = battle_config.feature_autotrade_sit; // initialize player CREATE(at->sd, struct map_session_data, 1); pc_setnewpc(at->sd, at->account_id, at->char_id, 0, gettick(), at->sex, 0); at->sd->state.autotrade = 1|4; at->sd->state.monster_ignore = (battle_config.autotrade_monsterignore); chrif_authreq(at->sd, true); uidb_put(buyingstore_autotrader_db, at->char_id, at); } Sql_FreeResult(mmysql_handle); // Init items for each autotraders iter = db_iterator(buyingstore_autotrader_db); for (at = (struct s_autotrader *)dbi_first(iter); dbi_exists(iter); at = (struct s_autotrader *)dbi_next(iter)) { uint16 j = 0; if (SQL_ERROR == Sql_Query(mmysql_handle, "SELECT `item_id`, `amount`, `price` " "FROM `%s` " "WHERE `buyingstore_id` = %d " "ORDER BY `index` ASC;", buyingstore_items_table, at->id ) ) { Sql_ShowDebug(mmysql_handle); continue; } if (!(at->count = (uint16)Sql_NumRows(mmysql_handle))) { map_quit(at->sd); buyingstore_autotrader_remove(at, true); continue; } //Init the list CREATE(at->entries, struct s_autotrade_entry *,at->count); //Add the item into list j = 0; while (SQL_SUCCESS == Sql_NextRow(mmysql_handle) && j < at->count) { char *data; CREATE(at->entries[j], struct s_autotrade_entry, 1); Sql_GetData(mmysql_handle, 0, &data, NULL); at->entries[j]->item_id = atoi(data); Sql_GetData(mmysql_handle, 1, &data, NULL); at->entries[j]->amount = atoi(data); Sql_GetData(mmysql_handle, 2, &data, NULL); at->entries[j]->price = atoi(data); j++; } items += j; Sql_FreeResult(mmysql_handle); } dbi_destroy(iter); ShowStatus("Done loading '"CL_WHITE"%d"CL_RESET"' buyingstore autotraders with '"CL_WHITE"%d"CL_RESET"' items.\n", db_size(buyingstore_autotrader_db), items); } }
/** Read item group data * Structure: GroupID,ItemID,Rate{,Amount,isMust,isAnnounced,Duration,GUID,isBound,isNamed} */ static void itemdb_read_itemgroup_sub(const char* filename, bool silent) { FILE *fp; int ln = 0, entries = 0; char line[1024]; if ((fp=fopen(filename,"r")) == NULL) { if(silent == 0) ShowError("Can't read %s\n", filename); return; } while (fgets(line,sizeof(line),fp)) { DBData data; int group_id = -1; unsigned int j, prob = 1; uint8 rand_group = 1; char *str[10], *p; struct s_item_group_random *random = NULL; struct s_item_group_db *group = NULL; struct s_item_group_entry entry; bool found = false; ln++; if (line[0] == '/' && line[1] == '/') continue; if (strstr(line,"import")) { char w1[16], w2[64]; if (sscanf(line,"%15[^:]: %63[^\r\n]",w1,w2) == 2 && strcmpi(w1,"import") == 0) { itemdb_read_itemgroup_sub(w2, 0); continue; } } memset(str,0,sizeof(str)); for (j = 0, p = line; j < 9 && p;j++) { str[j] = p; p = strchr(p,','); if (p) *p++=0; } if (str[0] == NULL) //Empty Group ID continue; if (j < 3) { if (j > 1) // Or else it barks on blank lines... ShowWarning("itemdb_read_itemgroup: Insufficient fields for entry at %s:%d\n", filename, ln); continue; } memset(&entry, 0, sizeof(entry)); entry.amount = 1; entry.bound = BOUND_NONE; // Checking group_id trim(str[0]); if (ISDIGIT(str[0][0])) group_id = atoi(str[0]); else // Try reads group id by const script_get_constant(trim(str[0]), &group_id); if (group_id < 0) { ShowWarning("itemdb_read_itemgroup: Invalid Group ID '%s' (%s:%d)\n", str[0], filename, ln); continue; } // Remove from DB if (strcmpi(str[1], "clear") == 0 && itemdb_group->remove(itemdb_group, db_ui2key(group_id), &data)) { itemdb_group_free(db_ui2key(group_id), &data, 0); ShowNotice("Item Group '%s' has been cleared.\n", str[0]); continue; } // Checking sub group prob = atoi(str[2]); if (str[4] != NULL) rand_group = atoi(str[4]); if (rand_group < 0 || rand_group > MAX_ITEMGROUP_RANDGROUP) { ShowWarning("itemdb_read_itemgroup: Invalid sub group '%d' for group '%s' in %s:%d\n", rand_group, str[0], filename, ln); continue; } if (rand_group != 0 && prob < 1) { ShowWarning("itemdb_read_itemgroup: Random item must has probability. Group '%s' in %s:%d\n", str[0], filename, ln); continue; } // Checking item trim(str[1]); if (ISDIGIT(str[1][0]) && ISDIGIT(str[1][1]) && itemdb_exists((entry.nameid = atoi(str[1])))) found = true; else { struct item_data *id = itemdb_searchname(str[1]); if (id) { entry.nameid = id->nameid; found = true; } } if (!found) { ShowWarning("itemdb_read_itemgroup: Non-existant item '%s' in %s:%d\n", str[1], filename, ln); continue; } if (str[3] != NULL) entry.amount = cap_value(atoi(str[3]),1,MAX_AMOUNT); if (str[5] != NULL) entry.isAnnounced= atoi(str[5]); if (str[6] != NULL) entry.duration = cap_value(atoi(str[6]),0,UINT16_MAX); #ifdef ENABLE_ITEM_GUID if (str[7] != NULL) entry.GUID = atoi(str[7]); #endif if (str[8] != NULL) entry.bound = cap_value(atoi(str[8]),BOUND_NONE,BOUND_MAX-1); if (str[9] != NULL) entry.isNamed = atoi(str[9]); if (!(group = (struct s_item_group_db *) uidb_get(itemdb_group, group_id))) { CREATE(group, struct s_item_group_db, 1); group->id = group_id; uidb_put(itemdb_group, group->id, group); } // Must item (rand_group == 0), place it here if (!rand_group) { RECREATE(group->must, struct s_item_group_entry, group->must_qty+1); group->must[group->must_qty++] = entry; // If 'must' item isn't set as random item, skip the next process if (!prob) { entries++; continue; } rand_group = 0; }