* Various server config cleanups

* Change some config variables that use `char` to `StringBuf`. So, don't need to change the char length anymore.
  * Renamed some inter table config variables postfix "_db" to "_table".
  * Added table checks for login-server (Account, IP Ban, & Login Log), map-server.
  * Regroup map-server table variables to `struct MapServer_Schema mapserv_schema_config`.
  * Regroup map-server global config to `struct Map_Config map_config`.
  * Split log file or table names in `log_athena.conf`. File path to `log_path: log/` and extension to `log_extension: .log`. So, if logging is enabled by using file or table, don't need to rename all log names.
  * Removed unnecessary configs in map_athena.conf: `help_txt`, `help2_txt`, and `charhelp_txt`.
  * Removed unused file 'conf/charhelp.txt'.

* Added new StringBuf function
  * `StringBuf* StringBuf_MallocInitial`
  * `StringBuf* StringBuf_FromStr`
  * `void StringBuf_InitialInit`
  * `int StringBuf_PrintfClear`

* Thanks to @aleos89 and @Mendonn at #91 for that StringBuf

Signed-off-by: Cydh Ramdh <house.bad@gmail.com>
This commit is contained in:
Cydh Ramdh
2015-01-26 14:38:00 +07:00
committed by aleos89
parent 2ad4972be8
commit 8baa1d7e0c
52 changed files with 1940 additions and 1268 deletions

View File

@@ -1,28 +0,0 @@
40:--- CHARACTER CMD ---
40:#statsall <char name> - Set all stats of a player to maximum.
40:#itemlist <char name> - Displays all items of a player.
40:#storagelist <char name> - Displays all items of a player's storage.
40:#stats <char name> - Displays a characters stats.
60:#option <char name> <param1> <param2> <param3> - Like @option command but only to target character.
50:#mountpeco <char name> - Give/remove to a player a peco (Class is required, but not skill).
50:#petrename <char name> - Re-enable pet rename to a player.
60:#save <char name> <map> <x> <y> - Changes the target players respawn point.
60:#baselvl/#blvl <char name> <#> - Change a characters base level.
60:#joblvl/#jlvl <char name> <#> - Change a characters job level.
60:#job/#jobchange <char name> <job ID> - Changes target characters job.
60:#zeny <char name> <amount> - Give/take a players Zeny
60:#cash <char name> <amount> - Give/take a player cash points
60:#points <char name> <amount> - Give/take a player Kafra points
60:#stpoint <char name> <amount> - Give/take a players stat points
60:#skpoint <char name> <amount> - give/take a players skill points
60:#skreset <char name> - Reset skills of a character.
60:#streset <char name> - Reset stats of a character.
60:#reset <char name> - Reset stats AND skills of a character.
60:#questskill <char name> <#> - Gives to a player the specified quest skill.
60:#lostskill <char name> <#> - Takes away the specified quest skill from the player.
60:#delitem <char name> <item_name_or_ID> <quantity> - Remove items from a character
50:#model <char name> <hair type> <hair color> <clothes color> - Changes a player's model
60:#disguise <char name> <monster_name_or_monster_ID> - Changes disguise of a player
60:#undisguise <char name> - Cancels disguise of a player
60:#changesex <char name> - Changes sex of a player (all characters of the account)
60:#warp/#rura+ <char name> <mapname> <x> <y> - Warps character to location of choice

View File

@@ -55,14 +55,14 @@ map_server_id: ragnarok
map_server_pw: ragnarok
map_server_db: ragnarok
// MySQL Log Database
// MySQL Log Database (Shared used with Login server for login logs)
log_db_ip: 127.0.0.1
log_db_port: 3306
log_db_id: ragnarok
log_db_pw: ragnarok
log_db_db: ragnarok
log_codepage:
log_login_db: loginlog
log_login_table: loginlog
// MySQL Reconnect Settings
// - mysql_reconnect_type:
@@ -72,82 +72,4 @@ log_login_db: loginlog
mysql_reconnect_type: 2
mysql_reconnect_count: 1
// DO NOT CHANGE ANYTHING BEYOND THIS LINE UNLESS YOU KNOW YOUR DATABASE DAMN WELL
// this is meant for people who KNOW their stuff, and for some reason want to change their
// database layout. [CLOWNISIUS]
// ALL MySQL Database Table names
// Login Database Tables
login_server_account_db: login
ipban_table: ipbanlist
// Shared
global_acc_reg_num_table: global_acc_reg_num
global_acc_reg_str_table: global_acc_reg_str
// Char Database Tables
char_db: char
hotkey_db: hotkey
scdata_db: sc_data
cart_db: cart_inventory
inventory_db: inventory
charlog_db: charlog
storage_db: storage
skill_db: skill
interlog_db: interlog
memo_db: memo
guild_db: guild
guild_alliance_db: guild_alliance
guild_castle_db: guild_castle
guild_expulsion_db: guild_expulsion
guild_member_db: guild_member
guild_skill_db: guild_skill
guild_position_db: guild_position
guild_storage_db: guild_storage
party_db: party
pet_db: pet
friend_db: friends
mail_db: mail
auction_db: auction
quest_db: quest
homunculus_db: homunculus
skill_homunculus_db: skill_homunculus
mercenary_db: mercenary
mercenary_owner_db: mercenary_owner
elemental_db: elemental
ragsrvinfo_db: ragsrvinfo
skillcooldown_db: skillcooldown
bonus_script_db: bonus_script
acc_reg_num_table: acc_reg_num
acc_reg_str_table: acc_reg_str
char_reg_str_table: char_reg_str
char_reg_num_table: char_reg_num
// Map Database Tables
buyingstore_db: buyingstores
buyingstore_items_db: buyingstore_items
item_db_db: item_db
item_db_re_db: item_db_re
item_db2_db: item_db2
//item_db2_db: item_db2_re
item_cash_db_db: item_cash_db
item_cash_db2_db: item_cash_db2
mob_db_db: mob_db
mob_db_re_db: mob_db_re
mob_db2_db: mob_db2
//mob_db2_db: mob_db2_re
mob_skill_db_db: mob_skill_db
mob_skill_db_re_db: mob_skill_db_re
mob_skill_db2_db: mob_skill_db2
//mob_skill_db2_db: mob_skill_db2_re
mapreg_table: mapreg
vending_db: vendings
vending_items_db: vending_items
market_table: market
db_roulette_table: db_roulette
// Use SQL item_db, mob_db and mob_skill_db for the map server? (yes/no)
use_sql_db: no
import: conf/import/inter_conf.txt

View File

@@ -151,14 +151,19 @@ log_timestamp_format: %m/%d/%Y %H:%M:%S
// log_cash_db: log/cashlog.log
// log_feeding_db: log/feedinglog.log
log_gm_db: atcommandlog
log_branch_db: branchlog
log_chat_db: chatlog
log_mvpdrop_db: mvplog
log_npc_db: npclog
log_pick_db: picklog
log_zeny_db: zenylog
log_cash_db: cashlog
log_feeding_db: feedinglog
log_gm_table: atcommandlog
log_branch_table: branchlog
log_chat_table: chatlog
log_mvpdrop_table: mvplog
log_npc_table: npclog
log_pick_table: picklog
log_zeny_table: zenylog
log_cash_table: cashlog
log_feeding_table: feedinglog
// If 'sql_logs' is no, logging will use files with path
// '<log_path>/log_filename.<log_extension>
log_path: log/
log_extension: .log
import: conf/import/log_conf.txt

View File

@@ -114,10 +114,44 @@ save_settings: 255
// Message of the day file, when a character logs on, this message is displayed.
motd_txt: conf/motd.txt
// When @help or @h is typed when you are a gm, this is displayed for helping new gms understand gm commands.
help_txt: conf/help.txt
help2_txt: conf/help2.txt
charhelp_txt: conf/charhelp.txt
// Prefered file for reading atcommand & charcommand symbols, alieases settings,
// and help.txt file lookup.
atcommand_conf_file: conf/atcommand_athena.conf
// Prefered file for reading player's group levels, commands, and permission list,.
group_conf_file: conf/groups.conf
// Check all required tables?
check_tables: yes
//===================================
// Map-server Tables
//===================================
buyingstore_table: buyingstores
buyingstore_items_table: buyingstore_items
mapreg_table: mapreg
market_table: market
vending_table: vendings
vending_items_table: vending_items
// Use SQL DB tables instead of TXT DB files? (yes/no)
use_sql_db: no
// If 'use_sql_db' is 'yes', these following tables will be used
item_db_table: item_db
item_db_re_table: item_db_re
item_db2_table: item_db2
//item_db2_table: item_db2_re
item_cash_db_table: item_cash_db
item_cash_db2_table: item_cash_db2
mob_db_table: mob_db
mob_db_re_table: mob_db_re
mob_db2_table: mob_db2
//mob_db2_table: mob_db2_re
mob_skill_db_table: mob_skill_db
mob_skill_db_re_table: mob_skill_db_re
mob_skill_db2_table: mob_skill_db2
//mob_skill_db2_table: mob_skill_db2_re
// Maps:
import: conf/maps_athena.conf

File diff suppressed because it is too large Load Diff

View File

@@ -10,6 +10,7 @@
#include "../common/core.h" // CORE_ST_LAST
#include "../common/msg_conf.h"
#include "../common/mmo.h"
#include "../common/strlib.h"
extern int login_fd; //login file descriptor
@@ -33,46 +34,55 @@ enum {
};
struct Schema_Config {
int db_use_sqldbs;
char db_path[1024];
char char_db[DB_NAME_LEN];
char scdata_db[DB_NAME_LEN];
char skillcooldown_db[DB_NAME_LEN];
char cart_db[DB_NAME_LEN];
char inventory_db[DB_NAME_LEN];
char charlog_db[DB_NAME_LEN];
char storage_db[DB_NAME_LEN];
char interlog_db[DB_NAME_LEN];
char skill_db[DB_NAME_LEN];
char memo_db[DB_NAME_LEN];
char guild_db[DB_NAME_LEN];
char guild_alliance_db[DB_NAME_LEN];
char guild_castle_db[DB_NAME_LEN];
char guild_expulsion_db[DB_NAME_LEN];
char guild_member_db[DB_NAME_LEN];
char guild_position_db[DB_NAME_LEN];
char guild_skill_db[DB_NAME_LEN];
char guild_storage_db[DB_NAME_LEN];
char party_db[DB_NAME_LEN];
char pet_db[DB_NAME_LEN];
char mail_db[DB_NAME_LEN]; // MAIL SYSTEM
char auction_db[DB_NAME_LEN]; // Auctions System
char friend_db[DB_NAME_LEN];
char hotkey_db[DB_NAME_LEN];
char quest_db[DB_NAME_LEN];
char homunculus_db[DB_NAME_LEN];
char skill_homunculus_db[DB_NAME_LEN];
char mercenary_db[DB_NAME_LEN];
char mercenary_owner_db[DB_NAME_LEN];
char ragsrvinfo_db[DB_NAME_LEN];
char elemental_db[DB_NAME_LEN];
char bonus_script_db[DB_NAME_LEN];
char acc_reg_num_table[DB_NAME_LEN];
char acc_reg_str_table[DB_NAME_LEN];
char char_reg_str_table[DB_NAME_LEN];
char char_reg_num_table[DB_NAME_LEN];
// Character related tables
StringBuf *char_table; ///< Main Charachter table
StringBuf *charlog_table; ///< Charlog table
StringBuf *bonus_script_table; ///< Stored bonus_script table
StringBuf *cart_table; ///< Cart inventory table
StringBuf *inventory_table; ///< Inventory table
StringBuf *storage_table; ///< Storage table
StringBuf *memo_table; ///< Memo table
StringBuf *scdata_table; ///< Stored SC table
StringBuf *skill_table; ///< Skill table
StringBuf *skillcooldown_table; ///< Skill Cooldown table
StringBuf *friend_table; ///< Friend list table
StringBuf *hotkey_table; ///< Hotkey list table
StringBuf *mail_table; ///< Mail table
StringBuf *quest_table; ///< Quest table
StringBuf *pet_table; ///< Pet table
StringBuf *elemental_table; ///< Elemental table
StringBuf *party_table; ///< Party table
// Homunculus tables
StringBuf *homunculus_table; ///< Homunculus table
StringBuf *homunculus_skill_table; ///< Homunculus skill table
// Mercenary Tables
StringBuf *mercenary_table; ///< Mercenary table
StringBuf *mercenary_owner_table; ///< Mercenary owner table
// Guild tables
StringBuf *guild_table; ///< Guild table
StringBuf *guild_alliance_table; ///< Guild alliance & enemy table
StringBuf *guild_castle_table; ///< Castle table
StringBuf *guild_expulsion_table; ///< Expulsion table
StringBuf *guild_member_table; ///< Guild member table
StringBuf *guild_position_table; ///< Guild member position table
StringBuf *guild_skill_table; ///< Guild skill table
StringBuf *guild_storage_table; ///< Guild storage table
// Other
StringBuf *acc_reg_num_table; ///< Account Registry (Number)
StringBuf *acc_reg_str_table; ///< Account Registry (String)
StringBuf *auction_table; ///< Auction table
StringBuf *char_reg_num_table; ///< Character Registry (Number)
StringBuf *char_reg_str_table; ///< Character Registry (String)
StringBuf *ragsrvinfo_table; ///< Server info table
StringBuf *interlog_table; ///< Inter log table
};
extern struct Schema_Config schema_config;
extern struct Schema_Config schema_config; /// Inter/char-server tables
/// Get inter/char-server table value. Table names @see Schema_Config
#define charserv_table(table) ( StringBuf_Value(schema_config.table) )
#if PACKETVER_SUPPORTS_PINCODE
/// Pincode system
@@ -158,6 +168,8 @@ struct CharServ_Config {
char default_map[MAP_NAME_LENGTH];
unsigned short default_map_x;
unsigned short default_map_y;
char db_path[16];
};
extern struct CharServ_Config charserv_config;

View File

