diff options
Diffstat (limited to 'src/char')
-rw-r--r-- | src/char/int_guild.c | 50 | ||||
-rw-r--r-- | src/char/int_quest.c | 67 |
2 files changed, 74 insertions, 43 deletions
diff --git a/src/char/int_guild.c b/src/char/int_guild.c index 427c57531..ec01dab5b 100644 --- a/src/char/int_guild.c +++ b/src/char/int_guild.c @@ -35,7 +35,7 @@ static const char dataToHex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9 static DBMap* guild_db_; // int guild_id -> struct guild* static DBMap *castle_db; -static unsigned int guild_exp[100]; +static unsigned int guild_exp[MAX_GUILDLEVEL]; int mapif_parse_GuildLeave(int fd,int guild_id,int account_id,int char_id,int flag,const char *mes); int mapif_guild_broken(int guild_id,int flag); @@ -598,16 +598,15 @@ static struct guild_castle* inter_guildcastle_fromsql(int castle_id) // Read exp_guild.txt -static bool exp_guild_parse_row(char* split[], int column, int current) -{ - unsigned int exp = (unsigned int)atol(split[0]); +static bool exp_guild_parse_row(char* split[], int column, int current) { + int64 exp = strtoll(split[0], NULL, 10); - if (exp >= UINT_MAX) { - ShowError("exp_guild: Invalid exp %d at line %d\n", exp, current); + if (exp < 0 || exp >= UINT_MAX) { + ShowError("exp_guild: Invalid exp %"PRId64" (valid range: 0 - %u) at line %d\n", exp, UINT_MAX, current); return false; } - guild_exp[current] = exp; + guild_exp[current] = (unsigned int)exp; return true; } @@ -725,7 +724,7 @@ int inter_guild_sql_init(void) castle_db = idb_alloc(DB_OPT_RELEASE_DATA); //Read exp file - sv->readdb("db", DBPATH"exp_guild.txt", ',', 1, 1, 100, exp_guild_parse_row); + sv->readdb("db", DBPATH"exp_guild.txt", ',', 1, 1, MAX_GUILDLEVEL, exp_guild_parse_row); timer->add_func_list(guild_save_timer, "guild_save_timer"); timer->add(timer->gettick() + 10000, guild_save_timer, 0, 0); @@ -794,14 +793,13 @@ static bool guild_check_empty(struct guild *g) return true; } -unsigned int guild_nextexp(int level) -{ +unsigned int guild_nextexp(int level) { if (level == 0) return 1; - if (level < 100 && level > 0) // Change by hack - return guild_exp[level-1]; + if (level <= 0 || level >= MAX_GUILDLEVEL) + return 0; - return 0; + return guild_exp[level-1]; } int guild_checkskill(struct guild *g,int id) @@ -825,7 +823,7 @@ int guild_calcinfo(struct guild *g) nextexp = guild_nextexp(g->guild_lv); // Consume guild exp and increase guild level - while(g->exp >= nextexp && nextexp > 0){ //fixed guild exp overflow [Kevin] + while(g->exp >= nextexp && nextexp > 0) { // nextexp would be 0 if g->guild_lv was >= MAX_GUILDLEVEL g->exp-=nextexp; g->guild_lv++; g->skill_point++; @@ -1424,24 +1422,20 @@ int mapif_parse_GuildMessage(int fd,int guild_id,int account_id,char *mes,int le } // Modification of the guild -int mapif_parse_GuildBasicInfoChange(int fd,int guild_id,int type,const char *data,int len) -{ - struct guild * g; - short dw=*((short *)data); +int mapif_parse_GuildBasicInfoChange(int fd, int guild_id, int type, const void *data, int len) { + struct guild *g; + short value = *((const int16 *)data); g = inter_guild_fromsql(guild_id); if(g==NULL) return 0; - switch(type) - { + switch(type) { case GBI_GUILDLV: - if(dw>0 && g->guild_lv+dw<=50) - { - g->guild_lv+=dw; - g->skill_point+=dw; - } - else if(dw<0 && g->guild_lv+dw>=1) - g->guild_lv+=dw; + if (value > 0 && g->guild_lv + value <= MAX_GUILDLEVEL) { + g->guild_lv += value; + g->skill_point += value; + } else if (value < 0 && g->guild_lv + value >= 1) + g->guild_lv += value; mapif_guild_info(-1,g); g->save_flag |= GS_LEVEL; return 0; @@ -1837,7 +1831,7 @@ int inter_guild_parse_frommap(int fd) case 0x3035: mapif_parse_GuildChangeMemberInfoShort(fd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14),RFIFOW(fd,15),RFIFOW(fd,17)); break; case 0x3036: mapif_parse_BreakGuild(fd,RFIFOL(fd,2)); break; case 0x3037: mapif_parse_GuildMessage(fd,RFIFOL(fd,4),RFIFOL(fd,8),(char*)RFIFOP(fd,12),RFIFOW(fd,2)-12); break; - case 0x3039: mapif_parse_GuildBasicInfoChange(fd,RFIFOL(fd,4),RFIFOW(fd,8),(const char*)RFIFOP(fd,10),RFIFOW(fd,2)-10); break; + case 0x3039: mapif_parse_GuildBasicInfoChange(fd,RFIFOL(fd,4),RFIFOW(fd,8),(const int16 *)RFIFOP(fd,10),RFIFOW(fd,2)-10); break; case 0x303A: mapif_parse_GuildMemberInfoChange(fd,RFIFOL(fd,4),RFIFOL(fd,8),RFIFOL(fd,12),RFIFOW(fd,16),(const char*)RFIFOP(fd,18),RFIFOW(fd,2)-18); break; case 0x303B: mapif_parse_GuildPosition(fd,RFIFOL(fd,4),RFIFOL(fd,8),(struct guild_position *)RFIFOP(fd,12)); break; case 0x303C: mapif_parse_GuildSkillUp(fd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOL(fd,14)); break; diff --git a/src/char/int_quest.c b/src/char/int_quest.c index f8a05bc8f..061dd89d9 100644 --- a/src/char/int_quest.c +++ b/src/char/int_quest.c @@ -31,6 +31,9 @@ struct quest *mapif_quests_fromsql(int char_id, int *count) { struct quest *questlog = NULL; struct quest tmp_quest; SqlStmt *stmt; + StringBuf buf; + int i; + int sqlerror = SQL_SUCCESS; if (!count) return NULL; @@ -42,18 +45,31 @@ struct quest *mapif_quests_fromsql(int char_id, int *count) { return NULL; } + StrBuf->Init(&buf); + StrBuf->AppendStr(&buf, "SELECT `quest_id`, `state`, `time`"); + for (i = 0; i < MAX_QUEST_OBJECTIVES; i++) { + StrBuf->Printf(&buf, ", `count%d`", i+1); + } + StrBuf->Printf(&buf, " FROM `%s` WHERE `char_id`=?", quest_db); + memset(&tmp_quest, 0, sizeof(struct quest)); - if (SQL_ERROR == SQL->StmtPrepare(stmt, "SELECT `quest_id`, `state`, `time`, `count1`, `count2`, `count3` FROM `%s` WHERE `char_id`=?", quest_db) + if (SQL_ERROR == SQL->StmtPrepare(stmt, StrBuf->Value(&buf)) || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &char_id, 0) || SQL_ERROR == SQL->StmtExecute(stmt) || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &tmp_quest.quest_id, 0, NULL, NULL) || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_INT, &tmp_quest.state, 0, NULL, NULL) || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_UINT, &tmp_quest.time, 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 3, SQLDT_INT, &tmp_quest.count[0], 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 4, SQLDT_INT, &tmp_quest.count[1], 0, NULL, NULL) - || SQL_ERROR == SQL->StmtBindColumn(stmt, 5, SQLDT_INT, &tmp_quest.count[2], 0, NULL, NULL) - ) { + ) + sqlerror = SQL_ERROR; + + StrBuf->Destroy(&buf); + + for (i = 0; sqlerror != SQL_ERROR && i < MAX_QUEST_OBJECTIVES; i++) { // Stop on the first error + sqlerror = SQL->StmtBindColumn(stmt, 3+i, SQLDT_INT, &tmp_quest.count[i], 0, NULL, NULL); + } + + if (sqlerror == SQL_ERROR) { SqlStmt_ShowDebug(stmt); SQL->StmtFree(stmt); *count = 0; @@ -62,7 +78,7 @@ struct quest *mapif_quests_fromsql(int char_id, int *count) { *count = (int)SQL->StmtNumRows(stmt); if (*count > 0) { - int i = 0; + i = 0; questlog = (struct quest *)aCalloc(*count, sizeof(struct quest)); while (SQL_SUCCESS == SQL->StmtNextRow(stmt)) { @@ -105,13 +121,25 @@ bool mapif_quest_delete(int char_id, int quest_id) { * @return false in case of errors, true otherwise */ bool mapif_quest_add(int char_id, struct quest qd) { - if (SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s`(`quest_id`, `char_id`, `state`, `time`, `count1`, `count2`, `count3`) " - "VALUES ('%d', '%d', '%d','%d', '%d', '%d', '%d')", - quest_db, qd.quest_id, char_id, qd.state, qd.time, qd.count[0], qd.count[1], qd.count[2]) - ) { + StringBuf buf; + int i; + + StrBuf->Init(&buf); + StrBuf->Printf(&buf, "INSERT INTO `%s`(`quest_id`, `char_id`, `state`, `time`", quest_db); + for (i = 0; i < MAX_QUEST_OBJECTIVES; i++) { + StrBuf->Printf(&buf, ", `count%d`", i+1); + } + StrBuf->Printf(&buf, ") VALUES ('%d', '%d', '%d', '%d'", qd.quest_id, char_id, qd.state, qd.time); + for (i = 0; i < MAX_QUEST_OBJECTIVES; i++) { + StrBuf->Printf(&buf, ", '%d'", qd.count[i]); + } + StrBuf->AppendStr(&buf, ")"); + if (SQL_ERROR == SQL->Query(sql_handle, StrBuf->Value(&buf))) { Sql_ShowDebug(sql_handle); + StrBuf->Destroy(&buf); return false; } + StrBuf->Destroy(&buf); return true; } @@ -124,13 +152,22 @@ bool mapif_quest_add(int char_id, struct quest qd) { * @return false in case of errors, true otherwise */ bool mapif_quest_update(int char_id, struct quest qd) { - if (SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `state`='%d', `count1`='%d', `count2`='%d', `count3`='%d' " - "WHERE `quest_id` = '%d' AND `char_id` = '%d'", - quest_db, qd.state, qd.count[0], qd.count[1], qd.count[2], qd.quest_id, char_id) - ) { + StringBuf buf; + int i; + + StrBuf->Init(&buf); + StrBuf->Printf(&buf, "UPDATE `%s` SET `state`='%d'", quest_db, qd.state); + for (i = 0; i < MAX_QUEST_OBJECTIVES; i++) { + StrBuf->Printf(&buf, ", `count%d`='%d'", i+1, qd.count[i]); + } + StrBuf->Printf(&buf, " WHERE `quest_id` = '%d' AND `char_id` = '%d'", qd.quest_id, char_id); + + if (SQL_ERROR == SQL->Query(sql_handle, StrBuf->Value(&buf))) { Sql_ShowDebug(sql_handle); + StrBuf->Destroy(&buf); return false; } + StrBuf->Destroy(&buf); return true; } @@ -148,7 +185,7 @@ int mapif_parse_quest_save(int fd) { struct quest *old_qd = NULL, *new_qd = NULL; bool success = true; - if (new_n) + if (new_n > 0) new_qd = (struct quest*)RFIFOP(fd,8); old_qd = mapif_quests_fromsql(char_id, &old_n); |