@@ -69,8 +69,8 @@ int chclif_parse_moveCharSlot( int fd, struct char_session_data* sd){
if( charserv_config.charmove_config.char_movetoused ){ // TODO: check if the target is in deletion process
// Admin is friendly and uses triangle exchange
if( SQL_ERROR == Sql_QueryStr(sql_handle, "START TRANSACTION")
|| SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `char_num`='%d' WHERE `char_id` = '%d'",schema_config.char_db, to, sd->found_char[from] )
|| SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `char_num`='%d' WHERE `char_id` = '%d'", schema_config.char_db, from, sd->found_char[to] )
|| SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `char_num`='%d' WHERE `char_id` = '%d'",charserv_table(char_table), to, sd->found_char[from] )
|| SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `char_num`='%d' WHERE `char_id` = '%d'", charserv_table(char_table), from, sd->found_char[to] )
|| SQL_ERROR == Sql_QueryStr(sql_handle, "COMMIT")
){
chclif_moveCharSlotReply( fd, sd, from, 1 );
@@ -83,7 +83,7 @@ int chclif_parse_moveCharSlot( int fd, struct char_session_data* sd){
chclif_moveCharSlotReply( fd, sd, from, 1 );
return 1;
}
}else if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `char_num`='%d' WHERE `char_id`='%d'", schema_config.char_db, to, sd->found_char[from] ) ){
}else if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `char_num`='%d' WHERE `char_id`='%d'", charserv_table(char_table), to, sd->found_char[from] ) ){
Sql_ShowDebug(sql_handle);
chclif_moveCharSlotReply( fd, sd, from, 1 );
return 1;
@@ -91,7 +91,7 @@ int chclif_parse_moveCharSlot( int fd, struct char_session_data* sd){
if( (charserv_config.charmove_config.char_moves_unlimited)==0 ){
sd->char_moves[from]--;
Sql_Query(sql_handle, "UPDATE `%s` SET `moves`='%d' WHERE `char_id`='%d'", schema_config.char_db, sd->char_moves[from], sd->found_char[from] );
Sql_Query(sql_handle, "UPDATE `%s` SET `moves`='%d' WHERE `char_id`='%d'", charserv_table(char_table), sd->char_moves[from], sd->found_char[from] );
}
// We successfully moved the char - time to notify the client
@@ -467,7 +467,7 @@ int chclif_parse_char_delete2_req(int fd, struct char_session_data* sd) {
return 1;
}
if( SQL_SUCCESS != Sql_Query(sql_handle, "SELECT `delete_date` FROM `%s` WHERE `char_id`='%d'", schema_config.char_db, char_id) || SQL_SUCCESS != Sql_NextRow(sql_handle) )
if( SQL_SUCCESS != Sql_Query(sql_handle, "SELECT `delete_date` FROM `%s` WHERE `char_id`='%d'", charserv_table(char_table), char_id) || SQL_SUCCESS != Sql_NextRow(sql_handle) )
{
Sql_ShowDebug(sql_handle);
chclif_char_delete2_ack(fd, char_id, 3, 0);
@@ -500,7 +500,7 @@ int chclif_parse_char_delete2_req(int fd, struct char_session_data* sd) {
// success
delete_date = time(NULL)+(charserv_config.char_config.char_del_delay);
if( SQL_SUCCESS != Sql_Query(sql_handle, "UPDATE `%s` SET `delete_date`='%lu' WHERE `char_id`='%d'", schema_config.char_db, (unsigned long)delete_date, char_id) )
if( SQL_SUCCESS != Sql_Query(sql_handle, "UPDATE `%s` SET `delete_date`='%lu' WHERE `char_id`='%d'", charserv_table(char_table), (unsigned long)delete_date, char_id) )
{
Sql_ShowDebug(sql_handle);
chclif_char_delete2_ack(fd, char_id, 3, 0);
@@ -545,7 +545,7 @@ int chclif_parse_char_delete2_accept(int fd, struct char_session_data* sd) {
return 1;
}
if( SQL_SUCCESS != Sql_Query(sql_handle, "SELECT `base_level`,`delete_date` FROM `%s` WHERE `char_id`='%d'", schema_config.char_db, char_id) || SQL_SUCCESS != Sql_NextRow(sql_handle) )
if( SQL_SUCCESS != Sql_Query(sql_handle, "SELECT `base_level`,`delete_date` FROM `%s` WHERE `char_id`='%d'", charserv_table(char_table), char_id) || SQL_SUCCESS != Sql_NextRow(sql_handle) )
{// data error
Sql_ShowDebug(sql_handle);
chclif_char_delete2_accept_ack(fd, char_id, 3);
@@ -611,7 +611,7 @@ int chclif_parse_char_delete2_cancel(int fd, struct char_session_data* sd) {
// there is no need to check, whether or not the character was
// queued for deletion, as the client prints an error message by
// itself, if it was not the case (@see char_delete2_cancel_ack)
if( SQL_SUCCESS != Sql_Query(sql_handle, "UPDATE `%s` SET `delete_date`='0' WHERE `char_id`='%d'", schema_config.char_db, char_id) )
if( SQL_SUCCESS != Sql_Query(sql_handle, "UPDATE `%s` SET `delete_date`='0' WHERE `char_id`='%d'", charserv_table(char_table), char_id) )
{
Sql_ShowDebug(sql_handle);
chclif_char_delete2_cancel_ack(fd, char_id, 2);
@@ -759,7 +759,7 @@ int chclif_parse_charselect(int fd, struct char_session_data* sd,uint32 ipl){
int slot = RFIFOB(fd,2);
RFIFOSKIP(fd,3);
if ( SQL_SUCCESS != Sql_Query(sql_handle, "SELECT `char_id` FROM `%s` WHERE `account_id`='%d' AND `char_num`='%d'", schema_config.char_db, sd->account_id, slot)
if ( SQL_SUCCESS != Sql_Query(sql_handle, "SELECT `char_id` FROM `%s` WHERE `account_id`='%d' AND `char_num`='%d'", charserv_table(char_table), sd->account_id, slot)
|| SQL_SUCCESS != Sql_NextRow(sql_handle)
|| SQL_SUCCESS != Sql_GetData(sql_handle, 0, &data, NULL) )
{ //Not found?? May be forged packet.
@@ -803,7 +803,7 @@ int chclif_parse_charselect(int fd, struct char_session_data* sd,uint32 ipl){
Sql_EscapeStringLen(sql_handle, esc_name, char_dat.name, strnlen(char_dat.name, NAME_LENGTH));
if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s`(`time`, `account_id`,`char_num`,`name`) VALUES (NOW(), '%d', '%d', '%s')",
schema_config.charlog_db, sd->account_id, slot, esc_name) )
charserv_table(charlog_table), sd->account_id, slot, esc_name) )
Sql_ShowDebug(sql_handle);
}
ShowInfo("Selected char: (Account %d: %d - %s)\n", sd->account_id, slot, char_dat.name);
@@ -1104,7 +1104,7 @@ void chclif_block_character( int fd, struct char_session_data* sd){
else {
WFIFOL(fd, 4+j*24) = 0;
sd->unban_time[i] = 0;
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `unban_time`='0' WHERE `char_id`='%d' LIMIT 1", schema_config.char_db, sd->found_char[i]) )
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `unban_time`='0' WHERE `char_id`='%d' LIMIT 1", charserv_table(char_table), sd->found_char[i]) )
Sql_ShowDebug(sql_handle);
}
len+=24;

View File

@@ -445,7 +445,7 @@ int chlogif_parse_ackchangesex(int fd, struct char_session_data* sd)
// 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)) {
if (SQL_ERROR == SqlStmt_Prepare(stmt, "SELECT `char_id`, `class`, `guild_id` FROM `%s` WHERE `account_id` = '%d'", charserv_table(char_table), acc) || SqlStmt_Execute(stmt)) {
SqlStmt_ShowDebug(stmt);
SqlStmt_Free(stmt);
}

View File

@@ -284,7 +284,7 @@ int chmapif_parse_askscdata(int fd){
aid = RFIFOL(fd,2);
cid = RFIFOL(fd,6);
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT type, tick, val1, val2, val3, val4 from `%s` WHERE `account_id` = '%d' AND `char_id`='%d'",
schema_config.scdata_db, aid, cid) )
charserv_table(scdata_table), aid, cid) )
{
Sql_ShowDebug(sql_handle);
return 1;
@@ -505,7 +505,7 @@ int chmapif_parse_req_saveskillcooldown(int fd){
int i;
StringBuf_Init(&buf);
StringBuf_Printf(&buf, "INSERT INTO `%s` (`account_id`, `char_id`, `skill`, `tick`) VALUES ", schema_config.skillcooldown_db);
StringBuf_Printf(&buf, "INSERT INTO `%s` (`account_id`, `char_id`, `skill`, `tick`) VALUES ", charserv_table(skillcooldown_table));
for( i = 0; i < count; ++i )
{
memcpy(&data,RFIFOP(fd,14+i*sizeof(struct skill_cooldown_data)),sizeof(struct skill_cooldown_data));
@@ -532,7 +532,7 @@ int chmapif_parse_req_skillcooldown(int fd){
cid = RFIFOL(fd,6);
RFIFOSKIP(fd, 10);
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT skill, tick FROM `%s` WHERE `account_id` = '%d' AND `char_id`='%d'",
schema_config.skillcooldown_db, aid, cid) )
charserv_table(skillcooldown_table), aid, cid) )
{
Sql_ShowDebug(sql_handle);
return 1;
@@ -561,7 +561,7 @@ int chmapif_parse_req_skillcooldown(int fd){
WFIFOW(fd,12) = count;
WFIFOSET(fd,WFIFOW(fd,2));
//Clear the data once loaded.
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `char_id`='%d'", schema_config.skillcooldown_db, aid, cid) )
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `char_id`='%d'", charserv_table(skillcooldown_table), aid, cid) )
Sql_ShowDebug(sql_handle);
}
}
@@ -667,7 +667,7 @@ int chmapif_parse_askrmfriend(int fd){
char_id = RFIFOL(fd,2);
friend_id = RFIFOL(fd,6);
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d' AND `friend_id`='%d' LIMIT 1",
schema_config.friend_db, char_id, friend_id) ) {
charserv_table(friend_table), char_id, friend_id) ) {
Sql_ShowDebug(sql_handle);
return 1;
}
@@ -741,7 +741,7 @@ int chmapif_parse_fwlog_changestatus(int fd){
RFIFOSKIP(fd,44);
Sql_EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH));
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`, `char_id` FROM `%s` WHERE `name` = '%s'", schema_config.char_db, esc_name) )
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`, `char_id` FROM `%s` WHERE `name` = '%s'", charserv_table(char_table), esc_name) )
Sql_ShowDebug(sql_handle);
else if( Sql_NumRows(sql_handle) == 0 ) {
result = 1; // 1-player not found
@@ -866,7 +866,7 @@ int chmapif_parse_updmapinfo(int fd){
char esc_server_name[sizeof(charserv_config.server_name)*2+1];
Sql_EscapeString(sql_handle, esc_server_name, charserv_config.server_name);
if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` SET `index`='%d',`name`='%s',`exp`='%d',`jexp`='%d',`drop`='%d'",
schema_config.ragsrvinfo_db, fd, esc_server_name, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10)) )
charserv_table(ragsrvinfo_table), fd, esc_server_name, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10)) )
Sql_ShowDebug(sql_handle);
RFIFOSKIP(fd,14);
}
@@ -950,7 +950,7 @@ int chmapif_parse_save_scdata(int fd){
count = RFIFOW(fd, 12);
// Whatever comes from the mapserver, now is the time to drop previous entries
if( Sql_Query( sql_handle, "DELETE FROM `%s` where `account_id` = %d and `char_id` = %d;", schema_config.scdata_db, aid, cid ) != SQL_SUCCESS ){
if( Sql_Query( sql_handle, "DELETE FROM `%s` where `account_id` = %d and `char_id` = %d;", charserv_table(scdata_table), aid, cid ) != SQL_SUCCESS ){
Sql_ShowDebug( sql_handle );
}
else if( count > 0 )
@@ -960,7 +960,7 @@ int chmapif_parse_save_scdata(int fd){
int i;
StringBuf_Init(&buf);
StringBuf_Printf(&buf, "INSERT INTO `%s` (`account_id`, `char_id`, `type`, `tick`, `val1`, `val2`, `val3`, `val4`) VALUES ", schema_config.scdata_db);
StringBuf_Printf(&buf, "INSERT INTO `%s` (`account_id`, `char_id`, `type`, `tick`, `val1`, `val2`, `val3`, `val4`) VALUES ", charserv_table(scdata_table));
for( i = 0; i < count; ++i )
{
memcpy (&data, RFIFOP(fd, 14+i*sizeof(struct status_change_data)), sizeof(struct status_change_data));
@@ -1221,7 +1221,7 @@ int chmapif_parse_reqcharban(int fd){
const char* name = (char*)RFIFOP(fd,10); // name of the target character
RFIFOSKIP(fd,10+NAME_LENGTH);
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`char_id`,`unban_time` FROM `%s` WHERE `name` = '%s'", schema_config.char_db, name) )
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`char_id`,`unban_time` FROM `%s` WHERE `name` = '%s'", charserv_table(char_table), name) )
Sql_ShowDebug(sql_handle);
else if( Sql_NumRows(sql_handle) == 0 ){
return 1; // 1-player not found
@@ -1250,7 +1250,7 @@ int chmapif_parse_reqcharban(int fd){
if( SQL_SUCCESS != SqlStmt_Prepare(stmt,
"UPDATE `%s` SET `unban_time` = ? WHERE `char_id` = ? LIMIT 1",
schema_config.char_db)
charserv_table(char_table))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_LONG, (void*)&unban_time, sizeof(unban_time))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_INT, (void*)&t_cid, sizeof(t_cid))
|| SQL_SUCCESS != SqlStmt_Execute(stmt)
@@ -1286,7 +1286,7 @@ int chmapif_parse_reqcharunban(int fd){
const char* name = (char*)RFIFOP(fd,6);
RFIFOSKIP(fd,6+NAME_LENGTH);
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `unban_time` = '0' WHERE `name` = '%s' LIMIT 1", schema_config.char_db, name) ) {
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `unban_time` = '0' WHERE `name` = '%s' LIMIT 1", charserv_table(char_table), name) ) {
Sql_ShowDebug(sql_handle);
return 1;
}
@@ -1316,7 +1316,7 @@ int chmapif_bonus_script_get(int fd) {
if (SQL_ERROR == SqlStmt_Prepare(stmt,
"SELECT `script`, `tick`, `flag`, `type`, `icon` FROM `%s` WHERE `char_id` = '%d' LIMIT %d",
schema_config.bonus_script_db, cid, MAX_PC_BONUS_SCRIPT) ||
charserv_table(bonus_script_table), cid, MAX_PC_BONUS_SCRIPT) ||
SQL_ERROR == SqlStmt_Execute(stmt) ||
SQL_ERROR == SqlStmt_BindColumn(stmt, 0, SQLDT_STRING, &tmp_bsdata.script_str, sizeof(tmp_bsdata.script_str), NULL, NULL) ||
SQL_ERROR == SqlStmt_BindColumn(stmt, 1, SQLDT_UINT32, &tmp_bsdata.tick, 0, NULL, NULL) ||
@@ -1357,7 +1357,7 @@ int chmapif_bonus_script_get(int fd) {
ShowInfo("Bonus Script loaded for CID=%d. Total: %d.\n", cid, i);
if (SQL_ERROR == SqlStmt_Prepare(stmt,"DELETE FROM `%s` WHERE `char_id`='%d'",schema_config.bonus_script_db,cid) ||
if (SQL_ERROR == SqlStmt_Prepare(stmt,"DELETE FROM `%s` WHERE `char_id`='%d'", charserv_table(bonus_script_table), cid) ||
SQL_ERROR == SqlStmt_Execute(stmt))
SqlStmt_ShowDebug(stmt);
}
@@ -1390,7 +1390,7 @@ int chmapif_bonus_script_save(int fd) {
uint8 i;
StringBuf_Init(&buf);
StringBuf_Printf(&buf, "INSERT INTO `%s` (`char_id`, `script`, `tick`, `flag`, `type`, `icon`) VALUES ", schema_config.bonus_script_db);
StringBuf_Printf(&buf, "INSERT INTO `%s` (`char_id`, `script`, `tick`, `flag`, `type`, `icon`) VALUES ", charserv_table(bonus_script_table));
for (i = 0; i < count; ++i) {
memcpy(&bsdata, RFIFOP(fd, 9 + i*sizeof(struct bonus_script_data)), sizeof(struct bonus_script_data));
Sql_EscapeString(sql_handle, esc_script, bsdata.script_str);
@@ -1555,7 +1555,7 @@ void chmapif_server_reset(int id){
WBUFW(buf,2) = j * 4 + 10;
chmapif_sendallwos(fd, buf, WBUFW(buf,2));
}
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `index`='%d'", schema_config.ragsrvinfo_db, map_server[id].fd) )
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `index`='%d'", charserv_table(ragsrvinfo_table), map_server[id].fd) )
Sql_ShowDebug(sql_handle);
online_char_db->foreach(online_char_db,char_db_setoffline,id); //Tag relevant chars as 'in disconnected' server.
chmapif_server_destroy(id);

View File

@@ -51,7 +51,7 @@ void auction_save(struct auction_data *auction)
StringBuf_Init(&buf);
StringBuf_Printf(&buf, "UPDATE `%s` SET `seller_id` = '%d', `seller_name` = ?, `buyer_id` = '%d', `buyer_name` = ?, `price` = '%d', `buynow` = '%d', `hours` = '%d', `timestamp` = '%lu', `nameid` = '%hu', `item_name` = ?, `type` = '%d', `refine` = '%d', `attribute` = '%d'",
schema_config.auction_db, 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);
charserv_table(auction_table), 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);
for( j = 0; j < MAX_SLOTS; j++ )
StringBuf_Printf(&buf, ", `card%d` = '%hu'", j, auction->item.card[j]);
StringBuf_Printf(&buf, " WHERE `auction_id` = '%d'", auction->auction_id);
@@ -82,7 +82,7 @@ unsigned int auction_create(struct auction_data *auction)
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`", schema_config.auction_db);
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`", charserv_table(auction_table));
for( j = 0; j < MAX_SLOTS; j++ )
StringBuf_Printf(&buf, ",`card%d`", j);
StringBuf_Printf(&buf, ") VALUES ('%d',?,'%d',?,'%d','%d','%d','%lu','%hu',?,'%d','%d','%d','%"PRIu64"'",
@@ -162,7 +162,7 @@ void auction_delete(struct auction_data *auction)
{
unsigned int auction_id = auction->auction_id;
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `auction_id` = '%d'", schema_config.auction_db, auction_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `auction_id` = '%d'", charserv_table(auction_table), auction_id) )
Sql_ShowDebug(sql_handle);
if( auction->auction_end_timer != INVALID_TIMER )
@@ -184,7 +184,7 @@ void inter_auctions_fromsql(void)
"`price`,`buynow`,`hours`,`timestamp`,`nameid`,`item_name`,`type`,`refine`,`attribute`,`unique_id`");
for( i = 0; i < MAX_SLOTS; i++ )
StringBuf_Printf(&buf, ",`card%d`", i);
StringBuf_Printf(&buf, " FROM `%s` ORDER BY `auction_id` DESC", schema_config.auction_db);
StringBuf_Printf(&buf, " FROM `%s` ORDER BY `auction_id` DESC", charserv_table(auction_table));
if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) )
Sql_ShowDebug(sql_handle);

View File

@@ -18,7 +18,7 @@ bool mapif_elemental_save(struct s_elemental* ele) {
if( SQL_ERROR == Sql_Query(sql_handle,
"INSERT INTO `%s` (`char_id`,`class`,`mode`,`hp`,`sp`,`max_hp`,`max_sp`,`atk1`,`atk2`,`matk`,`aspd`,`def`,`mdef`,`flee`,`hit`,`life_time`)"
"VALUES ('%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%u')",
schema_config.elemental_db, ele->char_id, ele->class_, ele->mode, ele->hp, ele->sp, ele->max_hp, ele->max_sp, ele->atk, ele->atk2, ele->matk, ele->amotion, ele->def, ele->mdef, ele->flee, ele->hit, ele->life_time) )
charserv_table(elemental_table), ele->char_id, ele->class_, ele->mode, ele->hp, ele->sp, ele->max_hp, ele->max_sp, ele->atk, ele->atk2, ele->matk, ele->amotion, ele->def, ele->mdef, ele->flee, ele->hit, ele->life_time) )
{
Sql_ShowDebug(sql_handle);
flag = false;
@@ -28,7 +28,7 @@ bool mapif_elemental_save(struct s_elemental* ele) {
} else if( SQL_ERROR == Sql_Query(sql_handle,
"UPDATE `%s` SET `char_id` = '%d', `class` = '%d', `mode` = '%d', `hp` = '%d', `sp` = '%d',"
"`max_hp` = '%d', `max_sp` = '%d', `atk1` = '%d', `atk2` = '%d', `matk` = '%d', `aspd` = '%d', `def` = '%d',"
"`mdef` = '%d', `flee` = '%d', `hit` = '%d', `life_time` = '%u' WHERE `ele_id` = '%d'", schema_config.elemental_db,
"`mdef` = '%d', `flee` = '%d', `hit` = '%d', `life_time` = '%u' WHERE `ele_id` = '%d'", charserv_table(elemental_table),
ele->char_id, ele->class_, ele->mode, ele->hp, ele->sp, ele->max_hp, ele->max_sp, ele->atk, ele->atk2,
ele->matk, ele->amotion, ele->def, ele->mdef, ele->flee, ele->hit, ele->life_time, ele->elemental_id) )
{ // Update DB entry
@@ -47,7 +47,7 @@ bool mapif_elemental_load(int ele_id, uint32 char_id, struct s_elemental *ele) {
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `class`, `mode`, `hp`, `sp`, `max_hp`, `max_sp`, `atk1`, `atk2`, `matk`, `aspd`,"
"`def`, `mdef`, `flee`, `hit`, `life_time` FROM `%s` WHERE `ele_id` = '%d' AND `char_id` = '%d'",
schema_config.elemental_db, ele_id, char_id) ) {
charserv_table(elemental_table), ele_id, char_id) ) {
Sql_ShowDebug(sql_handle);
return false;
}
@@ -80,7 +80,7 @@ bool mapif_elemental_load(int ele_id, uint32 char_id, struct s_elemental *ele) {
}
bool mapif_elemental_delete(int ele_id) {
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `ele_id` = '%d'", schema_config.elemental_db, ele_id) ) {
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `ele_id` = '%d'", charserv_table(elemental_table), ele_id) ) {
Sql_ShowDebug(sql_handle);
return false;
}

View File

@@ -88,9 +88,9 @@ static int guild_save_timer(int tid, unsigned int tick, int id, intptr_t data)
int inter_guild_removemember_tosql(uint32 account_id, uint32 char_id)
{
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE from `%s` where `account_id` = '%d' and `char_id` = '%d'", schema_config.guild_member_db, account_id, char_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE from `%s` where `account_id` = '%d' and `char_id` = '%d'", charserv_table(guild_member_table), account_id, char_id) )
Sql_ShowDebug(sql_handle);
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `guild_id` = '0' WHERE `char_id` = '%d'", schema_config.char_db, char_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `guild_id` = '0' WHERE `char_id` = '%d'", charserv_table(char_table), char_id) )
Sql_ShowDebug(sql_handle);
return 0;
}
@@ -138,7 +138,7 @@ int inter_guild_tosql(struct guild *g,int flag)
if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` "
"(`name`,`master`,`guild_lv`,`max_member`,`average_lv`,`char_id`) "
"VALUES ('%s', '%s', '%d', '%d', '%d', '%d')",
schema_config.guild_db, esc_name, esc_master, g->guild_lv, g->max_member, g->average_lv, g->member[0].char_id) )
charserv_table(guild_table), esc_name, esc_master, g->guild_lv, g->max_member, g->average_lv, g->member[0].char_id) )
{
Sql_ShowDebug(sql_handle);
if (g->guild_id == -1)
@@ -158,7 +158,7 @@ int inter_guild_tosql(struct guild *g,int flag)
bool add_comma = false;
StringBuf_Init(&buf);
StringBuf_Printf(&buf, "UPDATE `%s` SET ", schema_config.guild_db);
StringBuf_Printf(&buf, "UPDATE `%s` SET ", charserv_table(guild_table));
if (flag & GS_EMBLEM)
{
@@ -236,14 +236,14 @@ int inter_guild_tosql(struct guild *g,int flag)
Sql_EscapeStringLen(sql_handle, esc_name, m->name, strnlen(m->name, NAME_LENGTH));
if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`account_id`,`char_id`,`hair`,`hair_color`,`gender`,`class`,`lv`,`exp`,`exp_payper`,`online`,`position`,`name`) "
"VALUES ('%d','%d','%d','%d','%d','%d','%d','%d','%"PRIu64"','%d','%d','%d','%s')",
schema_config.guild_member_db, g->guild_id, m->account_id, m->char_id,
charserv_table(guild_member_table), g->guild_id, m->account_id, m->char_id,
m->hair, m->hair_color, m->gender,
m->class_, m->lv, m->exp, m->exp_payper, m->online, m->position, esc_name) )
Sql_ShowDebug(sql_handle);
if (m->modified&GS_MEMBER_NEW || new_guild == 1)
{
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `guild_id` = '%d' WHERE `char_id` = '%d'",
schema_config.char_db, g->guild_id, m->char_id) )
charserv_table(char_table), g->guild_id, m->char_id) )
Sql_ShowDebug(sql_handle);
}
m->modified = GS_MEMBER_UNMODIFIED;
@@ -260,7 +260,7 @@ int inter_guild_tosql(struct guild *g,int flag)
continue;
Sql_EscapeStringLen(sql_handle, esc_name, p->name, strnlen(p->name, NAME_LENGTH));
if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`position`,`name`,`mode`,`exp_mode`) VALUES ('%d','%d','%s','%d','%d')",
schema_config.guild_position_db, g->guild_id, i, esc_name, p->mode, p->exp_mode) )
charserv_table(guild_position_table), g->guild_id, i, esc_name, p->mode, p->exp_mode) )
Sql_ShowDebug(sql_handle);
p->modified = GS_POSITION_UNMODIFIED;
}
@@ -273,7 +273,7 @@ int inter_guild_tosql(struct guild *g,int flag)
// their info changed, not to mention this would also mess up oppositions!
// [Skotlex]
//if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id`='%d' OR `alliance_id`='%d'", guild_alliance_db, g->guild_id, g->guild_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id`='%d'", schema_config.guild_alliance_db, g->guild_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id`='%d'", charserv_table(guild_alliance_table), g->guild_id) )
{
Sql_ShowDebug(sql_handle);
}
@@ -288,7 +288,7 @@ int inter_guild_tosql(struct guild *g,int flag)
Sql_EscapeStringLen(sql_handle, esc_name, a->name, strnlen(a->name, NAME_LENGTH));
if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`opposition`,`alliance_id`,`name`) "
"VALUES ('%d','%d','%d','%s')",
schema_config.guild_alliance_db, g->guild_id, a->opposition, a->guild_id, esc_name) )
charserv_table(guild_alliance_table), g->guild_id, a->opposition, a->guild_id, esc_name) )
Sql_ShowDebug(sql_handle);
}
}
@@ -306,7 +306,7 @@ int inter_guild_tosql(struct guild *g,int flag)
Sql_EscapeStringLen(sql_handle, esc_name, e->name, strnlen(e->name, NAME_LENGTH));
Sql_EscapeStringLen(sql_handle, esc_mes, e->mes, strnlen(e->mes, sizeof(e->mes)));
if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`account_id`,`name`,`mes`) "
"VALUES ('%d','%d','%s','%s')", schema_config.guild_expulsion_db, g->guild_id, e->account_id, esc_name, esc_mes) )
"VALUES ('%d','%d','%s','%s')", charserv_table(guild_expulsion_table), g->guild_id, e->account_id, esc_name, esc_mes) )
Sql_ShowDebug(sql_handle);
}
}
@@ -318,7 +318,7 @@ int inter_guild_tosql(struct guild *g,int flag)
for(i=0;i<MAX_GUILDSKILL;i++){
if (g->skill[i].id>0 && g->skill[i].lv>0){
if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`id`,`lv`) VALUES ('%d','%d','%d')",
schema_config.guild_skill_db, g->guild_id, g->skill[i].id, g->skill[i].lv) )
charserv_table(guild_skill_table), g->guild_id, g->skill[i].id, g->skill[i].lv) )
Sql_ShowDebug(sql_handle);
}
}
@@ -350,7 +350,7 @@ struct guild * inter_guild_fromsql(int guild_id)
#endif
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT g.`name`,c.`name`,g.`guild_lv`,g.`connect_member`,g.`max_member`,g.`average_lv`,g.`exp`,g.`next_exp`,g.`skill_point`,g.`mes1`,g.`mes2`,g.`emblem_len`,g.`emblem_id`,g.`emblem_data` "
"FROM `%s` g LEFT JOIN `%s` c ON c.`char_id` = g.`char_id` WHERE g.`guild_id`='%d'", schema_config.guild_db, schema_config.char_db, guild_id) )
"FROM `%s` g LEFT JOIN `%s` c ON c.`char_id` = g.`char_id` WHERE g.`guild_id`='%d'", charserv_table(guild_table), charserv_table(char_table), guild_id) )
{
Sql_ShowDebug(sql_handle);
return NULL;
@@ -405,7 +405,7 @@ struct guild * inter_guild_fromsql(int guild_id)
// load guild member info
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`char_id`,`hair`,`hair_color`,`gender`,`class`,`lv`,`exp`,`exp_payper`,`online`,`position`,`name` "
"FROM `%s` WHERE `guild_id`='%d' ORDER BY `position`", schema_config.guild_member_db, guild_id) )
"FROM `%s` WHERE `guild_id`='%d' ORDER BY `position`", charserv_table(guild_member_table), guild_id) )
{
Sql_ShowDebug(sql_handle);
aFree(g);
@@ -433,7 +433,7 @@ struct guild * inter_guild_fromsql(int guild_id)
}
//printf("- Read guild_position %d from sql \n",guild_id);
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `position`,`name`,`mode`,`exp_mode` FROM `%s` WHERE `guild_id`='%d'", schema_config.guild_position_db, guild_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `position`,`name`,`mode`,`exp_mode` FROM `%s` WHERE `guild_id`='%d'", charserv_table(guild_position_table), guild_id) )
{
Sql_ShowDebug(sql_handle);
aFree(g);
@@ -455,7 +455,7 @@ struct guild * inter_guild_fromsql(int guild_id)
}
//printf("- Read guild_alliance %d from sql \n",guild_id);
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `opposition`,`alliance_id`,`name` FROM `%s` WHERE `guild_id`='%d'", schema_config.guild_alliance_db, guild_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `opposition`,`alliance_id`,`name` FROM `%s` WHERE `guild_id`='%d'", charserv_table(guild_alliance_table), guild_id) )
{
Sql_ShowDebug(sql_handle);
aFree(g);
@@ -471,7 +471,7 @@ struct guild * inter_guild_fromsql(int guild_id)
}
//printf("- Read guild_expulsion %d from sql \n",guild_id);
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`name`,`mes` FROM `%s` WHERE `guild_id`='%d'", schema_config.guild_expulsion_db, guild_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`name`,`mes` FROM `%s` WHERE `guild_id`='%d'", charserv_table(guild_expulsion_table), guild_id) )
{
Sql_ShowDebug(sql_handle);
aFree(g);
@@ -487,7 +487,7 @@ struct guild * inter_guild_fromsql(int guild_id)
}
//printf("- Read guild_skill %d from sql \n",guild_id);
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `id`,`lv` FROM `%s` WHERE `guild_id`='%d' ORDER BY `id`", schema_config.guild_skill_db, guild_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `id`,`lv` FROM `%s` WHERE `guild_id`='%d' ORDER BY `id`", charserv_table(guild_skill_table), guild_id) )
{
Sql_ShowDebug(sql_handle);
aFree(g);
@@ -527,7 +527,7 @@ int inter_guildcastle_tosql(struct guild_castle *gc)
StringBuf_Init(&buf);
StringBuf_Printf(&buf, "REPLACE INTO `%s` SET `castle_id`='%d', `guild_id`='%d', `economy`='%d', `defense`='%d', "
"`triggerE`='%d', `triggerD`='%d', `nextTime`='%d', `payTime`='%d', `createTime`='%d', `visibleC`='%d'",
schema_config.guild_castle_db, gc->castle_id, gc->guild_id, gc->economy, gc->defense,
charserv_table(guild_castle_table), gc->castle_id, gc->guild_id, gc->economy, gc->defense,
gc->triggerE, gc->triggerD, gc->nextTime, gc->payTime, gc->createTime, gc->visibleC);
for (i = 0; i < MAX_GUARDIANS; ++i)
StringBuf_Printf(&buf, ", `visibleG%d`='%d'", i, gc->guardian[i].visible);
@@ -557,7 +557,7 @@ static struct guild_castle* inter_guildcastle_fromsql(int castle_id)
"`triggerD`, `nextTime`, `payTime`, `createTime`, `visibleC`");
for (i = 0; i < MAX_GUARDIANS; ++i)
StringBuf_Printf(&buf, ", `visibleG%d`", i);
StringBuf_Printf(&buf, " FROM `%s` WHERE `castle_id`='%d'", schema_config.guild_castle_db, castle_id);
StringBuf_Printf(&buf, " FROM `%s` WHERE `castle_id`='%d'", charserv_table(guild_castle_table), castle_id);
if (SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf))) {
Sql_ShowDebug(sql_handle);
StringBuf_Destroy(&buf);
@@ -615,7 +615,7 @@ int inter_guild_CharOnline(uint32 char_id, int guild_id)
if (guild_id == -1) {
//Get guild_id from the database
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT guild_id FROM `%s` WHERE char_id='%d'", schema_config.char_db, char_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT guild_id FROM `%s` WHERE char_id='%d'", charserv_table(char_table), char_id) )
{
Sql_ShowDebug(sql_handle);
return 0;
@@ -666,7 +666,7 @@ int inter_guild_CharOffline(uint32 char_id, int guild_id)
if (guild_id == -1)
{
//Get guild_id from the database
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT guild_id FROM `%s` WHERE char_id='%d'", schema_config.char_db, char_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT guild_id FROM `%s` WHERE char_id='%d'", charserv_table(char_table), char_id) )
{
Sql_ShowDebug(sql_handle);
return 0;
@@ -724,7 +724,7 @@ int inter_guild_sql_init(void)
//Read exp file
for(i = 0; i<ARRAYLENGTH(filename); i++){
sv_readdb(db_path, filename[i], ',', 1, 1, 100, exp_guild_parse_row, i);
sv_readdb(charserv_config.db_path, filename[i], ',', 1, 1, 100, exp_guild_parse_row, i);
}
add_timer_func_list(guild_save_timer, "guild_save_timer");
@@ -760,7 +760,7 @@ int search_guildname(char *str)
Sql_EscapeStringLen(sql_handle, esc_name, str, safestrnlen(str, NAME_LENGTH));
//Lookup guilds with the same name
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT guild_id FROM `%s` WHERE name='%s'", schema_config.guild_db, esc_name) )
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT guild_id FROM `%s` WHERE name='%s'", charserv_table(guild_table), esc_name) )
{
Sql_ShowDebug(sql_handle);
return -1;
@@ -1256,7 +1256,7 @@ int mapif_parse_GuildLeave(int fd, int guild_id, uint32 account_id, uint32 char_
if( g == NULL )
{
// Unknown guild, just update the player
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `guild_id`='0' WHERE `account_id`='%d' AND `char_id`='%d'", schema_config.char_db, account_id, char_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `guild_id`='0' WHERE `account_id`='%d' AND `char_id`='%d'", charserv_table(char_table), account_id, char_id) )
Sql_ShowDebug(sql_handle);
// mapif_guild_withdraw(guild_id,account_id,char_id,flag,g->member[i].name,mes);
return 0;
@@ -1369,32 +1369,32 @@ int mapif_parse_BreakGuild(int fd,int guild_id)
// Delete guild from sql
//printf("- Delete guild %d from guild\n",guild_id);
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", schema_config.guild_db, guild_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", charserv_table(guild_table), guild_id) )
Sql_ShowDebug(sql_handle);
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", schema_config.guild_member_db, guild_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", charserv_table(guild_member_table), guild_id) )
Sql_ShowDebug(sql_handle);
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", schema_config.guild_castle_db, guild_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", charserv_table(guild_castle_table), guild_id) )
Sql_ShowDebug(sql_handle);
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", schema_config.guild_storage_db, guild_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", charserv_table(guild_storage_table), guild_id) )
Sql_ShowDebug(sql_handle);
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d' OR `alliance_id` = '%d'", schema_config.guild_alliance_db, guild_id, guild_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d' OR `alliance_id` = '%d'", charserv_table(guild_alliance_table), guild_id, guild_id) )
Sql_ShowDebug(sql_handle);
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", schema_config.guild_position_db, guild_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", charserv_table(guild_position_table), guild_id) )
Sql_ShowDebug(sql_handle);
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", schema_config.guild_skill_db, guild_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", charserv_table(guild_skill_table), guild_id) )
Sql_ShowDebug(sql_handle);
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", schema_config.guild_expulsion_db, guild_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '%d'", charserv_table(guild_expulsion_table), guild_id) )
Sql_ShowDebug(sql_handle);
//printf("- Update guild %d of char\n",guild_id);
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `guild_id`='0' WHERE `guild_id`='%d'", schema_config.char_db, guild_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `guild_id`='0' WHERE `guild_id`='%d'", charserv_table(char_table), guild_id) )
Sql_ShowDebug(sql_handle);
mapif_guild_broken(guild_id,0);

View File

@@ -92,7 +92,7 @@ bool mapif_homunculus_save(struct s_homunculus* hd)
if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` "
"(`char_id`, `class`,`prev_class`,`name`,`level`,`exp`,`intimacy`,`hunger`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`, `rename_flag`, `vaporize`) "
"VALUES ('%d', '%d', '%d', '%s', '%d', '%u', '%u', '%d', '%d', %d, '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
schema_config.homunculus_db, hd->char_id, hd->class_, hd->prev_class, esc_name, hd->level, hd->exp, hd->intimacy, hd->hunger, hd->str, hd->agi, hd->vit, hd->int_, hd->dex, hd->luk,
charserv_table(homunculus_table), hd->char_id, hd->class_, hd->prev_class, esc_name, hd->level, hd->exp, hd->intimacy, hd->hunger, hd->str, hd->agi, hd->vit, hd->int_, hd->dex, hd->luk,
hd->hp, hd->max_hp, hd->sp, hd->max_sp, hd->skillpts, hd->rename_flag, hd->vaporize) )
{
Sql_ShowDebug(sql_handle);
@@ -106,7 +106,7 @@ bool mapif_homunculus_save(struct s_homunculus* hd)
else
{
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `char_id`='%d', `class`='%d',`prev_class`='%d',`name`='%s',`level`='%d',`exp`='%u',`intimacy`='%u',`hunger`='%d', `str`='%d', `agi`='%d', `vit`='%d', `int`='%d', `dex`='%d', `luk`='%d', `hp`='%d',`max_hp`='%d',`sp`='%d',`max_sp`='%d',`skill_point`='%d', `rename_flag`='%d', `vaporize`='%d' WHERE `homun_id`='%d'",
schema_config.homunculus_db, hd->char_id, hd->class_, hd->prev_class, esc_name, hd->level, hd->exp, hd->intimacy, hd->hunger, hd->str, hd->agi, hd->vit, hd->int_, hd->dex, hd->luk,
charserv_table(homunculus_table), hd->char_id, hd->class_, hd->prev_class, esc_name, hd->level, hd->exp, hd->intimacy, hd->hunger, hd->str, hd->agi, hd->vit, hd->int_, hd->dex, hd->luk,
hd->hp, hd->max_hp, hd->sp, hd->max_sp, hd->skillpts, hd->rename_flag, hd->vaporize, hd->hom_id) )
{
Sql_ShowDebug(sql_handle);
@@ -118,7 +118,7 @@ bool mapif_homunculus_save(struct s_homunculus* hd)
int i;
stmt = SqlStmt_Malloc(sql_handle);
if( SQL_ERROR == SqlStmt_Prepare(stmt, "REPLACE INTO `%s` (`homun_id`, `id`, `lv`) VALUES (%d, ?, ?)", schema_config.skill_homunculus_db, hd->hom_id) )
if( SQL_ERROR == SqlStmt_Prepare(stmt, "REPLACE INTO `%s` (`homun_id`, `id`, `lv`) VALUES (%d, ?, ?)", charserv_table(skill_homunculus_table), hd->hom_id) )
SqlStmt_ShowDebug(stmt);
for( i = 0; i < MAX_HOMUNSKILL; ++i )
{
@@ -153,7 +153,7 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd)
memset(hd, 0, sizeof(*hd));
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `homun_id`,`char_id`,`class`,`prev_class`,`name`,`level`,`exp`,`intimacy`,`hunger`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`,`rename_flag`, `vaporize` FROM `%s` WHERE `homun_id`='%u'",
schema_config.homunculus_db, homun_id) )
charserv_table(homunculus_table), homun_id) )
{
Sql_ShowDebug(sql_handle);
return false;
@@ -199,7 +199,7 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd)
hd->hunger = cap_value(hd->hunger, 0, 100);
// Load Homunculus Skill
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `id`,`lv` FROM `%s` WHERE `homun_id`=%d", schema_config.skill_homunculus_db, homun_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `id`,`lv` FROM `%s` WHERE `homun_id`=%d", charserv_table(skill_homunculus_table), homun_id) )
{
Sql_ShowDebug(sql_handle);
return false;
@@ -229,8 +229,8 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd)
bool mapif_homunculus_delete(int homun_id)
{
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `homun_id` = '%u'", schema_config.homunculus_db, homun_id)
|| SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `homun_id` = '%u'", schema_config.skill_homunculus_db, homun_id)
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `homun_id` = '%u'", charserv_table(homunculus_table), homun_id)
|| SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `homun_id` = '%u'", charserv_table(skill_homunculus_table), homun_id)
) {
Sql_ShowDebug(sql_handle);
return false;

View File

@@ -31,7 +31,7 @@ static int mail_fromsql(uint32 char_id, struct mail_data* md)
// I keep the `status` < 3 just in case someone forget to apply the sqlfix
StringBuf_Printf(&buf, " FROM `%s` WHERE `dest_id`='%d' AND `status` < 3 ORDER BY `id` LIMIT %d",
schema_config.mail_db, char_id, MAIL_MAX_INBOX + 1);
charserv_table(mail_table), char_id, MAIL_MAX_INBOX + 1);
if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) )
Sql_ShowDebug(sql_handle);
@@ -82,7 +82,7 @@ static int mail_fromsql(uint32 char_id, struct mail_data* md)
msg = &md->msg[i];
if( msg->status == MAIL_NEW )
{
if ( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `status` = '%d' WHERE `id` = '%d'", schema_config.mail_db, MAIL_UNREAD, msg->id) )
if ( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `status` = '%d' WHERE `id` = '%d'", charserv_table(mail_table), MAIL_UNREAD, msg->id) )
Sql_ShowDebug(sql_handle);
msg->status = MAIL_UNREAD;
@@ -106,7 +106,7 @@ int mail_savemessage(struct mail_message* msg)
// 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`, `bound`", schema_config.mail_db);
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`, `bound`", charserv_table(mail_table));
for (j = 0; j < MAX_SLOTS; j++)
StringBuf_Printf(&buf, ", `card%d`", j);
StringBuf_Printf(&buf, ") VALUES (?, '%d', ?, '%d', ?, ?, '%lu', '%d', '%d', '%d', '%hu', '%d', '%d', '%d', '%"PRIu64"', '%d'",
@@ -147,7 +147,7 @@ static bool mail_loadmessage(int mail_id, struct mail_message* msg)
"`zeny`,`amount`,`nameid`,`refine`,`attribute`,`identify`,`unique_id`,`bound`");
for( j = 0; j < MAX_SLOTS; j++ )
StringBuf_Printf(&buf, ",`card%d`", j);
StringBuf_Printf(&buf, " FROM `%s` WHERE `id` = '%d'", schema_config.mail_db, mail_id);
StringBuf_Printf(&buf, " FROM `%s` WHERE `id` = '%d'", charserv_table(mail_table), mail_id);
if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf))
|| SQL_SUCCESS != Sql_NextRow(sql_handle) )
@@ -222,7 +222,7 @@ static void mapif_parse_Mail_requestinbox(int fd)
static void mapif_parse_Mail_read(int fd)
{
int mail_id = RFIFOL(fd,2);
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `status` = '%d' WHERE `id` = '%d'", schema_config.mail_db, MAIL_READ, mail_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `status` = '%d' WHERE `id` = '%d'", charserv_table(mail_table), MAIL_READ, mail_id) )
Sql_ShowDebug(sql_handle);
}
@@ -235,7 +235,7 @@ static bool mail_DeleteAttach(int mail_id)
int i;
StringBuf_Init(&buf);
StringBuf_Printf(&buf, "UPDATE `%s` SET `zeny` = '0', `nameid` = '0', `amount` = '0', `refine` = '0', `attribute` = '0', `identify` = '0'", schema_config.mail_db);
StringBuf_Printf(&buf, "UPDATE `%s` SET `zeny` = '0', `nameid` = '0', `amount` = '0', `refine` = '0', `attribute` = '0', `identify` = '0'", charserv_table(mail_table));
for (i = 0; i < MAX_SLOTS; i++)
StringBuf_Printf(&buf, ", `card%d` = '0'", i);
StringBuf_Printf(&buf, " WHERE `id` = '%d'", mail_id);
@@ -291,7 +291,7 @@ static void mapif_parse_Mail_getattach(int fd)
static void mapif_Mail_delete(int fd, uint32 char_id, int mail_id)
{
bool failed = false;
if ( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '%d'", schema_config.mail_db, mail_id) )
if ( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '%d'", charserv_table(mail_table), mail_id) )
{
Sql_ShowDebug(sql_handle);
failed = true;
@@ -340,7 +340,7 @@ static void mapif_Mail_return(int fd, uint32 char_id, int mail_id)
{
if( msg.dest_id != char_id)
return;
else if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '%d'", schema_config.mail_db, mail_id) )
else if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '%d'", charserv_table(mail_table), mail_id) )
Sql_ShowDebug(sql_handle);
else
{
@@ -405,7 +405,7 @@ static void mapif_parse_Mail_send(int fd)
// Try to find the Dest Char by Name
Sql_EscapeStringLen(sql_handle, esc_name, msg.dest_name, strnlen(msg.dest_name, NAME_LENGTH));
if ( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`, `char_id` FROM `%s` WHERE `name` = '%s'", schema_config.char_db, esc_name) )
if ( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`, `char_id` FROM `%s` WHERE `name` = '%s'", charserv_table(char_table), esc_name) )
Sql_ShowDebug(sql_handle);
else
if ( SQL_SUCCESS == Sql_NextRow(sql_handle) )

View File

@@ -15,7 +15,7 @@ bool mercenary_owner_fromsql(uint32 char_id, struct mmo_charstatus *status)
{
char* data;
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `merc_id`, `arch_calls`, `arch_faith`, `spear_calls`, `spear_faith`, `sword_calls`, `sword_faith` FROM `%s` WHERE `char_id` = '%d'", schema_config.mercenary_owner_db, char_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `merc_id`, `arch_calls`, `arch_faith`, `spear_calls`, `spear_faith`, `sword_calls`, `sword_faith` FROM `%s` WHERE `char_id` = '%d'", charserv_table(mercenary_owner_table), char_id) )
{
Sql_ShowDebug(sql_handle);
return false;
@@ -42,7 +42,7 @@ bool mercenary_owner_fromsql(uint32 char_id, struct mmo_charstatus *status)
bool mercenary_owner_tosql(uint32 char_id, struct mmo_charstatus *status)
{
if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`char_id`, `merc_id`, `arch_calls`, `arch_faith`, `spear_calls`, `spear_faith`, `sword_calls`, `sword_faith`) VALUES ('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
schema_config.mercenary_owner_db, char_id, status->mer_id, status->arch_calls, status->arch_faith, status->spear_calls, status->spear_faith, status->sword_calls, status->sword_faith) )
charserv_table(mercenary_owner_table), char_id, status->mer_id, status->arch_calls, status->arch_faith, status->spear_calls, status->spear_faith, status->sword_calls, status->sword_faith) )
{
Sql_ShowDebug(sql_handle);
return false;
@@ -53,10 +53,10 @@ bool mercenary_owner_tosql(uint32 char_id, struct mmo_charstatus *status)
bool mercenary_owner_delete(uint32 char_id)
{
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d'", schema_config.mercenary_owner_db, char_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d'", charserv_table(mercenary_owner_table), char_id) )
Sql_ShowDebug(sql_handle);
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d'", schema_config.mercenary_db, char_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d'", charserv_table(mercenary_table), char_id) )
Sql_ShowDebug(sql_handle);
return true;
@@ -70,7 +70,7 @@ bool mapif_mercenary_save(struct s_mercenary* merc)
{ // Create new DB entry
if( SQL_ERROR == Sql_Query(sql_handle,
"INSERT INTO `%s` (`char_id`,`class`,`hp`,`sp`,`kill_counter`,`life_time`) VALUES ('%d','%d','%d','%d','%u','%u')",
schema_config.mercenary_db, merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time) )
charserv_table(mercenary_table), merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time) )
{
Sql_ShowDebug(sql_handle);
flag = false;
@@ -80,7 +80,7 @@ bool mapif_mercenary_save(struct s_mercenary* merc)
}
else if( SQL_ERROR == Sql_Query(sql_handle,
"UPDATE `%s` SET `char_id` = '%d', `class` = '%d', `hp` = '%d', `sp` = '%d', `kill_counter` = '%u', `life_time` = '%u' WHERE `mer_id` = '%d'",
schema_config.mercenary_db, merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time, merc->mercenary_id) )
charserv_table(mercenary_table), merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time, merc->mercenary_id) )
{ // Update DB entry
Sql_ShowDebug(sql_handle);
flag = false;
@@ -97,7 +97,7 @@ bool mapif_mercenary_load(int merc_id, uint32 char_id, struct s_mercenary *merc)
merc->mercenary_id = merc_id;
merc->char_id = char_id;
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `class`, `hp`, `sp`, `kill_counter`, `life_time` FROM `%s` WHERE `mer_id` = '%d' AND `char_id` = '%d'", schema_config.mercenary_db, merc_id, char_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `class`, `hp`, `sp`, `kill_counter`, `life_time` FROM `%s` WHERE `mer_id` = '%d' AND `char_id` = '%d'", charserv_table(mercenary_table), merc_id, char_id) )
{
Sql_ShowDebug(sql_handle);
return false;
@@ -123,7 +123,7 @@ bool mapif_mercenary_load(int merc_id, uint32 char_id, struct s_mercenary *merc)
bool mapif_mercenary_delete(int merc_id)
{
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `mer_id` = '%d'", schema_config.mercenary_db, merc_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `mer_id` = '%d'", charserv_table(mercenary_table), merc_id) )
{
Sql_ShowDebug(sql_handle);
return false;

View File

@@ -127,9 +127,9 @@ int inter_party_tosql(struct party *p, int flag, int index)
if( flag & PS_BREAK )
{// Break the party
// we'll skip name-checking and just reset everyone with the same party id [celest]
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d'", schema_config.char_db, party_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d'", charserv_table(char_table), party_id) )
Sql_ShowDebug(sql_handle);
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `party_id`='%d'", schema_config.party_db, party_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `party_id`='%d'", charserv_table(party_table), party_id) )
Sql_ShowDebug(sql_handle);
//Remove from memory
idb_remove(party_db_, party_id);
@@ -141,7 +141,7 @@ int inter_party_tosql(struct party *p, int flag, int index)
if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` "
"(`name`, `exp`, `item`, `leader_id`, `leader_char`) "
"VALUES ('%s', '%d', '%d', '%d', '%d')",
schema_config.party_db, esc_name, p->exp, p->item, p->member[index].account_id, p->member[index].char_id) )
charserv_table(party_table), esc_name, p->exp, p->item, p->member[index].account_id, p->member[index].char_id) )
{
Sql_ShowDebug(sql_handle);
return 0;
@@ -152,28 +152,28 @@ int inter_party_tosql(struct party *p, int flag, int index)
if( flag & PS_BASIC )
{// Update party info.
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `name`='%s', `exp`='%d', `item`='%d' WHERE `party_id`='%d'",
schema_config.party_db, esc_name, p->exp, p->item, party_id) )
charserv_table(party_table), esc_name, p->exp, p->item, party_id) )
Sql_ShowDebug(sql_handle);
}
if( flag & PS_LEADER )
{// Update leader
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `leader_id`='%d', `leader_char`='%d' WHERE `party_id`='%d'",
schema_config.party_db, p->member[index].account_id, p->member[index].char_id, party_id) )
charserv_table(party_table), p->member[index].account_id, p->member[index].char_id, party_id) )
Sql_ShowDebug(sql_handle);
}
if( flag & PS_ADDMEMBER )
{// Add one party member.
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `party_id`='%d' WHERE `account_id`='%d' AND `char_id`='%d'",
schema_config.char_db, party_id, p->member[index].account_id, p->member[index].char_id) )
charserv_table(char_table), party_id, p->member[index].account_id, p->member[index].char_id) )
Sql_ShowDebug(sql_handle);
}
if( flag & PS_DELMEMBER )
{// Remove one party member.
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d' AND `account_id`='%d' AND `char_id`='%d'",
schema_config.char_db, party_id, p->member[index].account_id, p->member[index].char_id) )
charserv_table(char_table), party_id, p->member[index].account_id, p->member[index].char_id) )
Sql_ShowDebug(sql_handle);
}
@@ -207,7 +207,7 @@ struct party_data *inter_party_fromsql(int party_id)
p = party_pt;
memset(p, 0, sizeof(struct party_data));
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `party_id`, `name`,`exp`,`item`, `leader_id`, `leader_char` FROM `%s` WHERE `party_id`='%d'", schema_config.party_db, party_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `party_id`, `name`,`exp`,`item`, `leader_id`, `leader_char` FROM `%s` WHERE `party_id`='%d'", charserv_table(party_table), party_id) )
{
Sql_ShowDebug(sql_handle);
return NULL;
@@ -225,7 +225,7 @@ struct party_data *inter_party_fromsql(int party_id)
Sql_FreeResult(sql_handle);
// Load members
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`char_id`,`name`,`base_level`,`last_map`,`online`,`class` FROM `%s` WHERE `party_id`='%d'", schema_config.char_db, party_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`char_id`,`name`,`base_level`,`last_map`,`online`,`class` FROM `%s` WHERE `party_id`='%d'", charserv_table(char_table), party_id) )
{
Sql_ShowDebug(sql_handle);
return NULL;
@@ -289,7 +289,7 @@ struct party_data* search_partyname(char* str)
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'", schema_config.party_db, esc_name) )
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `party_id` FROM `%s` WHERE `name`='%s'", charserv_table(party_table), esc_name) )
Sql_ShowDebug(sql_handle);
else if( SQL_SUCCESS == Sql_NextRow(sql_handle) )
{
@@ -304,7 +304,7 @@ struct party_data* search_partyname(char* str)
// Returns whether this party can keep having exp share or not.
int party_check_exp_share(struct party_data *p)
{
return (p->party.count < 2 || p->max_lv - p->min_lv <= party_share_level);
return (p->party.count < 2 || p->max_lv - p->min_lv <= inter_config.party_share_level);
}
// Is there any member in the party?
@@ -594,7 +594,7 @@ int mapif_parse_PartyLeave(int fd, int party_id, uint32 account_id, uint32 char_
p = inter_party_fromsql(party_id);
if( p == NULL )
{// Party does not exists?
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d'", schema_config.char_db, party_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d'", charserv_table(char_table), party_id) )
Sql_ShowDebug(sql_handle);
return 0;
}
@@ -748,7 +748,7 @@ int mapif_parse_PartyShareLevel(int fd,unsigned int share_lvl)
struct party_data *p;
DBIterator* iter = db_iterator(party_db_);
party_share_level = share_lvl;
inter_config.party_share_level = share_lvl;
for(p = (struct party_data *)dbi_first(iter); dbi_exists(iter); p = (struct party_data *)dbi_next(iter)) { //Update online parties
if(p->party.count > 1)
@@ -802,7 +802,7 @@ int inter_party_CharOnline(uint32 char_id, int party_id)
{// Get party_id from the database
char* data;
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT party_id FROM `%s` WHERE char_id='%d'", schema_config.char_db, char_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT party_id FROM `%s` WHERE char_id='%d'", charserv_table(char_table), char_id) )
{
Sql_ShowDebug(sql_handle);
return 0;
@@ -848,7 +848,7 @@ int inter_party_CharOffline(uint32 char_id, int party_id) {
{// Get guild_id from the database
char* data;
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT party_id FROM `%s` WHERE char_id='%d'", schema_config.char_db, char_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT party_id FROM `%s` WHERE char_id='%d'", charserv_table(char_table), char_id) )
{
Sql_ShowDebug(sql_handle);
return 0;

View File

@@ -30,7 +30,7 @@ int inter_pet_tosql(int pet_id, struct s_pet* p)
if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` "
"(`class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate`) "
"VALUES ('%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
schema_config.pet_db, p->class_, esc_name, p->account_id, p->char_id, p->level, p->egg_id,
charserv_table(pet_table), p->class_, esc_name, p->account_id, p->char_id, p->level, p->egg_id,
p->equip, p->intimate, p->hungry, p->rename_flag, p->incubate) )
{
Sql_ShowDebug(sql_handle);
@@ -41,7 +41,7 @@ int inter_pet_tosql(int pet_id, struct s_pet* p)
else
{// Update pet.
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `class`='%d',`name`='%s',`account_id`='%d',`char_id`='%d',`level`='%d',`egg_id`='%d',`equip`='%d',`intimate`='%d',`hungry`='%d',`rename_flag`='%d',`incubate`='%d' WHERE `pet_id`='%d'",
schema_config.pet_db, p->class_, esc_name, p->account_id, p->char_id, p->level, p->egg_id,
charserv_table(pet_table), p->class_, esc_name, p->account_id, p->char_id, p->level, p->egg_id,
p->equip, p->intimate, p->hungry, p->rename_flag, p->incubate, p->pet_id) )
{
Sql_ShowDebug(sql_handle);
@@ -66,7 +66,7 @@ int inter_pet_fromsql(int pet_id, struct s_pet* p)
//`pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate`)
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate` FROM `%s` WHERE `pet_id`='%d'", schema_config.pet_db, pet_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate` FROM `%s` WHERE `pet_id`='%d'", charserv_table(pet_table), pet_id) )
{
Sql_ShowDebug(sql_handle);
return 0;
@@ -112,7 +112,7 @@ void inter_pet_sql_final(void){
int inter_pet_delete(int pet_id){
ShowInfo("delete pet request: %d...\n",pet_id);
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `pet_id`='%d'", schema_config.pet_db, pet_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `pet_id`='%d'", charserv_table(pet_table), pet_id) )
Sql_ShowDebug(sql_handle);
return 0;
}

View File

@@ -38,7 +38,7 @@ struct quest *mapif_quests_fromsql(uint32 char_id, int *count) {
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)
if( SQL_ERROR == SqlStmt_Prepare(stmt, "SELECT `quest_id`, `state`, `time`, `count1`, `count2`, `count3` FROM `%s` WHERE `char_id`=? ", charserv_table(quest_table))
|| 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)
@@ -83,7 +83,7 @@ struct quest *mapif_quests_fromsql(uint32 char_id, int *count) {
* @return false in case of errors, true otherwise
*/
bool mapif_quest_delete(uint32 char_id, int quest_id) {
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `quest_id` = '%d' AND `char_id` = '%d'", schema_config.quest_db, quest_id, char_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `quest_id` = '%d' AND `char_id` = '%d'", charserv_table(quest_table), quest_id, char_id) )
{
Sql_ShowDebug(sql_handle);
return false;
@@ -100,7 +100,7 @@ bool mapif_quest_delete(uint32 char_id, int quest_id) {
* @return false in case of errors, true otherwise
*/
bool mapif_quest_add(uint32 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')", schema_config.quest_db, qd.quest_id, char_id, qd.state, qd.time, qd.count[0], qd.count[1], qd.count[2]) )
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')", charserv_table(quest_table), qd.quest_id, char_id, qd.state, qd.time, qd.count[0], qd.count[1], qd.count[2]) )
{
Sql_ShowDebug(sql_handle);
return false;
@@ -117,7 +117,7 @@ bool mapif_quest_add(uint32 char_id, struct quest qd) {
* @return false in case of errors, true otherwise
*/
bool mapif_quest_update(uint32 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'", schema_config.quest_db, qd.state, qd.count[0], qd.count[1], qd.count[2], qd.quest_id, char_id) )
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'", charserv_table(quest_table), qd.state, qd.count[0], qd.count[1], qd.count[2], qd.quest_id, char_id) )
{
Sql_ShowDebug(sql_handle);
return false;

View File

@@ -35,7 +35,7 @@ int storage_fromsql(uint32 account_id, struct storage_data* p)
StringBuf_AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`expire_time`,`bound`,`unique_id`");
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`", schema_config.storage_db, account_id);
StringBuf_Printf(&buf, " FROM `%s` WHERE `account_id`='%d' ORDER BY `nameid`", charserv_table(storage_table), account_id);
if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) )
Sql_ShowDebug(sql_handle);
@@ -91,7 +91,7 @@ int guild_storage_fromsql(int guild_id, struct guild_storage* p)
StringBuf_AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`bound`,`unique_id`");
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`", schema_config.guild_storage_db, guild_id);
StringBuf_Printf(&buf, " FROM `%s` WHERE `guild_id`='%d' ORDER BY `nameid`", charserv_table(guild_storage_table), guild_id);
if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) )
Sql_ShowDebug(sql_handle);
@@ -139,13 +139,13 @@ void inter_storage_sql_final(void)
// Delete char storage
int inter_storage_delete(uint32 account_id)
{
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id`='%d'", schema_config.storage_db, account_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id`='%d'", charserv_table(storage_table), account_id) )
Sql_ShowDebug(sql_handle);
return 0;
}
int inter_guild_storage_delete(int guild_id)
{
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id`='%d'", schema_config.guild_storage_db, guild_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `guild_id`='%d'", charserv_table(guild_storage_table), guild_id) )
Sql_ShowDebug(sql_handle);
return 0;
}
@@ -155,7 +155,7 @@ int inter_guild_storage_delete(int guild_id)
int mapif_load_guild_storage(int fd,uint32 account_id,int guild_id, char flag)
{
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `guild_id` FROM `%s` WHERE `guild_id`='%d'", schema_config.guild_db, guild_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `guild_id` FROM `%s` WHERE `guild_id`='%d'", charserv_table(guild_table), guild_id) )
Sql_ShowDebug(sql_handle);
else if( Sql_NumRows(sql_handle) > 0 )
{// guild exists
@@ -215,7 +215,7 @@ int mapif_parse_SaveGuildStorage(int fd)
}
else
{
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `guild_id` FROM `%s` WHERE `guild_id`='%d'", schema_config.guild_db, guild_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `guild_id` FROM `%s` WHERE `guild_id`='%d'", charserv_table(guild_table), guild_id) )
Sql_ShowDebug(sql_handle);
else if( Sql_NumRows(sql_handle) > 0 )
{// guild exists
@@ -293,7 +293,7 @@ int mapif_parse_itembound_retrieve(int fd)
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", schema_config.inventory_db,char_id, BOUND_GUILD);
StringBuf_Printf(&buf, " FROM `%s` WHERE `char_id`='%d' AND `bound` = %d", charserv_table(inventory_table),char_id, BOUND_GUILD);
stmt = SqlStmt_Malloc(sql_handle);
if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) ||
@@ -335,7 +335,7 @@ int mapif_parse_itembound_retrieve(int fd)
// Delete bound items from player's inventory
StringBuf_Clear(&buf);
StringBuf_Printf(&buf, "DELETE FROM `%s` WHERE `bound` = %d",schema_config.inventory_db, BOUND_GUILD);
StringBuf_Printf(&buf, "DELETE FROM `%s` WHERE `bound` = %d",charserv_table(inventory_table), BOUND_GUILD);
if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) ||
SQL_ERROR == SqlStmt_Execute(stmt) )
{
@@ -379,7 +379,7 @@ int mapif_parse_itembound_retrieve(int fd)
if (j) {
StringBuf buf2;
StringBuf_Init(&buf2);
StringBuf_Printf(&buf2, "UPDATE `%s` SET %s WHERE `char_id`='%d'", schema_config.char_db, StringBuf_Value(&buf), char_id);
StringBuf_Printf(&buf2, "UPDATE `%s` SET %s WHERE `char_id`='%d'", charserv_table(char_table), StringBuf_Value(&buf), char_id);
if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) ||
SQL_ERROR == SqlStmt_Execute(stmt) )

View File

@@ -33,14 +33,9 @@
Sql* sql_handle = NULL; ///Link to mysql db, connection FD
int char_server_port = 3306;
char char_server_ip[32] = "127.0.0.1";
char char_server_id[32] = "ragnarok";
char char_server_pw[32] = ""; // Allow user to send empty password (bugreport:7787)
char char_server_db[32] = "ragnarok";
char default_codepage[32] = ""; //Feature by irmin.
unsigned int party_share_level = 10;
struct Inter_Config inter_config;
static void inter_config_init(void);
static void inter_config_final(void);
// recv. packet list
int inter_recv_packet_length[] = {
@@ -408,7 +403,7 @@ void mapif_parse_accinfo(int fd) {
account_id = atoi(query);
if (account_id < START_ACCOUNT_NUM) { // is string
if ( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`name`,`class`,`base_level`,`job_level`,`online` FROM `%s` WHERE `name` LIKE '%s' LIMIT 10", schema_config.char_db, query_esq)
if ( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`name`,`class`,`base_level`,`job_level`,`online` FROM `%s` WHERE `name` LIKE '%s' LIMIT 10", charserv_table(char_table), query_esq)
|| Sql_NumRows(sql_handle) == 0 ) {
if( Sql_NumRows(sql_handle) == 0 ) {
inter_to_fd(fd, u_fd, u_aid, (char *)msg_txt(212) ,query);
@@ -481,7 +476,7 @@ void mapif_accinfo_ack(bool success, int map_fd, int u_fd, int u_aid, int accoun
inter_to_fd(map_fd, u_fd, u_aid, (char *)msg_txt(223), logincount, lastlogin);
inter_to_fd(map_fd, u_fd, u_aid, (char *)msg_txt(224));
if ( SQL_ERROR == Sql_Query(sql_handle, "SELECT `char_id`, `name`, `char_num`, `class`, `base_level`, `job_level`, `online` FROM `%s` WHERE `account_id` = '%d' ORDER BY `char_num` LIMIT %d", schema_config.char_db, account_id, MAX_CHARS)
if ( SQL_ERROR == Sql_Query(sql_handle, "SELECT `char_id`, `name`, `char_num`, `class`, `base_level`, `job_level`, `online` FROM `%s` WHERE `account_id` = '%d' ORDER BY `char_num` LIMIT %d", charserv_table(char_table), account_id, MAX_CHARS)
|| Sql_NumRows(sql_handle) == 0 )
{
if( Sql_NumRows(sql_handle) == 0 )
@@ -573,11 +568,11 @@ int inter_accreg_fromsql(uint32 account_id, uint32 char_id, int fd, int type)
switch( type ) {
case 3: //char reg
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `char_id`='%d'", schema_config.char_reg_str_table, char_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `char_id`='%d'", charserv_table(char_reg_str_table), char_id) )
Sql_ShowDebug(sql_handle);
break;
case 2: //account reg
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `account_id`='%d'", schema_config.acc_reg_str_table, account_id) )
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `account_id`='%d'", charserv_table(acc_reg_str_table), account_id) )
Sql_ShowDebug(sql_handle);
break;
case 1: //account2 reg
@@ -654,11 +649,11 @@ int inter_accreg_fromsql(uint32 account_id, uint32 char_id, int fd, int type)
switch( type ) {
case 3: //char reg
if (SQL_ERROR == Sql_Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `char_id`='%d'", schema_config.char_reg_num_table, char_id))
if (SQL_ERROR == Sql_Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `char_id`='%d'", charserv_table(char_reg_num_table), char_id))
Sql_ShowDebug(sql_handle);
break;
case 2: //account reg
if (SQL_ERROR == Sql_Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `account_id`='%d'", schema_config.acc_reg_num_table, account_id))
if (SQL_ERROR == Sql_Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `account_id`='%d'", charserv_table(acc_reg_num_table), account_id))
Sql_ShowDebug(sql_handle);
break;
#if 0 // This is already checked above.
@@ -731,6 +726,31 @@ int inter_accreg_fromsql(uint32 account_id, uint32 char_id, int fd, int type)
return 1;
}
/**
* Set default hardcoded Inter-serv configurations
**/
static void inter_config_init(void) {
inter_config.party_share_level = 10;
inter_config.char_server_port = 3306;
inter_config.char_server_ip = StringBuf_FromStr("127.0.0.1");
inter_config.char_server_id = StringBuf_FromStr("ragnarok");
inter_config.char_server_pw = StringBuf_FromStr("");
inter_config.char_server_db = StringBuf_FromStr("ragnarok");
inter_config.default_codepage = StringBuf_FromStr("");
}
/**
* Destroy necessary inter_config values
**/
static void inter_config_final(void) {
StringBuf_Free(inter_config.char_server_ip);
StringBuf_Free(inter_config.char_server_id);
StringBuf_Free(inter_config.char_server_pw);
StringBuf_Free(inter_config.char_server_db);
StringBuf_Free(inter_config.default_codepage);
}
/*==========================================
* read config file
*------------------------------------------*/
@@ -755,19 +775,19 @@ static int inter_config_read(const char* cfgName)
continue;
if(!strcmpi(w1,"char_server_ip"))
strcpy(char_server_ip,w2);
StringBuf_PrintfClear(inter_config.char_server_ip, w2);
else if(!strcmpi(w1,"char_server_port"))
char_server_port = atoi(w2);
inter_config.char_server_port = atoi(w2);
else if(!strcmpi(w1,"char_server_id"))
strcpy(char_server_id,w2);
StringBuf_PrintfClear(inter_config.char_server_id, w2);
else if(!strcmpi(w1,"char_server_pw"))
strcpy(char_server_pw,w2);
StringBuf_PrintfClear(inter_config.char_server_pw, w2);
else if(!strcmpi(w1,"char_server_db"))
strcpy(char_server_db,w2);
StringBuf_PrintfClear(inter_config.char_server_db, w2);
else if(!strcmpi(w1,"default_codepage"))
strcpy(default_codepage,w2);
StringBuf_PrintfClear(inter_config.default_codepage, w2);
else if(!strcmpi(w1,"party_share_level"))
party_share_level = (unsigned int)atof(w2);
inter_config.party_share_level = (unsigned short)atof(w2);
else if(!strcmpi(w1,"log_inter"))
charserv_config.log_inter = atoi(w2);
else if(!strcmpi(w1,"import"))
@@ -792,7 +812,7 @@ int inter_log(char* fmt, ...)
va_end(ap);
Sql_EscapeStringLen(sql_handle, esc_str, str, strnlen(str, sizeof(str)));
if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` (`time`, `log`) VALUES (NOW(), '%s')", schema_config.interlog_db, esc_str) )
if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` (`time`, `log`) VALUES (NOW(), '%s')", charserv_table(interlog_table), esc_str) )
Sql_ShowDebug(sql_handle);
return 0;
@@ -803,26 +823,30 @@ int inter_init_sql(const char *file)
{
//int i;
inter_config_init();
inter_config_read(file);
//DB connection initialized
sql_handle = Sql_Malloc();
ShowInfo("Connect Character DB server.... (Character Server)\n");
if( SQL_ERROR == Sql_Connect(sql_handle, char_server_id, char_server_pw, char_server_ip, (uint16)char_server_port, char_server_db) )
if( SQL_ERROR == Sql_Connect(sql_handle, StringBuf_Value(inter_config.char_server_id), StringBuf_Value(inter_config.char_server_pw), StringBuf_Value(inter_config.char_server_ip), inter_config.char_server_port, StringBuf_Value(inter_config.char_server_db)) )
{
ShowError("Couldn't connect with uname='%s',passwd='%s',host='%s',port='%d',database='%s'\n",
char_server_id, char_server_pw, char_server_ip, char_server_port, char_server_db);
StringBuf_Value(inter_config.char_server_id), StringBuf_Value(inter_config.char_server_pw), StringBuf_Value(inter_config.char_server_ip), inter_config.char_server_port, StringBuf_Value(inter_config.char_server_db));
Sql_ShowDebug(sql_handle);
Sql_Free(sql_handle);
exit(EXIT_FAILURE);
}
if( *default_codepage ) {
if( SQL_ERROR == Sql_SetEncoding(sql_handle, default_codepage) )
if( StringBuf_Length(inter_config.default_codepage) ) {
if( SQL_ERROR == Sql_SetEncoding(sql_handle, StringBuf_Value(inter_config.default_codepage)) )
Sql_ShowDebug(sql_handle);
}
ShowStatus("Character server connection: Database '"CL_WHITE"%s"CL_RESET"' at '"CL_WHITE"%s"CL_RESET"'\n", StringBuf_Value(inter_config.char_server_db), StringBuf_Value(inter_config.char_server_ip));
wis_db = idb_alloc(DB_OPT_RELEASE_DATA);
inter_guild_sql_init();
inter_storage_sql_init();
inter_party_sql_init();
@@ -851,6 +875,7 @@ void inter_final(void)
inter_elemental_sql_final();
inter_mail_sql_final();
inter_auction_sql_final();
inter_config_final();
if(geoip_cache) aFree(geoip_cache);
@@ -1023,7 +1048,7 @@ int mapif_parse_WisRequest(int fd)
safestrncpy(name, (char*)RFIFOP(fd,28), NAME_LENGTH); //Received name may be too large and not contain \0! [Skotlex]
Sql_EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH));
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `name` FROM `%s` WHERE `name`='%s'", schema_config.char_db, esc_name) )
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `name` FROM `%s` WHERE `name`='%s'", charserv_table(char_table), esc_name) )
Sql_ShowDebug(sql_handle);
// search if character exists before to ask all map-servers

View File

@@ -20,7 +20,19 @@ int inter_log(char *fmt,...);
#define inter_cfgName "conf/inter_athena.conf"
extern unsigned int party_share_level;
struct Inter_Config {
unsigned short char_server_port; ///< char-server port
StringBuf *char_server_ip; ///< char-server hostname/ip
StringBuf *char_server_id; ///< char-server username
StringBuf *char_server_pw; ///< char-server password
StringBuf *char_server_db; ///< char-server database
StringBuf *default_codepage; ///< Codepage [irmin]
StringBuf testbuf;
unsigned short party_share_level; ///< Party share level
};
extern struct Inter_Config inter_config; /// Inter/char-server configuration with database
extern Sql* sql_handle;
extern Sql* lsql_handle;

View File

@@ -1069,17 +1069,36 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc
/// Allocates a StringBuf
StringBuf* StringBuf_Malloc()
{
return StringBuf_MallocInitial(1024);
}
StringBuf* StringBuf_MallocInitial(unsigned int initial)
{
StringBuf* self;
CREATE(self, StringBuf, 1);
StringBuf_Init(self);
StringBuf_InitialInit(self, initial);
return self;
}
StringBuf* StringBuf_FromStr(const char* str)
{
StringBuf* self = StringBuf_MallocInitial((unsigned int)strlen(str)+1);
StringBuf_AppendStr(self, str);
return self;
}
/// Initializes a previously allocated StringBuf
void StringBuf_Init(StringBuf* self)
{
self->max_ = 1024;
StringBuf_InitialInit(self, 1024);
}
void StringBuf_InitialInit(StringBuf* self, unsigned int initial)
{
self->max_ = initial;
self->initial_ = initial;
self->ptr_ = self->buf_ = (char*)aMalloc(self->max_ + 1);
}
@@ -1096,6 +1115,18 @@ int StringBuf_Printf(StringBuf* self, const char* fmt, ...)
return len;
}
int StringBuf_PrintfClear(StringBuf* self, const char* fmt, ...) {
int len;
va_list ap;
self->ptr_ = self->buf_;
va_start(ap, fmt);
len = StringBuf_Vprintf(self, fmt, ap);
va_end(ap);
return len;
}
/// Appends the result of vprintf to the StringBuf
int StringBuf_Vprintf(StringBuf* self, const char* fmt, va_list ap)
{
@@ -1150,7 +1181,7 @@ int StringBuf_AppendStr(StringBuf* self, const char* str)
if( needed >= available )
{// not enough space, expand the buffer (minimum expansion = 1024)
int off = (int)(self->ptr_ - self->buf_);
self->max_ += max(needed, 1024);
self->max_ += max((unsigned int)needed, self->initial_);
self->buf_ = (char*)aRealloc(self->buf_, self->max_ + 1);
self->ptr_ = self->buf_ + off;
}

View File

@@ -137,12 +137,17 @@ struct StringBuf
char *buf_;
char *ptr_;
unsigned int max_;
unsigned int initial_;
};
typedef struct StringBuf StringBuf;
StringBuf* StringBuf_Malloc(void);
StringBuf* StringBuf_MallocInitial(unsigned int initial);
StringBuf* StringBuf_FromStr(const char* str);
void StringBuf_InitialInit(StringBuf* self, unsigned int initial);
void StringBuf_Init(StringBuf* self);
int StringBuf_Printf(StringBuf* self, const char* fmt, ...);
int StringBuf_PrintfClear(StringBuf* self, const char* fmt, ...);
int StringBuf_Vprintf(StringBuf* self, const char* fmt, va_list args);
int StringBuf_Append(StringBuf* self, const StringBuf *sbuf);
int StringBuf_AppendStr(StringBuf* self, const char* str);

View File

@@ -23,18 +23,18 @@
typedef struct AccountDB_SQL {
AccountDB vtable; // public interface
Sql* accounts; // SQL handle accounts storage
char db_hostname[64]; // Doubled for long hostnames (bugreport:8003)
uint16 db_port;
char db_username[32];
char db_password[32];
char db_database[32];
char codepage[32];
StringBuf *db_hostname;
StringBuf *db_username;
StringBuf *db_password;
StringBuf *db_database;
StringBuf *codepage;
// other settings
bool case_sensitive;
//table name
char account_db[32];
char global_acc_reg_num_table[32];
char global_acc_reg_str_table[32];
StringBuf *account_table;
StringBuf *global_acc_reg_num_table;
StringBuf *global_acc_reg_str_table;
} AccountDB_SQL;
@@ -59,6 +59,10 @@ static AccountDBIterator* account_db_sql_iterator(AccountDB* self);
static void account_db_sql_iter_destroy(AccountDBIterator* self);
static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account* acc);
static void account_db_init_conf(AccountDB* self);
static void account_db_destroy_conf(AccountDB* self);
static bool account_db_check_tables(AccountDB* self);
static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, uint32 account_id);
static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, bool is_new);
@@ -77,21 +81,14 @@ AccountDB* account_db_sql(void) {
db->vtable.load_num = &account_db_sql_load_num;
db->vtable.load_str = &account_db_sql_load_str;
db->vtable.iterator = &account_db_sql_iterator;
db->vtable.init_conf = &account_db_init_conf;
db->vtable.destroy_conf = &account_db_destroy_conf;
db->vtable.check_tables = &account_db_check_tables;
// initialize to default values
db->accounts = NULL;
// local sql settings
safestrncpy(db->db_hostname, "127.0.0.1", sizeof(db->db_hostname));
db->db_port = 3306;
safestrncpy(db->db_username, "ragnarok", sizeof(db->db_username));
safestrncpy(db->db_password, "ragnarok", sizeof(db->db_password));
safestrncpy(db->db_database, "ragnarok", sizeof(db->db_database));
safestrncpy(db->codepage, "", sizeof(db->codepage));
db->accounts = NULL;
// other settings
db->case_sensitive = false;
safestrncpy(db->account_db, "login", sizeof(db->account_db));
safestrncpy(db->global_acc_reg_num_table, "global_acc_reg_num", sizeof(db->global_acc_reg_num_table));
safestrncpy(db->global_acc_reg_str_table, "global_acc_reg_str", sizeof(db->global_acc_reg_str_table));
return &db->vtable;
}
@@ -99,6 +96,70 @@ AccountDB* account_db_sql(void) {
/* ------------------------------------------------------------------------- */
static void account_db_init_conf(AccountDB* self) {
AccountDB_SQL* db = (AccountDB_SQL*)self;
db->db_port = 3306;
db->db_hostname = StringBuf_FromStr("127.0.0.1");
db->db_username = StringBuf_FromStr("ragnarok");
db->db_password = StringBuf_FromStr("");
db->db_database = StringBuf_FromStr("ragnarok");
db->codepage = StringBuf_FromStr("");
db->account_table = StringBuf_FromStr("login");
db->global_acc_reg_num_table = StringBuf_FromStr("global_acc_reg_num");
db->global_acc_reg_str_table = StringBuf_FromStr("global_acc_reg_str");
}
static void account_db_destroy_conf(AccountDB* self) {
AccountDB_SQL* db = (AccountDB_SQL*)self;
StringBuf_Free(db->db_hostname);
StringBuf_Free(db->db_username);
StringBuf_Free(db->db_password);
StringBuf_Free(db->db_database);
StringBuf_Free(db->codepage);
StringBuf_Free(db->account_table);
StringBuf_Free(db->global_acc_reg_num_table);
StringBuf_Free(db->global_acc_reg_str_table);
}
static bool account_db_check_tables(AccountDB* self) {
AccountDB_SQL* db = (AccountDB_SQL*)self;
ShowInfo("Start checking DB integrity (Login)\n");
// Account table
if( SQL_ERROR == Sql_Query(db->accounts,
"SELECT `account_id`, `userid`, `user_pass`, `sex`, `email`, `group_id`, `state`, `unban_time`, `expiration_time`, "
"`logincount`, `lastlogin`, `last_ip`, `birthdate`, `character_slots`, `pincode`, `pincode_change`, `bank_vault`, "
"`vip_time`, `old_group` "
"FROM `%s`;", StringBuf_Value(db->account_table)) )
{
Sql_ShowDebug(db->accounts);
return false;
}
// Account registry number table
if( SQL_ERROR == Sql_Query(db->accounts,
"SELECT `account_id`, `key`, `index`, `value` "
"FROM `%s`;", StringBuf_Value(db->global_acc_reg_num_table)) )
{
Sql_ShowDebug(db->accounts);
return false;
}
// Account registry string table
if( SQL_ERROR == Sql_Query(db->accounts,
"SELECT `account_id`, `key`, `index`, `value` "
"FROM `%s`;", StringBuf_Value(db->global_acc_reg_str_table)) )
{
Sql_ShowDebug(db->accounts);
return false;
}
return true;
}
/**
* Establish the database connection.
@@ -107,39 +168,29 @@ AccountDB* account_db_sql(void) {
static bool account_db_sql_init(AccountDB* self) {
AccountDB_SQL* db = (AccountDB_SQL*)self;
Sql* sql_handle;
const char* username = "ragnarok";
const char* password = "";
const char* hostname = "127.0.0.1";
uint16 port = 3306;
const char* database = "ragnarok";
const char* codepage = "";
db->accounts = Sql_Malloc();
sql_handle = db->accounts;
if( db->db_hostname[0] != '\0' )
{// local settings
username = db->db_username;
password = db->db_password;
hostname = db->db_hostname;
port = db->db_port;
database = db->db_database;
codepage = db->codepage;
}
if( SQL_ERROR == Sql_Connect(sql_handle, username, password, hostname, port, database) )
if( SQL_ERROR == Sql_Connect(sql_handle, StringBuf_Value(db->db_username), StringBuf_Value(db->db_password), StringBuf_Value(db->db_hostname), db->db_port, StringBuf_Value(db->db_database)) )
{
ShowError("Couldn't connect with uname='%s',passwd='%s',host='%s',port='%d',database='%s'\n",
username, password, hostname, port, database);
ShowError("Couldn't connect with uname='%s',passwd='%s',host='%s',port='%d',database='%s'\n",
StringBuf_Value(db->db_username), StringBuf_Value(db->db_password), StringBuf_Value(db->db_hostname), db->db_port, StringBuf_Value(db->db_database));
Sql_ShowDebug(sql_handle);
Sql_Free(db->accounts);
db->accounts = NULL;
return false;
}
if( codepage[0] != '\0' && SQL_ERROR == Sql_SetEncoding(sql_handle, codepage) )
if( StringBuf_Length(db->codepage) && SQL_ERROR == Sql_SetEncoding(sql_handle, StringBuf_Value(db->codepage)) )
Sql_ShowDebug(sql_handle);
if (!self->check_tables(self)) {
ShowFatalError("login-server (login) : A table is missing in sql-server, please fix it, see (sql-files/main.sql for structure) \n");
exit(EXIT_FAILURE);
}
ShowStatus("Login server connection: Database '"CL_WHITE"%s"CL_RESET"' at '"CL_WHITE"%s"CL_RESET"'\n", StringBuf_Value(db->db_database), StringBuf_Value(db->db_hostname));
return true;
}
@@ -150,6 +201,7 @@ static bool account_db_sql_init(AccountDB* self) {
static void account_db_sql_destroy(AccountDB* self){
AccountDB_SQL* db = (AccountDB_SQL*)self;
account_db_destroy_conf(self);
Sql_Free(db->accounts);
db->accounts = NULL;
aFree(db);
@@ -173,29 +225,28 @@ static bool account_db_sql_get_property(AccountDB* self, const char* key, char*
if( strncmpi(key, signature, strlen(signature)) == 0 ) {
key += strlen(signature);
if( strcmpi(key, "ip") == 0 )
safesnprintf(buf, buflen, "%s", db->db_hostname);
safesnprintf(buf, buflen, "%s", StringBuf_Value(db->db_hostname));
else
if( strcmpi(key, "port") == 0 )
safesnprintf(buf, buflen, "%d", db->db_port);
else
if( strcmpi(key, "id") == 0 )
safesnprintf(buf, buflen, "%s", db->db_username);
safesnprintf(buf, buflen, "%s", StringBuf_Value(db->db_username));
else
if( strcmpi(key, "pw") == 0 )
safesnprintf(buf, buflen, "%s", db->db_password);
safesnprintf(buf, buflen, "%s", StringBuf_Value(db->db_password));
else
if( strcmpi(key, "db") == 0 )
safesnprintf(buf, buflen, "%s", db->db_database);
safesnprintf(buf, buflen, "%s", StringBuf_Value(db->db_database));
else
if( strcmpi(key, "account_db") == 0 )
safesnprintf(buf, buflen, "%s", db->account_db);
else
if( strcmpi(key, "global_acc_reg_str_table") == 0 )
safesnprintf(buf, buflen, "%s", db->global_acc_reg_str_table);
if( strcmpi(key, "account_table") == 0 )
safesnprintf(buf, buflen, "%s", StringBuf_Value(db->account_table));
else
if( strcmpi(key, "global_acc_reg_num_table") == 0 )
safesnprintf(buf, buflen, "%s", db->global_acc_reg_num_table);
safesnprintf(buf, buflen, "%s", StringBuf_Value(db->global_acc_reg_num_table));
else
if( strcmpi(key, "global_acc_reg_str_table") == 0 )
safesnprintf(buf, buflen, "%s", StringBuf_Value(db->global_acc_reg_str_table));
return false;// not found
return true;
}
@@ -204,7 +255,7 @@ static bool account_db_sql_get_property(AccountDB* self, const char* key, char*
if( strncmpi(key, signature, strlen(signature)) == 0 ) {
key += strlen(signature);
if( strcmpi(key, "codepage") == 0 )
safesnprintf(buf, buflen, "%s", db->codepage);
safesnprintf(buf, buflen, "%s", StringBuf_Value(db->codepage));
else
if( strcmpi(key, "case_sensitive") == 0 )
safesnprintf(buf, buflen, "%d", (db->case_sensitive ? 1 : 0));
@@ -232,28 +283,28 @@ static bool account_db_sql_set_property(AccountDB* self, const char* key, const
if( strncmp(key, signature, strlen(signature)) == 0 ) {
key += strlen(signature);
if( strcmpi(key, "ip") == 0 )
safestrncpy(db->db_hostname, value, sizeof(db->db_hostname));
StringBuf_PrintfClear(db->db_hostname, value);
else
if( strcmpi(key, "port") == 0 )
db->db_port = (uint16)strtoul(value, NULL, 10);
else
if( strcmpi(key, "id") == 0 )
safestrncpy(db->db_username, value, sizeof(db->db_username));
StringBuf_PrintfClear(db->db_username, value);
else
if( strcmpi(key, "pw") == 0 )
safestrncpy(db->db_password, value, sizeof(db->db_password));
StringBuf_PrintfClear(db->db_password, value);
else
if( strcmpi(key, "db") == 0 )
safestrncpy(db->db_database, value, sizeof(db->db_database));
StringBuf_PrintfClear(db->db_database, value);
else
if( strcmpi(key, "account_db") == 0 )
safestrncpy(db->account_db, value, sizeof(db->account_db));
else
if( strcmpi(key, "global_acc_reg_str_table") == 0 )
safestrncpy(db->global_acc_reg_str_table, value, sizeof(db->global_acc_reg_str_table));
StringBuf_PrintfClear(db->account_table, value);
else
if( strcmpi(key, "global_acc_reg_num_table") == 0 )
safestrncpy(db->global_acc_reg_num_table, value, sizeof(db->global_acc_reg_num_table));
StringBuf_PrintfClear(db->global_acc_reg_num_table, value);
else
if( strcmpi(key, "global_acc_reg_str_table") == 0 )
StringBuf_PrintfClear(db->global_acc_reg_str_table, value);
else
return false;// not found
return true;
@@ -263,7 +314,7 @@ static bool account_db_sql_set_property(AccountDB* self, const char* key, const
if( strncmpi(key, signature, strlen(signature)) == 0 ) {
key += strlen(signature);
if( strcmpi(key, "codepage") == 0 )
safestrncpy(db->codepage, value, sizeof(db->codepage));
StringBuf_PrintfClear(db->codepage, value);
else
if( strcmpi(key, "case_sensitive") == 0 )
db->case_sensitive = (config_switch(value)==1);
@@ -298,7 +349,7 @@ static bool account_db_sql_create(AccountDB* self, struct mmo_account* acc) {
char* data;
size_t len;
if( SQL_SUCCESS != Sql_Query(sql_handle, "SELECT MAX(`account_id`)+1 FROM `%s`", db->account_db) )
if( SQL_SUCCESS != Sql_Query(sql_handle, "SELECT MAX(`account_id`)+1 FROM `%s`", StringBuf_Value(db->account_table)) )
{
Sql_ShowDebug(sql_handle);
return false;
@@ -344,9 +395,9 @@ static bool account_db_sql_remove(AccountDB* self, const uint32 account_id) {
bool result = false;
if( SQL_SUCCESS != Sql_QueryStr(sql_handle, "START TRANSACTION")
|| SQL_SUCCESS != Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = %d", db->account_db, account_id)
|| SQL_SUCCESS != Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = %d", db->global_acc_reg_num_table, account_id)
|| SQL_SUCCESS != Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = %d", db->global_acc_reg_str_table, account_id) )
|| SQL_SUCCESS != Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = %d", StringBuf_Value(db->account_table), account_id)
|| SQL_SUCCESS != Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = %d", StringBuf_Value(db->global_acc_reg_num_table), account_id) )
|| SQL_SUCCESS != Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = %d", StringBuf_Value(db->global_acc_reg_str_table), account_id) )
Sql_ShowDebug(sql_handle);
else
result = true;
@@ -400,7 +451,7 @@ static bool account_db_sql_load_str(AccountDB* self, struct mmo_account* acc, co
// get the list of account IDs for this user ID
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id` FROM `%s` WHERE `userid`= %s '%s'",
db->account_db, (db->case_sensitive ? "BINARY" : ""), esc_userid) )
StringBuf_Value(db->account_table), (db->case_sensitive ? "BINARY" : ""), esc_userid) )
{
Sql_ShowDebug(sql_handle);
return false;
@@ -468,7 +519,7 @@ static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account
// get next account ID
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id` FROM `%s` WHERE `account_id` > '%d' ORDER BY `account_id` ASC LIMIT 1",
db->account_db, iter->last_account_id) )
StringBuf_Value(db->account_table), iter->last_account_id) )
{
Sql_ShowDebug(sql_handle);
return false;
@@ -509,7 +560,7 @@ static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, uint32
#else
"SELECT `account_id`,`userid`,`user_pass`,`sex`,`email`,`group_id`,`state`,`unban_time`,`expiration_time`,`logincount`,`lastlogin`,`last_ip`,`birthdate`,`character_slots`,`pincode`, `pincode_change` FROM `%s` WHERE `account_id` = %d",
#endif
db->account_db, account_id )
StringBuf_Value(db->account_table), account_id )
) {
Sql_ShowDebug(sql_handle);
return false;
@@ -576,7 +627,7 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo
#else
"INSERT INTO `%s` (`account_id`, `userid`, `user_pass`, `sex`, `email`, `group_id`, `state`, `unban_time`, `expiration_time`, `logincount`, `lastlogin`, `last_ip`, `birthdate`, `character_slots`, `pincode`, `pincode_change`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
#endif
db->account_db)
StringBuf_Value(db->account_table))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_INT, (void*)&acc->account_id, sizeof(acc->account_id))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, (void*)acc->userid, strlen(acc->userid))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 2, SQLDT_STRING, (void*)acc->pass, strlen(acc->pass))
@@ -611,7 +662,7 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo
#else
"UPDATE `%s` SET `userid`=?,`user_pass`=?,`sex`=?,`email`=?,`group_id`=?,`state`=?,`unban_time`=?,`expiration_time`=?,`logincount`=?,`lastlogin`=?,`last_ip`=?,`birthdate`=?,`character_slots`=?,`pincode`=?, `pincode_change`=? WHERE `account_id` = '%d'",
#endif
db->account_db, acc->account_id)
StringBuf_Value(db->account_table), acc->account_id)
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, (void*)acc->userid, strlen(acc->userid))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, (void*)acc->pass, strlen(acc->pass))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 2, SQLDT_ENUM, (void*)&acc->sex, sizeof(acc->sex))

View File

@@ -136,6 +136,10 @@ struct AccountDB {
/// @param self Database
/// @return Iterator
AccountDBIterator* (*iterator)(AccountDB* self);
void (*init_conf)(AccountDB* self);
void (*destroy_conf)(AccountDB* self);
bool (*check_tables)(AccountDB* self);
};
void mmo_send_global_accreg(AccountDB* self, int fd, int account_id, int char_id);

View File

@@ -18,23 +18,64 @@
#include "loginlog.h"
#include <stdlib.h>
// login sql settings
static char ipban_db_hostname[32] = "127.0.0.1";
static uint16 ipban_db_port = 3306;
static char ipban_db_username[32] = "ragnarok";
static char ipban_db_password[32] = "";
static char ipban_db_database[32] = "ragnarok";
static char ipban_codepage[32] = "";
static char ipban_table[32] = "ipbanlist";
// globals
static Sql* sql_handle = NULL;
static int cleanup_timer_id = INVALID_TIMER;
static bool ipban_inited = false;
// login sql settings
struct Ipban_Config {
uint16 ipban_db_port;
StringBuf *ipban_db_hostname;
StringBuf *ipban_db_username;
StringBuf *ipban_db_password;
StringBuf *ipban_db_database;
StringBuf *ipban_codepage;
StringBuf *ipban_table;
int cleanup_timer_id;
bool ipban_inited;
};
struct Ipban_Config ipban_config;
//early declaration
int ipban_cleanup(int tid, unsigned int tick, int id, intptr_t data);
void ipban_config_init(void) {
ipban_config.ipban_db_port = 3306;
ipban_config.ipban_db_hostname = StringBuf_FromStr("127.0.0.1");
ipban_config.ipban_db_username = StringBuf_FromStr("ragnarok");
ipban_config.ipban_db_password = StringBuf_FromStr("");
ipban_config.ipban_db_database = StringBuf_FromStr("ragnarok");
ipban_config.ipban_codepage = StringBuf_FromStr("");
ipban_config.ipban_table = StringBuf_FromStr("ipbanlist");
ipban_config.cleanup_timer_id = INVALID_TIMER;
ipban_config.ipban_inited = false;
}
static void ipban_config_final(void) {
StringBuf_Free(ipban_config.ipban_db_hostname);
StringBuf_Free(ipban_config.ipban_db_username);
StringBuf_Free(ipban_config.ipban_db_password);
StringBuf_Free(ipban_config.ipban_db_database);
StringBuf_Free(ipban_config.ipban_codepage);
StringBuf_Free(ipban_config.ipban_table);
}
static bool ipban_check_table(void) {
ShowInfo("Start checking DB integrity (IP Ban)\n");
// IP ban List
if( SQL_ERROR == Sql_Query(sql_handle,
"SELECT `list`, `btime`, `rtime`, `reason` "
"FROM `%s`;", StringBuf_Value(ipban_config.ipban_table)) )
{
Sql_ShowDebug(sql_handle);
return false;
}
return true;
}
/**
* Check if ip is in the active bans list.
* @param ip: ipv4 ip to check if ban
@@ -49,7 +90,7 @@ bool ipban_check(uint32 ip) {
return false;// ipban disabled
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT count(*) FROM `%s` WHERE `rtime` > NOW() AND (`list` = '%u.*.*.*' OR `list` = '%u.%u.*.*' OR `list` = '%u.%u.%u.*' OR `list` = '%u.%u.%u.%u')",
ipban_table, p[3], p[3], p[2], p[3], p[2], p[1], p[3], p[2], p[1], p[0]) )
StringBuf_Value(ipban_config.ipban_table), p[3], p[3], p[2], p[3], p[2], p[1], p[3], p[2], p[1], p[0]) )
{
Sql_ShowDebug(sql_handle);
// close connection because we can't verify their connectivity.
@@ -84,7 +125,7 @@ void ipban_log(uint32 ip) {
{
uint8* p = (uint8*)&ip;
if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s`(`list`,`btime`,`rtime`,`reason`) VALUES ('%u.%u.%u.*', NOW() , NOW() + INTERVAL %d MINUTE ,'Password error ban')",
ipban_table, p[3], p[2], p[1], login_config.dynamic_pass_failure_ban_duration) )
StringBuf_Value(ipban_config.ipban_table), p[3], p[2], p[1], login_config.dynamic_pass_failure_ban_duration) )
Sql_ShowDebug(sql_handle);
}
}
@@ -118,7 +159,7 @@ int ipban_cleanup(int tid, unsigned int tick, int id, intptr_t data) {
bool ipban_config_read(const char* key, const char* value) {
const char* signature;
if( ipban_inited )
if( ipban_config.ipban_inited )
return false;// settings can only be changed before init
signature = "ipban_db_";
@@ -126,19 +167,19 @@ bool ipban_config_read(const char* key, const char* value) {
{
key += strlen(signature);
if( strcmpi(key, "ip") == 0 )
safestrncpy(ipban_db_hostname, value, sizeof(ipban_db_hostname));
StringBuf_PrintfClear(ipban_config.ipban_db_hostname, value);
else
if( strcmpi(key, "port") == 0 )
ipban_db_port = (uint16)strtoul(value, NULL, 10);
ipban_config.ipban_db_port = (uint16)strtoul(value, NULL, 10);
else
if( strcmpi(key, "id") == 0 )
safestrncpy(ipban_db_username, value, sizeof(ipban_db_username));
StringBuf_PrintfClear(ipban_config.ipban_db_username, value);
else
if( strcmpi(key, "pw") == 0 )
safestrncpy(ipban_db_password, value, sizeof(ipban_db_password));
StringBuf_PrintfClear(ipban_config.ipban_db_password, value);
else
if( strcmpi(key, "db") == 0 )
safestrncpy(ipban_db_database, value, sizeof(ipban_db_database));
StringBuf_PrintfClear(ipban_config.ipban_db_database, value);
else
return false;// not found
return true;
@@ -149,10 +190,10 @@ bool ipban_config_read(const char* key, const char* value) {
{
key += strlen(signature);
if( strcmpi(key, "codepage") == 0 )
safestrncpy(ipban_codepage, value, sizeof(ipban_codepage));
StringBuf_PrintfClear(ipban_config.ipban_codepage, value);
else
if( strcmpi(key, "ipban_table") == 0 )
safestrncpy(ipban_table, value, sizeof(ipban_table));
StringBuf_PrintfClear(ipban_config.ipban_table, value);
else
if( strcmpi(key, "enable") == 0 )
login_config.ipban = (bool)config_switch(value);
@@ -184,47 +225,37 @@ bool ipban_config_read(const char* key, const char* value) {
* Launched at login-serv start, create db or other long scope variable here.
*/
void ipban_init(void) {
const char* username = ipban_db_username;
const char* password = ipban_db_password;
const char* hostname = ipban_db_hostname;
uint16 port = ipban_db_port;
const char* database = ipban_db_database;
const char* codepage = ipban_codepage;
ipban_inited = true;
ipban_config.ipban_inited = true;
if( !login_config.ipban )
return;// ipban disabled
if( ipban_db_hostname[0] != '\0' )
{// local settings
username = ipban_db_username;
password = ipban_db_password;
hostname = ipban_db_hostname;
port = ipban_db_port;
database = ipban_db_database;
codepage = ipban_codepage;
}
// establish connections
sql_handle = Sql_Malloc();
if( SQL_ERROR == Sql_Connect(sql_handle, username, password, hostname, port, database) )
if( SQL_ERROR == Sql_Connect(sql_handle, StringBuf_Value(ipban_config.ipban_db_username), StringBuf_Value(ipban_config.ipban_db_password), StringBuf_Value(ipban_config.ipban_db_hostname), ipban_config.ipban_db_port, StringBuf_Value(ipban_config.ipban_db_database)) )
{
ShowError("Couldn't connect with uname='%s',passwd='%s',host='%s',port='%d',database='%s'\n",
username, password, hostname, port, database);
ShowError("Couldn't connect with uname='%s',passwd='%s',host='%s',port='%d',database='%s'\n",
StringBuf_Value(ipban_config.ipban_db_username), StringBuf_Value(ipban_config.ipban_db_password), StringBuf_Value(ipban_config.ipban_db_hostname), ipban_config.ipban_db_port, StringBuf_Value(ipban_config.ipban_db_database));
Sql_ShowDebug(sql_handle);
Sql_Free(sql_handle);
exit(EXIT_FAILURE);
}
ShowInfo("Ipban conection made\n");
if( codepage[0] != '\0' && SQL_ERROR == Sql_SetEncoding(sql_handle, codepage) )
ShowInfo("Ipban conection made\n");
if( StringBuf_Length(ipban_config.ipban_codepage) && SQL_ERROR == Sql_SetEncoding(sql_handle, StringBuf_Value(ipban_config.ipban_codepage)) )
Sql_ShowDebug(sql_handle);
if (!ipban_check_table()) {
ShowFatalError("login-server (ipban) : A table is missing in sql-server, please fix it, see (sql-files/main.sql for structure) \n");
exit(EXIT_FAILURE);
}
ShowStatus("Ipban connection: Database '"CL_WHITE"%s"CL_RESET"' at '"CL_WHITE"%s"CL_RESET"'\n", StringBuf_Value(ipban_config.ipban_db_database), StringBuf_Value(ipban_config.ipban_db_hostname));
if( login_config.ipban_cleanup_interval > 0 )
{ // set up periodic cleanup of connection history and active bans
add_timer_func_list(ipban_cleanup, "ipban_cleanup");
cleanup_timer_id = add_timer_interval(gettick()+10, ipban_cleanup, 0, 0, login_config.ipban_cleanup_interval*1000);
ipban_config.cleanup_timer_id = add_timer_interval(gettick()+10, ipban_cleanup, 0, 0, login_config.ipban_cleanup_interval*1000);
} else // make sure it gets cleaned up on login-server start regardless of interval-based cleanups
ipban_cleanup(0,0,0,0);
}
@@ -239,9 +270,10 @@ void ipban_final(void) {
if( login_config.ipban_cleanup_interval > 0 )
// release data
delete_timer(cleanup_timer_id, ipban_cleanup);
delete_timer(ipban_config.cleanup_timer_id, ipban_cleanup);
ipban_cleanup(0,0,0,0); // always clean up on login-server stop
ipban_config_final();
// close connections
Sql_Free(sql_handle);

View File

@@ -47,4 +47,6 @@ void ipban_init(void);
*/
void ipban_final(void);
void ipban_config_init(void);
#endif // __IPBAN_H_INCLUDED__

View File

@@ -723,8 +723,6 @@ void login_set_defaults() {
}
/// Constructor destructor and signal handlers
/**
@@ -817,11 +815,14 @@ int do_init(int argc, char** argv) {
// initialize engine
accounts = account_db_sql();
accounts->init_conf(accounts);
// read login-server configuration
login_set_defaults();
logcnslif_get_options(argc,argv);
ipban_config_init();
loginlog_config_init();
login_config_read(login_config.loginconf_name, true);
msg_config_read(login_config.msgconf_name);
login_lan_config_read(login_config.lanconf_name);
@@ -859,6 +860,7 @@ int do_init(int argc, char** argv) {
exit(EXIT_FAILURE);
} else {
if(!accounts->init(accounts)) {
accounts->destroy_conf(accounts);
ShowFatalError("do_init: Failed to initialize account engine.\n");
exit(EXIT_FAILURE);
}

View File

@@ -15,25 +15,76 @@
#include "../common/showmsg.h"
#include <stdlib.h> // exit
// global sql settings (in ipban_sql.c)
static char global_db_hostname[64] = "127.0.0.1"; // Doubled to reflect the change on commit #0f2dd7f
static uint16 global_db_port = 3306;
static char global_db_username[32] = "ragnarok";
static char global_db_password[32] = ""; //empty by default since mysql is empty by default as well
static char global_db_database[32] = "ragnarok";
static char global_codepage[32] = "";
// local sql settings
static char log_db_hostname[64] = ""; // Doubled to reflect the change on commit #0f2dd7f
static uint16 log_db_port = 0;
static char log_db_username[32] = "";
static char log_db_password[32] = "";
static char log_db_database[32] = "";
static char log_codepage[32] = "";
static char log_login_db[256] = "loginlog";
static Sql* sql_handle = NULL;
static bool enabled = false;
struct Loginlog_Config {
// global sql settings (in ipban_sql.c)
uint16 global_db_port;
StringBuf *global_db_hostname;
StringBuf *global_db_username;
StringBuf *global_db_password;
StringBuf *global_db_database;
StringBuf *global_codepage;
// local sql settings
uint16 log_db_port;
StringBuf *log_db_hostname;
StringBuf *log_db_username;
StringBuf *log_db_password;
StringBuf *log_db_database;
StringBuf *log_codepage;
StringBuf *log_login_table;
bool enabled;
};
struct Loginlog_Config loginlog_config; /// LoginLog config
void loginlog_config_init(void) {
loginlog_config.global_db_port = 3306;
loginlog_config.global_db_hostname = StringBuf_FromStr("127.0.0.1");
loginlog_config.global_db_username = StringBuf_FromStr("ragnarok");
loginlog_config.global_db_password = StringBuf_FromStr("");
loginlog_config.global_db_database = StringBuf_FromStr("ragnarok");
loginlog_config.global_codepage = StringBuf_FromStr("");
loginlog_config.log_db_port = 3306;
loginlog_config.log_db_hostname = StringBuf_FromStr("127.0.0.1");
loginlog_config.log_db_username = StringBuf_FromStr("ragnarok");
loginlog_config.log_db_password = StringBuf_FromStr("");
loginlog_config.log_db_database = StringBuf_FromStr("ragnarok");
loginlog_config.log_codepage = StringBuf_FromStr("");
loginlog_config.log_login_table = StringBuf_FromStr("loginlog");
loginlog_config.enabled = false;;
}
static void loginlog_config_final(void) {
StringBuf_Free(loginlog_config.global_db_hostname);
StringBuf_Free(loginlog_config.global_db_username);
StringBuf_Free(loginlog_config.global_db_password);
StringBuf_Free(loginlog_config.global_db_database);
StringBuf_Free(loginlog_config.global_codepage);
StringBuf_Free(loginlog_config.log_db_hostname);
StringBuf_Free(loginlog_config.log_db_username);
StringBuf_Free(loginlog_config.log_db_password);
StringBuf_Free(loginlog_config.log_db_database);
StringBuf_Free(loginlog_config.log_codepage);
StringBuf_Free(loginlog_config.log_login_table);
}
static bool loginlog_check_table(void) {
ShowInfo("Start checking DB integrity (Login Log)\n");
// IP ban List
if( SQL_ERROR == Sql_Query(sql_handle,
"SELECT `time`, `ip`, `user`, `rcode`, `log` "
"FROM `%s`;", StringBuf_Value(loginlog_config.log_login_table)) )
{
Sql_ShowDebug(sql_handle);
return false;
}
return true;
}
/**
* Get the number of failed login attempts by the ip in the last minutes.
@@ -44,11 +95,11 @@ static bool enabled = false;
unsigned long loginlog_failedattempts(uint32 ip, unsigned int minutes) {
unsigned long failures = 0;
if( !enabled )
if( !loginlog_config.enabled )
return 0;
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT count(*) FROM `%s` WHERE `ip` = '%s' AND `rcode` = '1' AND `time` > NOW() - INTERVAL %d MINUTE",
log_login_db, ip2str(ip,NULL), minutes) )// how many times failed account? in one ip.
StringBuf_Value(loginlog_config.log_login_table), ip2str(ip,NULL), minutes) )// how many times failed account? in one ip.
Sql_ShowDebug(sql_handle);
if( SQL_SUCCESS == Sql_NextRow(sql_handle) )
@@ -74,7 +125,7 @@ void login_log(uint32 ip, const char* username, int rcode, const char* message)
char esc_message[255*2+1];
int retcode;
if( !enabled )
if( !loginlog_config.enabled )
return;
Sql_EscapeStringLen(sql_handle, esc_username, username, strnlen(username, NAME_LENGTH));
@@ -82,7 +133,7 @@ void login_log(uint32 ip, const char* username, int rcode, const char* message)
retcode = Sql_Query(sql_handle,
"INSERT INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '%s', '%s', '%d', '%s')",
log_login_db, ip2str(ip,NULL), esc_username, rcode, esc_message);
StringBuf_Value(loginlog_config.log_login_table), ip2str(ip,NULL), esc_username, rcode, esc_message);
if( retcode != SQL_SUCCESS )
Sql_ShowDebug(sql_handle);
@@ -102,50 +153,49 @@ bool loginlog_config_read(const char* key, const char* value) {
{
key += strlen(signature);
if( strcmpi(key, "db_hostname") == 0 )
safestrncpy(global_db_hostname, value, sizeof(global_db_hostname));
StringBuf_PrintfClear(loginlog_config.global_db_hostname, value);
else
if( strcmpi(key, "db_port") == 0 )
global_db_port = (uint16)strtoul(value, NULL, 10);
loginlog_config.global_db_port = (uint16)strtoul(value, NULL, 10);
else
if( strcmpi(key, "db_username") == 0 )
safestrncpy(global_db_username, value, sizeof(global_db_username));
StringBuf_PrintfClear(loginlog_config.global_db_username, value);
else
if( strcmpi(key, "db_password") == 0 )
safestrncpy(global_db_password, value, sizeof(global_db_password));
StringBuf_PrintfClear(loginlog_config.global_db_password, value);
else
if( strcmpi(key, "db_database") == 0 )
safestrncpy(global_db_database, value, sizeof(global_db_database));
StringBuf_PrintfClear(loginlog_config.global_db_database, value);
else
if( strcmpi(key, "codepage") == 0 )
safestrncpy(global_codepage, value, sizeof(global_codepage));
StringBuf_PrintfClear(loginlog_config.global_codepage, value);
else
return false;// not found
return true;
}
if( strcmpi(key, "log_db_ip") == 0 )
safestrncpy(log_db_hostname, value, sizeof(log_db_hostname));
StringBuf_PrintfClear(loginlog_config.log_db_hostname, value);
else
if( strcmpi(key, "log_db_port") == 0 )
log_db_port = (uint16)strtoul(value, NULL, 10);
loginlog_config.log_db_port = (uint16)strtoul(value, NULL, 10);
else
if( strcmpi(key, "log_db_id") == 0 )
safestrncpy(log_db_username, value, sizeof(log_db_username));
StringBuf_PrintfClear(loginlog_config.log_db_username, value);
else
if( strcmpi(key, "log_db_pw") == 0 )
safestrncpy(log_db_password, value, sizeof(log_db_password));
StringBuf_PrintfClear(loginlog_config.log_db_password, value);
else
if( strcmpi(key, "log_db_db") == 0 )
safestrncpy(log_db_database, value, sizeof(log_db_database));
StringBuf_PrintfClear(loginlog_config.log_db_database, value);
else
if( strcmpi(key, "log_codepage") == 0 )
safestrncpy(log_codepage, value, sizeof(log_codepage));
StringBuf_PrintfClear(loginlog_config.log_codepage, value);
else
if( strcmpi(key, "log_login_db") == 0 )
safestrncpy(log_login_db, value, sizeof(log_login_db));
if( strcmpi(key, "log_login_table") == 0 )
StringBuf_PrintfClear(loginlog_config.log_login_table, value);
else
return false;
return true;
}
@@ -158,48 +208,54 @@ bool loginlog_config_read(const char* key, const char* value) {
* @return true if success else exit execution
*/
bool loginlog_init(void) {
const char* username;
const char* password;
const char* hostname;
uint16 port;
const char* database;
const char* codepage;
StringBuf* username;
StringBuf* password;
StringBuf* hostname;
uint16 port;
StringBuf* database;
StringBuf* codepage;
if( log_db_hostname[0] != '\0' )
if( StringBuf_Length(loginlog_config.log_db_hostname) )
{// local settings
username = log_db_username;
password = log_db_password;
hostname = log_db_hostname;
port = log_db_port;
database = log_db_database;
codepage = log_codepage;
username = loginlog_config.log_db_username;
password = loginlog_config.log_db_password;
hostname = loginlog_config.log_db_hostname;
port = loginlog_config.log_db_port;
database = loginlog_config.log_db_database;
codepage = loginlog_config.log_codepage;
}
else
{// global settings
username = global_db_username;
password = global_db_password;
hostname = global_db_hostname;
port = global_db_port;
database = global_db_database;
codepage = global_codepage;
username = loginlog_config.global_db_username;
password = loginlog_config.global_db_password;
hostname = loginlog_config.global_db_hostname;
port = loginlog_config.global_db_port;
database = loginlog_config.global_db_database;
codepage = loginlog_config.global_codepage;
}
sql_handle = Sql_Malloc();
if( SQL_ERROR == Sql_Connect(sql_handle, username, password, hostname, port, database) )
if( SQL_ERROR == Sql_Connect(sql_handle, StringBuf_Value(username), StringBuf_Value(password), StringBuf_Value(hostname), port, StringBuf_Value(database)) )
{
ShowError("Couldn't connect with uname='%s',passwd='%s',host='%s',port='%d',database='%s'\n",
username, password, hostname, port, database);
ShowError("Couldn't connect with uname='%s',passwd='%s',host='%s',port='%d',database='%s'\n",
StringBuf_Value(username), StringBuf_Value(password), StringBuf_Value(hostname), port, StringBuf_Value(database));
Sql_ShowDebug(sql_handle);
Sql_Free(sql_handle);
exit(EXIT_FAILURE);
}
if( codepage[0] != '\0' && SQL_ERROR == Sql_SetEncoding(sql_handle, codepage) )
if( StringBuf_Length(codepage) && SQL_ERROR == Sql_SetEncoding(sql_handle, StringBuf_Value(codepage)) )
Sql_ShowDebug(sql_handle);
enabled = true;
if (!loginlog_check_table()) {
ShowFatalError("login-server (loginlog) : A table is missing in sql-server, please fix it, see (sql-files/logs.sql for structure) \n");
exit(EXIT_FAILURE);
}
loginlog_config.enabled = true;
ShowStatus("Loginlog connection: Database '"CL_WHITE"%s"CL_RESET"' at '"CL_WHITE"%s"CL_RESET"'\n", StringBuf_Value(database), StringBuf_Value(username));
return true;
}
@@ -212,5 +268,6 @@ bool loginlog_init(void) {
bool loginlog_final(void) {
Sql_Free(sql_handle);
sql_handle = NULL;
loginlog_config_final();
return true;
}

View File

@@ -54,6 +54,8 @@ bool loginlog_init(void);
*/
bool loginlog_final(void);
void loginlog_config_init(void);
#ifdef __cplusplus
}
#endif

View File

@@ -3060,7 +3060,7 @@ ACMD_FUNC(night)
{
nullpo_retr(-1, sd);
if (night_flag != 1) {
if (!map_config.night_flag) {
map_night_timer(night_timer_tid, 0, 0, 1);
} else {
clif_displaymessage(fd, msg_txt(sd,89)); // Night mode is already enabled.
@@ -3077,7 +3077,7 @@ ACMD_FUNC(day)
{
nullpo_retr(-1, sd);
if (night_flag != 0) {
if (map_config.night_flag) {
map_day_timer(day_timer_tid, 0, 0, 1);
} else {
clif_displaymessage(fd, msg_txt(sd,90)); // Day mode is already enabled.
@@ -3463,12 +3463,12 @@ ACMD_FUNC(breakguild)
ACMD_FUNC(agitstart)
{
nullpo_retr(-1, sd);
if (agit_flag == 1) {
if (map_config.agit_flag) {
clif_displaymessage(fd, msg_txt(sd,73)); // War of Emperium is currently in progress.
return -1;
}
agit_flag = 1;
map_config.agit_flag = true;
guild_agit_start();
clif_displaymessage(fd, msg_txt(sd,72)); // War of Emperium has been initiated.
@@ -3481,12 +3481,12 @@ ACMD_FUNC(agitstart)
ACMD_FUNC(agitstart2)
{
nullpo_retr(-1, sd);
if (agit2_flag == 1) {
if (map_config.agit2_flag) {
clif_displaymessage(fd, msg_txt(sd,404)); // "War of Emperium SE is currently in progress."
return -1;
}
agit2_flag = 1;
map_config.agit2_flag = true;
guild_agit2_start();
clif_displaymessage(fd, msg_txt(sd,403)); // "War of Emperium SE has been initiated."
@@ -3499,12 +3499,12 @@ ACMD_FUNC(agitstart2)
ACMD_FUNC(agitend)
{
nullpo_retr(-1, sd);
if (agit_flag == 0) {
if (!map_config.agit_flag) {
clif_displaymessage(fd, msg_txt(sd,75)); // War of Emperium is currently not in progress.
return -1;
}
agit_flag = 0;
map_config.agit_flag = false;
guild_agit_end();
clif_displaymessage(fd, msg_txt(sd,74)); // War of Emperium has been ended.
@@ -3517,12 +3517,12 @@ ACMD_FUNC(agitend)
ACMD_FUNC(agitend2)
{
nullpo_retr(-1, sd);
if (agit2_flag == 0) {
if (!map_config.agit2_flag) {
clif_displaymessage(fd, msg_txt(sd,406)); // "War of Emperium SE is currently not in progress."
return -1;
}
agit2_flag = 0;
map_config.agit2_flag = false;
guild_agit2_end();
clif_displaymessage(fd, msg_txt(sd,405)); // "War of Emperium SE has been ended."
@@ -4291,7 +4291,7 @@ ACMD_FUNC(guildspy)
memset(guild_name, '\0', sizeof(guild_name));
memset(atcmd_output, '\0', sizeof(atcmd_output));
if (!enable_spy)
if (!map_config.enable_spy)
{
clif_displaymessage(fd, msg_txt(sd,1125)); // The mapserver has spy command support disabled.
return -1;
@@ -4332,7 +4332,7 @@ ACMD_FUNC(partyspy)
memset(party_name, '\0', sizeof(party_name));
memset(atcmd_output, '\0', sizeof(atcmd_output));
if (!enable_spy)
if (!map_config.enable_spy)
{
clif_displaymessage(fd, msg_txt(sd,1125)); // The mapserver has spy command support disabled.
return -1;
@@ -4609,12 +4609,12 @@ ACMD_FUNC(servertime)
clif_displaymessage(fd, temp);
if (battle_config.night_duration == 0 && battle_config.day_duration == 0) {
if (night_flag == 0)
if (!map_config.night_flag)
clif_displaymessage(fd, msg_txt(sd,231)); // Game time: The game is in permanent daylight.
else
clif_displaymessage(fd, msg_txt(sd,232)); // Game time: The game is in permanent night.
} else if (battle_config.night_duration == 0)
if (night_flag == 1) { // we start with night
if (map_config.night_flag) { // we start with night
timer_data = get_timer(day_timer_tid);
sprintf(temp, msg_txt(sd,233), txt_time(DIFF_TICK(timer_data->tick,gettick())/1000)); // Game time: The game is in night for %s.
clif_displaymessage(fd, temp);
@@ -4622,7 +4622,7 @@ ACMD_FUNC(servertime)
} else
clif_displaymessage(fd, msg_txt(sd,231)); // Game time: The game is in permanent daylight.
else if (battle_config.day_duration == 0)
if (night_flag == 0) { // we start with day
if (!map_config.night_flag) { // we start with day
timer_data = get_timer(night_timer_tid);
sprintf(temp, msg_txt(sd,235), txt_time(DIFF_TICK(timer_data->tick,gettick())/1000)); // Game time: The game is in daylight for %s.
clif_displaymessage(fd, temp);
@@ -4631,7 +4631,7 @@ ACMD_FUNC(servertime)
clif_displaymessage(fd, msg_txt(sd,232)); // Game time: The game is in permanent night.
else {
const struct TimerData * timer_data2;
if (night_flag == 0) {
if (!map_config.night_flag) {
timer_data = get_timer(night_timer_tid);
timer_data2 = get_timer(day_timer_tid);
sprintf(temp, msg_txt(sd,235), txt_time(DIFF_TICK(timer_data->tick,gettick())/1000)); // Game time: The game is in daylight for %s.
@@ -5821,11 +5821,11 @@ ACMD_FUNC(autotrade) {
sd->state.monster_ignore = 1;
if( sd->state.vending ){
if( Sql_Query( mmysql_handle, "UPDATE `%s` SET `autotrade` = 1 WHERE `id` = %d;", vendings_db, sd->vender_id ) != SQL_SUCCESS ){
if( Sql_Query( mmysql_handle, "UPDATE `%s` SET `autotrade` = 1 WHERE `id` = %d;", mapserv_table(vendings_table), sd->vender_id ) != SQL_SUCCESS ){
Sql_ShowDebug( mmysql_handle );
}
}else if( sd->state.buyingstore ){
if( Sql_Query( mmysql_handle, "UPDATE `%s` SET `autotrade` = 1 WHERE `id` = %d;", buyingstores_db, sd->buyer_id ) != SQL_SUCCESS ){
if( Sql_Query( mmysql_handle, "UPDATE `%s` SET `autotrade` = 1 WHERE `id` = %d;", mapserv_table(buyingstores_table), sd->buyer_id ) != SQL_SUCCESS ){
Sql_ShowDebug( mmysql_handle );
}
}
@@ -6962,7 +6962,7 @@ ACMD_FUNC(gmotd)
{
FILE* fp;
if( ( fp = fopen(motd_txt, "r") ) != NULL )
if( ( fp = fopen(StringBuf_Value(map_config.motd_txt), "r") ) != NULL )
{
char buf[CHAT_SIZE_MAX];
size_t len;

View File

@@ -7499,7 +7499,7 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f
{
struct mob_data *md = BL_CAST(BL_MOB, t_bl);
if( !((agit_flag || agit2_flag) && map[m].flag.gvg_castle) && md->guardian_data && md->guardian_data->guild_id )
if( !((map_config.agit_flag || map_config.agit2_flag) && map[m].flag.gvg_castle) && md->guardian_data && md->guardian_data->guild_id )
return 0; // Disable guardians/emperiums owned by Guilds on non-woe times.
break;
}
@@ -7567,7 +7567,7 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f
case BL_MOB:
{
struct mob_data *md = BL_CAST(BL_MOB, s_bl);
if( !((agit_flag || agit2_flag) && map[m].flag.gvg_castle) && md->guardian_data && md->guardian_data->guild_id )
if( !((map_config.agit_flag || map_config.agit2_flag) && map[m].flag.gvg_castle) && md->guardian_data && md->guardian_data->guild_id )
return 0; // Disable guardians/emperium owned by Guilds on non-woe times.
if( !md->special_state.ai )
@@ -8277,7 +8277,7 @@ void rAthena_report(char* date, char *time_c) {
config |= C_SECURE_NPCTIMEOUT;
#endif
/* non-define part */
if( db_use_sqldbs )
if( mapserv_schema_config.db_use_sqldbs )
config |= C_SQL_DBS;
if( log_config.sql_logs )

View File

@@ -228,12 +228,12 @@ int8 buyingstore_create(struct map_session_data* sd, int zenylimit, unsigned cha
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_db, 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 ){
mapserv_table(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_db);
StringBuf_Printf(&buf, "INSERT INTO `%s`(`buyingstore_id`,`index`,`item_id`,`amount`,`price`) VALUES", mapserv_table(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)
@@ -259,8 +259,8 @@ void buyingstore_close(struct map_session_data* sd) {
if( sd->state.buyingstore ) {
if(
Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE buyingstore_id = %d;", buyingstore_items_db, sd->buyer_id ) != SQL_SUCCESS ||
Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE `id` = %d;", buyingstores_db, sd->buyer_id ) != SQL_SUCCESS
Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE buyingstore_id = %d;", mapserv_table(buyingstore_items_table), sd->buyer_id ) != SQL_SUCCESS ||
Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE `id` = %d;", mapserv_table(buyingstores_table), sd->buyer_id ) != SQL_SUCCESS
) {
Sql_ShowDebug(mmysql_handle);
}
@@ -452,11 +452,11 @@ void buyingstore_trade(struct map_session_data* sd, uint32 account_id, unsigned
pl_sd->buyingstore.items[listidx].amount-= amount;
if( pl_sd->buyingstore.items[listidx].amount > 0 ){
if( Sql_Query( mmysql_handle, "UPDATE `%s` SET `amount` = %d WHERE `buyingstore_id` = %d AND `index` = %d;", buyingstore_items_db, pl_sd->buyingstore.items[listidx].amount, pl_sd->buyer_id, listidx ) != SQL_SUCCESS ){
if( Sql_Query( mmysql_handle, "UPDATE `%s` SET `amount` = %d WHERE `buyingstore_id` = %d AND `index` = %d;", mapserv_table(buyingstore_items_table), pl_sd->buyingstore.items[listidx].amount, pl_sd->buyer_id, listidx ) != SQL_SUCCESS ){
Sql_ShowDebug( mmysql_handle );
}
}else{
if( Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE `buyingstore_id` = %d AND `index` = %d;", buyingstore_items_db, pl_sd->buyer_id, listidx ) != SQL_SUCCESS ){
if( Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE `buyingstore_id` = %d AND `index` = %d;", mapserv_table(buyingstore_items_table), pl_sd->buyer_id, listidx ) != SQL_SUCCESS ){
Sql_ShowDebug( mmysql_handle );
}
}
@@ -471,7 +471,7 @@ void buyingstore_trade(struct map_session_data* sd, uint32 account_id, unsigned
clif_buyingstore_update_item(pl_sd, nameid, amount, sd->status.char_id, zeny);
}
if( save_settings&CHARSAVE_BANK ) {
if( map_config.save_settings&CHARSAVE_BANK ) {
chrif_save(sd, 0);
chrif_save(pl_sd, 0);
}
@@ -488,7 +488,7 @@ void buyingstore_trade(struct map_session_data* sd, uint32 account_id, unsigned
}
else
{// continue buying
if( Sql_Query( mmysql_handle, "UPDATE `%s` SET `limit` = %d WHERE `id` = %d;", buyingstores_db, pl_sd->buyingstore.zenylimit, pl_sd->buyer_id ) != SQL_SUCCESS ){
if( Sql_Query( mmysql_handle, "UPDATE `%s` SET `limit` = %d WHERE `id` = %d;", mapserv_table(buyingstores_table), pl_sd->buyingstore.zenylimit, pl_sd->buyer_id ) != SQL_SUCCESS ){
Sql_ShowDebug( mmysql_handle );
}
@@ -656,7 +656,7 @@ void do_init_buyingstore_autotrade( void ) {
"FROM `%s` "
"WHERE `autotrade` = 1 AND `limit` > 0 AND (SELECT COUNT(`buyingstore_id`) FROM `%s` WHERE `buyingstore_id` = `id`) > 0 "
"ORDER BY `id`;",
buyingstores_db, buyingstore_items_db ) != SQL_SUCCESS )
mapserv_table(buyingstores_table), mapserv_table(buyingstore_items_table) ) != SQL_SUCCESS )
{
Sql_ShowDebug(mmysql_handle);
return;
@@ -712,7 +712,7 @@ void do_init_buyingstore_autotrade( void ) {
"FROM `%s` "
"WHERE `buyingstore_id` = %d "
"ORDER BY `index` ASC;",
buyingstore_items_db, at->id ) )
mapserv_table(buyingstore_items_table), at->id ) )
{
Sql_ShowDebug(mmysql_handle);
continue;
@@ -747,8 +747,8 @@ void do_init_buyingstore_autotrade( void ) {
}
// Everything is loaded fine, their entries will be reinserted once they are loaded
if (Sql_Query( mmysql_handle, "DELETE FROM `%s`;", buyingstores_db ) != SQL_SUCCESS ||
Sql_Query( mmysql_handle, "DELETE FROM `%s`;", buyingstore_items_db ) != SQL_SUCCESS)
if (Sql_Query( mmysql_handle, "DELETE FROM `%s`;", mapserv_table(buyingstores_table) ) != SQL_SUCCESS ||
Sql_Query( mmysql_handle, "DELETE FROM `%s`;", mapserv_table(buyingstore_items_table) ) != SQL_SUCCESS)
{
Sql_ShowDebug(mmysql_handle);
}

View File

@@ -14,9 +14,6 @@
struct cash_item_db cash_shop_items[CASHSHOP_TAB_SEARCH];
bool cash_shop_defined = false;
extern char item_cash_db_db[32];
extern char item_cash_db2_db[32];
/*
* Reads one line from database and assigns it to RAM.
* return
@@ -98,7 +95,7 @@ static void cashshop_read_db_txt( void ){
* parses line and sends them to parse_dbrow.
*/
static int cashshop_read_db_sql( void ){
const char* cash_db_name[] = { item_cash_db_db, item_cash_db2_db };
const char* cash_db_name[] = { mapserv_table(item_cash_db_table), mapserv_table(item_cash_db2_table) };
int fi;
for( fi = 0; fi < ARRAYLENGTH( cash_db_name ); ++fi ){
@@ -144,7 +141,7 @@ static int cashshop_read_db_sql( void ){
* based on 'db_use_sqldbs' in conf/map_athena.conf.
*/
static void cashshop_read_db( void ){
if( db_use_sqldbs ){
if( mapserv_schema_config.db_use_sqldbs ){
cashshop_read_db_sql();
} else {
cashshop_read_db_txt();

View File

@@ -584,7 +584,7 @@ int chrif_sendmapack(int fd) {
}
// Server name
memcpy(wisp_server_name, RFIFOP(fd,5), NAME_LENGTH);
memcpy(map_config.wisp_server_name, RFIFOP(fd,5), NAME_LENGTH);
ShowStatus("Map-server connected to char-server '"CL_WHITE"%s"CL_RESET"'.\n", wisp_server_name);
// Default map

View File

@@ -498,7 +498,7 @@ int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target
WFIFOSET(fd,len);
}
}
if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
if (!map_config.enable_spy) //Skip unnecessary parsing. [Skotlex]
break;
iter = mapit_getallusers();
@@ -584,7 +584,7 @@ int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target
}
}
}
if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
if (!map_config.enable_spy) //Skip unnecessary parsing. [Skotlex]
break;
iter = mapit_getallusers();
@@ -10205,7 +10205,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
if(hom_is_active(sd->hd))
hom_init_timers(sd->hd);
if (night_flag && map[sd->bl.m].flag.nightenabled) {
if (map_config.night_flag && map[sd->bl.m].flag.nightenabled) {
sd->state.night = 1;
clif_status_load(&sd->bl, SI_NIGHT, 1);
}
@@ -10254,7 +10254,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
(map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
if( night_flag && map[sd->bl.m].flag.nightenabled )
if( map_config.night_flag && map[sd->bl.m].flag.nightenabled )
{ //Display night.
if( !sd->state.night )
{
@@ -10596,7 +10596,7 @@ void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
sprintf(gm_msg, "Hack on NameRequest: character '%s' (account: %d) requested the name of an invisible target (id: %d).\n", sd->status.name, sd->status.account_id, id);
ShowWarning(gm_msg);
// information is sent to all online GMs
intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
intif_wis_message_to_gm(map_config.wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
return;
}
*/
@@ -11063,7 +11063,7 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd)
if (dstsd->state.autotrade == 1) {
char output[256];
safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
clif_wis_message(fd, map_config.wisp_server_name, output, strlen(output) + 1);
return;
}
@@ -13218,7 +13218,7 @@ void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
if( !emblem_len || !sd->state.gmaster_flag )
return;
if(!(battle_config.emblem_woe_change) && (agit_flag || agit2_flag) ){
if(!(battle_config.emblem_woe_change) && (map_config.agit_flag || map_config.agit2_flag) ){
clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,385)); //"You not allowed to change emblem during woe"
return;
}
@@ -13908,7 +13908,7 @@ void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
type = RFIFOB(fd,info->pos[1]);
if( type == 0 ) { // Add name to ignore list (block)
if (strcmp(wisp_server_name, nick) == 0) {
if (strcmp(map_config.wisp_server_name, nick) == 0) {
clif_wisexin(sd, type, 1); // fail
return;
}

View File

@@ -598,7 +598,7 @@ int guild_invite(struct map_session_data *sd, struct map_session_data *tsd) {
if(tsd->status.guild_id>0 ||
tsd->guild_invite>0 ||
((agit_flag || agit2_flag) && map[tsd->bl.m].flag.gvg_castle))
((map_config.agit_flag || map_config.agit2_flag) && map[tsd->bl.m].flag.gvg_castle))
{ //Can't invite people inside castles. [Skotlex]
clif_guild_inviteack(sd,0);
return 0;
@@ -762,7 +762,7 @@ int guild_leave(struct map_session_data* sd, int guild_id, uint32 account_id, ui
if(sd->status.account_id!=account_id ||
sd->status.char_id!=char_id || sd->status.guild_id!=guild_id ||
((agit_flag || agit2_flag) && map[sd->bl.m].flag.gvg_castle))
((map_config.agit_flag || map_config.agit2_flag) && map[sd->bl.m].flag.gvg_castle))
return 0;
guild_trade_bound_cancel(sd);
@@ -794,7 +794,7 @@ int guild_expulsion(struct map_session_data* sd, int guild_id, uint32 account_id
//Can't leave inside guild castles.
if ((tsd = map_id2sd(account_id)) &&
tsd->status.char_id == char_id &&
((agit_flag || agit2_flag) && map[tsd->bl.m].flag.gvg_castle))
((map_config.agit_flag || map_config.agit2_flag) && map[tsd->bl.m].flag.gvg_castle))
return 0;
// find the member and perform expulsion
@@ -1327,7 +1327,7 @@ int guild_skillupack(int guild_id,uint16 skill_id,uint32 account_id) {
void guild_guildaura_refresh(struct map_session_data *sd, uint16 skill_id, uint16 skill_lv) {
struct skill_unit_group* group = NULL;
int type = status_skill2sc(skill_id);
if( !(battle_config.guild_aura&((agit_flag || agit2_flag)?2:1)) &&
if( !(battle_config.guild_aura&((map_config.agit_flag || map_config.agit2_flag)?2:1)) &&
!(battle_config.guild_aura&(map_flag_gvg2(sd->bl.m)?8:4)) )
return;
if( !skill_lv )
@@ -1395,7 +1395,7 @@ int guild_reqalliance(struct map_session_data *sd,struct map_session_data *tsd)
struct guild *g[2];
int i;
if(agit_flag || agit2_flag) { // Disable alliance creation during woe [Valaris]
if(map_config.agit_flag || map_config.agit2_flag) { // Disable alliance creation during woe [Valaris]
clif_displaymessage(sd->fd,msg_txt(sd,676)); //"Alliances cannot be made during Guild Wars!"
return 0;
} // end addition [Valaris]
@@ -1511,7 +1511,7 @@ int guild_reply_reqalliance(struct map_session_data *sd,uint32 account_id,int fl
int guild_delalliance(struct map_session_data *sd,int guild_id,int flag) {
nullpo_ret(sd);
if(agit_flag || agit2_flag) { // Disable alliance breaking during woe [Valaris]
if(map_config.agit_flag || map_config.agit2_flag) { // Disable alliance breaking during woe [Valaris]
clif_displaymessage(sd->fd,msg_txt(sd,677)); //"Alliances cannot be broken during Guild Wars!"
return 0;
} // end addition [Valaris]
@@ -1548,7 +1548,7 @@ int guild_opposition(struct map_session_data *sd,struct map_session_data *tsd) {
clif_guild_oppositionack(sd,2);
return 0;
}
if(agit_flag || agit2_flag) // Prevent the changing of alliances to oppositions during WoE.
if(map_config.agit_flag || map_config.agit2_flag) // Prevent the changing of alliances to oppositions during WoE.
return 0;
//Change alliance to opposition.
intif_guild_alliance( sd->status.guild_id,tsd->status.guild_id,

View File

@@ -2358,7 +2358,7 @@ static void intif_parse_Mail_send(int fd)
else
{
clif_Mail_send(sd->fd, false);
if( save_settings&CHARSAVE_MAIL )
if( map_config.save_settings&CHARSAVE_MAIL )
chrif_save(sd, 0);
}
}
@@ -2476,7 +2476,7 @@ static void intif_parse_Auction_register(int fd)
if( auction.auction_id > 0 )
{
clif_Auction_message(sd->fd, 1); // Confirmation Packet ??
if( save_settings&CHARSAVE_AUCTION )
if( map_config.save_settings&CHARSAVE_AUCTION )
chrif_save(sd,0);
}
else

View File

@@ -1076,7 +1076,7 @@ bool itemdb_parse_roulette_db(void)
uint32 count = 0;
// retrieve all rows from the item database
if (SQL_ERROR == Sql_Query(mmysql_handle, "SELECT * FROM `%s`", db_roulette_table)) {
if (SQL_ERROR == Sql_Query(mmysql_handle, "SELECT * FROM `%s`", roulette_table)) {
Sql_ShowDebug(mmysql_handle);
return false;
}
@@ -1156,7 +1156,7 @@ bool itemdb_parse_roulette_db(void)
}
}
ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, db_roulette_table);
ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, roulette_table);
return true;
}
@@ -1498,11 +1498,11 @@ static int itemdb_read_sqldb(void) {
const char* item_db_name[] = {
#ifdef RENEWAL
item_db_re_db,
mapserv_table(item_db_re_table),
#else
item_db_db,
mapserv_table(item_db_table),
#endif
item_db2_db
mapserv_table(item_db2_table)
};
int fi;
@@ -1583,7 +1583,7 @@ static void itemdb_read(void) {
"/"DBIMPORT,
};
if (db_use_sqldbs)
if (mapserv_schema_config.db_use_sqldbs)
itemdb_read_sqldb();
else
itemdb_readdb();

View File

@@ -39,10 +39,8 @@ typedef enum e_log_filter
}
e_log_filter;
struct Log_Config log_config;
#ifdef SQL_INNODB
// database is using an InnoDB engine so do not use DELAYED
#define LOG_QUERY "INSERT"
@@ -170,12 +168,12 @@ void log_branch(struct map_session_data* sd)
#ifdef BETA_THREAD_TEST
char entry[512];
int e_length = 0;
e_length = sprintf(entry, LOG_QUERY " INTO `%s` (`branch_date`, `account_id`, `char_id`, `char_name`, `map`) VALUES (NOW(), '%d', '%d', '%s', '%s')", log_config.log_branch, sd->status.account_id, sd->status.char_id, sd->status.name, mapindex_id2name(sd->mapindex));
e_length = sprintf(entry, LOG_QUERY " INTO `%s` (`branch_date`, `account_id`, `char_id`, `char_name`, `map`) VALUES (NOW(), '%d', '%d', '%s', '%s')", StringBuf_Value(log_config.schema.branch_table), sd->status.account_id, sd->status.char_id, sd->status.name, mapindex_id2name(sd->mapindex));
queryThread_log(entry,e_length);
#else
SqlStmt* stmt;
stmt = SqlStmt_Malloc(logmysql_handle);
if( SQL_SUCCESS != SqlStmt_Prepare(stmt, LOG_QUERY " INTO `%s` (`branch_date`, `account_id`, `char_id`, `char_name`, `map`) VALUES (NOW(), '%d', '%d', ?, '%s')", log_config.log_branch, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex) )
if( SQL_SUCCESS != SqlStmt_Prepare(stmt, LOG_QUERY " INTO `%s` (`branch_date`, `account_id`, `char_id`, `char_name`, `map`) VALUES (NOW(), '%d', '%d', ?, '%s')", StringBuf_Value(log_config.schema.branch_table), 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_Execute(stmt) )
{
@@ -192,7 +190,7 @@ void log_branch(struct map_session_data* sd)
time_t curtime;
FILE* logfp;
if( ( logfp = fopen(log_config.log_branch, "a") ) == NULL )
if( ( logfp = fopen(StringBuf_Value(log_config.schema.branch_table), "a") ) == NULL )
return;
time(&curtime);
strftime(timestring, sizeof(timestring), log_timestamp_format, localtime(&curtime));
@@ -219,11 +217,11 @@ void log_pick(int id, int16 m, e_log_pick_type type, int amount, struct item* it
char entry[512];
int e_length = 0;
e_length = sprintf(entry, LOG_QUERY " INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`, `unique_id`, `bound`) VALUES (NOW(), '%d', '%c', '%hu', '%d', '%d', '%hu', '%hu', '%hu', '%hu', '%s', '%"PRIu64"', '%d')",
log_config.log_pick, id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], map[m].name?map[m].name:"", itm->unique_id, itm->bound);
StringBuf_Value(log_config.schema.pick_table), id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], map[m].name?map[m].name:"", itm->unique_id, itm->bound);
queryThread_log(entry,e_length);
#else
if( SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`, `unique_id`, `bound`) VALUES (NOW(), '%d', '%c', '%hu', '%d', '%d', '%hu', '%hu', '%hu', '%hu', '%s', '%"PRIu64"', '%d')",
log_config.log_pick, id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], map[m].name?map[m].name:"", itm->unique_id, itm->bound) )
StringBuf_Value(log_config.schema.pick_table), id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], map[m].name?map[m].name:"", itm->unique_id, itm->bound) )
{
Sql_ShowDebug(logmysql_handle);
return;
@@ -236,7 +234,7 @@ void log_pick(int id, int16 m, e_log_pick_type type, int amount, struct item* it
time_t curtime;
FILE* logfp;
if( ( logfp = fopen(log_config.log_pick, "a") ) == NULL )
if( ( logfp = fopen(StringBuf_Value(log_config.schema.pick_table), "a") ) == NULL )
return;
time(&curtime);
strftime(timestring, sizeof(timestring), log_timestamp_format, localtime(&curtime));
@@ -274,11 +272,11 @@ void log_zeny(struct map_session_data* sd, e_log_pick_type type, struct map_sess
char entry[512];
int e_length = 0;
e_length = sprintf(entry, LOG_QUERY " INTO `%s` (`time`, `char_id`, `src_id`, `type`, `amount`, `map`) VALUES (NOW(), '%d', '%d', '%c', '%d', '%s')",
log_config.log_zeny, sd->status.char_id, src_sd->status.char_id, log_picktype2char(type), amount, mapindex_id2name(sd->mapindex));
StringBuf_Value(log_config.schema.zeny_table), sd->status.char_id, src_sd->status.char_id, log_picktype2char(type), amount, mapindex_id2name(sd->mapindex));
queryThread_log(entry,e_length);
#else
if( SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `src_id`, `type`, `amount`, `map`) VALUES (NOW(), '%d', '%d', '%c', '%d', '%s')",
log_config.log_zeny, sd->status.char_id, src_sd->status.char_id, log_picktype2char(type), amount, mapindex_id2name(sd->mapindex)) )
StringBuf_Value(log_config.schema.zeny_table), sd->status.char_id, src_sd->status.char_id, log_picktype2char(type), amount, mapindex_id2name(sd->mapindex)) )
{
Sql_ShowDebug(logmysql_handle);
return;
@@ -291,7 +289,7 @@ void log_zeny(struct map_session_data* sd, e_log_pick_type type, struct map_sess
time_t curtime;
FILE* logfp;
if( ( logfp = fopen(log_config.log_zeny, "a") ) == NULL )
if( ( logfp = fopen(StringBuf_Value(log_config.schema.zeny_table), "a") ) == NULL )
return;
time(&curtime);
strftime(timestring, sizeof(timestring), log_timestamp_format, localtime(&curtime));
@@ -315,11 +313,11 @@ void log_mvpdrop(struct map_session_data* sd, int monster_id, unsigned int* log_
char entry[512];
int e_length = 0;
e_length = sprintf(entry, LOG_QUERY " INTO `%s` (`mvp_date`, `kill_char_id`, `monster_id`, `prize`, `mvpexp`, `map`) VALUES (NOW(), '%d', '%d', '%hu', '%u', '%s') ",
log_config.log_mvpdrop, sd->status.char_id, monster_id, (unsigned short)log_mvp[0], log_mvp[1], mapindex_id2name(sd->mapindex));
StringBuf_Value(log_config.schema.mvpdrop_table), sd->status.char_id, monster_id, (unsigned short)log_mvp[0], log_mvp[1], mapindex_id2name(sd->mapindex));
queryThread_log(entry,e_length);
#else
if( SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`mvp_date`, `kill_char_id`, `monster_id`, `prize`, `mvpexp`, `map`) VALUES (NOW(), '%d', '%d', '%hu', '%u', '%s') ",
log_config.log_mvpdrop, sd->status.char_id, monster_id, (unsigned short)log_mvp[0], log_mvp[1], mapindex_id2name(sd->mapindex)) )
StringBuf_Value(log_config.schema.mvpdrop_table), sd->status.char_id, monster_id, (unsigned short)log_mvp[0], log_mvp[1], mapindex_id2name(sd->mapindex)) )
{
Sql_ShowDebug(logmysql_handle);
return;
@@ -332,7 +330,7 @@ void log_mvpdrop(struct map_session_data* sd, int monster_id, unsigned int* log_
time_t curtime;
FILE* logfp;
if( ( logfp = fopen(log_config.log_mvpdrop,"a") ) == NULL )
if( ( logfp = fopen(StringBuf_Value(log_config.schema.mvpdrop_table),"a") ) == NULL )
return;
time(&curtime);
strftime(timestring, sizeof(timestring), log_timestamp_format, localtime(&curtime));
@@ -356,13 +354,13 @@ void log_atcommand(struct map_session_data* sd, const char* message)
#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);
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')", StringBuf_Value(log_config.schema.command_table), 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) )
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', ?)", StringBuf_Value(log_config.schema.command_table), 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) )
@@ -380,7 +378,7 @@ void log_atcommand(struct map_session_data* sd, const char* message)
time_t curtime;
FILE* logfp;
if( ( logfp = fopen(log_config.log_gm, "a") ) == NULL )
if( ( logfp = fopen(StringBuf_Value(log_config.schema.command_table), "a") ) == NULL )
return;
time(&curtime);
strftime(timestring, sizeof(timestring), log_timestamp_format, localtime(&curtime));
@@ -403,12 +401,12 @@ void log_npc(struct map_session_data* sd, const char* message)
#ifdef BETA_THREAD_TEST
char entry[512];
int e_length = 0;
e_length = sprintf(entry, LOG_QUERY " INTO `%s` (`npc_date`, `account_id`, `char_id`, `char_name`, `map`, `mes`) VALUES (NOW(), '%d', '%d', '%s', '%s', '%s')", log_config.log_npc, sd->status.account_id, sd->status.char_id, sd->status.name, mapindex_id2name(sd->mapindex), message );
e_length = sprintf(entry, LOG_QUERY " INTO `%s` (`npc_date`, `account_id`, `char_id`, `char_name`, `map`, `mes`) VALUES (NOW(), '%d', '%d', '%s', '%s', '%s')", StringBuf_Value(log_config.schema.npc_table), 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` (`npc_date`, `account_id`, `char_id`, `char_name`, `map`, `mes`) VALUES (NOW(), '%d', '%d', ?, '%s', ?)", log_config.log_npc, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex) )
if( SQL_SUCCESS != SqlStmt_Prepare(stmt, LOG_QUERY " INTO `%s` (`npc_date`, `account_id`, `char_id`, `char_name`, `map`, `mes`) VALUES (NOW(), '%d', '%d', ?, '%s', ?)", StringBuf_Value(log_config.schema.npc_table), 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) )
@@ -426,7 +424,7 @@ void log_npc(struct map_session_data* sd, const char* message)
time_t curtime;
FILE* logfp;
if( ( logfp = fopen(log_config.log_npc, "a") ) == NULL )
if( ( logfp = fopen(StringBuf_Value(log_config.schema.npc_table), "a") ) == NULL )
return;
time(&curtime);
strftime(timestring, sizeof(timestring), log_timestamp_format, localtime(&curtime));
@@ -444,7 +442,7 @@ void log_chat(e_log_chat_type type, int type_id, int src_charid, int src_accid,
return;
}
if( log_config.log_chat_woe_disable && ( agit_flag || agit2_flag ) )
if( log_config.log_chat_woe_disable && ( map_config.agit_flag || map_config.agit2_flag ) )
{// no chat logging during woe
return;
}
@@ -453,13 +451,13 @@ void log_chat(e_log_chat_type type, int type_id, int src_charid, int src_accid,
#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 );
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')", StringBuf_Value(log_config.schema.chat_table), 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)
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', ?, ?)", StringBuf_Value(log_config.schema.chat_table), 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) )
@@ -477,7 +475,7 @@ void log_chat(e_log_chat_type type, int type_id, int src_charid, int src_accid,
time_t curtime;
FILE* logfp;
if( ( logfp = fopen(log_config.log_chat, "a") ) == NULL )
if( ( logfp = fopen(StringBuf_Value(log_config.schema.chat_table), "a") ) == NULL )
return;
time(&curtime);
strftime(timestring, sizeof(timestring), log_timestamp_format, localtime(&curtime));
@@ -498,11 +496,11 @@ void log_cash( struct map_session_data* sd, e_log_pick_type type, e_log_cash_typ
char entry[512];
int e_length = 0;
e_length = sprintf( entry, LOG_QUERY " INTO `%s` ( `time`, `char_id`, `type`, `cash_type`, `amount`, `map` ) VALUES ( NOW(), '%d', '%c', '%c', '%d', '%s' )",
log_config.log_cash, sd->status.char_id, log_picktype2char( type ), log_cashtype2char( cash_type ), amount, mapindex_id2name( sd->mapindex ) );
StringBuf_Value(log_config.schema.cash_table), sd->status.char_id, log_picktype2char( type ), log_cashtype2char( cash_type ), amount, mapindex_id2name( sd->mapindex ) );
queryThread_log( entry, e_length );
#else
if( SQL_ERROR == Sql_Query( logmysql_handle, LOG_QUERY " INTO `%s` ( `time`, `char_id`, `type`, `cash_type`, `amount`, `map` ) VALUES ( NOW(), '%d', '%c', '%c', '%d', '%s' )",
log_config.log_cash, sd->status.char_id, log_picktype2char( type ), log_cashtype2char( cash_type ), amount, mapindex_id2name( sd->mapindex ) ) )
StringBuf_Value(log_config.schema.cash_table), sd->status.char_id, log_picktype2char( type ), log_cashtype2char( cash_type ), amount, mapindex_id2name( sd->mapindex ) ) )
{
Sql_ShowDebug( logmysql_handle );
return;
@@ -513,7 +511,7 @@ void log_cash( struct map_session_data* sd, e_log_pick_type type, e_log_cash_typ
time_t curtime;
FILE* logfp;
if( ( logfp = fopen( log_config.log_cash, "a" ) ) == NULL )
if( ( logfp = fopen( StringBuf_Value(log_config.schema.cash_table), "a" ) ) == NULL )
return;
time( &curtime );
strftime( timestring, sizeof( timestring ), log_timestamp_format, localtime( &curtime ) );
@@ -585,27 +583,210 @@ void log_feeding(struct map_session_data *sd, e_log_feeding_type type, unsigned
void log_set_defaults(void)
{
memset(&log_config, 0, sizeof(log_config));
log_config.enable_logs = LOG_TYPE_ALL;
log_config.filter = LOG_FILTER_ALL;
log_config.sql_logs = true;
log_config.log_chat_woe_disable = false;
//LOG FILTER Default values
log_config.refine_items_log = 5; // log refined items, with refine >= +5
log_config.rare_items_log = 100; // log rare items. drop chance <= 1%
log_config.price_items_log = 1000; // 1000z
log_config.amount_items_log = 100;
// Logging
log_config.cash = true;
log_config.branch = 0;
log_config.mvpdrop = 0;
log_config.zeny = 0;
log_config.commands = true;
log_config.npc = true;
log_config.chat = LOG_CHAT_NONE;
safestrncpy(log_timestamp_format, "%m/%d/%Y %H:%M:%S", sizeof(log_timestamp_format));
// Default filter
log_config.refine_items_log = 5; // log refined items, with refine >= +5
log_config.rare_items_log = 100; // log rare items. drop chance <= 1%
log_config.price_items_log = 1000; // 1000z
log_config.amount_items_log = 100; // Log if a single item amount >= 100
}
void log_config_init(void) {
log_set_defaults();
log_config.log_path = StringBuf_FromStr("log/");
log_config.log_ext = StringBuf_FromStr(".log");
log_config.schema.branch_table = StringBuf_FromStr("branchlog");
log_config.schema.cash_table = StringBuf_FromStr("cashlog");
log_config.schema.chat_table = StringBuf_FromStr("chatlog");
log_config.schema.command_table = StringBuf_FromStr("atcommandlog");
log_config.schema.mvpdrop_table = StringBuf_FromStr("mvplog");
log_config.schema.npc_table = StringBuf_FromStr("npclog");
log_config.schema.pick_table = StringBuf_FromStr("picklog");
log_config.schema.zeny_table = StringBuf_FromStr("zenylog");
log_config.schema.feeding_table = StringBuf_FromStr("feedinglog");
}
void log_config_final(void) {
StringBuf_Free(log_config.log_path);
StringBuf_Free(log_config.log_ext);
StringBuf_Free(log_config.schema.branch_table);
StringBuf_Free(log_config.schema.cash_table);
StringBuf_Free(log_config.schema.chat_table);
StringBuf_Free(log_config.schema.command_table);
StringBuf_Free(log_config.schema.mvpdrop_table);
StringBuf_Free(log_config.schema.npc_table);
StringBuf_Free(log_config.schema.pick_table);
StringBuf_Free(log_config.schema.zeny_table);
StringBuf_Free(log_config.schema.feeding_table);
}
/**
* Report final logging state
**/
void log_config_read_done(void) {
#define LOG_CONFIG_PATH(log) {\
StringBuf_PrintfClear(log_config.schema.log, "%s%s%s", StringBuf_Value(log_config.log_path), StringBuf_Value(log_config.schema.log), StringBuf_Value(log_config.log_ext));\
}
const char* target = log_config.sql_logs ? "table" : "file";
if (!log_config.sql_logs) {
LOG_CONFIG_PATH(pick_table);
LOG_CONFIG_PATH(branch_table);
LOG_CONFIG_PATH(chat_table);
LOG_CONFIG_PATH(command_table);
LOG_CONFIG_PATH(mvpdrop_table);
LOG_CONFIG_PATH(npc_table);
LOG_CONFIG_PATH(zeny_table);
LOG_CONFIG_PATH(cash_table);
LOG_CONFIG_PATH(feeding_table);
}
if (log_config.enable_logs && log_config.filter) {
ShowInfo("Logging item transactions to %s: '%s'.\n", target, StringBuf_Value(log_config.schema.pick_table));
}
if (log_config.branch) {
ShowInfo("Logging monster summon item usage to %s: '%s'.\n", target, StringBuf_Value(log_config.schema.branch_table));
}
if (log_config.chat) {
ShowInfo("Logging chat to %s: '%s'.\n", target, StringBuf_Value(log_config.schema.chat_table));
}
if (log_config.commands) {
ShowInfo("Logging commands to %s: '%s'.\n", target, StringBuf_Value(log_config.schema.command_table));
}
if (log_config.mvpdrop) {
ShowInfo("Logging MVP monster rewards to %s: '%s'.\n", target, StringBuf_Value(log_config.schema.mvpdrop_table));
}
if (log_config.npc) {
ShowInfo("Logging 'logmes' messages to %s: '%s'.\n", target, StringBuf_Value(log_config.schema.npc_table));
}
if (log_config.zeny) {
ShowInfo("Logging Zeny transactions to %s: '%s'.\n", StringBuf_Value(log_config.schema.zeny_table));
}
if (log_config.cash) {
ShowInfo("Logging Cash transactions to %s: '%s'.\n", target, StringBuf_Value(log_config.schema.cash_table));
}
if (log_config.feeding) {
ShowInfo("Logging Feeding items to %s: '%s'.\n", target, StringBuf_Value(log_config.schema.feeding_table));
}
#undef LOG_CONFIG_PATH
}
/**
* Check all tables, check all fields are sitting
* Only for table logs.
**/
bool log_check_tables(void) {
if (!log_config.enable_logs || !log_config.sql_logs)
return true;
ShowInfo("Start checking DB integrity (Log DB)\n");
// branchlog
if( log_config.branch && SQL_ERROR == Sql_Query(logmysql_handle,
"SELECT `branch_id`, `branch_date`, `account_id`, `char_id`, `char_name`, `map` "
"FROM `%s`;", StringBuf_Value(log_config.schema.branch_table)) )
{
Sql_ShowDebug(logmysql_handle);
return false;
}
// cashlog
if( log_config.cash && SQL_ERROR == Sql_Query(logmysql_handle,
"SELECT `id`, `time`, `char_id`, `type`, `cash_type`, `amount`, `map` "
"FROM `%s`;", StringBuf_Value(log_config.schema.cash_table)) )
{
Sql_ShowDebug(logmysql_handle);
return false;
}
// chatlog
if( log_config.chat && SQL_ERROR == Sql_Query(logmysql_handle,
"SELECT `id`, `time`, `type`, `type_id`, `src_charid`, `src_accountid`, `src_map`, `src_map_x`, `src_map_y`, `dst_charname`, `message` "
"FROM `%s`;", StringBuf_Value(log_config.schema.chat_table)) )
{
Sql_ShowDebug(logmysql_handle);
return false;
}
// atcommandlog
if( log_config.commands && SQL_ERROR == Sql_Query(logmysql_handle,
"SELECT `atcommand_id`, `atcommand_date`, `account_id`, `char_id`, `char_name`, `map`, `command` "
"FROM `%s`;", StringBuf_Value(log_config.schema.command_table)) )
{
Sql_ShowDebug(logmysql_handle);
return false;
}
// mvplog
if( log_config.mvpdrop && SQL_ERROR == Sql_Query(logmysql_handle,
"SELECT `mvp_id`, `mvp_date`, `kill_char_id`, `monster_id`, `prize`, `mvpexp`, `map` "
"FROM `%s`;", StringBuf_Value(log_config.schema.mvpdrop_table)) )
{
Sql_ShowDebug(logmysql_handle);
return false;
}
// npclog
if( log_config.npc && SQL_ERROR == Sql_Query(logmysql_handle,
"SELECT `npc_id`, `npc_date`, `account_id`, `char_id`, `char_name`, `map`, `mes` "
"FROM `%s`;", StringBuf_Value(log_config.schema.npc_table)) )
{
Sql_ShowDebug(logmysql_handle);
return false;
}
// picklog
if( log_config.filter && SQL_ERROR == Sql_Query(logmysql_handle,
"SELECT `id`, `time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, "
"`unique_id`, `map`, `bound` "
"FROM `%s`;", StringBuf_Value(log_config.schema.pick_table)) )
{
Sql_ShowDebug(logmysql_handle);
return false;
}
// zenylog
if( log_config.zeny && SQL_ERROR == Sql_Query(logmysql_handle,
"SELECT `id`, `time`, `char_id`, `src_id`, `type`, `amount`, `map` "
"FROM `%s`;", StringBuf_Value(log_config.schema.zeny_table)) )
{
Sql_ShowDebug(logmysql_handle);
return false;
}
// feedinglog
if( log_config.feeding && SQL_ERROR == Sql_Query(logmysql_handle,
"SELECT `id`, `time`, `char_id`, `target_id`, `target_class`, `type`, `intimacy`, `item_id`, `map`, `x`, `y` "
"FROM `%s`;", StringBuf_Value(log_config.schema.feeding_table)) )
{
Sql_ShowDebug(logmysql_handle);
return false;
}
return true;
}
int log_config_read(const char* cfgName)
{
static int count = 0;
char line[1024], w1[1024], w2[1024];
char line[1024];
FILE *fp;
if( count++ == 0 )
log_set_defaults();
if( ( fp = fopen(cfgName, "r") ) == NULL )
{
ShowError("Log configuration file not found at: %s\n", cfgName);
@@ -614,6 +795,7 @@ int log_config_read(const char* cfgName)
while( fgets(line, sizeof(line), fp) )
{
char w1[32], w2[32];
if( line[0] == '/' && line[1] == '/' )
continue;
@@ -634,9 +816,9 @@ int log_config_read(const char* cfgName)
log_config.amount_items_log = atoi(w2);
//end of common filter settings
else if( strcmpi(w1, "log_branch") == 0 )
log_config.branch = config_switch(w2);
log_config.branch = (bool)config_switch(w2);
else if( strcmpi(w1, "log_filter") == 0 )
log_config.filter = config_switch(w2);
log_config.filter = (e_log_filter)config_switch(w2);
else if( strcmpi(w1, "log_zeny") == 0 )
log_config.zeny = config_switch(w2);
else if( strcmpi( w1, "log_cash" ) == 0 )
@@ -646,34 +828,35 @@ int log_config_read(const char* cfgName)
else if( strcmpi(w1, "log_npc") == 0 )
log_config.npc = config_switch(w2);
else if( strcmpi(w1, "log_chat") == 0 )
log_config.chat = config_switch(w2);
log_config.chat = (e_log_chat_type)config_switch(w2);
else if( strcmpi(w1, "log_mvpdrop") == 0 )
log_config.mvpdrop = config_switch(w2);
else if( strcmpi(w1, "log_feeding") == 0 )
log_config.feeding = config_switch(w2);
else if( strcmpi(w1, "log_chat_woe_disable") == 0 )
log_config.log_chat_woe_disable = (bool)config_switch(w2);
else if( strcmpi(w1, "log_branch_db") == 0 )
safestrncpy(log_config.log_branch, w2, sizeof(log_config.log_branch));
else if( strcmpi(w1, "log_pick_db") == 0 )
safestrncpy(log_config.log_pick, w2, sizeof(log_config.log_pick));
else if( strcmpi(w1, "log_zeny_db") == 0 )
safestrncpy(log_config.log_zeny, w2, sizeof(log_config.log_zeny));
else if( strcmpi(w1, "log_mvpdrop_db") == 0 )
safestrncpy(log_config.log_mvpdrop, w2, sizeof(log_config.log_mvpdrop));
else if( strcmpi(w1, "log_gm_db") == 0 )
safestrncpy(log_config.log_gm, w2, sizeof(log_config.log_gm));
else if( strcmpi(w1, "log_npc_db") == 0 )
safestrncpy(log_config.log_npc, w2, sizeof(log_config.log_npc));
else if( strcmpi(w1, "log_chat_db") == 0 )
safestrncpy(log_config.log_chat, w2, sizeof(log_config.log_chat));
else if( strcmpi( w1, "log_cash_db" ) == 0 )
safestrncpy( log_config.log_cash, w2, sizeof( log_config.log_cash ) );
else if( strcmpi( w1, "log_feeding_db" ) == 0 )
safestrncpy( log_config.log_feeding, w2, sizeof( log_config.log_feeding ) );
// log file timestamp format
else if( strcmpi( w1, "log_timestamp_format" ) == 0 )
safestrncpy(log_timestamp_format, w2, sizeof(log_timestamp_format));
else if( strcmpi(w1, "log_branch_table") == 0 )
StringBuf_PrintfClear(log_config.schema.branch_table, "%s", w2);
else if( strcmpi(w1, "log_pick_table") == 0 )
StringBuf_PrintfClear(log_config.schema.pick_table, "%s", w2);
else if( strcmpi(w1, "log_zeny_table") == 0 )
StringBuf_PrintfClear(log_config.schema.zeny_table, "%s", w2);
else if( strcmpi(w1, "log_mvpdrop_table") == 0 )
StringBuf_PrintfClear(log_config.schema.mvpdrop_table, "%s", w2);
else if( strcmpi(w1, "log_gm_table") == 0 )
StringBuf_PrintfClear(log_config.schema.command_table, "%s", w2);
else if( strcmpi(w1, "log_npc_table") == 0 )
StringBuf_PrintfClear(log_config.schema.npc_table, "%s", w2);
else if( strcmpi(w1, "log_chat_table") == 0 )
StringBuf_PrintfClear(log_config.schema.chat_table, "%s", w2);
else if( strcmpi( w1, "log_cash_table" ) == 0 )
StringBuf_PrintfClear(log_config.schema.cash_table, "%s", w2);
else if( strcmpi( w1, "log_feeding_table" ) == 0 )
StringBuf_PrintfClear(log_config.schema.feeding_table, "%s", w2);
else if( strcmpi( w1, "log_path" ) == 0 )
StringBuf_PrintfClear(log_config.log_path, "%s", w2);
else if( strcmpi( w1, "log_extension" ) == 0 )
StringBuf_PrintfClear(log_config.log_ext, "%s", w2);
//support the import command, just like any other config
else if( strcmpi(w1,"import") == 0 )
log_config_read(w2);
@@ -683,46 +866,5 @@ int log_config_read(const char* cfgName)
}
fclose(fp);
if( --count == 0 )
{// report final logging state
const char* target = log_config.sql_logs ? "table" : "file";
if( log_config.enable_logs && log_config.filter )
{
ShowInfo("Logging item transactions to %s '%s'.\n", target, log_config.log_pick);
}
if( log_config.branch )
{
ShowInfo("Logging monster summon item usage to %s '%s'.\n", target, log_config.log_pick);
}
if( log_config.chat )
{
ShowInfo("Logging chat to %s '%s'.\n", target, log_config.log_chat);
}
if( log_config.commands )
{
ShowInfo("Logging commands to %s '%s'.\n", target, log_config.log_gm);
}
if( log_config.mvpdrop )
{
ShowInfo("Logging MVP monster rewards to %s '%s'.\n", target, log_config.log_mvpdrop);
}
if( log_config.npc )
{
ShowInfo("Logging 'logmes' messages to %s '%s'.\n", target, log_config.log_npc);
}
if( log_config.zeny )
{
ShowInfo("Logging Zeny transactions to %s '%s'.\n", target, log_config.log_zeny);
}
if( log_config.cash ){
ShowInfo( "Logging Cash transactions to %s '%s'.\n", target, log_config.log_cash );
}
if( log_config.feeding ){
ShowInfo( "Logging Feeding items to %s '%s'.\n", target, log_config.log_feeding );
}
}
return 0;
}

View File

@@ -12,6 +12,7 @@ struct item;
typedef enum e_log_chat_type
{
LOG_CHAT_NONE = 0,
LOG_CHAT_GLOBAL = 0x01,
LOG_CHAT_WHISPER = 0x02,
LOG_CHAT_PARTY = 0x04,
@@ -80,19 +81,50 @@ void log_mvpdrop(struct map_session_data* sd, int monster_id, unsigned int* log_
int log_config_read(const char* cfgName);
extern struct Log_Config
{
e_log_pick_type enable_logs;
int filter;
bool sql_logs;
bool log_chat_woe_disable;
bool cash;
int rare_items_log,refine_items_log,price_items_log,amount_items_log; //for filter
int branch, mvpdrop, zeny, commands, npc, chat;
unsigned feeding : 2;
char log_branch[64], log_pick[64], log_zeny[64], log_mvpdrop[64], log_gm[64], log_npc[64], log_chat[64], log_cash[64];
char log_feeding[64];
} log_config;
/// Log Config structure
struct Log_Config {
uint32 enable_logs; ///< Values @see e_log_pick_type
uint16 filter; ///< Values @see e_log_filter
bool sql_logs; ///< Enable SQL log instead of file log
bool log_chat_woe_disable; ///< Disable chat logging on WOE
bool cash; ///< Log cash usage
bool branch; ///< Log item branch usage
bool mvpdrop; ///< Log MVP Drop
uint32 zeny; ///< Log Zeny usage if zeny spent is more than 'zeny'
bool commands; ///< Log Comman usage
bool npc; ///< Log NPC 'logmes' command
uint8 chat; ///< Log Chat @see e_log_chat_type
uint8 feeding; ///< Log Feeding usage
// Filter
uint16 rare_items_log; ///< Log if droprate is less than 'rare_items_log'
uint8 refine_items_log; ///< Log if refine value is more than 'refine_items_log'
uint32 price_items_log; ///< Log if item buy price is more than 'price_items_log'
uint16 amount_items_log; ///< Log if single item amount is more than 'amount_items_log'
StringBuf *log_path; ///< Path to log file (Used if 'sql_logs' is no)
StringBuf *log_ext; ///< Log file extension (Used if 'sql_logs' is no)
struct s_log_schema_config {
StringBuf *branch_table; ///< Branch log table/file with path
StringBuf *cash_table; ///< Cash log table/file with path
StringBuf *chat_table; ///< Chat log table/file with path
StringBuf *command_table; ///< Command log table/file with path
StringBuf *mvpdrop_table; ///< MVP Drop log table/file with path
StringBuf *npc_table; ///< NPC log table/file with path
StringBuf *pick_table; ///< Pick log table/file with path
StringBuf *zeny_table; ///< Zeny log table/file with path
StringBuf *feeding_table; ///< Feeding log table/file with path
} schema; ///< Log filepathes or tables
};
/// Log Config used values
extern struct Log_Config log_config;
void log_config_init(void);
void log_config_final(void);
void log_config_read_done(void);
bool log_check_tables(void);
#ifdef BETA_THREAD_TEST
struct {

View File

@@ -43,42 +43,21 @@
#ifndef _WIN32
#endif
char default_codepage[32] = "";
int map_server_port = 3306;
char map_server_ip[32] = "127.0.0.1";
char map_server_id[32] = "ragnarok";
char map_server_pw[32] = "";
char map_server_db[32] = "ragnarok";
Sql* mmysql_handle;
Sql* mmysql_handle; /// Map-server handle
Sql* qsmysql_handle; /// For query_sql
Sql* logmysql_handle; /// Log database handle
int db_use_sqldbs = 0;
char buyingstores_db[32] = "buyingstores";
char buyingstore_items_db[32] = "buyingstore_items";
char item_db_db[32] = "item_db";
char item_db2_db[32] = "item_db2";
char item_db_re_db[32] = "item_db_re";
char item_cash_db_db[32] = "item_cash_db";
char item_cash_db2_db[32] = "item_cash_db2";
char mob_db_db[32] = "mob_db";
char mob_db_re_db[32] = "mob_db_re";
char mob_db2_db[32] = "mob_db2";
char mob_skill_db_db[32] = "mob_skill_db";
char mob_skill_db_re_db[32] = "mob_skill_db_re";
char mob_skill_db2_db[32] = "mob_skill_db2";
char vendings_db[32] = "vendings";
char vending_items_db[32] = "vending_items";
char market_table[32] = "market";
char db_roulette_table[32] = "db_roulette";
struct Map_Config map_config; /// Map configurations
static void map_inter_config_init(void);
static void map_inter_config_final(void);
// log database
char log_db_ip[32] = "127.0.0.1";
int log_db_port = 3306;
char log_db_id[32] = "ragnarok";
char log_db_pw[32] = "ragnarok";
char log_db_db[32] = "log";
Sql* logmysql_handle;
struct MapServer_Schema mapserv_schema_config; /// map-server tables
static void map_schema_init(void);
static void map_schema_final(void);
struct MapServer_File mapserv_file_config; /// Sub files needed for map-server
static void map_file_init(void);
static void map_file_final(void);
// DBMap declaration
static DBMap* id_db=NULL; /// int id -> struct block_list*
@@ -108,13 +87,6 @@ struct map_data map[MAX_MAP_PER_SERVER];
int map_num = 0;
int map_port=0;
int autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
int minsave_interval = 100;
unsigned char save_settings = CHARSAVE_ALL;
int agit_flag = 0;
int agit2_flag = 0;
int night_flag = 0; // 0=day, 1=night [Yor]
#ifdef ADJUST_SKILL_DAMAGE
struct eri *map_skill_damage_ers = NULL;
#endif
@@ -142,19 +114,8 @@ struct map_cache_map_info {
int32 len;
};
char motd_txt[256] = "conf/motd.txt";
char help_txt[256] = "conf/help.txt";
char help2_txt[256] = "conf/help2.txt";
char charhelp_txt[256] = "conf/charhelp.txt";
char wisp_server_name[NAME_LENGTH] = "Server"; // can be modified in char-server configuration file
struct s_map_default map_default;
int console = 0;
int enable_spy = 0; //To enable/disable @spy commands, which consume too much cpu time when sending packets. [Skotlex]
int enable_grf = 0; //To enable/disable reading maps from GRF files, bypassing mapcache [blackhole89]
/*==========================================
* server player count (of all mapservers)
*------------------------------------------*/
@@ -3522,7 +3483,7 @@ int map_readallmaps (void)
};
char map_cache_decode_buffer[MAX_MAP_SIZE];
if( enable_grf )
if( map_config.enable_grf )
ShowStatus("Loading maps (using GRF files)...\n");
else {
char* mapcachefilepath[] = {
@@ -3560,7 +3521,7 @@ int map_readallmaps (void)
bool success = false;
unsigned short idx = 0;
if( enable_grf ){
if( map_config.enable_grf ){
// show progress
ShowStatus("Loading maps [%i/%i]: %s"CL_CLL"\r", i, map_num, map[i].name);
@@ -3619,7 +3580,7 @@ int map_readallmaps (void)
// intialization and configuration-dependent adjustments of mapflags
map_flags_init();
if( !enable_grf ) {
if( !map_config.enable_grf ) {
// The cache isn't needed anymore, so free it. [Shinryo]
if( map_cache_buffer[1] != NULL ){
aFree(map_cache_buffer[1]);
@@ -3713,6 +3674,49 @@ int parse_console(const char* buf){
return 0;
}
/**
* Get table names
* @param w1 Config name
* @param w2 Config value
**/
static bool map_schema_read_conf(const char *w1, const char *w2) {
#define SCHEMA_CONF(var,str) \
if (!strcmpi(w1,(str))) {\
StringBuf_PrintfClear(mapserv_schema_config.var, "%s", w2);\
return true;\
}\
if (strcmpi(w1,"use_sql_db")==0) {
mapserv_schema_config.db_use_sqldbs = config_switch(w2);
ShowStatus ("Using SQL dbs: %s\n",w2);
return true;
}
SCHEMA_CONF(buyingstores_table, "buyingstore_table")
SCHEMA_CONF(buyingstore_items_table, "buyingstore_items_table")
SCHEMA_CONF(mapreg_table, "mapreg_table")
SCHEMA_CONF(market_table, "market_table")
SCHEMA_CONF(roulette_table, "db_roulette")
SCHEMA_CONF(vendings_table, "vending_table")
SCHEMA_CONF(vending_items_table, "vending_items_table")
// TXT -> SQL DB
SCHEMA_CONF(item_db_table, "item_db_table")
SCHEMA_CONF(item_db_re_table, "item_db_re_table")
SCHEMA_CONF(item_db2_table, "item_db2_table")
SCHEMA_CONF(mob_db_table, "mob_db_table")
SCHEMA_CONF(mob_db_re_table, "mob_db_re_table")
SCHEMA_CONF(mob_db2_table, "mob_db2_table")
SCHEMA_CONF(mob_skill_db_table, "mob_skill_db_table")
SCHEMA_CONF(mob_skill_db_re_table, "mob_skill_db_re_table")
SCHEMA_CONF(mob_skill_db2_table, "mob_skill_db2_table")
SCHEMA_CONF(item_cash_db_table, "item_cash_db_table")
SCHEMA_CONF(item_cash_db2_table, "item_cash_db2_table")
return false;
#undef SCHEMA_CONF
}
/*==========================================
* Read map server configuration files (conf/map_athena.conf...)
*------------------------------------------*/
@@ -3777,39 +3781,39 @@ int map_config_read(char *cfgName)
else if (strcmpi(w1, "delnpc") == 0)
npc_delsrcfile(w2);
else if (strcmpi(w1, "autosave_time") == 0) {
autosave_interval = atoi(w2);
if (autosave_interval < 1) //Revert to default saving.
autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
map_config.autosave_interval = atoi(w2);
if (map_config.autosave_interval < 1) //Revert to default saving.
map_config.autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
else
autosave_interval *= 1000; //Pass from sec to ms
map_config.autosave_interval *= 1000; //Pass from sec to ms
} else if (strcmpi(w1, "minsave_time") == 0) {
minsave_interval= atoi(w2);
if (minsave_interval < 1)
minsave_interval = 1;
map_config.minsave_interval = atoi(w2);
if (map_config.minsave_interval < 1)
map_config.minsave_interval = 1;
} else if (strcmpi(w1, "save_settings") == 0)
save_settings = cap_value(atoi(w2),CHARSAVE_NONE,CHARSAVE_ALL);
map_config.save_settings = cap_value(atoi(w2),CHARSAVE_NONE,CHARSAVE_ALL);
else if (strcmpi(w1, "motd_txt") == 0)
strcpy(motd_txt, w2);
else if (strcmpi(w1, "help_txt") == 0)
strcpy(help_txt, w2);
else if (strcmpi(w1, "help2_txt") == 0)
strcpy(help2_txt, w2);
else if (strcmpi(w1, "charhelp_txt") == 0)
strcpy(charhelp_txt, w2);
StringBuf_PrintfClear(mapserv_file_config.motd, "%s", w2);
else if (strcmpi(w1, "group_conf_file") == 0)
StringBuf_PrintfClear(mapserv_file_config.group, "%s", w2);
else if (strcmpi(w1, "atcommand_conf_file") == 0)
StringBuf_PrintfClear(mapserv_file_config.atcommand, "%s", w2);
else if(strcmpi(w1,"db_path") == 0)
safestrncpy(db_path,w2,ARRAYLENGTH(db_path));
else if (strcmpi(w1, "console") == 0) {
console = config_switch(w2);
if (console)
map_config.console = config_switch(w2);
if (map_config.console)
ShowNotice("Console Commands are enabled.\n");
} else if (strcmpi(w1, "enable_spy") == 0)
enable_spy = config_switch(w2);
map_config.enable_spy = config_switch(w2);
else if (strcmpi(w1, "use_grf") == 0)
enable_grf = config_switch(w2);
map_config.enable_grf = config_switch(w2);
else if (strcmpi(w1, "console_msg_log") == 0)
console_msg_log = atoi(w2);//[Ind]
else if (strcmpi(w1, "console_log_filepath") == 0)
safestrncpy(console_log_filepath, w2, sizeof(console_log_filepath));
else if (strcmpi(w1,"check_tables") == 0)
map_config.check_tables = config_switch(w2);
else if (map_schema_read_conf(w1, w2))
continue;
else if (strcmpi(w1, "import") == 0)
map_config_read(w2);
else
@@ -3874,9 +3878,284 @@ void map_reloadnpc(bool clear)
#endif
}
int inter_config_read(char *cfgName)
/**
* Initialize default configurations
**/
static void map_inter_config_init(void) {
map_config.map_server_port = 3306;
map_config.map_server_ip = StringBuf_FromStr("127.0.0.1");
map_config.map_server_id = StringBuf_FromStr("ragnarok");
map_config.map_server_pw = StringBuf_FromStr("");
map_config.map_server_db = StringBuf_FromStr("ragnarok");
map_config.default_codepage = StringBuf_FromStr("");
map_config.log_db_port = 3306;
map_config.log_db_ip = StringBuf_FromStr("127.0.0.1");
map_config.log_db_id = StringBuf_FromStr("ragnarok");
map_config.log_db_pw = StringBuf_FromStr("");
map_config.log_db_db = StringBuf_FromStr("log");
safestrncpy(map_config.wisp_server_name, "Server", sizeof(map_config.wisp_server_name));
map_config.autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
map_config.minsave_interval = 100;
map_config.save_settings = CHARSAVE_ALL;
map_config.agit_flag = false;
map_config.agit2_flag = false;
map_config.night_flag = false;
map_config.console = false;
map_config.enable_spy = false;
map_config.enable_grf = false;
}
/**
* Finalize default configurations
**/
static void map_inter_config_final(void) {
StringBuf_Free(map_config.map_server_ip);
StringBuf_Free(map_config.map_server_id);
StringBuf_Free(map_config.map_server_pw);
StringBuf_Free(map_config.map_server_db);
StringBuf_Free(map_config.default_codepage);
StringBuf_Free(map_config.log_db_ip);
StringBuf_Free(map_config.log_db_id);
StringBuf_Free(map_config.log_db_pw);
StringBuf_Free(map_config.log_db_db);
}
/**
* Initialize default map-server tables
**/
static void map_schema_init(void) {
mapserv_schema_config.db_use_sqldbs = false;
mapserv_schema_config.buyingstores_table = StringBuf_FromStr("buyingstores");
mapserv_schema_config.buyingstore_items_table = StringBuf_FromStr("buyingstore_items");
mapserv_schema_config.item_db_table = StringBuf_FromStr("item_db");
mapserv_schema_config.item_db2_table = StringBuf_FromStr("item_db2");
mapserv_schema_config.item_db_re_table = StringBuf_FromStr("item_db_re");
mapserv_schema_config.item_cash_db_table = StringBuf_FromStr("item_cash_db");
mapserv_schema_config.item_cash_db2_table = StringBuf_FromStr("item_cash_db2");
mapserv_schema_config.mapreg_table = StringBuf_FromStr("mapreg");
mapserv_schema_config.market_table = StringBuf_FromStr("market");
mapserv_schema_config.mob_db_table = StringBuf_FromStr("mob_db");
mapserv_schema_config.mob_db_re_table = StringBuf_FromStr("mob_db_re");
mapserv_schema_config.mob_db2_table = StringBuf_FromStr("mob_db2");
mapserv_schema_config.mob_skill_db_table = StringBuf_FromStr("mob_skill_db");
mapserv_schema_config.mob_skill_db_re_table = StringBuf_FromStr("mob_skill_db_re");
mapserv_schema_config.mob_skill_db2_table = StringBuf_FromStr("mob_skill_db2");
mapserv_schema_config.roulette_table = StringBuf_FromStr("db_roulette");
mapserv_schema_config.vendings_table = StringBuf_FromStr("vendings");
mapserv_schema_config.vending_items_table = StringBuf_FromStr("vending_items");
}
/**
* Finalize map-server tables
**/
static void map_schema_final(void) {
StringBuf_Free(mapserv_schema_config.buyingstores_table);
StringBuf_Free(mapserv_schema_config.buyingstore_items_table);
StringBuf_Free(mapserv_schema_config.item_db_table);
StringBuf_Free(mapserv_schema_config.item_db2_table);
StringBuf_Free(mapserv_schema_config.item_db_re_table);
StringBuf_Free(mapserv_schema_config.item_cash_db_table);
StringBuf_Free(mapserv_schema_config.item_cash_db2_table);
StringBuf_Free(mapserv_schema_config.mapreg_table);
StringBuf_Free(mapserv_schema_config.market_table);
StringBuf_Free(mapserv_schema_config.mob_db_table);
StringBuf_Free(mapserv_schema_config.mob_db_re_table);
StringBuf_Free(mapserv_schema_config.mob_db2_table);
StringBuf_Free(mapserv_schema_config.mob_skill_db_table);
StringBuf_Free(mapserv_schema_config.mob_skill_db_re_table);
StringBuf_Free(mapserv_schema_config.mob_skill_db2_table);
StringBuf_Free(mapserv_schema_config.roulette_table);
StringBuf_Free(mapserv_schema_config.vendings_table);
StringBuf_Free(mapserv_schema_config.vending_items_table);
}
/**
* Initialize default map-server files
**/
static void map_file_init(void) {
mapserv_file_config.group = StringBuf_FromStr("conf/groups.conf");
mapserv_file_config.atcommand = StringBuf_FromStr("conf/atcommand_athena.conf");
mapserv_file_config.motd = StringBuf_FromStr("conf/motd.txt");
}
/**
* Finalize map-server files
**/
static void map_file_final(void) {
StringBuf_Free(mapserv_file_config.group);
StringBuf_Free(mapserv_file_config.atcommand);
StringBuf_Free(mapserv_file_config.motd);
}
/**
* Check all tables, check all fields are sitting
**/
static bool map_check_tables(void) {
uint16 i;
// These tables must be there
const char* sqltable[] = {
mapserv_table(buyingstores_table),
mapserv_table(buyingstore_items_table),
mapserv_table(mapreg_table),
mapserv_table(market_table),
mapserv_table(roulette_table),
mapserv_table(vendings_table),
mapserv_table(vending_items_table),
};
ShowInfo("Start checking DB integrity\n");
for (i = 0; i < ARRAYLENGTH(sqltable); i++) {
if (SQL_ERROR == Sql_Query(mmysql_handle, "SELECT * FROM `%s`;", sqltable[i])) {
Sql_ShowDebug(mmysql_handle);
return false;
}
}
// buyingstores
if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT `id`, `account_id`, `char_id`, `sex`, `map`, `x`, `y`, "
"`title`, `limit`, `body_direction`, `head_direction`, `sit`, `autotrade` "
"FROM `%s`;", mapserv_table(buyingstores_table)) )
{
Sql_ShowDebug(mmysql_handle);
return false;
}
// buyingstore_items
if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT `buyingstore_id`, `index`, `item_id`, `amount`, `price` "
"FROM `%s`;", mapserv_table(buyingstore_items_table)) )
{
Sql_ShowDebug(mmysql_handle);
return false;
}
// market
if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT `name`, `nameid`, `price`, `amount`, `flag` "
"FROM `%s`;", mapserv_table(market_table)) )
{
Sql_ShowDebug(mmysql_handle);
return false;
}
// roulette
if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT `index`, `level`, `item_id`, `amount`, `flag` "
"FROM `%s`;", mapserv_table(roulette_table)) )
{
Sql_ShowDebug(mmysql_handle);
return false;
}
// vendings
if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT `id`, `account_id`, `char_id`, `sex`, `map`, `x`, `y`, "
"`title`, `body_direction`, `head_direction`, `sit`, `autotrade` "
"FROM `%s`;", mapserv_table(vendings_table)) )
{
Sql_ShowDebug(mmysql_handle);
return false;
}
// vending_items
if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT `vending_id`, `index`, `cartinventory_id`, `amount`, `price` "
"FROM `%s`;", mapserv_table(vending_items_table)) )
{
Sql_ShowDebug(mmysql_handle);
return false;
}
// Depends on mapserv_schema_config.db_use_sqldbs
if (mapserv_schema_config.db_use_sqldbs) {
const char* sqltable2[] = {
#ifdef RENEWAL
mapserv_table(item_db_re_table),
#else
mapserv_table(item_db_table),
#endif
mapserv_table(item_db2_table),
mapserv_table(item_cash_db_table),
mapserv_table(item_cash_db2_table),
#ifdef RENEWAL
mapserv_table(mob_db_re_table),
#else
mapserv_table(mob_db_table),
#endif
mapserv_table(mob_db2_table),
#ifdef RENEWAL
mapserv_table(mob_skill_db_re_table),
#else
mapserv_table(mob_skill_db_table),
#endif
mapserv_table(mob_skill_db2_table),
};
for (i = 0; i < ARRAYLENGTH(sqltable2); i++) {
if (SQL_ERROR == Sql_Query(mmysql_handle, "SELECT * FROM `%s`;", sqltable2[i])) {
Sql_ShowDebug(mmysql_handle);
return false;
}
}
// item tables
for (i = 0; i < 2; i++) {
if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT `id`, `name_english`, `name_japanese`, `type`, `price_buy`, `price_sell`, "
"`weight`, "/*`attack`, */"`defense`, `range`, `slots`, `equip_jobs`, `equip_upper`, `equip_genders`, `equip_locations`, "
"`weapon_level`, `equip_level`, `refineable`, `view`, `script`, `equip_script`, `unequip_script` "
"FROM `%s`;", sqltable2[i]) )
{
Sql_ShowDebug(mmysql_handle);
return false;
}
}
// cash tables
for (i = 2; i < 4; i++) {
if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT `tab`, `item_id`, `price` "
"FROM `%s`;", sqltable2[i]) )
{
Sql_ShowDebug(mmysql_handle);
return false;
}
}
// mob tables
for (i = 4; i < 6; i++) {
if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT `ID`, `Sprite`, `kName`, `iName`, `LV`, `HP`, `SP`, `EXP`, `JEXP`, `Range1`, "
"`ATK1`, `ATK2`, `DEF`, `MDEF`, `STR`, `AGI`, `VIT`, `INT`, `DEX`, `LUK`, `Range2`, `Range3`, `Scale`, `Race`, `Element`, "
"`Mode`, `Speed`, `aDelay`, `aMotion`, `dMotion`, `MEXP`, `MVP1id`, `MVP1per`, `MVP2id`, `MVP2per`, `MVP3id`, `MVP3per`, "
"`Drop1id`, `Drop1per`, `Drop2id`, `Drop2per`, `Drop3id`, `Drop3per`, `Drop4id`, `Drop4per`, `Drop5id`, `Drop5per`, `Drop6id`, "
"`Drop6per`, `Drop7id`, `Drop7per`, `Drop8id`, `Drop8per`, `Drop9id`, `Drop9per`, `DropCardid`, `DropCardper` "
"FROM `%s`;", sqltable2[i]) )
{
Sql_ShowDebug(mmysql_handle);
return false;
}
}
// mob skill tables
for (i = 6; i < 8; i++) {
if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT `MOB_ID`, `INFO`, `STATE`, `SKILL_ID`, `SKILL_LV`, `RATE`, `CASTTIME`, "
"`DELAY`, `CANCELABLE`, `TARGET`, `CONDITION`, `CONDITION_VALUE`, `VAL1`, `VAL2`, `VAL3`, `VAL4`, `VAL5`, "
"`EMOTION`, `CHAT` "
"FROM `%s`;", sqltable2[i]) )
{
Sql_ShowDebug(mmysql_handle);
return false;
}
}
}
return true;
}
int map_inter_config_read(char *cfgName)
{
char line[1024],w1[1024],w2[1024];
char line[1024];
FILE *fp;
fp=fopen(cfgName,"r");
@@ -3886,90 +4165,38 @@ int inter_config_read(char *cfgName)
}
while(fgets(line, sizeof(line), fp))
{
char w1[32],w2[32];
if(line[0] == '/' && line[1] == '/')
continue;
if( sscanf(line,"%1023[^:]: %1023[^\r\n]",w1,w2) < 2 )
if( sscanf(line,"%31[^:]: %31[^\r\n]",w1,w2) < 2 )
continue;
if( strcmpi( w1, "buyingstore_db" ) == 0 )
strcpy( buyingstores_db, w2 );
else if( strcmpi( w1, "buyingstore_items_db" ) == 0 )
strcpy( buyingstore_items_db, w2 );
else if(strcmpi(w1,"item_db_db")==0)
strcpy(item_db_db,w2);
else if(strcmpi(w1,"item_db2_db")==0)
strcpy(item_db2_db,w2);
else if(strcmpi(w1,"item_db_re_db")==0)
strcpy(item_db_re_db,w2);
else if(strcmpi(w1,"mob_db_db")==0)
strcpy(mob_db_db,w2);
else if(strcmpi(w1,"mob_db_re_db")==0)
strcpy(mob_db_re_db,w2);
else if(strcmpi(w1,"mob_db2_db")==0)
strcpy(mob_db2_db,w2);
else if(strcmpi(w1,"mob_skill_db_db")==0)
strcpy(mob_skill_db_db,w2);
else if(strcmpi(w1,"mob_skill_db_re_db")==0)
strcpy(mob_skill_db_re_db,w2);
else if(strcmpi(w1,"mob_skill_db2_db")==0)
strcpy(mob_skill_db2_db,w2);
else if( strcmpi( w1, "item_cash_db_db" ) == 0 )
strcpy( item_cash_db_db, w2 );
else if( strcmpi( w1, "item_cash_db2_db" ) == 0 )
strcpy( item_cash_db2_db, w2 );
else if( strcmpi( w1, "vending_db" ) == 0 )
strcpy( vendings_db, w2 );
else if( strcmpi( w1, "vending_items_db" ) == 0 )
strcpy(vending_items_db, w2);
else if( strcmpi(w1, "db_roulette_table") == 0)
strcpy(db_roulette_table, w2);
else if (strcmpi(w1, "market_table") == 0)
strcpy(market_table, w2);
else
//Map Server SQL DB
if(strcmpi(w1,"map_server_ip")==0)
strcpy(map_server_ip, w2);
else
if(strcmpi(w1,"map_server_port")==0)
map_server_port=atoi(w2);
else
if(strcmpi(w1,"map_server_id")==0)
strcpy(map_server_id, w2);
else
if(strcmpi(w1,"map_server_pw")==0)
strcpy(map_server_pw, w2);
else
if(strcmpi(w1,"map_server_db")==0)
strcpy(map_server_db, w2);
else
if(strcmpi(w1,"default_codepage")==0)
strcpy(default_codepage, w2);
else
if(strcmpi(w1,"use_sql_db")==0) {
db_use_sqldbs = config_switch(w2);
ShowStatus ("Using SQL dbs: %s\n",w2);
} else
if(strcmpi(w1,"log_db_ip")==0)
strcpy(log_db_ip, w2);
else
if(strcmpi(w1,"log_db_id")==0)
strcpy(log_db_id, w2);
else
if(strcmpi(w1,"log_db_pw")==0)
strcpy(log_db_pw, w2);
else
if(strcmpi(w1,"log_db_port")==0)
log_db_port = atoi(w2);
else
if(strcmpi(w1,"log_db_db")==0)
strcpy(log_db_db, w2);
else
if( mapreg_config_read(w1,w2) )
continue;
else if(strcmpi(w1,"map_server_ip")==0)
StringBuf_PrintfClear(map_config.map_server_ip, w2);
else if(strcmpi(w1,"map_server_port")==0)
map_config.map_server_port = atoi(w2);
else if(strcmpi(w1,"map_server_id")==0)
StringBuf_PrintfClear(map_config.map_server_id, w2);
else if(strcmpi(w1,"map_server_pw")==0)
StringBuf_PrintfClear(map_config.map_server_pw, w2);
else if(strcmpi(w1,"map_server_db")==0)
StringBuf_PrintfClear(map_config.map_server_db, w2);
else if(strcmpi(w1,"default_codepage")==0)
StringBuf_PrintfClear(map_config.default_codepage, w2);
else if(strcmpi(w1,"log_db_ip")==0)
StringBuf_PrintfClear(map_config.log_db_ip, w2);
else if(strcmpi(w1,"log_db_id")==0)
StringBuf_PrintfClear(map_config.log_db_id, w2);
else if(strcmpi(w1,"log_db_pw")==0)
StringBuf_PrintfClear(map_config.log_db_pw, w2);
else if(strcmpi(w1,"log_db_port")==0)
map_config.log_db_port = atoi(w2);
else if(strcmpi(w1,"log_db_db")==0)
StringBuf_PrintfClear(map_config.log_db_db, w2);
//support the import command, just like any other config
else
if(strcmpi(w1,"import")==0)
inter_config_read(w2);
else if(strcmpi(w1,"import")==0)
map_inter_config_read(w2);
}
fclose(fp);
@@ -3986,11 +4213,11 @@ int map_sql_init(void)
qsmysql_handle = Sql_Malloc();
ShowInfo("Connecting to the Map DB Server....\n");
if( SQL_ERROR == Sql_Connect(mmysql_handle, map_server_id, map_server_pw, map_server_ip, map_server_port, map_server_db) ||
SQL_ERROR == Sql_Connect(qsmysql_handle, map_server_id, map_server_pw, map_server_ip, map_server_port, map_server_db) )
if( SQL_ERROR == Sql_Connect(mmysql_handle, map_server_id(), map_server_pw(), map_server_ip(), map_server_port(), map_server_db()) ||
SQL_ERROR == Sql_Connect(qsmysql_handle, map_server_id(), map_server_pw(), map_server_ip(), map_server_port(), map_server_db()) )
{
ShowError("Couldn't connect with uname='%s',passwd='%s',host='%s',port='%d',database='%s'\n",
map_server_id, map_server_pw, map_server_ip, map_server_port, map_server_db);
map_server_id(), map_server_pw(), map_server_ip(), map_server_port(), map_server_db());
Sql_ShowDebug(mmysql_handle);
Sql_Free(mmysql_handle);
Sql_ShowDebug(qsmysql_handle);
@@ -3999,12 +4226,19 @@ int map_sql_init(void)
}
ShowStatus("Connect success! (Map Server Connection)\n");
if( strlen(default_codepage) > 0 ) {
if ( SQL_ERROR == Sql_SetEncoding(mmysql_handle, default_codepage) )
if( map_server_codepage_len() > 0 ) {
if ( SQL_ERROR == Sql_SetEncoding(mmysql_handle, map_server_codepage()) )
Sql_ShowDebug(mmysql_handle);
if ( SQL_ERROR == Sql_SetEncoding(qsmysql_handle, default_codepage) )
if ( SQL_ERROR == Sql_SetEncoding(qsmysql_handle, map_server_codepage()) )
Sql_ShowDebug(qsmysql_handle);
}
if (map_config.check_tables && !map_check_tables()) {
ShowFatalError("map-server: A table is missing from the sql-server, please fix it, see (sql-files/main.sql or sql-files/logs.sql for structure) \n");
exit(EXIT_FAILURE);
}
ShowStatus("Map server connection: Database '"CL_WHITE"%s"CL_RESET"' at '"CL_WHITE"%s"CL_RESET"'\n", map_server_db(), map_server_ip());
return 0;
}
@@ -4032,19 +4266,25 @@ int log_sql_init(void)
// log db connection
logmysql_handle = Sql_Malloc();
ShowInfo(""CL_WHITE"[SQL]"CL_RESET": Connecting to the Log Database "CL_WHITE"%s"CL_RESET" At "CL_WHITE"%s"CL_RESET"...\n",log_db_db,log_db_ip);
if ( SQL_ERROR == Sql_Connect(logmysql_handle, log_db_id, log_db_pw, log_db_ip, log_db_port, log_db_db) ){
ShowInfo(""CL_WHITE"[SQL]"CL_RESET": Connecting to the Log Database "CL_WHITE"%s"CL_RESET" At "CL_WHITE"%s"CL_RESET"...\n", log_db_db(), log_db_ip());
if ( SQL_ERROR == Sql_Connect(logmysql_handle, log_db_id(), log_db_pw(), log_db_ip(), log_db_port(), log_db_db()) ){
ShowError("Couldn't connect with uname='%s',passwd='%s',host='%s',port='%d',database='%s'\n",
log_db_id, log_db_pw, log_db_ip, log_db_port, log_db_db);
log_db_id(), log_db_pw(), log_db_ip(), log_db_port(), log_db_db());
Sql_ShowDebug(logmysql_handle);
Sql_Free(logmysql_handle);
exit(EXIT_FAILURE);
}
ShowStatus(""CL_WHITE"[SQL]"CL_RESET": Successfully '"CL_GREEN"connected"CL_RESET"' to Database '"CL_WHITE"%s"CL_RESET"'.\n", log_db_db);
if( strlen(default_codepage) > 0 )
if ( SQL_ERROR == Sql_SetEncoding(logmysql_handle, default_codepage) )
if( map_server_codepage_len() > 0 )
if ( SQL_ERROR == Sql_SetEncoding(logmysql_handle, map_server_codepage()) )
Sql_ShowDebug(logmysql_handle);
ShowStatus(""CL_WHITE"[SQL]"CL_RESET": Successfully '"CL_GREEN"connected"CL_RESET"' to Log Database '"CL_WHITE"%s"CL_RESET"'.\n", log_db_db());
if (!log_check_tables()) {
ShowFatalError("map-server (log): A table is missing from the sql-server, please fix it, see (sql-files/logs.sql for structure) \n");
exit(EXIT_FAILURE);
}
#endif
return 0;
}
@@ -4360,7 +4600,7 @@ void do_final(void)
}
mapindex_final();
if(enable_grf)
if(map_config.enable_grf)
grfio_final();
id_db->destroy(id_db, NULL);
@@ -4376,6 +4616,10 @@ void do_final(void)
ers_destroy(map_skill_damage_ers);
#endif
map_inter_config_final();
map_schema_final();
map_file_final();
log_config_final();
map_sql_close();
ShowStatus("Finished.\n");
@@ -4554,7 +4798,6 @@ int do_init(int argc, char *argv[])
LOG_CONF_NAME="conf/log_athena.conf";
MAP_CONF_NAME = "conf/map_athena.conf";
BATTLE_CONF_FILENAME = "conf/battle_athena.conf";
ATCOMMAND_CONF_FILENAME = "conf/atcommand_athena.conf";
SCRIPT_CONF_NAME = "conf/script_athena.conf";
GRF_PATH_FILENAME = "conf/grf-files.txt";
safestrncpy(console_log_filepath, "./log/map-msg_log.log", sizeof(console_log_filepath));
@@ -4580,6 +4823,11 @@ int do_init(int argc, char *argv[])
cli_get_options(argc,argv);
rnd_init();
map_inter_config_init();
map_schema_init();
map_file_init();
log_config_init();
map_config_read(MAP_CONF_NAME);
// loads npcs
@@ -4608,8 +4856,10 @@ int do_init(int argc, char *argv[])
battle_config_read(BATTLE_CONF_FILENAME);
script_config_read(SCRIPT_CONF_NAME);
inter_config_read(INTER_CONF_NAME);
map_inter_config_read(INTER_CONF_NAME);
log_config_read(LOG_CONF_NAME);
log_config_read_done();
id_db = idb_alloc(DB_OPT_BASE);
pc_db = idb_alloc(DB_OPT_BASE); //Added for reliable map_id2sd() use. [Skotlex]
@@ -4630,7 +4880,7 @@ int do_init(int argc, char *argv[])
log_sql_init();
mapindex_init();
if(enable_grf)
if(map_config.enable_grf)
grfio_init(GRF_PATH_FILENAME);
map_readallmaps();
@@ -4686,7 +4936,7 @@ int do_init(int argc, char *argv[])
exit(EXIT_FAILURE);
#endif
if( console ){ //start listening
if( map_config.console ){ //start listening
add_timer_func_list(parse_console_timer, "parse_console_timer");
add_timer_interval(gettick()+1000, parse_console_timer, 0, 0, 1000); //start in 1s each 1sec
}

View File

@@ -10,6 +10,7 @@
#include "../common/mapindex.h"
#include "../common/db.h"
#include "../common/msg_conf.h"
#include "../common/strlib.h"
#include "../config/core.h"
@@ -51,6 +52,102 @@ void map_msg_reload(void);
#define MAX_VENDING 12
#define MAX_MAP_SIZE 512*512 // Wasn't there something like this already? Can't find it.. [Shinryo]
struct MapServer_Schema {
bool db_use_sqldbs;
StringBuf *buyingstores_table; ///< Buyingstore table (buyer & autotrader)
StringBuf *buyingstore_items_table; ///< Buyingstore items table (buyer & autotrader)
StringBuf *item_cash_db_table; ///< Item cash table
StringBuf *item_cash_db2_table; ///< Item cash table
StringBuf *item_db_table; ///< Item DB table
StringBuf *item_db2_table; ///< Item DB table
StringBuf *item_db_re_table; ///< Item DB table
StringBuf *mapreg_table; ///< Mapreg table, used in mapreg.c
StringBuf *market_table; ///< Market table
StringBuf *mob_db_table; ///< Mob DB table
StringBuf *mob_db_re_table; ///< Mob DB table
StringBuf *mob_db2_table; ///< Mob DB table
StringBuf *mob_skill_db_table; ///< Mob Skill table
StringBuf *mob_skill_db_re_table; ///< Mob Skill table
StringBuf *mob_skill_db2_table; ///< Mob Skill table
StringBuf *roulette_table; ///< Roulette table
StringBuf *vendings_table; ///< Vending table (vendor & autotrader)
StringBuf *vending_items_table; ///< Vending items table (vendor & autotrader)
};
extern struct MapServer_Schema mapserv_schema_config; /// map-server tables
/// Get map-server table value. Table names @see MapServer_Schema
#define mapserv_table(table) ( StringBuf_Value(mapserv_schema_config.table) )
struct MapServer_File {
StringBuf *group; ///< Prefered file for groups.conf
StringBuf *atcommand; ///< Prefered file for atcommand_athena.conf
StringBuf *motd; ///< Prefered file for motd
};
extern struct MapServer_File mapserv_file_config;
/// Get file name
#define mapserv_file(filename) ( StringBuf_Value(mapserv_file_config.filename) )
struct Map_Config {
// Map-server
uint16 map_server_port;
StringBuf *map_server_ip;
StringBuf *map_server_id;
StringBuf *map_server_pw;
StringBuf *map_server_db;
StringBuf *default_codepage;
// Log Database
uint16 log_db_port;
StringBuf *log_db_ip;
StringBuf *log_db_id;
StringBuf *log_db_pw;
StringBuf *log_db_db;
char wisp_server_name[NAME_LENGTH]; // can be modified in char-server configuration file
uint32 autosave_interval;
uint32 minsave_interval;
uint8 save_settings;
bool agit_flag;
bool agit2_flag;
bool night_flag; // False = day, True = night [Yor]
bool console;
bool enable_spy; //To enable/disable @spy commands, which consume too much cpu time when sending packets. [Skotlex]
bool enable_grf; //To enable/disable reading maps from GRF files, bypassing mapcache [blackhole89]
bool check_tables;
};
extern struct Map_Config map_config;
/// Getter of map_server_port
#define map_server_port() ( map_config.map_server_port )
/// Getter of map_server_ip Hostname
#define map_server_ip() ( StringBuf_Value(map_config.map_server_ip) )
/// Getter of map_server_id Username
#define map_server_id() ( StringBuf_Value(map_config.map_server_id) )
/// Getter of map_server_pw Password
#define map_server_pw() ( StringBuf_Value(map_config.map_server_pw) )
/// Getter of map_server_db Database
#define map_server_db() ( StringBuf_Value(map_config.map_server_db) )
/// Getter of map's default_codepage
#define map_server_codepage() ( StringBuf_Value(map_config.default_codepage) )
/// Get map's default_codepage length
#define map_server_codepage_len() ( StringBuf_Length(map_config.default_codepage) )
/// Getter of log_db_port
#define log_db_port() ( map_config.log_db_port )
/// Getter of log_db_ip Hostname
#define log_db_ip() ( StringBuf_Value(map_config.log_db_ip) )
/// Getter of log_db_id Username
#define log_db_id() ( StringBuf_Value(map_config.log_db_id) )
/// Getter of log_db_pw Password
#define log_db_pw() ( StringBuf_Value(map_config.log_db_pw) )
/// Getter of log_db_db Database
#define log_db_db() ( StringBuf_Value(map_config.log_db_db) )
/** Added definitions for WoESE objects and other [L0ne_W0lf], [aleos] */
enum MOBID {
MOBID_PORING = 1002,
@@ -273,9 +370,9 @@ enum e_mapid {
#define DEFAULT_AUTOSAVE_INTERVAL 5*60*1000
//Specifies maps where players may hit each other
#define map_flag_vs(m) (map[m].flag.pvp || map[m].flag.gvg_dungeon || map[m].flag.gvg || ((agit_flag || agit2_flag) && map[m].flag.gvg_castle) || map[m].flag.battleground)
#define map_flag_vs(m) (map[m].flag.pvp || map[m].flag.gvg_dungeon || map[m].flag.gvg || ((map_config.agit_flag || map_config.agit2_flag) && map[m].flag.gvg_castle) || map[m].flag.battleground)
//Specifies maps that have special GvG/WoE restrictions
#define map_flag_gvg(m) (map[m].flag.gvg || ((agit_flag || agit2_flag) && map[m].flag.gvg_castle))
#define map_flag_gvg(m) (map[m].flag.gvg || ((map_config.agit_flag || map_config.agit2_flag) && map[m].flag.gvg_castle))
//Specifies if the map is tagged as GvG/WoE (regardless of agit_flag status)
#define map_flag_gvg2(m) (map[m].flag.gvg || map[m].flag.gvg_castle)
// No Kill Steal Protection
@@ -771,26 +868,6 @@ void map_setgatcell(int16 m, int16 x, int16 y, int gat);
extern struct map_data map[];
extern int map_num;
extern int autosave_interval;
extern int minsave_interval;
extern unsigned char save_settings;
extern int agit_flag;
extern int agit2_flag;
extern int night_flag; // 0=day, 1=night [Yor]
extern int enable_spy; //Determines if @spy commands are active.
extern char motd_txt[];
extern char help_txt[];
extern char help2_txt[];
extern char charhelp_txt[];
extern char wisp_server_name[];
struct s_map_default {
char mapname[MAP_NAME_LENGTH];
unsigned short x;
unsigned short y;
};
extern struct s_map_default map_default;
/// Type of 'save_settings'
@@ -983,48 +1060,12 @@ typedef struct elemental_data TBL_ELEM;
#define BL_CAST(type_, bl) \
( ((bl) == (struct block_list*)NULL || (bl)->type != (type_)) ? (T ## type_ *)NULL : (T ## type_ *)(bl) )
#ifdef BETA_THREAD_TEST
extern char default_codepage[32];
extern int map_server_port;
extern char map_server_ip[32];
extern char map_server_id[32];
extern char map_server_pw[32];
extern char map_server_db[32];
extern char log_db_ip[32];
extern int log_db_port;
extern char log_db_id[32];
extern char log_db_pw[32];
extern char log_db_db[32];
#endif
#include "../common/sql.h"
extern int db_use_sqldbs;
extern Sql* mmysql_handle;
extern Sql* qsmysql_handle;
extern Sql* logmysql_handle;
extern char buyingstores_db[32];
extern char buyingstore_items_db[32];
extern char item_db_db[32];
extern char item_db2_db[32];
extern char item_db_re_db[32];
extern char mob_db_db[32];
extern char mob_db_re_db[32];
extern char mob_db2_db[32];
extern char mob_skill_db_db[32];
extern char mob_skill_db_re_db[32];
extern char mob_skill_db2_db[32];
extern char vendings_db[32];
extern char vending_items_db[32];
extern char market_table[32];
extern char db_roulette_table[32];
void do_shutdown(void);
#endif /* _MAP_H_ */

View File

@@ -4017,11 +4017,12 @@ static int mob_read_sqldb(void)
{
const char* mob_db_name[] = {
#ifndef RENEWAL
mob_db_db,
mapserv_table(mob_db_table),
#else
mob_db_re_db,
mapserv_table(mob_db_re_table),
#endif
mob_db2_db };
mapserv_table(mob_db2_table)
};
int fi;
for( fi = 0; fi < ARRAYLENGTH(mob_db_name); ++fi ) {
@@ -4531,11 +4532,12 @@ static int mob_read_sqlskilldb(void)
{
const char* mob_skill_db_name[] = {
#ifndef RENEWAL
mob_skill_db_db,
mapserv_table(mob_skill_db_table),
#else
mob_skill_db_re_db,
mapserv_table(mob_skill_db_re_table),
#endif
mob_skill_db2_db };
mapserv_table(mob_skill_db2_table)
};
int fi;
if( battle_config.mob_skill_rate == 0 ) {
@@ -4939,7 +4941,7 @@ static void mob_load(void)
safesnprintf(dbsubpath2,n1,"%s%s",db_path,dbsubpath[i]);
}
if (db_use_sqldbs && i==0) //only read once for sql
if (mapserv_schema_config.db_use_sqldbs && i==0) //only read once for sql
{
mob_read_sqldb();
mob_read_sqlskilldb();

View File

@@ -10106,9 +10106,9 @@ static int pc_autosave(int tid, unsigned int tick, int id, intptr_t data)
}
mapit_free(iter);
interval = autosave_interval/(map_usercount()+1);
if(interval < minsave_interval)
interval = minsave_interval;
interval = map_config.autosave_interval/(map_usercount()+1);
if(interval < map_config.minsave_interval)
interval = map_config.minsave_interval;
add_timer(gettick()+interval,pc_autosave,0,0);
return 0;
@@ -10116,10 +10116,10 @@ static int pc_autosave(int tid, unsigned int tick, int id, intptr_t data)
static int pc_daynight_timer_sub(struct map_session_data *sd,va_list ap)
{
if (sd->state.night != night_flag && map[sd->bl.m].flag.nightenabled)
if (sd->state.night != map_config.night_flag && map[sd->bl.m].flag.nightenabled)
{ //Night/day state does not match.
clif_status_load(&sd->bl, SI_NIGHT, night_flag); //New night effect by dynamix [Skotlex]
sd->state.night = night_flag;
clif_status_load(&sd->bl, SI_NIGHT, map_config.night_flag); //New night effect by dynamix [Skotlex]
sd->state.night = map_config.night_flag;
return 1;
}
return 0;
@@ -10135,10 +10135,10 @@ int map_day_timer(int tid, unsigned int tick, int id, intptr_t data)
if (data == 0 && battle_config.day_duration <= 0) // if we want a day
return 0;
if (!night_flag)
if (!map_config.night_flag)
return 0; //Already day.
night_flag = 0; // 0=day, 1=night [Yor]
map_config.night_flag = 0; // 0=day, 1=night [Yor]
map_foreachpc(pc_daynight_timer_sub);
strcpy(tmp_soutput, (data == 0) ? msg_txt(NULL,502) : msg_txt(NULL,60)); // The day has arrived!
intif_broadcast(tmp_soutput, strlen(tmp_soutput) + 1, BC_DEFAULT);
@@ -10156,10 +10156,10 @@ int map_night_timer(int tid, unsigned int tick, int id, intptr_t data)
if (data == 0 && battle_config.night_duration <= 0) // if we want a night
return 0;
if (night_flag)
if (map_config.night_flag)
return 0; //Already nigth.
night_flag = 1; // 0=day, 1=night [Yor]
map_config.night_flag = 1; // 0=day, 1=night [Yor]
map_foreachpc(pc_daynight_timer_sub);
strcpy(tmp_soutput, (data == 0) ? msg_txt(NULL,503) : msg_txt(NULL,59)); // The night has fallen...
intif_broadcast(tmp_soutput, strlen(tmp_soutput) + 1, BC_DEFAULT);
@@ -10987,11 +10987,12 @@ void pc_readdb(void) {
int pc_read_motd(void)
{
FILE* fp;
const char *motd_file = mapserv_file(motd);
// clear old MOTD
memset(motd_text, 0, sizeof(motd_text));
// read current MOTD
if( ( fp = fopen(motd_txt, "r") ) != NULL )
if( ( fp = fopen(motd_file, "r") ) != NULL )
{
unsigned int entries = 0;
@@ -11010,7 +11011,7 @@ int pc_read_motd(void)
char * ptr;
buf[len] = 0;
if( ( ptr = strstr(buf, " :") ) != NULL && ptr-buf >= NAME_LENGTH ) // crashes newer clients
ShowWarning("Found sequence '"CL_WHITE" :"CL_RESET"' on line '"CL_WHITE"%u"CL_RESET"' in '"CL_WHITE"%s"CL_RESET"'. This can cause newer clients to crash.\n", lines, motd_txt);
ShowWarning("Found sequence '"CL_WHITE" :"CL_RESET"' on line '"CL_WHITE"%u"CL_RESET"' in '"CL_WHITE"%s"CL_RESET"'. This can cause newer clients to crash.\n", lines, motd_file);
}
else {// empty line
buf[0] = ' ';
@@ -11019,10 +11020,10 @@ int pc_read_motd(void)
entries++;
}
fclose(fp);
ShowStatus("Done reading '"CL_WHITE"%u"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, motd_txt);
ShowStatus("Done reading '"CL_WHITE"%u"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, motd_file);
}
else
ShowWarning("File '"CL_WHITE"%s"CL_RESET"' not found.\n", motd_txt);
ShowWarning("File '"CL_WHITE"%s"CL_RESET"' not found.\n", motd_file);
return 0;
}
@@ -11228,7 +11229,7 @@ void pc_check_expiration(struct map_session_data *sd) {
char tmpstr[1024];
strftime(tmpstr,sizeof(tmpstr) - 1,msg_txt(sd,501),localtime(&exp_time)); // "Your account time limit is: %d-%m-%Y %H:%M:%S."
clif_wis_message(sd->fd,wisp_server_name,tmpstr,strlen(tmpstr) + 1);
clif_wis_message(sd->fd,map_config.wisp_server_name,tmpstr,strlen(tmpstr) + 1);
pc_expire_check(sd);
}
@@ -11324,7 +11325,7 @@ enum e_BANKING_DEPOSIT_ACK pc_bank_deposit(struct map_session_data *sd, int mone
sd->bank_vault += money;
pc_setreg2(sd, BANK_VAULT_VAR, sd->bank_vault);
if( save_settings&CHARSAVE_BANK )
if( map_config.save_settings&CHARSAVE_BANK )
chrif_save(sd,0);
return BDA_SUCCESS;
}
@@ -11352,7 +11353,7 @@ enum e_BANKING_WITHDRAW_ACK pc_bank_withdraw(struct map_session_data *sd, int mo
sd->bank_vault -= money;
pc_setreg2(sd, BANK_VAULT_VAR, sd->bank_vault);
if( save_settings&CHARSAVE_BANK )
if( map_config.save_settings&CHARSAVE_BANK )
chrif_save(sd,0);
return BWA_SUCCESS;
}
@@ -11927,10 +11928,10 @@ void do_init_pc(void) {
add_timer_func_list(pc_expiration_timer, "pc_expiration_timer");
add_timer_func_list(pc_autotrade_timer, "pc_autotrade_timer");
add_timer(gettick() + autosave_interval, pc_autosave, 0, 0);
add_timer(gettick() + map_config.autosave_interval, pc_autosave, 0, 0);
// 0=day, 1=night [Yor]
night_flag = battle_config.night_at_start ? 1 : 0;
map_config.night_flag = battle_config.night_at_start ? 1 : 0;
if (battle_config.day_duration > 0 && battle_config.night_duration > 0) {
int day_duration = battle_config.day_duration;
@@ -11939,8 +11940,8 @@ void do_init_pc(void) {
add_timer_func_list(map_day_timer, "map_day_timer");
add_timer_func_list(map_night_timer, "map_night_timer");
day_timer_tid = add_timer_interval(gettick() + (night_flag ? 0 : day_duration) + night_duration, map_day_timer, 0, 0, day_duration + night_duration);
night_timer_tid = add_timer_interval(gettick() + day_duration + (night_flag ? night_duration : 0), map_night_timer, 0, 0, day_duration + night_duration);
day_timer_tid = add_timer_interval(gettick() + (map_config.night_flag ? 0 : day_duration) + night_duration, map_day_timer, 0, 0, day_duration + night_duration);
night_timer_tid = add_timer_interval(gettick() + day_duration + (map_config.night_flag ? night_duration : 0), map_night_timer, 0, 0, day_duration + night_duration);
}
do_init_pc_groups();

View File

@@ -510,7 +510,7 @@ int pet_birth_process(struct map_session_data *sd, struct s_pet *pet)
intif_save_petdata(sd->status.account_id,pet);
if (save_settings&CHARSAVE_PET)
if (map_config.save_settings&CHARSAVE_PET)
chrif_save(sd,0); //is it REALLY Needed to save the char for hatching a pet? [Skotlex]
if(sd->bl.prev != NULL) {

View File

@@ -106,7 +106,7 @@ int quest_add(TBL_PC *sd, int quest_id)
clif_quest_add(sd, &sd->quest_log[n]);
clif_quest_update_objective(sd, &sd->quest_log[n], 0);
if( save_settings&CHARSAVE_QUEST )
if( map_config.save_settings&CHARSAVE_QUEST )
chrif_save(sd,0);
return 0;
@@ -159,7 +159,7 @@ int quest_change(TBL_PC *sd, int qid1, int qid2)
clif_quest_add(sd, &sd->quest_log[i]);
clif_quest_update_objective(sd, &sd->quest_log[i], 0);
if( save_settings&CHARSAVE_QUEST )
if( map_config.save_settings&CHARSAVE_QUEST )
chrif_save(sd,0);
return 0;
@@ -198,7 +198,7 @@ int quest_delete(TBL_PC *sd, int quest_id)
clif_quest_delete(sd, quest_id);
if( save_settings&CHARSAVE_QUEST )
if( map_config.save_settings&CHARSAVE_QUEST )
chrif_save(sd,0);
return 0;
@@ -326,7 +326,7 @@ int quest_update_status(TBL_PC *sd, int quest_id, enum quest_state status)
clif_quest_delete(sd, quest_id);
if( save_settings&CHARSAVE_QUEST )
if( map_config.save_settings&CHARSAVE_QUEST )
chrif_save(sd,0);
return 0;

View File

@@ -4458,31 +4458,31 @@ static void *queryThread_main(void *x) {
Sql *queryThread_handle = Sql_Malloc();
int i;
if ( SQL_ERROR == Sql_Connect(queryThread_handle, map_server_id, map_server_pw, map_server_ip, map_server_port, map_server_db) ){
if ( SQL_ERROR == Sql_Connect(queryThread_handle, map_server_id(), map_server_pw(), map_server_ip(), map_server_port(), map_server_db()) ){
ShowError("Couldn't connect with uname='%s',passwd='%s',host='%s',port='%d',database='%s'\n",
map_server_id, map_server_pw, map_server_ip, map_server_port, map_server_db);
map_server_id(), map_server_pw(), map_server_ip(), map_server_port(), map_server_db());
Sql_ShowDebug(queryThread_handle);
Sql_Free(queryThread_handle);
exit(EXIT_FAILURE);
}
if( strlen(default_codepage) > 0 )
if ( SQL_ERROR == Sql_SetEncoding(queryThread_handle, default_codepage) )
if( map_server_codepage_len() > 0 )
if ( SQL_ERROR == Sql_SetEncoding(queryThread_handle, map_server_codepage()) )
Sql_ShowDebug(queryThread_handle);
if( log_config.sql_logs ) {
logmysql_handle = Sql_Malloc();
if ( SQL_ERROR == Sql_Connect(logmysql_handle, log_db_id, log_db_pw, log_db_ip, log_db_port, log_db_db) ){
if ( SQL_ERROR == Sql_Connect(logmysql_handle, log_db_id(), log_db_pw(), log_db_ip(), log_db_port(), log_db_db()) ){
ShowError("Couldn't connect with uname='%s',passwd='%s',host='%s',port='%d',database='%s'\n",
log_db_id, log_db_pw, log_db_ip, log_db_port, log_db_db);
log_db_id(), log_db_pw(), log_db_ip(), log_db_port(), log_db_db());
Sql_ShowDebug(logmysql_handle);
Sql_Free(logmysql_handle);
exit(EXIT_FAILURE);
}
if( strlen(default_codepage) > 0 )
if ( SQL_ERROR == Sql_SetEncoding(logmysql_handle, default_codepage) )
if( map_server_codepage_len() > 0 )
if ( SQL_ERROR == Sql_SetEncoding(logmysql_handle, map_server_codepage()) )
Sql_ShowDebug(logmysql_handle);
}
@@ -12247,32 +12247,36 @@ BUILDIN_FUNC(maprespawnguildid)
BUILDIN_FUNC(agitstart)
{
if(agit_flag==1) return SCRIPT_CMD_SUCCESS; // Agit already Start.
agit_flag=1;
if (map_config.agit_flag)
return SCRIPT_CMD_SUCCESS; // Agit already Start.
map_config.agit_flag = true;
guild_agit_start();
return SCRIPT_CMD_SUCCESS;
}
BUILDIN_FUNC(agitend)
{
if(agit_flag==0) return SCRIPT_CMD_SUCCESS; // Agit already End.
agit_flag=0;
if (!map_config.agit_flag)
return SCRIPT_CMD_SUCCESS; // Agit already End.
map_config.agit_flag = false;
guild_agit_end();
return SCRIPT_CMD_SUCCESS;
}
BUILDIN_FUNC(agitstart2)
{
if(agit2_flag==1) return SCRIPT_CMD_SUCCESS; // Agit2 already Start.
agit2_flag=1;
if (map_config.agit2_flag)
return SCRIPT_CMD_SUCCESS; // Agit2 already Start.
map_config.agit2_flag = true;
guild_agit2_start();
return SCRIPT_CMD_SUCCESS;
}
BUILDIN_FUNC(agitend2)
{
if(agit2_flag==0) return SCRIPT_CMD_SUCCESS; // Agit2 already End.
agit2_flag=0;
if (!map_config.agit2_flag)
return SCRIPT_CMD_SUCCESS; // Agit2 already End.
map_config.agit2_flag = false;
guild_agit2_end();
return SCRIPT_CMD_SUCCESS;
}
@@ -12282,7 +12286,7 @@ BUILDIN_FUNC(agitend2)
*------------------------------------------*/
BUILDIN_FUNC(agitcheck)
{
script_pushint(st,agit_flag);
script_pushint(st,map_config.agit_flag?1:0);
return SCRIPT_CMD_SUCCESS;
}
@@ -12291,7 +12295,7 @@ BUILDIN_FUNC(agitcheck)
*------------------------------------------*/
BUILDIN_FUNC(agitcheck2)
{
script_pushint(st,agit2_flag);
script_pushint(st,map_config.agit2_flag?1:0);
return SCRIPT_CMD_SUCCESS;
}
@@ -14626,13 +14630,13 @@ BUILDIN_FUNC(summon)
*------------------------------------------*/
BUILDIN_FUNC(isnight)
{
script_pushint(st,(night_flag == 1));
script_pushint(st,map_config.night_flag?1:0);
return SCRIPT_CMD_SUCCESS;
}
BUILDIN_FUNC(isday)
{
script_pushint(st,(night_flag == 0));
script_pushint(st,(!map_config.night_flag)?1:0);
return SCRIPT_CMD_SUCCESS;
}
@@ -14834,12 +14838,12 @@ BUILDIN_FUNC(getrefine)
*-------------------------------------------------------*/
BUILDIN_FUNC(night)
{
if (night_flag != 1) map_night_timer(night_timer_tid, 0, 0, 1);
if (!map_config.night_flag) map_night_timer(night_timer_tid, 0, 0, 1);
return SCRIPT_CMD_SUCCESS;
}
BUILDIN_FUNC(day)
{
if (night_flag != 0) map_day_timer(day_timer_tid, 0, 0, 1);
if (map_config.night_flag) map_day_timer(day_timer_tid, 0, 0, 1);
return SCRIPT_CMD_SUCCESS;
}

View File

@@ -721,7 +721,7 @@ bool skill_isNotOk(uint16 skill_id, struct map_session_data *sd)
case GD_EMERGENCYCALL:
case GD_ITEMEMERGENCYCALL:
if (
!(battle_config.emergency_call&((agit_flag || agit2_flag)?2:1)) ||
!(battle_config.emergency_call&((map_config.agit_flag || map_config.agit2_flag)?2:1)) ||
!(battle_config.emergency_call&(map[m].flag.gvg || map[m].flag.gvg_castle?8:4)) ||
(battle_config.emergency_call&16 && map[m].flag.nowarpto && !map[m].flag.gvg_castle)
) {

View File

@@ -373,7 +373,7 @@ void storage_storageclose(struct map_session_data* sd)
clif_storageclose(sd);
if( save_settings&4 )
if( map_config.save_settings&CHARSAVE_STORAGE )
chrif_save(sd,0); //Invokes the storage saving as well.
sd->state.storage_flag = 0;
@@ -391,7 +391,7 @@ void storage_storage_quit(struct map_session_data* sd, int flag)
{
nullpo_retv(sd);
if (save_settings&4)
if (map_config.save_settings&CHARSAVE_STORAGE)
chrif_save(sd, flag); //Invokes the storage saving as well.
sd->state.storage_flag = 0;
@@ -828,7 +828,7 @@ void gstorage_storageclose(struct map_session_data* sd)
clif_storageclose(sd);
if (stor->opened) {
if (save_settings&CHARSAVE_STORAGE)
if (map_config.save_settings&CHARSAVE_STORAGE)
chrif_save(sd, 0); //This one also saves the storage. [Skotlex]
else
gstorage_storagesave(sd->status.account_id, sd->status.guild_id,0);
@@ -856,14 +856,14 @@ void gstorage_storage_quit(struct map_session_data* sd, int flag)
stor->opened = 0;
clif_storageclose(sd);
if (save_settings&CHARSAVE_STORAGE)
if (map_config.save_settings&CHARSAVE_STORAGE)
chrif_save(sd,0);
return;
}
if (stor->opened) {
if (save_settings&CHARSAVE_STORAGE)
if (map_config.save_settings&CHARSAVE_STORAGE)
chrif_save(sd,0);
else
gstorage_storagesave(sd->status.account_id,sd->status.guild_id,1);

View File

@@ -200,9 +200,9 @@ int impossible_trade_check(struct map_session_data *sd)
if (inventory[index].amount < sd->deal.item[i].amount) { // if more than the player have -> hack
sprintf(message_to_gm, msg_txt(sd,538), sd->status.name, sd->status.account_id); // Hack on trade: character '%s' (account: %d) try to trade more items that he has.
intif_wis_message_to_gm(wisp_server_name, PC_PERM_RECEIVE_HACK_INFO, message_to_gm);
intif_wis_message_to_gm(map_config.wisp_server_name, PC_PERM_RECEIVE_HACK_INFO, message_to_gm);
sprintf(message_to_gm, msg_txt(sd,539), inventory[index].amount, inventory[index].nameid, sd->deal.item[i].amount); // This player has %d of a kind of item (id: %d), and try to trade %d of them.
intif_wis_message_to_gm(wisp_server_name, PC_PERM_RECEIVE_HACK_INFO, message_to_gm);
intif_wis_message_to_gm(map_config.wisp_server_name, PC_PERM_RECEIVE_HACK_INFO, message_to_gm);
// if we block people
if (battle_config.ban_hack_trade < 0) {
chrif_req_login_operation(-1, sd->status.name, CHRIF_OP_LOGIN_BLOCK, 0, 0, 0); // type: 1 - block
@@ -219,7 +219,7 @@ int impossible_trade_check(struct map_session_data *sd)
// message about the ban
strcpy(message_to_gm, msg_txt(sd,508)); // This player hasn't been banned (Ban option is disabled).
intif_wis_message_to_gm(wisp_server_name, PC_PERM_RECEIVE_HACK_INFO, message_to_gm);
intif_wis_message_to_gm(map_config.wisp_server_name, PC_PERM_RECEIVE_HACK_INFO, message_to_gm);
return 1;
}
@@ -643,7 +643,7 @@ void trade_tradecommit(struct map_session_data *sd)
clif_tradecompleted(tsd, 0);
// save both player to avoid crash: they always have no advantage/disadvantage between the 2 players
if (save_settings&CHARSAVE_TRADE) {
if (map_config.save_settings&CHARSAVE_TRADE) {
chrif_save(sd,0);
chrif_save(tsd,0);
}

View File

@@ -51,8 +51,8 @@ void vending_closevending(struct map_session_data* sd)
nullpo_retv(sd);
if( sd->state.vending ) {
if( Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE vending_id = %d;", vending_items_db, sd->vender_id ) != SQL_SUCCESS ||
Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE `id` = %d;", vendings_db, sd->vender_id ) != SQL_SUCCESS ) {
if( Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE vending_id = %d;", mapserv_table(vending_items_table), sd->vender_id ) != SQL_SUCCESS ||
Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE `id` = %d;", mapserv_table(vendings_table), sd->vender_id ) != SQL_SUCCESS ) {
Sql_ShowDebug(mmysql_handle);
}
@@ -207,11 +207,11 @@ void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const ui
z += ((double)vsd->vending[i].value * (double)amount);
if( vsd->vending[vend_list[i]].amount ) {
if( Sql_Query( mmysql_handle, "UPDATE `%s` SET `amount` = %d WHERE `vending_id` = %d and `cartinventory_id` = %d", vending_items_db, vsd->vending[vend_list[i]].amount, vsd->vender_id, vsd->status.cart[idx].id ) != SQL_SUCCESS ) {
if( Sql_Query( mmysql_handle, "UPDATE `%s` SET `amount` = %d WHERE `vending_id` = %d and `cartinventory_id` = %d", mapserv_table(vending_items_table), vsd->vending[vend_list[i]].amount, vsd->vender_id, vsd->status.cart[idx].id ) != SQL_SUCCESS ) {
Sql_ShowDebug( mmysql_handle );
}
} else {
if( Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE `vending_id` = %d and `cartinventory_id` = %d", vending_items_db, vsd->vender_id, vsd->status.cart[idx].id ) != SQL_SUCCESS ) {
if( Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE `vending_id` = %d and `cartinventory_id` = %d", mapserv_table(vending_items_table), vsd->vender_id, vsd->status.cart[idx].id ) != SQL_SUCCESS ) {
Sql_ShowDebug( mmysql_handle );
}
}
@@ -246,7 +246,7 @@ void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const ui
vsd->vend_num = cursor;
//Always save BOTH: customer (buyer) and vender
if( save_settings&CHARSAVE_VENDING ) {
if( map_config.save_settings&CHARSAVE_VENDING ) {
chrif_save(sd,0);
chrif_save(vsd,0);
}
@@ -300,7 +300,7 @@ int8 vending_openvending(struct map_session_data* sd, const char* message, const
return 3;
}
if (save_settings&CHARSAVE_VENDING) // Avoid invalid data from saving
if (map_config.save_settings&CHARSAVE_VENDING) // Avoid invalid data from saving
chrif_save(sd, 0);
// filter out invalid items
@@ -358,12 +358,12 @@ int8 vending_openvending(struct map_session_data* sd, const char* message, const
if( Sql_Query( mmysql_handle, "INSERT INTO `%s`(`id`, `account_id`, `char_id`, `sex`, `map`, `x`, `y`, `title`, `autotrade`, `body_direction`, `head_direction`, `sit`) "
"VALUES( %d, %d, %d, '%c', '%s', %d, %d, '%s', %d, '%d', '%d', '%d' );",
vendings_db, sd->vender_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->state.autotrade, at ? at->dir : sd->ud.dir, at ? at->head_dir : sd->head_dir, at ? at->sit : pc_issit(sd) ) != SQL_SUCCESS ) {
mapserv_table(vendings_table), sd->vender_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->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`(`vending_id`,`index`,`cartinventory_id`,`amount`,`price`) VALUES", vending_items_db);
StringBuf_Printf(&buf, "INSERT INTO `%s`(`vending_id`,`index`,`cartinventory_id`,`amount`,`price`) VALUES", mapserv_table(vending_items_table));
for (i = 0; i < count; i++) {
StringBuf_Printf(&buf, "(%d,%d,%d,%d,%d)", sd->vender_id, i, sd->status.cart[sd->vending[i].index].id, sd->vending[i].amount, sd->vending[i].value);
if (i < count-1)
@@ -549,7 +549,7 @@ void do_init_vending_autotrade(void)
"FROM `%s` "
"WHERE `autotrade` = 1 AND (SELECT COUNT(`vending_id`) FROM `%s` WHERE `vending_id` = `id`) > 0 "
"ORDER BY `id`;",
vendings_db, vending_items_db ) != SQL_SUCCESS )
mapserv_table(vendings_table), mapserv_table(vending_items_table) ) != SQL_SUCCESS )
{
Sql_ShowDebug(mmysql_handle);
return;
@@ -604,7 +604,7 @@ void do_init_vending_autotrade(void)
"FROM `%s` "
"WHERE `vending_id` = %d "
"ORDER BY `index` ASC;",
vending_items_db, at->id ) )
mapserv_table(vending_items_table), at->id ) )
{
Sql_ShowDebug(mmysql_handle);
continue;
@@ -639,8 +639,8 @@ void do_init_vending_autotrade(void)
}
// Everything is loaded fine, their entries will be reinserted once they are loaded
if (Sql_Query( mmysql_handle, "DELETE FROM `%s`;", vendings_db ) != SQL_SUCCESS ||
Sql_Query( mmysql_handle, "DELETE FROM `%s`;", vending_items_db ) != SQL_SUCCESS) {
if (Sql_Query( mmysql_handle, "DELETE FROM `%s`;", mapserv_table(vendings_table) ) != SQL_SUCCESS ||
Sql_Query( mmysql_handle, "DELETE FROM `%s`;", mapserv_table(vending_items_table) ) != SQL_SUCCESS) {
Sql_ShowDebug(mmysql_handle);
}
}