Compare commits

...

17 Commits

Author SHA1 Message Date
aleos
c1a00dc88e Corrects alerts from LGTM 2020-08-17 11:46:26 -04:00
aleos
fb61671b6a Merge branch 'master' into cleanup/serverconfigs 2020-08-17 08:52:15 -04:00
aleos89
093502802e Corrected Channel config parsing 2019-08-29 09:31:35 -04:00
aleos89
9265732e51 Resolved some string issues 2019-08-29 09:12:46 -04:00
aleos89
daec4e0d95 Corrected a compile error on Linux 2019-08-29 08:48:03 -04:00
aleos89
f75b93edbb Corrected inter_server.yml parsing 2019-08-29 08:22:07 -04:00
aleos89
3766c701a8 Minor cleanups
* Follow up to 429e266.
2019-08-28 14:52:23 -04:00
aleos89
429e266149 Merge branch 'master' into cleanup/serverconfigs 2019-08-28 12:33:48 -04:00
aleos89
a82eff7a9e Merge branch 'master' into cleanup/serverconfigs
Conflicts:
	src/char/char.c
	src/map/map.h
2016-06-17 12:46:14 -04:00
aleos89
5c3c7b04d4 Merged to master
* Fixed various compile warnings/errors.
2016-02-22 12:50:44 -05:00
aleos89
3602957660 Follow up to 9925632 2016-02-22 12:34:44 -05:00
aleos89
57b0f83270 Updated to master
* Resolved various merge conflicts.
* Resolved various compile errors.
2016-02-22 12:34:41 -05:00
aleos89
9ff4017d67 * Fixed a few compile errors from previous rebase. 2016-02-22 12:34:39 -05:00
Cydh Ramdh
4ca0690a98 Move table names from inter_athena.conf to their perspective server config file as suggested by @Lemongrass
Signed-off-by: Cydh Ramdh <house.bad@gmail.com>
2016-02-22 12:34:36 -05:00
Cydh Ramdh
ca3b06479d Added map-server config for prefered file lookup:
* group_conf_file: groups.conf
* atcommand_conf_file: groups.conf

NOTE:
Those files aren't for importing, but "which file do you want to read..."

Signed-off-by: Cydh Ramdh <house.bad@gmail.com>
2016-02-22 12:34:33 -05:00
Cydh Ramdh
e4ef8d43d8 Follow up 9d08909fff48f3e285a1905c5675a17f742ed28e
* Remove leftover while testing

Signed-off-by: Cydh Ramdh <house.bad@gmail.com>
2016-02-22 12:34:31 -05:00
Cydh Ramdh
8baa1d7e0c * 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>
2016-02-22 12:34:29 -05:00
60 changed files with 2006 additions and 1456 deletions

View File

@@ -676,6 +676,7 @@ int config_read_file(config_t *config, const char *filename)
{ {
config->error_text = __io_error; config->error_text = __io_error;
config->error_type = CONFIG_ERR_FILE_IO; config->error_type = CONFIG_ERR_FILE_IO;
config->error_file = filename; // Put error filename here, for more info
return(CONFIG_FALSE); return(CONFIG_FALSE);
} }

View File

@@ -200,6 +200,9 @@ char_del_restriction: 3
// What folder the DB files are in (item_db.txt, etc.) // What folder the DB files are in (item_db.txt, etc.)
db_path: db db_path: db
// Should we check if sql-tables are correct on server startup ?
char_checkdb: yes
//=================================== //===================================
// Pincode system // Pincode system
//=================================== //===================================
@@ -290,4 +293,48 @@ mail_delete_days: 15
// Default: yes // Default: yes
mail_retrieve: yes mail_retrieve: yes
//===================================
// Char/Inter-server Tables
//===================================
acc_reg_num_table: acc_reg_num
acc_reg_str_table: acc_reg_str
achievement_table: achievement
auction_table: auction
bonus_script_table: bonus_script
cart_table: cart_inventory
char_reg_num_table: char_reg_num
char_reg_str_table: char_reg_str
char_table: char
charlog_table: charlog
clan_alliance_table: clan_alliance
clan_table: clan
elemental_table: elemental
friend_table: friends
guild_table: guild
guild_alliance_table: guild_alliance
guild_castle_table: guild_castle
guild_expulsion_table: guild_expulsion
guild_member_table: guild_member
guild_position_table: guild_position
guild_skill_table: guild_skill
guild_storage_table: guild_storage
hotkey_table: hotkey
homunculus_table: homunculus
homunculus_skill_table: skill_homunculus
interlog_table: interlog
inventory_table: inventory
mail_attachment_table: mail_attachments
mail_table: mail
memo_table: memo
mercenary_table: mercenary
mercenary_owner_table: mercenary_owner
party_table: party
pet_table: pet
quest_table: quest
ragsrvinfo_table: ragsrvinfo
scdata_table: sc_data
skill_table: skill
skillcooldown_table: skillcooldown
storage_table: storage
import: conf/import/char_conf.txt import: conf/import/char_conf.txt

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_pw: ragnarok
map_server_db: 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_ip: 127.0.0.1
log_db_port: 3306 log_db_port: 3306
log_db_id: ragnarok log_db_id: ragnarok
log_db_pw: ragnarok log_db_pw: ragnarok
log_db_db: ragnarok log_db_db: ragnarok
log_codepage: log_codepage:
log_login_db: loginlog log_login_table: loginlog
// MySQL Reconnect Settings // MySQL Reconnect Settings
// - mysql_reconnect_type: // - mysql_reconnect_type:
@@ -72,85 +72,6 @@ log_login_db: loginlog
mysql_reconnect_type: 2 mysql_reconnect_type: 2
mysql_reconnect_count: 1 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
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
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
mail_attachment_db: mail_attachments
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
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
clan_table: clan
clan_alliance_table: clan_alliance
// Map Database Tables
buyingstore_table: buyingstores
buyingstore_items_table: buyingstore_items
item_table: item_db
renewal-item_table: item_db_re
item2_table: item_db2
renewal-item2_table: item_db2_re
item_cash_table: item_cash_db
item_cash2_table: item_cash_db2
mob_table: mob_db
renewal-mob_table: mob_db_re
mob2_table: mob_db2
renewal-mob2_table: mob_db2_re
mob_skill_table: mob_skill_db
renewal-mob_skill_table: mob_skill_db_re
mob_skill2_table: mob_skill_db2
renewal-mob_skill2_table: mob_skill_db2_re
mapreg_table: mapreg
sales_table: sales
vending_table: vendings
vending_items_table: vending_items
market_table: market
roulette_table: db_roulette
guild_storage_log: guild_storage_log
// Use SQL item_db, mob_db and mob_skill_db for the map server? (yes/no)
use_sql_db: no
inter_server_conf: inter_server.yml inter_server_conf: inter_server.yml
import: conf/import/inter_conf.txt import: conf/import/inter_conf.txt

View File

@@ -150,14 +150,19 @@ log_timestamp_format: %m/%d/%Y %H:%M:%S
// log_cash_db: log/cashlog.log // log_cash_db: log/cashlog.log
// log_feeding_db: log/feedinglog.log // log_feeding_db: log/feedinglog.log
log_gm_db: atcommandlog log_gm_table: atcommandlog
log_branch_db: branchlog log_branch_table: branchlog
log_chat_db: chatlog log_chat_table: chatlog
log_mvpdrop_db: mvplog log_mvpdrop_table: mvplog
log_npc_db: npclog log_npc_table: npclog
log_pick_db: picklog log_pick_table: picklog
log_zeny_db: zenylog log_zeny_table: zenylog
log_cash_db: cashlog log_cash_table: cashlog
log_feeding_db: feedinglog 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 import: conf/import/log_conf.txt

View File

@@ -179,5 +179,19 @@ use_web_auth_token: yes
//client_hash: 10, cb1ea78023d337c38e8ba5124e2338ae //client_hash: 10, cb1ea78023d337c38e8ba5124e2338ae
//client_hash: 99, disabled //client_hash: 99, disabled
//New registration flood protection [Kevin]
//Number of new registration allowed
allowed_regs: 1
//Time in second before the counter for the number of registration is reset
time_allowed: 10
//===================================
// Login-server Tables
//===================================
global_acc_reg_num_table: global_acc_reg_num
global_acc_reg_str_table: global_acc_reg_str
ipban_list_table: ipbanlist
login_server_account_table: login
import: conf/inter_athena.conf import: conf/inter_athena.conf
import: conf/import/login_conf.txt import: conf/import/login_conf.txt

View File

@@ -116,11 +116,50 @@ save_settings: 4095
// Message of the day file, when a character logs on, this message is displayed. // Message of the day file, when a character logs on, this message is displayed.
motd_txt: conf/motd.txt 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. // Prefered file for reading atcommand & charcommand symbols, alieases settings,
charhelp_txt: conf/charhelp.txt // 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
// Load channel config from // Load channel config from
channel_conf: conf/channels.conf channel_conf_file: conf/channels.conf
// Check all required tables?
check_tables: yes
//===================================
// Map-server Tables
//===================================
buyingstore_table: buyingstores
buyingstore_items_table: buyingstore_items
guild_storage_log_table: guild_storage_log
mapreg_table: mapreg
market_table: market
roulette_table: db_roulette
sales_table: sales
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: // Maps:
import: conf/maps_athena.conf import: conf/maps_athena.conf

File diff suppressed because it is too large Load Diff

View File

@@ -4,6 +4,7 @@
#ifndef CHAR_HPP #ifndef CHAR_HPP
#define CHAR_HPP #define CHAR_HPP
#include <string>
#include <vector> #include <vector>
#include "../common/core.hpp" // CORE_ST_LAST #include "../common/core.hpp" // CORE_ST_LAST
@@ -47,49 +48,63 @@ enum e_char_del_response {
}; };
struct Schema_Config { struct Schema_Config {
int db_use_sqldbs; // Character related tables
char db_path[1024]; std::string char_table; ///< Main Charachter table
char char_db[DB_NAME_LEN]; std::string charlog_table; ///< Charlog table
char scdata_db[DB_NAME_LEN]; std::string bonus_script_table; ///< Stored bonus_script table
char skillcooldown_db[DB_NAME_LEN]; std::string cart_table; ///< Cart inventory table
char cart_db[DB_NAME_LEN]; std::string inventory_table; ///< Inventory table
char inventory_db[DB_NAME_LEN]; std::string storage_table; ///< Storage table
char charlog_db[DB_NAME_LEN]; std::string memo_table; ///< Memo table
char storage_db[DB_NAME_LEN]; std::string scdata_table; ///< Stored SC table
char interlog_db[DB_NAME_LEN]; std::string skill_table; ///< Skill table
char skill_db[DB_NAME_LEN]; std::string skillcooldown_table; ///< Skill Cooldown table
char memo_db[DB_NAME_LEN]; std::string friend_table; ///< Friend list table
char guild_db[DB_NAME_LEN]; std::string hotkey_table; ///< Hotkey list table
char guild_alliance_db[DB_NAME_LEN]; std::string quest_table; ///< Quest table
char guild_castle_db[DB_NAME_LEN]; std::string pet_table; ///< Pet table
char guild_expulsion_db[DB_NAME_LEN]; std::string elemental_table; ///< Elemental table
char guild_member_db[DB_NAME_LEN]; std::string party_table; ///< Party table
char guild_position_db[DB_NAME_LEN]; std::string auction_table; ///< Auction table
char guild_skill_db[DB_NAME_LEN]; std::string achievement_table; ///< Achievement table
char guild_storage_db[DB_NAME_LEN];
char party_db[DB_NAME_LEN]; // Mail tables
char pet_db[DB_NAME_LEN]; std::string mail_table; ///< Mail table
char mail_db[DB_NAME_LEN]; // MAIL SYSTEM std::string mail_attachment_table; ///< Mail Attachments table
char mail_attachment_db[DB_NAME_LEN];
char auction_db[DB_NAME_LEN]; // Auctions System // Homunculus tables
char friend_db[DB_NAME_LEN]; std::string homunculus_table; ///< Homunculus table
char hotkey_db[DB_NAME_LEN]; std::string homunculus_skill_table; ///< Homunculus skill table
char quest_db[DB_NAME_LEN];
char homunculus_db[DB_NAME_LEN]; // Mercenary Tables
char skill_homunculus_db[DB_NAME_LEN]; std::string mercenary_table; ///< Mercenary table
char mercenary_db[DB_NAME_LEN]; std::string mercenary_owner_table; ///< Mercenary owner table
char mercenary_owner_db[DB_NAME_LEN];
char elemental_db[DB_NAME_LEN]; // Guild tables
char bonus_script_db[DB_NAME_LEN]; std::string guild_table; ///< Guild table
char acc_reg_num_table[DB_NAME_LEN]; std::string guild_alliance_table; ///< Guild alliance & enemy table
char acc_reg_str_table[DB_NAME_LEN]; std::string guild_castle_table; ///< Castle table
char char_reg_str_table[DB_NAME_LEN]; std::string guild_expulsion_table; ///< Expulsion table
char char_reg_num_table[DB_NAME_LEN]; std::string guild_member_table; ///< Guild member table
char clan_table[DB_NAME_LEN]; std::string guild_position_table; ///< Guild member position table
char clan_alliance_table[DB_NAME_LEN]; std::string guild_skill_table; ///< Guild skill table
char achievement_table[DB_NAME_LEN]; std::string guild_storage_table; ///< Guild storage table
// Clan tables
std::string clan_table; ///< Clan table
std::string clan_alliance_table; ///< Clan Alliance table
// Other
std::string acc_reg_num_table; ///< Account Registry (Number)
std::string acc_reg_str_table; ///< Account Registry (String)
std::string char_reg_num_table; ///< Character Registry (Number)
std::string char_reg_str_table; ///< Character Registry (String)
std::string 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) ( schema_config.table.c_str() )
#if PACKETVER_SUPPORTS_PINCODE #if PACKETVER_SUPPORTS_PINCODE
/// Pincode system /// Pincode system
@@ -190,6 +205,8 @@ struct CharServ_Config {
int mail_retrieve; int mail_retrieve;
int allowed_job_flag; int allowed_job_flag;
std::string db_path;
}; };
extern struct CharServ_Config charserv_config; extern struct CharServ_Config charserv_config;

View File

@@ -72,8 +72,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 if( charserv_config.charmove_config.char_movetoused ){ // TODO: check if the target is in deletion process
// Admin is friendly and uses triangle exchange // Admin is friendly and uses triangle exchange
if( SQL_ERROR == Sql_QueryStr(sql_handle, "START TRANSACTION") 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'",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'", 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), from, sd->found_char[to] )
|| SQL_ERROR == Sql_QueryStr(sql_handle, "COMMIT") || SQL_ERROR == Sql_QueryStr(sql_handle, "COMMIT")
){ ){
chclif_moveCharSlotReply( fd, sd, from, 1 ); chclif_moveCharSlotReply( fd, sd, from, 1 );
@@ -86,7 +86,7 @@ int chclif_parse_moveCharSlot( int fd, struct char_session_data* sd){
chclif_moveCharSlotReply( fd, sd, from, 1 ); chclif_moveCharSlotReply( fd, sd, from, 1 );
return 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); Sql_ShowDebug(sql_handle);
chclif_moveCharSlotReply( fd, sd, from, 1 ); chclif_moveCharSlotReply( fd, sd, from, 1 );
return 1; return 1;
@@ -94,7 +94,7 @@ int chclif_parse_moveCharSlot( int fd, struct char_session_data* sd){
if( (charserv_config.charmove_config.char_moves_unlimited)==0 ){ if( (charserv_config.charmove_config.char_moves_unlimited)==0 ){
sd->char_moves[from]--; 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 // We successfully moved the char - time to notify the client
@@ -499,7 +499,7 @@ int chclif_parse_char_delete2_req(int fd, struct char_session_data* sd) {
return 1; return 1;
} }
if( SQL_SUCCESS != Sql_Query(sql_handle, "SELECT `delete_date`,`party_id`,`guild_id` 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`,`party_id`,`guild_id` FROM `%s` WHERE `char_id`='%d'", charserv_table(char_table), char_id) || SQL_SUCCESS != Sql_NextRow(sql_handle) )
{ {
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
chclif_char_delete2_ack(fd, char_id, 3, 0); chclif_char_delete2_ack(fd, char_id, 3, 0);
@@ -530,7 +530,7 @@ int chclif_parse_char_delete2_req(int fd, struct char_session_data* sd) {
// success // success
delete_date = time(NULL)+(charserv_config.char_config.char_del_delay); 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); Sql_ShowDebug(sql_handle);
chclif_char_delete2_ack(fd, char_id, 3, 0); chclif_char_delete2_ack(fd, char_id, 3, 0);
@@ -648,7 +648,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 // there is no need to check, whether or not the character was
// queued for deletion, as the client prints an error message by // queued for deletion, as the client prints an error message by
// itself, if it was not the case (@see char_delete2_cancel_ack) // 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); Sql_ShowDebug(sql_handle);
chclif_char_delete2_cancel_ack(fd, char_id, 2); chclif_char_delete2_cancel_ack(fd, char_id, 2);
@@ -828,7 +828,7 @@ int chclif_parse_charselect(int fd, struct char_session_data* sd,uint32 ipl){
} }
// Check if the character exists and is not scheduled for deletion // Check if the character exists and is not scheduled for deletion
if ( SQL_SUCCESS != Sql_Query(sql_handle, "SELECT `char_id` FROM `%s` WHERE `account_id`='%d' AND `char_num`='%d' AND `delete_date` = 0", 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' AND `delete_date` = 0", charserv_table(char_table), sd->account_id, slot)
|| SQL_SUCCESS != Sql_NextRow(sql_handle) || SQL_SUCCESS != Sql_NextRow(sql_handle)
|| SQL_SUCCESS != Sql_GetData(sql_handle, 0, &data, NULL) ) || SQL_SUCCESS != Sql_GetData(sql_handle, 0, &data, NULL) )
{ //Not found?? May be forged packet. { //Not found?? May be forged packet.
@@ -870,7 +870,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)); 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')", 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); Sql_ShowDebug(sql_handle);
} }
ShowInfo("Selected char: (Account %d: %d - %s)\n", sd->account_id, slot, char_dat.name); ShowInfo("Selected char: (Account %d: %d - %s)\n", sd->account_id, slot, char_dat.name);
@@ -1215,7 +1215,7 @@ void chclif_block_character( int fd, struct char_session_data* sd){
else { else {
WFIFOL(fd, 4+j*24) = 0; WFIFOL(fd, 4+j*24) = 0;
sd->unban_time[i] = 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); Sql_ShowDebug(sql_handle);
} }
len+=24; len+=24;

View File

@@ -415,10 +415,10 @@ void chlogif_parse_change_sex_sub(int sex, int acc, int char_id, int class_, int
else if (class_ == JOB_BABY_KAGEROU || class_ == JOB_BABY_OBORO) else if (class_ == JOB_BABY_KAGEROU || class_ == JOB_BABY_OBORO)
class_ = (sex == SEX_MALE ? JOB_BABY_KAGEROU : JOB_BABY_OBORO); class_ = (sex == SEX_MALE ? JOB_BABY_KAGEROU : JOB_BABY_OBORO);
if (SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `equip` = '0' WHERE `char_id` = '%d'", schema_config.inventory_db, char_id)) if (SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `equip` = '0' WHERE `char_id` = '%d'", charserv_table(inventory_table), char_id))
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
if (SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `class` = '%d', `weapon` = '0', `shield` = '0', `head_top` = '0', `head_mid` = '0', `head_bottom` = '0' WHERE `char_id` = '%d'", schema_config.char_db, class_, char_id)) if (SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `class` = '%d', `weapon` = '0', `shield` = '0', `head_top` = '0', `head_mid` = '0', `head_bottom` = '0' WHERE `char_id` = '%d'", charserv_table(char_table), class_, char_id))
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
if (guild_id) // If there is a guild, update the guild_member data [Skotlex] if (guild_id) // If there is a guild, update the guild_member data [Skotlex]
inter_guild_sex_changed(guild_id, acc, char_id, sex); inter_guild_sex_changed(guild_id, acc, char_id, sex);
@@ -446,7 +446,7 @@ int chlogif_parse_ackchangesex(int fd)
// get characters // get characters
stmt = SqlStmt_Malloc(sql_handle); 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_ShowDebug(stmt);
SqlStmt_Free(stmt); SqlStmt_Free(stmt);
} }
@@ -487,7 +487,7 @@ int chlogif_parse_ackchangecharsex(int char_id, int sex)
char *data; char *data;
// get character data // get character data
if (SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`class`,`guild_id` FROM `%s` WHERE `char_id` = '%d'", schema_config.char_db, char_id)) { if (SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`class`,`guild_id` FROM `%s` WHERE `char_id` = '%d'", charserv_table(char_table), char_id)) {
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
return 1; return 1;
} }
@@ -501,7 +501,7 @@ int chlogif_parse_ackchangecharsex(int char_id, int sex)
Sql_GetData(sql_handle, 2, &data, NULL); guild_id = atoi(data); Sql_GetData(sql_handle, 2, &data, NULL); guild_id = atoi(data);
Sql_FreeResult(sql_handle); Sql_FreeResult(sql_handle);
if (SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `sex` = '%c' WHERE `char_id` = '%d'", schema_config.char_db, sex == SEX_MALE ? 'M' : 'F', char_id)) { if (SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `sex` = '%c' WHERE `char_id` = '%d'", charserv_table(char_table), sex == SEX_MALE ? 'M' : 'F', char_id)) {
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
return 1; return 1;
} }

View File

@@ -280,7 +280,7 @@ int chmapif_parse_askscdata(int fd){
aid = RFIFOL(fd,2); aid = RFIFOL(fd,2);
cid = RFIFOL(fd,6); 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'", 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); Sql_ShowDebug(sql_handle);
return 1; return 1;
@@ -507,7 +507,7 @@ int chmapif_parse_req_saveskillcooldown(int fd){
int i; int i;
StringBuf_Init(&buf); 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 ) for( i = 0; i < count; ++i )
{ {
memcpy(&data,RFIFOP(fd,14+i*sizeof(struct skill_cooldown_data)),sizeof(struct skill_cooldown_data)); memcpy(&data,RFIFOP(fd,14+i*sizeof(struct skill_cooldown_data)),sizeof(struct skill_cooldown_data));
@@ -534,7 +534,7 @@ int chmapif_parse_req_skillcooldown(int fd){
cid = RFIFOL(fd,6); cid = RFIFOL(fd,6);
RFIFOSKIP(fd, 10); RFIFOSKIP(fd, 10);
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT skill, tick FROM `%s` WHERE `account_id` = '%d' AND `char_id`='%d'", 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); Sql_ShowDebug(sql_handle);
return 1; return 1;
@@ -563,7 +563,7 @@ int chmapif_parse_req_skillcooldown(int fd){
WFIFOW(fd,12) = count; WFIFOW(fd,12) = count;
WFIFOSET(fd,WFIFOW(fd,2)); WFIFOSET(fd,WFIFOW(fd,2));
//Clear the data once loaded. //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); Sql_ShowDebug(sql_handle);
} }
} }
@@ -669,7 +669,7 @@ int chmapif_parse_askrmfriend(int fd){
char_id = RFIFOL(fd,2); char_id = RFIFOL(fd,2);
friend_id = RFIFOL(fd,6); 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", 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); Sql_ShowDebug(sql_handle);
return 1; return 1;
} }
@@ -743,7 +743,7 @@ int chmapif_parse_fwlog_changestatus(int fd){
RFIFOSKIP(fd,44); RFIFOSKIP(fd,44);
Sql_EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); 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); Sql_ShowDebug(sql_handle);
else if( Sql_NumRows(sql_handle) == 0 ) { else if( Sql_NumRows(sql_handle) == 0 ) {
result = 1; // 1-player not found result = 1; // 1-player not found
@@ -932,7 +932,7 @@ int chmapif_parse_save_scdata(int fd){
count = RFIFOW(fd, 12); count = RFIFOW(fd, 12);
// Whatever comes from the mapserver, now is the time to drop previous entries // 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 ); Sql_ShowDebug( sql_handle );
} }
else if( count > 0 ) else if( count > 0 )
@@ -942,7 +942,7 @@ int chmapif_parse_save_scdata(int fd){
int i; int i;
StringBuf_Init(&buf); 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 ) for( i = 0; i < count; ++i )
{ {
memcpy (&data, RFIFOP(fd, 14+i*sizeof(struct status_change_data)), sizeof(struct status_change_data)); memcpy (&data, RFIFOP(fd, 14+i*sizeof(struct status_change_data)), sizeof(struct status_change_data));
@@ -1172,7 +1172,7 @@ int chmapif_parse_reqcharban(int fd){
RFIFOSKIP(fd,10+NAME_LENGTH); RFIFOSKIP(fd,10+NAME_LENGTH);
Sql_EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); Sql_EscapeStringLen(sql_handle, esc_name, name, strnlen(name, 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, esc_name) ) if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`char_id`,`unban_time` FROM `%s` WHERE `name` = '%s'", charserv_table(char_table), esc_name) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
else if( Sql_NumRows(sql_handle) == 0 ){ else if( Sql_NumRows(sql_handle) == 0 ){
return 1; // 1-player not found return 1; // 1-player not found
@@ -1201,7 +1201,7 @@ int chmapif_parse_reqcharban(int fd){
if( SQL_SUCCESS != SqlStmt_Prepare(stmt, if( SQL_SUCCESS != SqlStmt_Prepare(stmt,
"UPDATE `%s` SET `unban_time` = ? WHERE `char_id` = ? LIMIT 1", "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, 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_BindParam(stmt, 1, SQLDT_INT, (void*)&t_cid, sizeof(t_cid))
|| SQL_SUCCESS != SqlStmt_Execute(stmt) || SQL_SUCCESS != SqlStmt_Execute(stmt)
@@ -1239,7 +1239,7 @@ int chmapif_parse_reqcharunban(int fd){
RFIFOSKIP(fd,6+NAME_LENGTH); RFIFOSKIP(fd,6+NAME_LENGTH);
Sql_EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); Sql_EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH));
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `unban_time` = '0' WHERE `name` = '%s' LIMIT 1", schema_config.char_db, esc_name) ) { if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `unban_time` = '0' WHERE `name` = '%s' LIMIT 1", charserv_table(char_table), esc_name) ) {
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
return 1; return 1;
} }
@@ -1269,7 +1269,7 @@ int chmapif_bonus_script_get(int fd) {
if (SQL_ERROR == SqlStmt_Prepare(stmt, if (SQL_ERROR == SqlStmt_Prepare(stmt,
"SELECT `script`, `tick`, `flag`, `type`, `icon` FROM `%s` WHERE `char_id` = '%d' LIMIT %d", "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_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, 0, SQLDT_STRING, &tmp_bsdata.script_str, sizeof(tmp_bsdata.script_str), NULL, NULL) ||
SQL_ERROR == SqlStmt_BindColumn(stmt, 1, SQLDT_INT64, &tmp_bsdata.tick, 0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 1, SQLDT_INT64, &tmp_bsdata.tick, 0, NULL, NULL) ||
@@ -1310,7 +1310,7 @@ int chmapif_bonus_script_get(int fd) {
ShowInfo("Bonus Script loaded for CID=%d. Total: %d.\n", cid, i); 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)) SQL_ERROR == SqlStmt_Execute(stmt))
SqlStmt_ShowDebug(stmt); SqlStmt_ShowDebug(stmt);
} }
@@ -1333,7 +1333,7 @@ int chmapif_bonus_script_save(int fd) {
uint32 cid = RFIFOL(fd,4); uint32 cid = RFIFOL(fd,4);
uint8 count = RFIFOB(fd,8); uint8 count = RFIFOB(fd,8);
if (SQL_ERROR == Sql_Query(sql_handle,"DELETE FROM `%s` WHERE `char_id` = '%d'", schema_config.bonus_script_db, cid)) if (SQL_ERROR == Sql_Query(sql_handle,"DELETE FROM `%s` WHERE `char_id` = '%d'", charserv_table(bonus_script_table), cid))
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
if (count > 0) { if (count > 0) {
@@ -1343,7 +1343,7 @@ int chmapif_bonus_script_save(int fd) {
uint8 i; uint8 i;
StringBuf_Init(&buf); 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) { for (i = 0; i < count; ++i) {
memcpy(&bsdata, RFIFOP(fd, 9 + i*sizeof(struct bonus_script_data)), sizeof(struct bonus_script_data)); 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); Sql_EscapeString(sql_handle, esc_script, bsdata.script_str);

View File

@@ -42,7 +42,7 @@ struct achievement *mapif_achievements_fromsql(uint32 char_id, int *count)
StringBuf_AppendStr(&buf, "SELECT `id`, COALESCE(UNIX_TIMESTAMP(`completed`),0), COALESCE(UNIX_TIMESTAMP(`rewarded`),0)"); StringBuf_AppendStr(&buf, "SELECT `id`, COALESCE(UNIX_TIMESTAMP(`completed`),0), COALESCE(UNIX_TIMESTAMP(`rewarded`),0)");
for (i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; ++i) for (i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; ++i)
StringBuf_Printf(&buf, ", `count%d`", i + 1); StringBuf_Printf(&buf, ", `count%d`", i + 1);
StringBuf_Printf(&buf, " FROM `%s` WHERE `char_id` = '%u'", schema_config.achievement_table, char_id); StringBuf_Printf(&buf, " FROM `%s` WHERE `char_id` = '%u'", charserv_table(achievement_table), char_id);
stmt = SqlStmt_Malloc(sql_handle); stmt = SqlStmt_Malloc(sql_handle);
if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf))
@@ -94,7 +94,7 @@ struct achievement *mapif_achievements_fromsql(uint32 char_id, int *count)
*/ */
bool mapif_achievement_delete(uint32 char_id, int achievement_id) bool mapif_achievement_delete(uint32 char_id, int achievement_id)
{ {
if (SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '%d' AND `char_id` = '%u'", schema_config.achievement_table, achievement_id, char_id)) { if (SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '%d' AND `char_id` = '%u'", charserv_table(achievement_table), achievement_id, char_id)) {
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
return false; return false;
} }

View File

@@ -52,7 +52,7 @@ void auction_save(struct auction_data *auction)
StringBuf_Init(&buf); 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` = '%u', `item_name` = ?, `type` = '%d', `refine` = '%d', `attribute` = '%d'", 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` = '%u', `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++ ) for( j = 0; j < MAX_SLOTS; j++ )
StringBuf_Printf(&buf, ", `card%d` = '%u'", j, auction->item.card[j]); StringBuf_Printf(&buf, ", `card%d` = '%u'", j, auction->item.card[j]);
for (j = 0; j < MAX_ITEM_RDM_OPT; j++) { for (j = 0; j < MAX_ITEM_RDM_OPT; j++) {
@@ -88,7 +88,7 @@ unsigned int auction_create(struct auction_data *auction)
auction->timestamp = time(NULL) + (auction->hours * 3600); auction->timestamp = time(NULL) + (auction->hours * 3600);
StringBuf_Init(&buf); 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++ ) for( j = 0; j < MAX_SLOTS; j++ )
StringBuf_Printf(&buf, ",`card%d`", j); StringBuf_Printf(&buf, ",`card%d`", j);
for (j = 0; j < MAX_ITEM_RDM_OPT; ++j) { for (j = 0; j < MAX_ITEM_RDM_OPT; ++j) {
@@ -177,7 +177,7 @@ void auction_delete(struct auction_data *auction)
{ {
unsigned int auction_id = auction->auction_id; 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); Sql_ShowDebug(sql_handle);
if( auction->auction_end_timer != INVALID_TIMER ) if( auction->auction_end_timer != INVALID_TIMER )
@@ -204,7 +204,7 @@ void inter_auctions_fromsql(void)
StringBuf_Printf(&buf, ", `option_val%d`", i); StringBuf_Printf(&buf, ", `option_val%d`", i);
StringBuf_Printf(&buf, ", `option_parm%d`", i); StringBuf_Printf(&buf, ", `option_parm%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)) ) if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);

View File

@@ -21,7 +21,7 @@
static DBMap* clan_db; // int clan_id -> struct clan* static DBMap* clan_db; // int clan_id -> struct clan*
int inter_clan_removemember_tosql(uint32 account_id, uint32 char_id){ int inter_clan_removemember_tosql(uint32 account_id, uint32 char_id){
if( SQL_ERROR == Sql_Query( sql_handle, "UPDATE `%s` SET `clan_id` = '0' WHERE `char_id` = '%d'", schema_config.char_db, char_id ) ){ if( SQL_ERROR == Sql_Query( sql_handle, "UPDATE `%s` SET `clan_id` = '0' WHERE `char_id` = '%d'", charserv_table(char_table), char_id ) ){
Sql_ShowDebug( sql_handle ); Sql_ShowDebug( sql_handle );
return 1; return 1;
}else{ }else{
@@ -44,7 +44,7 @@ struct clan* inter_clan_fromsql(int clan_id){
return clan; return clan;
} }
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `name`, `master`, `mapname`, `max_member` FROM `%s` WHERE `clan_id`='%d'", schema_config.clan_table, clan_id) ){ if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `name`, `master`, `mapname`, `max_member` FROM `%s` WHERE `clan_id`='%d'", charserv_table(clan_table), clan_id) ){
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
return NULL; return NULL;
} }
@@ -71,7 +71,7 @@ struct clan* inter_clan_fromsql(int clan_id){
clan->max_member = MAX_CLAN; clan->max_member = MAX_CLAN;
} }
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `opposition`,`alliance_id`,`name` FROM `%s` WHERE `clan_id`='%d'", schema_config.clan_alliance_table, clan_id) ){ if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `opposition`,`alliance_id`,`name` FROM `%s` WHERE `clan_id`='%d'", charserv_table(clan_alliance_table), clan_id) ){
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
aFree(clan); aFree(clan);
return NULL; return NULL;
@@ -209,7 +209,7 @@ int inter_clan_init(void){
clan_db = idb_alloc(DB_OPT_RELEASE_DATA); clan_db = idb_alloc(DB_OPT_RELEASE_DATA);
if( SQL_ERROR == Sql_Query( sql_handle, "SELECT `clan_id` FROM `%s`", schema_config.clan_table ) ){ if( SQL_ERROR == Sql_Query( sql_handle, "SELECT `clan_id` FROM `%s`", charserv_table(clan_table) ) ){
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
return 1; return 1;
} }

View File

@@ -22,7 +22,7 @@ bool mapif_elemental_save(struct s_elemental* ele) {
if( SQL_ERROR == Sql_Query(sql_handle, 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`)" "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','%u','%u','%u','%u','%d','%d','%d','%d','%d','%d','%d','%d','%" PRtf "')", "VALUES ('%d','%d','%d','%u','%u','%u','%u','%d','%d','%d','%d','%d','%d','%d','%d','%" PRtf "')",
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); Sql_ShowDebug(sql_handle);
flag = false; flag = false;
@@ -32,7 +32,7 @@ bool mapif_elemental_save(struct s_elemental* ele) {
} else if( SQL_ERROR == Sql_Query(sql_handle, } else if( SQL_ERROR == Sql_Query(sql_handle,
"UPDATE `%s` SET `char_id` = '%d', `class` = '%d', `mode` = '%d', `hp` = '%u', `sp` = '%u'," "UPDATE `%s` SET `char_id` = '%d', `class` = '%d', `mode` = '%d', `hp` = '%u', `sp` = '%u',"
"`max_hp` = '%u', `max_sp` = '%u', `atk1` = '%d', `atk2` = '%d', `matk` = '%d', `aspd` = '%d', `def` = '%d'," "`max_hp` = '%u', `max_sp` = '%u', `atk1` = '%d', `atk2` = '%d', `matk` = '%d', `aspd` = '%d', `def` = '%d',"
"`mdef` = '%d', `flee` = '%d', `hit` = '%d', `life_time` = '%" PRtf "' WHERE `ele_id` = '%d'", schema_config.elemental_db, "`mdef` = '%d', `flee` = '%d', `hit` = '%d', `life_time` = '%" PRtf "' 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->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) ) ele->matk, ele->amotion, ele->def, ele->mdef, ele->flee, ele->hit, ele->life_time, ele->elemental_id) )
{ // Update DB entry { // Update DB entry
@@ -51,7 +51,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`," 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'", "`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); Sql_ShowDebug(sql_handle);
return false; return false;
} }
@@ -84,7 +84,7 @@ bool mapif_elemental_load(int ele_id, uint32 char_id, struct s_elemental *ele) {
} }
bool mapif_elemental_delete(int ele_id) { 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); Sql_ShowDebug(sql_handle);
return false; return false;
} }

View File

@@ -94,9 +94,9 @@ TIMER_FUNC(guild_save_timer){
int inter_guild_removemember_tosql(uint32 char_id) int inter_guild_removemember_tosql(uint32 char_id)
{ {
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE from `%s` where `char_id` = '%d'", schema_config.guild_member_db, char_id) ) if( SQL_ERROR == Sql_Query(sql_handle, "DELETE from `%s` where `char_id` = '%d'", charserv_table(guild_member_table), char_id) )
Sql_ShowDebug(sql_handle); 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); Sql_ShowDebug(sql_handle);
return 0; return 0;
} }
@@ -144,7 +144,7 @@ int inter_guild_tosql(struct guild *g,int flag)
if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` " if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` "
"(`name`,`master`,`guild_lv`,`max_member`,`average_lv`,`char_id`) " "(`name`,`master`,`guild_lv`,`max_member`,`average_lv`,`char_id`) "
"VALUES ('%s', '%s', '%d', '%d', '%d', '%d')", "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); Sql_ShowDebug(sql_handle);
return 0; //Failed to create guild! return 0; //Failed to create guild!
@@ -163,7 +163,7 @@ int inter_guild_tosql(struct guild *g,int flag)
bool add_comma = false; bool add_comma = false;
StringBuf_Init(&buf); 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) if (flag & GS_EMBLEM)
{ {
@@ -243,12 +243,12 @@ int inter_guild_tosql(struct guild *g,int flag)
//Since nothing references guild member table as foreign keys, it's safe to use REPLACE INTO //Since nothing references guild member table as foreign keys, it's safe to use REPLACE INTO
if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`char_id`,`exp`,`position`) " if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`char_id`,`exp`,`position`) "
"VALUES ('%d','%d','%" PRIu64 "','%d')", "VALUES ('%d','%d','%" PRIu64 "','%d')",
schema_config.guild_member_db, g->guild_id, m->char_id, m->exp, m->position ) ) charserv_table(guild_member_table), g->guild_id, m->char_id, m->exp, m->position ) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
if (m->modified&GS_MEMBER_NEW || new_guild == 1) 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'", 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); Sql_ShowDebug(sql_handle);
} }
m->modified = GS_MEMBER_UNMODIFIED; m->modified = GS_MEMBER_UNMODIFIED;
@@ -265,7 +265,7 @@ int inter_guild_tosql(struct guild *g,int flag)
continue; continue;
Sql_EscapeStringLen(sql_handle, esc_name, p->name, strnlen(p->name, NAME_LENGTH)); 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')", 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); Sql_ShowDebug(sql_handle);
p->modified = GS_POSITION_UNMODIFIED; p->modified = GS_POSITION_UNMODIFIED;
} }
@@ -278,7 +278,7 @@ int inter_guild_tosql(struct guild *g,int flag)
// their info changed, not to mention this would also mess up oppositions! // their info changed, not to mention this would also mess up oppositions!
// [Skotlex] // [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' 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); Sql_ShowDebug(sql_handle);
} }
@@ -293,7 +293,7 @@ int inter_guild_tosql(struct guild *g,int flag)
Sql_EscapeStringLen(sql_handle, esc_name, a->name, strnlen(a->name, NAME_LENGTH)); 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`) " if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`guild_id`,`opposition`,`alliance_id`,`name`) "
"VALUES ('%d','%d','%d','%s')", "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); Sql_ShowDebug(sql_handle);
} }
} }
@@ -311,7 +311,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_name, e->name, strnlen(e->name, NAME_LENGTH));
Sql_EscapeStringLen(sql_handle, esc_mes, e->mes, strnlen(e->mes, sizeof(e->mes))); 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`) " 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); Sql_ShowDebug(sql_handle);
} }
} }
@@ -323,7 +323,7 @@ int inter_guild_tosql(struct guild *g,int flag)
for(i=0;i<MAX_GUILDSKILL;i++){ for(i=0;i<MAX_GUILDSKILL;i++){
if (g->skill[i].id>0 && g->skill[i].lv>0){ 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')", 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); Sql_ShowDebug(sql_handle);
} }
} }
@@ -355,7 +355,7 @@ struct guild * inter_guild_fromsql(int guild_id)
#endif #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`,COALESCE(UNIX_TIMESTAMP(g.`last_master_change`),0), g.`emblem_data` " 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`,COALESCE(UNIX_TIMESTAMP(g.`last_master_change`),0), 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); Sql_ShowDebug(sql_handle);
return NULL; return NULL;
@@ -411,7 +411,7 @@ struct guild * inter_guild_fromsql(int guild_id)
// load guild member info // load guild member info
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `c`.`account_id`,`m`.`char_id`,`c`.`hair`,`c`.`hair_color`,`c`.`sex`,`c`.`class`,`c`.`base_level`,`m`.`exp`,`c`.`online`,`m`.`position`,`c`.`name`,coalesce(UNIX_TIMESTAMP(`c`.`last_login`),0) " if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `c`.`account_id`,`m`.`char_id`,`c`.`hair`,`c`.`hair_color`,`c`.`sex`,`c`.`class`,`c`.`base_level`,`m`.`exp`,`c`.`online`,`m`.`position`,`c`.`name`,coalesce(UNIX_TIMESTAMP(`c`.`last_login`),0) "
"FROM `%s` `m` INNER JOIN `%s` `c` on `c`.`char_id`=`m`.`char_id` WHERE `m`.`guild_id`='%d' ORDER BY `position`", schema_config.guild_member_db, schema_config.char_db, guild_id) ) "FROM `%s` `m` INNER JOIN `%s` `c` on `c`.`char_id`=`m`.`char_id` WHERE `m`.`guild_id`='%d' ORDER BY `position`", charserv_table(guild_member_table), charserv_table(char_table), guild_id) )
{ {
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
aFree(g); aFree(g);
@@ -451,7 +451,7 @@ struct guild * inter_guild_fromsql(int guild_id)
} }
//printf("- Read guild_position %d from sql \n",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); Sql_ShowDebug(sql_handle);
aFree(g); aFree(g);
@@ -473,7 +473,7 @@ struct guild * inter_guild_fromsql(int guild_id)
} }
//printf("- Read guild_alliance %d from sql \n",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); Sql_ShowDebug(sql_handle);
aFree(g); aFree(g);
@@ -489,7 +489,7 @@ struct guild * inter_guild_fromsql(int guild_id)
} }
//printf("- Read guild_expulsion %d from sql \n",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); Sql_ShowDebug(sql_handle);
aFree(g); aFree(g);
@@ -505,7 +505,7 @@ struct guild * inter_guild_fromsql(int guild_id)
} }
//printf("- Read guild_skill %d from sql \n",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); Sql_ShowDebug(sql_handle);
aFree(g); aFree(g);
@@ -571,7 +571,7 @@ int inter_guildcastle_tosql(struct guild_castle *gc)
StringBuf_Init(&buf); StringBuf_Init(&buf);
StringBuf_Printf(&buf, "REPLACE INTO `%s` SET `castle_id`='%d', `guild_id`='%d', `economy`='%d', `defense`='%d', " 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'", "`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); gc->triggerE, gc->triggerD, gc->nextTime, gc->payTime, gc->createTime, gc->visibleC);
for (i = 0; i < MAX_GUARDIANS; ++i) for (i = 0; i < MAX_GUARDIANS; ++i)
StringBuf_Printf(&buf, ", `visibleG%d`='%d'", i, gc->guardian[i].visible); StringBuf_Printf(&buf, ", `visibleG%d`='%d'", i, gc->guardian[i].visible);
@@ -601,7 +601,7 @@ struct guild_castle* inter_guildcastle_fromsql(int castle_id)
"`triggerD`, `nextTime`, `payTime`, `createTime`, `visibleC`"); "`triggerD`, `nextTime`, `payTime`, `createTime`, `visibleC`");
for (i = 0; i < MAX_GUARDIANS; ++i) for (i = 0; i < MAX_GUARDIANS; ++i)
StringBuf_Printf(&buf, ", `visibleG%d`", 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))) { if (SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf))) {
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
StringBuf_Destroy(&buf); StringBuf_Destroy(&buf);
@@ -659,7 +659,7 @@ int inter_guild_CharOnline(uint32 char_id, int guild_id)
if (guild_id == -1) { if (guild_id == -1) {
//Get guild_id from the database //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); Sql_ShowDebug(sql_handle);
return 0; return 0;
@@ -710,7 +710,7 @@ int inter_guild_CharOffline(uint32 char_id, int guild_id)
if (guild_id == -1) if (guild_id == -1)
{ {
//Get guild_id from the database //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); Sql_ShowDebug(sql_handle);
return 0; return 0;
@@ -768,7 +768,7 @@ int inter_guild_sql_init(void)
//Read exp file //Read exp file
for(i = 0; i<ARRAYLENGTH(filename); i++){ for(i = 0; i<ARRAYLENGTH(filename); i++){
sv_readdb(db_path, filename[i], ',', 1, 1, MAX_GUILDLEVEL, exp_guild_parse_row, i > 0); sv_readdb(charserv_config.db_path.c_str(), filename[i], ',', 1, 1, MAX_GUILDLEVEL, exp_guild_parse_row, i > 0);
} }
add_timer_func_list(guild_save_timer, "guild_save_timer"); add_timer_func_list(guild_save_timer, "guild_save_timer");
@@ -804,7 +804,7 @@ int search_guildname(char *str)
Sql_EscapeStringLen(sql_handle, esc_name, str, safestrnlen(str, NAME_LENGTH)); Sql_EscapeStringLen(sql_handle, esc_name, str, safestrnlen(str, NAME_LENGTH));
//Lookup guilds with the same name //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); Sql_ShowDebug(sql_handle);
return -1; return -1;
@@ -1316,7 +1316,7 @@ int mapif_parse_GuildLeave(int fd, int guild_id, uint32 account_id, uint32 char_
if( g == NULL ) if( g == NULL )
{ {
// Unknown guild, just update the player // 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); Sql_ShowDebug(sql_handle);
// mapif_guild_withdraw(guild_id,account_id,char_id,flag,g->member[i].name,mes); // mapif_guild_withdraw(guild_id,account_id,char_id,flag,g->member[i].name,mes);
return 0; return 0;
@@ -1429,32 +1429,32 @@ int mapif_parse_BreakGuild(int fd,int guild_id)
// Delete guild from sql // Delete guild from sql
//printf("- Delete guild %d from guild\n",guild_id); //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); 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); 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); 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); 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); 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); 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); 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); Sql_ShowDebug(sql_handle);
//printf("- Update guild %d of char\n",guild_id); //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); Sql_ShowDebug(sql_handle);
mapif_guild_broken(guild_id,0); mapif_guild_broken(guild_id,0);

View File

@@ -95,7 +95,7 @@ bool mapif_homunculus_save(struct s_homunculus* hd)
if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` " 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`, `autofeed`) " "(`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`, `autofeed`) "
"VALUES ('%d', '%d', '%d', '%s', '%d', '%u', '%u', '%d', '%d', %d, '%d', '%d', '%d', '%d', '%u', '%u', '%u', '%u', '%d', '%d', '%d', '%d')", "VALUES ('%d', '%d', '%d', '%s', '%d', '%u', '%u', '%d', '%d', %d, '%d', '%d', '%d', '%d', '%u', '%u', '%u', '%u', '%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, hd->autofeed) ) hd->hp, hd->max_hp, hd->sp, hd->max_sp, hd->skillpts, hd->rename_flag, hd->vaporize, hd->autofeed) )
{ {
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
@@ -109,7 +109,7 @@ bool mapif_homunculus_save(struct s_homunculus* hd)
else 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`='%u',`max_hp`='%u',`sp`='%u',`max_sp`='%u',`skill_point`='%d', `rename_flag`='%d', `vaporize`='%d', `autofeed`='%d' WHERE `homun_id`='%d'", 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`='%u',`max_hp`='%u',`sp`='%u',`max_sp`='%u',`skill_point`='%d', `rename_flag`='%d', `vaporize`='%d', `autofeed`='%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->autofeed, hd->hom_id) ) hd->hp, hd->max_hp, hd->sp, hd->max_sp, hd->skillpts, hd->rename_flag, hd->vaporize, hd->autofeed, hd->hom_id) )
{ {
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
@@ -121,7 +121,7 @@ bool mapif_homunculus_save(struct s_homunculus* hd)
int i; int i;
stmt = SqlStmt_Malloc(sql_handle); 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(homunculus_skill_table), hd->hom_id) )
SqlStmt_ShowDebug(stmt); SqlStmt_ShowDebug(stmt);
for( i = 0; i < MAX_HOMUNSKILL; ++i ) for( i = 0; i < MAX_HOMUNSKILL; ++i )
{ {
@@ -156,7 +156,7 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd)
memset(hd, 0, sizeof(*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`, `autofeed` FROM `%s` WHERE `homun_id`='%u'", 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`, `autofeed` FROM `%s` WHERE `homun_id`='%u'",
schema_config.homunculus_db, homun_id) ) charserv_table(homunculus_table), homun_id) )
{ {
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
return false; return false;
@@ -203,7 +203,7 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd)
hd->hunger = cap_value(hd->hunger, 0, 100); hd->hunger = cap_value(hd->hunger, 0, 100);
// Load Homunculus Skill // 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(homunculus_skill_table), homun_id) )
{ {
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
return false; return false;
@@ -233,8 +233,8 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd)
bool mapif_homunculus_delete(int homun_id) 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) 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'", schema_config.skill_homunculus_db, homun_id) || SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `homun_id` = '%u'", charserv_table(homunculus_skill_table), homun_id)
) { ) {
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
return false; return false;

View File

@@ -30,7 +30,7 @@ int mail_fromsql(uint32 char_id, struct mail_data* md)
md->full = false; md->full = false;
// First we prefill the msg ids // First we prefill the msg ids
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `id` FROM `%s` WHERE `dest_id`='%d' AND `status` < 3 ORDER BY `id` LIMIT %d", schema_config.mail_db, char_id, MAIL_MAX_INBOX + 1) ){ if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `id` FROM `%s` WHERE `dest_id`='%d' AND `status` < 3 ORDER BY `id` LIMIT %d", charserv_table(mail_table), char_id, MAIL_MAX_INBOX + 1) ){
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
return 0; return 0;
} }
@@ -59,7 +59,7 @@ int mail_fromsql(uint32 char_id, struct mail_data* md)
if( msg->status == MAIL_NEW ) 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); Sql_ShowDebug(sql_handle);
msg->status = MAIL_UNREAD; msg->status = MAIL_UNREAD;
@@ -84,7 +84,7 @@ int mail_savemessage(struct mail_message* msg)
// build message save query // build message save query
StringBuf_Init(&buf); StringBuf_Init(&buf);
StringBuf_Printf(&buf, "INSERT INTO `%s` (`send_name`, `send_id`, `dest_name`, `dest_id`, `title`, `message`, `time`, `status`, `zeny`,`type`", schema_config.mail_db); StringBuf_Printf(&buf, "INSERT INTO `%s` (`send_name`, `send_id`, `dest_name`, `dest_id`, `title`, `message`, `time`, `status`, `zeny`,`type`", charserv_table(mail_table));
StringBuf_Printf(&buf, ") VALUES (?, '%d', ?, '%d', ?, ?, '%lu', '%d', '%d', '%d'", msg->send_id, msg->dest_id, (unsigned long)msg->timestamp, msg->status, msg->zeny, msg->type); StringBuf_Printf(&buf, ") VALUES (?, '%d', ?, '%d', ?, ?, '%lu', '%d', '%d', '%d'", msg->send_id, msg->dest_id, (unsigned long)msg->timestamp, msg->status, msg->zeny, msg->type);
StringBuf_AppendStr(&buf, ")"); StringBuf_AppendStr(&buf, ")");
@@ -106,7 +106,7 @@ int mail_savemessage(struct mail_message* msg)
SqlStmt_Free(stmt); SqlStmt_Free(stmt);
StringBuf_Clear(&buf); StringBuf_Clear(&buf);
StringBuf_Printf(&buf,"INSERT INTO `%s` (`id`, `index`, `amount`, `nameid`, `refine`, `attribute`, `identify`, `unique_id`, `bound`", schema_config.mail_attachment_db); StringBuf_Printf(&buf,"INSERT INTO `%s` (`id`, `index`, `amount`, `nameid`, `refine`, `attribute`, `identify`, `unique_id`, `bound`", charserv_table(mail_attachment_table));
for (j = 0; j < MAX_SLOTS; j++) for (j = 0; j < MAX_SLOTS; j++)
StringBuf_Printf(&buf, ", `card%d`", j); StringBuf_Printf(&buf, ", `card%d`", j);
for (j = 0; j < MAX_ITEM_RDM_OPT; ++j) { for (j = 0; j < MAX_ITEM_RDM_OPT; ++j) {
@@ -155,7 +155,7 @@ bool mail_loadmessage(int mail_id, struct mail_message* msg)
StringBuf buf; StringBuf buf;
char* data; char* data;
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `id`,`send_name`,`send_id`,`dest_name`,`dest_id`,`title`,`message`,`time`,`status`,`zeny`,`type` FROM `%s` WHERE `id` = '%d'", schema_config.mail_db, mail_id ) if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `id`,`send_name`,`send_id`,`dest_name`,`dest_id`,`title`,`message`,`time`,`status`,`zeny`,`type` FROM `%s` WHERE `id` = '%d'", charserv_table(mail_table), mail_id )
|| SQL_SUCCESS != Sql_NextRow(sql_handle) ){ || SQL_SUCCESS != Sql_NextRow(sql_handle) ){
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
Sql_FreeResult(sql_handle); Sql_FreeResult(sql_handle);
@@ -193,7 +193,7 @@ bool mail_loadmessage(int mail_id, struct mail_message* msg)
StringBuf_Printf(&buf, ", `option_val%d`", j); StringBuf_Printf(&buf, ", `option_val%d`", j);
StringBuf_Printf(&buf, ", `option_parm%d`", j); StringBuf_Printf(&buf, ", `option_parm%d`", j);
} }
StringBuf_Printf(&buf, " FROM `%s`", schema_config.mail_attachment_db); StringBuf_Printf(&buf, " FROM `%s`", charserv_table(mail_attachment_table));
StringBuf_Printf(&buf, " WHERE `id` = '%d'", mail_id); StringBuf_Printf(&buf, " WHERE `id` = '%d'", mail_id);
StringBuf_AppendStr(&buf, " ORDER BY `index` ASC"); StringBuf_AppendStr(&buf, " ORDER BY `index` ASC");
StringBuf_Printf(&buf, " LIMIT %d", MAIL_MAX_ITEM); StringBuf_Printf(&buf, " LIMIT %d", MAIL_MAX_ITEM);
@@ -250,7 +250,7 @@ int mail_timer_sub( int limit, enum mail_inbox_type type ){
memset(mails, 0, sizeof(mails)); memset(mails, 0, sizeof(mails));
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `id`,`char_id`,`account_id` FROM `%s` `m` INNER JOIN `%s` `c` ON `c`.`char_id`=`m`.`dest_id` WHERE `type` = '%d' AND `time` <= UNIX_TIMESTAMP( NOW() - INTERVAL %d DAY ) ORDER BY `id` LIMIT %d", schema_config.mail_db, schema_config.char_db, type, limit, MAIL_MAX_INBOX + 1) ){ if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `id`,`char_id`,`account_id` FROM `%s` `m` INNER JOIN `%s` `c` ON `c`.`char_id`=`m`.`dest_id` WHERE `type` = '%d' AND `time` <= UNIX_TIMESTAMP( NOW() - INTERVAL %d DAY ) ORDER BY `id` LIMIT %d", charserv_table(mail_table), charserv_table(char_table), type, limit, MAIL_MAX_INBOX + 1) ){
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
return 0; return 0;
} }
@@ -331,7 +331,7 @@ void mapif_parse_Mail_requestinbox(int fd)
void mapif_parse_Mail_read(int fd) void mapif_parse_Mail_read(int fd)
{ {
int mail_id = RFIFOL(fd,2); 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); Sql_ShowDebug(sql_handle);
} }
@@ -339,7 +339,7 @@ void mapif_parse_Mail_read(int fd)
* Client Attachment Request * Client Attachment Request
*------------------------------------------*/ *------------------------------------------*/
bool mail_DeleteAttach(int mail_id){ bool mail_DeleteAttach(int mail_id){
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '%d'", schema_config.mail_attachment_db, mail_id ) ){ if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '%d'", charserv_table(mail_attachment_table), mail_id ) ){
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
return false; return false;
} }
@@ -366,7 +366,7 @@ void mapif_Mail_getattach(int fd, uint32 char_id, int mail_id, int type)
if( type & MAIL_ATT_ZENY ){ if( type & MAIL_ATT_ZENY ){
if( msg.zeny > 0 ){ if( msg.zeny > 0 ){
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `zeny` = 0 WHERE `id` = '%d'", schema_config.mail_db, mail_id ) ){ if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `zeny` = 0 WHERE `id` = '%d'", charserv_table(mail_table), mail_id ) ){
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
return; return;
} }
@@ -424,8 +424,8 @@ void mapif_Mail_delete(int fd, uint32 char_id, int mail_id, bool deleted)
bool failed = false; bool failed = false;
if( !deleted ){ if( !deleted ){
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_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '%d'", schema_config.mail_attachment_db, mail_id) ) SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '%d'", charserv_table(mail_attachment_table), mail_id) )
{ {
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
failed = true; failed = true;
@@ -481,8 +481,8 @@ void mapif_Mail_return(int fd, uint32 char_id, int mail_id)
{ {
if( msg.dest_id != char_id) if( msg.dest_id != char_id)
return; 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_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '%d'", schema_config.mail_attachment_db, mail_id) ) || SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `id` = '%d'", charserv_table(mail_attachment_table), mail_id) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
// If it was not sent by the server, since we do not want to return mails to the server // If it was not sent by the server, since we do not want to return mails to the server
else if( msg.send_id != 0 ) else if( msg.send_id != 0 )
@@ -553,7 +553,7 @@ void mapif_parse_Mail_send(int fd)
memcpy(&msg, RFIFOP(fd,8), sizeof(struct mail_message)); memcpy(&msg, RFIFOP(fd,8), sizeof(struct mail_message));
if( msg.dest_id != 0 ){ if( msg.dest_id != 0 ){
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `char_id`, `name` FROM `%s` WHERE `char_id` = '%u'", schema_config.char_db, msg.dest_id) ){ if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `char_id`, `name` FROM `%s` WHERE `char_id` = '%u'", charserv_table(char_table), msg.dest_id) ){
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
return; return;
} }
@@ -573,7 +573,7 @@ void mapif_parse_Mail_send(int fd)
// Try to find the Dest Char by Name // Try to find the Dest Char by Name
Sql_EscapeStringLen(sql_handle, esc_name, msg.dest_name, strnlen(msg.dest_name, NAME_LENGTH)); 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); Sql_ShowDebug(sql_handle);
}else if ( SQL_SUCCESS == Sql_NextRow(sql_handle) ){ }else if ( SQL_SUCCESS == Sql_NextRow(sql_handle) ){
#if PACKETVER < 20150513 #if PACKETVER < 20150513
@@ -653,7 +653,7 @@ void mapif_parse_Mail_receiver_check( int fd ){
// Try to find the Dest Char by Name // Try to find the Dest Char by Name
Sql_EscapeStringLen( sql_handle, esc_name, name, strnlen( name, NAME_LENGTH ) ); Sql_EscapeStringLen( sql_handle, esc_name, name, strnlen( name, NAME_LENGTH ) );
if( SQL_ERROR == Sql_Query( sql_handle, "SELECT `char_id`,`class`,`base_level` FROM `%s` WHERE `name` = '%s'", schema_config.char_db, esc_name ) ){ if( SQL_ERROR == Sql_Query( sql_handle, "SELECT `char_id`,`class`,`base_level` FROM `%s` WHERE `name` = '%s'", charserv_table(char_table), esc_name ) ){
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
}else if( SQL_SUCCESS == Sql_NextRow(sql_handle) ){ }else if( SQL_SUCCESS == Sql_NextRow(sql_handle) ){
char *data; char *data;

View File

@@ -19,7 +19,7 @@ bool mercenary_owner_fromsql(uint32 char_id, struct mmo_charstatus *status)
{ {
char* data; 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); Sql_ShowDebug(sql_handle);
return false; return false;
@@ -46,7 +46,7 @@ bool mercenary_owner_fromsql(uint32 char_id, struct mmo_charstatus *status)
bool mercenary_owner_tosql(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')", 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); Sql_ShowDebug(sql_handle);
return false; return false;
@@ -57,10 +57,10 @@ bool mercenary_owner_tosql(uint32 char_id, struct mmo_charstatus *status)
bool mercenary_owner_delete(uint32 char_id) 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); 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); Sql_ShowDebug(sql_handle);
return true; return true;
@@ -74,7 +74,7 @@ bool mapif_mercenary_save(struct s_mercenary* merc)
{ // Create new DB entry { // Create new DB entry
if( SQL_ERROR == Sql_Query(sql_handle, if( SQL_ERROR == Sql_Query(sql_handle,
"INSERT INTO `%s` (`char_id`,`class`,`hp`,`sp`,`kill_counter`,`life_time`) VALUES ('%d','%d','%u','%u','%u','%" PRtf "')", "INSERT INTO `%s` (`char_id`,`class`,`hp`,`sp`,`kill_counter`,`life_time`) VALUES ('%d','%d','%u','%u','%u','%" PRtf "')",
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); Sql_ShowDebug(sql_handle);
flag = false; flag = false;
@@ -84,7 +84,7 @@ bool mapif_mercenary_save(struct s_mercenary* merc)
} }
else if( SQL_ERROR == Sql_Query(sql_handle, else if( SQL_ERROR == Sql_Query(sql_handle,
"UPDATE `%s` SET `char_id` = '%d', `class` = '%d', `hp` = '%u', `sp` = '%u', `kill_counter` = '%u', `life_time` = '%" PRtf "' WHERE `mer_id` = '%d'", "UPDATE `%s` SET `char_id` = '%d', `class` = '%d', `hp` = '%u', `sp` = '%u', `kill_counter` = '%u', `life_time` = '%" PRtf "' 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 { // Update DB entry
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
flag = false; flag = false;
@@ -101,7 +101,7 @@ bool mapif_mercenary_load(int merc_id, uint32 char_id, struct s_mercenary *merc)
merc->mercenary_id = merc_id; merc->mercenary_id = merc_id;
merc->char_id = char_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); Sql_ShowDebug(sql_handle);
return false; return false;
@@ -127,7 +127,7 @@ bool mapif_mercenary_load(int merc_id, uint32 char_id, struct s_mercenary *merc)
bool mapif_mercenary_delete(int merc_id) 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); Sql_ShowDebug(sql_handle);
return false; return false;

View File

@@ -130,9 +130,9 @@ int inter_party_tosql(struct party *p, int flag, int index)
if( flag & PS_BREAK ) if( flag & PS_BREAK )
{// Break the party {// Break the party
// we'll skip name-checking and just reset everyone with the same party id [celest] // 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); 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); Sql_ShowDebug(sql_handle);
//Remove from memory //Remove from memory
idb_remove(party_db_, party_id); idb_remove(party_db_, party_id);
@@ -144,7 +144,7 @@ int inter_party_tosql(struct party *p, int flag, int index)
if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` " if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` "
"(`name`, `exp`, `item`, `leader_id`, `leader_char`) " "(`name`, `exp`, `item`, `leader_id`, `leader_char`) "
"VALUES ('%s', '%d', '%d', '%d', '%d')", "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); Sql_ShowDebug(sql_handle);
return 0; return 0;
@@ -155,28 +155,28 @@ int inter_party_tosql(struct party *p, int flag, int index)
if( flag & PS_BASIC ) if( flag & PS_BASIC )
{// Update party info. {// Update party info.
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `name`='%s', `exp`='%d', `item`='%d' WHERE `party_id`='%d'", 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); Sql_ShowDebug(sql_handle);
} }
if( flag & PS_LEADER ) if( flag & PS_LEADER )
{// Update leader {// Update leader
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `leader_id`='%d', `leader_char`='%d' WHERE `party_id`='%d'", 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); Sql_ShowDebug(sql_handle);
} }
if( flag & PS_ADDMEMBER ) if( flag & PS_ADDMEMBER )
{// Add one party member. {// 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'", 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); Sql_ShowDebug(sql_handle);
} }
if( flag & PS_DELMEMBER ) if( flag & PS_DELMEMBER )
{// Remove one party member. {// 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'", 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); Sql_ShowDebug(sql_handle);
} }
@@ -210,7 +210,7 @@ struct party_data *inter_party_fromsql(int party_id)
p = party_pt; p = party_pt;
memset(p, 0, sizeof(struct party_data)); 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); Sql_ShowDebug(sql_handle);
return NULL; return NULL;
@@ -228,7 +228,7 @@ struct party_data *inter_party_fromsql(int party_id)
Sql_FreeResult(sql_handle); Sql_FreeResult(sql_handle);
// Load members // 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); Sql_ShowDebug(sql_handle);
return NULL; return NULL;
@@ -292,7 +292,7 @@ struct party_data* search_partyname(char* str)
struct party_data* p = NULL; struct party_data* p = NULL;
Sql_EscapeStringLen(sql_handle, esc_name, str, safestrnlen(str, NAME_LENGTH)); 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); Sql_ShowDebug(sql_handle);
else if( SQL_SUCCESS == Sql_NextRow(sql_handle) ) else if( SQL_SUCCESS == Sql_NextRow(sql_handle) )
{ {
@@ -342,7 +342,7 @@ int party_check_family_share(struct party_data *p) {
// Returns whether this party can keep having exp share or not. // Returns whether this party can keep having exp share or not.
int party_check_exp_share(struct party_data *p) int party_check_exp_share(struct party_data *p)
{ {
return (p->party.count < 2 || p->max_lv - p->min_lv <= party_share_level || party_check_family_share(p)); return (p->party.count < 2 || p->max_lv - p->min_lv <= inter_config.party_share_level || party_check_family_share(p));
} }
// Is there any member in the party? // Is there any member in the party?
@@ -634,7 +634,7 @@ int mapif_parse_PartyLeave(int fd, int party_id, uint32 account_id, uint32 char_
p = inter_party_fromsql(party_id); p = inter_party_fromsql(party_id);
if( p == NULL ) if( p == NULL )
{// Party does not exists? {// 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); Sql_ShowDebug(sql_handle);
return 0; return 0;
} }
@@ -790,7 +790,7 @@ int mapif_parse_PartyShareLevel(int fd,unsigned int share_lvl)
struct party_data *p; struct party_data *p;
DBIterator* iter = db_iterator(party_db_); 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 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) if(p->party.count > 1)
@@ -844,7 +844,7 @@ int inter_party_CharOnline(uint32 char_id, int party_id)
{// Get party_id from the database {// Get party_id from the database
char* data; 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); Sql_ShowDebug(sql_handle);
return 0; return 0;
@@ -890,7 +890,7 @@ int inter_party_CharOffline(uint32 char_id, int party_id) {
{// Get guild_id from the database {// Get guild_id from the database
char* data; 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); Sql_ShowDebug(sql_handle);
return 0; return 0;

View File

@@ -35,7 +35,7 @@ int inter_pet_tosql(int pet_id, struct s_pet* p)
if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` " 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`,`autofeed`) " "(`class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate`,`autofeed`) "
"VALUES ('%d', '%s', '%d', '%d', '%d', '%u', '%u', '%d', '%d', '%d', '%d', '%d')", "VALUES ('%d', '%s', '%d', '%d', '%d', '%u', '%u', '%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, p->autofeed) ) p->equip, p->intimate, p->hungry, p->rename_flag, p->incubate, p->autofeed) )
{ {
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
@@ -46,7 +46,7 @@ int inter_pet_tosql(int pet_id, struct s_pet* p)
else else
{// Update pet. {// 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`='%u',`equip`='%u',`intimate`='%d',`hungry`='%d',`rename_flag`='%d',`incubate`='%d',`autofeed`='%d' WHERE `pet_id`='%d'", if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `class`='%d',`name`='%s',`account_id`='%d',`char_id`='%d',`level`='%d',`egg_id`='%u',`equip`='%u',`intimate`='%d',`hungry`='%d',`rename_flag`='%d',`incubate`='%d',`autofeed`='%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->autofeed, p->pet_id) ) p->equip, p->intimate, p->hungry, p->rename_flag, p->incubate, p->autofeed, p->pet_id) )
{ {
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
@@ -71,7 +71,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`,`autofeed`) //`pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate`,`autofeed`)
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`,`autofeed` 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`,`autofeed` FROM `%s` WHERE `pet_id`='%d'", charserv_table(pet_table), pet_id) )
{ {
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
return 0; return 0;
@@ -118,7 +118,7 @@ void inter_pet_sql_final(void){
int inter_pet_delete(int pet_id){ int inter_pet_delete(int pet_id){
ShowInfo("delete pet request: %d...\n",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); Sql_ShowDebug(sql_handle);
return 0; return 0;
} }

View File

@@ -40,7 +40,7 @@ struct quest *mapif_quests_fromsql(uint32 char_id, int *count) {
memset(&tmp_quest, 0, sizeof(struct quest)); 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_BindParam(stmt, 0, SQLDT_INT, &char_id, 0)
|| SQL_ERROR == SqlStmt_Execute(stmt) || SQL_ERROR == SqlStmt_Execute(stmt)
|| SQL_ERROR == SqlStmt_BindColumn(stmt, 0, SQLDT_INT, &tmp_quest.quest_id, 0, NULL, NULL) || SQL_ERROR == SqlStmt_BindColumn(stmt, 0, SQLDT_INT, &tmp_quest.quest_id, 0, NULL, NULL)
@@ -85,7 +85,7 @@ struct quest *mapif_quests_fromsql(uint32 char_id, int *count) {
* @return false in case of errors, true otherwise * @return false in case of errors, true otherwise
*/ */
bool mapif_quest_delete(uint32 char_id, int quest_id) { 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); Sql_ShowDebug(sql_handle);
return false; return false;
@@ -102,7 +102,7 @@ bool mapif_quest_delete(uint32 char_id, int quest_id) {
* @return false in case of errors, true otherwise * @return false in case of errors, true otherwise
*/ */
bool mapif_quest_add(uint32 char_id, struct quest qd) { 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', '%u', '%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', '%u', '%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); Sql_ShowDebug(sql_handle);
return false; return false;
@@ -119,7 +119,7 @@ bool mapif_quest_add(uint32 char_id, struct quest qd) {
* @return false in case of errors, true otherwise * @return false in case of errors, true otherwise
*/ */
bool mapif_quest_update(uint32 char_id, struct quest qd) { 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); Sql_ShowDebug(sql_handle);
return false; return false;

View File

@@ -38,14 +38,14 @@ int inter_premiumStorage_getMax(uint8 id) {
* @param id: Storage ID * @param id: Storage ID
* @return Table name * @return Table name
*/ */
const char *inter_premiumStorage_getTableName(uint8 id) { const std::string inter_premiumStorage_getTableName(uint8 id) {
std::shared_ptr<s_storage_table> storage = interServerDb.find( id ); std::shared_ptr<s_storage_table> storage = interServerDb.find( id );
if( storage != nullptr ){ if( storage != nullptr ){
return storage->table; return storage->table;
} }
return schema_config.storage_db; return charserv_table(storage_table);
} }
/** /**
@@ -195,7 +195,7 @@ void inter_storage_sql_final(void)
*/ */
bool mapif_load_guild_storage(int fd,uint32 account_id,int guild_id, char flag) bool 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); Sql_ShowDebug(sql_handle);
else if( Sql_NumRows(sql_handle) > 0 ) else if( Sql_NumRows(sql_handle) > 0 )
{// guild exists {// guild exists
@@ -259,7 +259,7 @@ bool mapif_parse_SaveGuildStorage(int fd)
} }
else 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); Sql_ShowDebug(sql_handle);
else if( Sql_NumRows(sql_handle) > 0 ) else if( Sql_NumRows(sql_handle) > 0 )
{// guild exists {// guild exists
@@ -342,7 +342,7 @@ bool mapif_parse_itembound_retrieve(int fd)
StringBuf_Printf(&buf, ", `option_val%d`", j); StringBuf_Printf(&buf, ", `option_val%d`", j);
StringBuf_Printf(&buf, ", `option_parm%d`", j); StringBuf_Printf(&buf, ", `option_parm%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); stmt = SqlStmt_Malloc(sql_handle);
if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) || if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) ||
@@ -388,7 +388,7 @@ bool mapif_parse_itembound_retrieve(int fd)
// Delete bound items from player's inventory // Delete bound items from player's inventory
StringBuf_Clear(&buf); StringBuf_Clear(&buf);
StringBuf_Printf(&buf, "DELETE FROM `%s` WHERE `char_id` = %d AND `bound` = %d",schema_config.inventory_db, char_id, BOUND_GUILD); StringBuf_Printf(&buf, "DELETE FROM `%s` WHERE `char_id` = %d AND `bound` = %d", charserv_table(inventory_table), char_id, BOUND_GUILD);
if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) || if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) ||
SQL_ERROR == SqlStmt_Execute(stmt) ) SQL_ERROR == SqlStmt_Execute(stmt) )
{ {
@@ -432,7 +432,7 @@ bool mapif_parse_itembound_retrieve(int fd)
if (j) { if (j) {
StringBuf buf2; StringBuf buf2;
StringBuf_Init(&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)) || if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf)) ||
SQL_ERROR == SqlStmt_Execute(stmt) ) SQL_ERROR == SqlStmt_Execute(stmt) )

View File

@@ -4,6 +4,8 @@
#ifndef INT_STORAGE_HPP #ifndef INT_STORAGE_HPP
#define INT_STORAGE_HPP #define INT_STORAGE_HPP
#include <string>
#include "../common/cbasetypes.hpp" #include "../common/cbasetypes.hpp"
struct s_storage; struct s_storage;
@@ -12,7 +14,7 @@ void inter_storage_sql_init(void);
void inter_storage_sql_final(void); void inter_storage_sql_final(void);
int inter_premiumStorage_getMax(uint8 id); int inter_premiumStorage_getMax(uint8 id);
const char *inter_premiumStorage_getTableName(uint8 id); const std::string inter_premiumStorage_getTableName(uint8 id);
const char *inter_premiumStorage_getPrintableName(uint8 id); const char *inter_premiumStorage_getPrintableName(uint8 id);
bool inter_storage_parse_frommap(int fd); bool inter_storage_parse_frommap(int fd);

View File

@@ -35,7 +35,7 @@
#include "int_quest.hpp" #include "int_quest.hpp"
#include "int_storage.hpp" #include "int_storage.hpp"
std::string cfgFile = "inter_athena.yml"; ///< Inter-Config file std::string cfgFile = "inter_server.yml"; ///< Inter-Config file
InterServerDatabase interServerDb; InterServerDatabase interServerDb;
#define WISDATA_TTL (60*1000) //Wis data Time To Live (60 seconds) #define WISDATA_TTL (60*1000) //Wis data Time To Live (60 seconds)
@@ -44,13 +44,8 @@ InterServerDatabase interServerDb;
Sql* sql_handle = NULL; ///Link to mysql db, connection FD Sql* sql_handle = NULL; ///Link to mysql db, connection FD
int char_server_port = 3306; struct Inter_Config inter_config;
char char_server_ip[64] = "127.0.0.1"; static void inter_config_init(void);
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;
/// Received packet Lengths from map-server /// Received packet Lengths from map-server
int inter_recv_packet_length[] = { int inter_recv_packet_length[] = {
@@ -453,7 +448,7 @@ void mapif_parse_accinfo(int fd) {
account_id = atoi(query); account_id = atoi(query);
if (account_id < START_ACCOUNT_NUM) { // is string 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 ) { || Sql_NumRows(sql_handle) == 0 ) {
if( Sql_NumRows(sql_handle) == 0 ) { if( Sql_NumRows(sql_handle) == 0 ) {
inter_to_fd(fd, u_fd, u_aid, (char *)msg_txt(212) ,query); inter_to_fd(fd, u_fd, u_aid, (char *)msg_txt(212) ,query);
@@ -525,7 +520,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(223), logincount, lastlogin);
inter_to_fd(map_fd, u_fd, u_aid, (char *)msg_txt(224)); 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 ) || Sql_NumRows(sql_handle) == 0 )
{ {
if( Sql_NumRows(sql_handle) == 0 ) if( Sql_NumRows(sql_handle) == 0 )
@@ -579,36 +574,36 @@ void inter_savereg(uint32 account_id, uint32 char_id, const char *key, uint32 in
} else if ( key[0] == '#' ) { // local account reg } else if ( key[0] == '#' ) { // local account reg
if( is_string ) { if( is_string ) {
if( string_value ) { if( string_value ) {
if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`account_id`,`key`,`index`,`value`) VALUES ('%" PRIu32 "','%s','%" PRIu32 "','%s')", schema_config.acc_reg_str_table, account_id, esc_key, index, esc_val) ) if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`account_id`,`key`,`index`,`value`) VALUES ('%" PRIu32 "','%s','%" PRIu32 "','%s')", schema_config.acc_reg_str_table.c_str(), account_id, esc_key, index, esc_val) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
} else { } else {
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%" PRIu32 "' AND `key` = '%s' AND `index` = '%" PRIu32 "' LIMIT 1", schema_config.acc_reg_str_table, account_id, esc_key, index) ) if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%" PRIu32 "' AND `key` = '%s' AND `index` = '%" PRIu32 "' LIMIT 1", schema_config.acc_reg_str_table.c_str(), account_id, esc_key, index) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
} }
} else { } else {
if( int_value ) { if( int_value ) {
if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`account_id`,`key`,`index`,`value`) VALUES ('%" PRIu32 "','%s','%" PRIu32 "','%" PRId64 "')", schema_config.acc_reg_num_table, account_id, esc_key, index, int_value) ) if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`account_id`,`key`,`index`,`value`) VALUES ('%" PRIu32 "','%s','%" PRIu32 "','%" PRId64 "')", schema_config.acc_reg_num_table.c_str(), account_id, esc_key, index, int_value) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
} else { } else {
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%" PRIu32 "' AND `key` = '%s' AND `index` = '%" PRIu32 "' LIMIT 1", schema_config.acc_reg_num_table, account_id, esc_key, index) ) if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%" PRIu32 "' AND `key` = '%s' AND `index` = '%" PRIu32 "' LIMIT 1", schema_config.acc_reg_num_table.c_str(), account_id, esc_key, index) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
} }
} }
} else { /* char reg */ } else { /* char reg */
if( is_string ) { if( is_string ) {
if( string_value ) { if( string_value ) {
if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`char_id`,`key`,`index`,`value`) VALUES ('%" PRIu32 "','%s','%" PRIu32 "','%s')", schema_config.char_reg_str_table, char_id, esc_key, index, esc_val) ) if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`char_id`,`key`,`index`,`value`) VALUES ('%" PRIu32 "','%s','%" PRIu32 "','%s')", schema_config.char_reg_str_table.c_str(), char_id, esc_key, index, esc_val) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
} else { } else {
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%" PRIu32 "' AND `key` = '%s' AND `index` = '%" PRIu32 "' LIMIT 1", schema_config.char_reg_str_table, char_id, esc_key, index) ) if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%" PRIu32 "' AND `key` = '%s' AND `index` = '%" PRIu32 "' LIMIT 1", schema_config.char_reg_str_table.c_str(), char_id, esc_key, index) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
} }
} else { } else {
if( int_value ) { if( int_value ) {
if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`char_id`,`key`,`index`,`value`) VALUES ('%" PRIu32 "','%s','%" PRIu32 "','%" PRId64 "')", schema_config.char_reg_num_table, char_id, esc_key, index, int_value) ) if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`char_id`,`key`,`index`,`value`) VALUES ('%" PRIu32 "','%s','%" PRIu32 "','%" PRId64 "')", schema_config.char_reg_num_table.c_str(), char_id, esc_key, index, int_value) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
} else { } else {
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%" PRIu32 "' AND `key` = '%s' AND `index` = '%" PRIu32 "' LIMIT 1", schema_config.char_reg_num_table, char_id, esc_key, index) ) if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%" PRIu32 "' AND `key` = '%s' AND `index` = '%" PRIu32 "' LIMIT 1", schema_config.char_reg_num_table.c_str(), char_id, esc_key, index) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
} }
} }
@@ -624,11 +619,11 @@ int inter_accreg_fromsql(uint32 account_id, uint32 char_id, int fd, int type)
switch( type ) { switch( type ) {
case 3: //char reg case 3: //char reg
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `char_id`='%" PRIu32 "'", schema_config.char_reg_str_table, char_id) ) if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `char_id`='%" PRIu32 "'", charserv_table(char_reg_str_table), char_id) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
break; break;
case 2: //account reg case 2: //account reg
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `account_id`='%" PRIu32 "'", schema_config.acc_reg_str_table, account_id) ) if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `account_id`='%" PRIu32 "'", charserv_table(acc_reg_str_table), account_id) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
break; break;
case 1: //account2 reg case 1: //account2 reg
@@ -705,11 +700,11 @@ int inter_accreg_fromsql(uint32 account_id, uint32 char_id, int fd, int type)
switch( type ) { switch( type ) {
case 3: //char reg case 3: //char reg
if (SQL_ERROR == Sql_Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `char_id`='%" PRIu32 "'", schema_config.char_reg_num_table, char_id)) if (SQL_ERROR == Sql_Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `char_id`='%" PRIu32 "'", charserv_table(char_reg_num_table), char_id))
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
break; break;
case 2: //account reg case 2: //account reg
if (SQL_ERROR == Sql_Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `account_id`='%" PRIu32 "'", schema_config.acc_reg_num_table, account_id)) if (SQL_ERROR == Sql_Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `account_id`='%" PRIu32 "'", charserv_table(acc_reg_num_table), account_id))
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
break; break;
#if 0 // This is already checked above. #if 0 // This is already checked above.
@@ -782,6 +777,20 @@ int inter_accreg_fromsql(uint32 account_id, uint32 char_id, int fd, int type)
return 1; 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 = "127.0.0.1";
inter_config.char_server_id = "ragnarok";
inter_config.char_server_pw = "";
inter_config.char_server_db = "ragnarok";
inter_config.default_codepage = "";
}
/*========================================== /*==========================================
* read config file * read config file
*------------------------------------------*/ *------------------------------------------*/
@@ -806,19 +815,19 @@ int inter_config_read(const char* cfgName)
continue; continue;
if(!strcmpi(w1,"char_server_ip")) if(!strcmpi(w1,"char_server_ip"))
safestrncpy(char_server_ip,w2,sizeof(char_server_ip)); inter_config.char_server_ip = w2;
else if(!strcmpi(w1,"char_server_port")) 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")) else if(!strcmpi(w1,"char_server_id"))
safestrncpy(char_server_id,w2,sizeof(char_server_id)); inter_config.char_server_id = w2;
else if(!strcmpi(w1,"char_server_pw")) else if(!strcmpi(w1,"char_server_pw"))
safestrncpy(char_server_pw,w2,sizeof(char_server_pw)); inter_config.char_server_pw = w2;
else if(!strcmpi(w1,"char_server_db")) else if(!strcmpi(w1,"char_server_db"))
safestrncpy(char_server_db,w2,sizeof(char_server_db)); inter_config.char_server_db = w2;
else if(!strcmpi(w1,"default_codepage")) else if(!strcmpi(w1,"default_codepage"))
safestrncpy(default_codepage,w2,sizeof(default_codepage)); inter_config.default_codepage = w2;
else if(!strcmpi(w1,"party_share_level")) 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")) else if(!strcmpi(w1,"log_inter"))
charserv_config.log_inter = atoi(w2); charserv_config.log_inter = atoi(w2);
else if(!strcmpi(w1,"inter_server_conf")) else if(!strcmpi(w1,"inter_server_conf"))
@@ -845,7 +854,7 @@ int inter_log(const char* fmt, ...)
va_end(ap); va_end(ap);
Sql_EscapeStringLen(sql_handle, esc_str, str, strnlen(str, sizeof(str))); 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); Sql_ShowDebug(sql_handle);
return 0; return 0;
@@ -930,26 +939,30 @@ uint64 InterServerDatabase::parseBodyNode( const YAML::Node& node ){
// initialize // initialize
int inter_init_sql(const char *file) int inter_init_sql(const char *file)
{ {
inter_config_init();
inter_config_read(file); inter_config_read(file);
//DB connection initialized //DB connection initialized
sql_handle = Sql_Malloc(); sql_handle = Sql_Malloc();
ShowInfo("Connect Character DB server.... (Character Server)\n"); 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, inter_config.char_server_id.c_str(), inter_config.char_server_pw.c_str(), inter_config.char_server_ip.c_str(), inter_config.char_server_port, inter_config.char_server_db.c_str()) )
{ {
ShowError("Couldn't connect with username = '%s', password = '%s', host = '%s', port = '%d', database = '%s'\n", ShowError("Couldn't connect with username = '%s', password = '%s', host = '%s', port = '%d', database = '%s'\n",
char_server_id, char_server_pw, char_server_ip, char_server_port, char_server_db); inter_config.char_server_id.c_str(), inter_config.char_server_pw.c_str(), inter_config.char_server_ip.c_str(), inter_config.char_server_port, inter_config.char_server_db.c_str());
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
Sql_Free(sql_handle); Sql_Free(sql_handle);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if( *default_codepage ) { if( !inter_config.default_codepage.empty() ) {
if( SQL_ERROR == Sql_SetEncoding(sql_handle, default_codepage) ) if( SQL_ERROR == Sql_SetEncoding(sql_handle, inter_config.default_codepage.c_str()) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
} }
ShowStatus("Character server connection: Database '" CL_WHITE "%s" CL_RESET "' at '" CL_WHITE "%s" CL_RESET "'\n", inter_config.char_server_db.c_str(), inter_config.char_server_ip.c_str());
wis_db = idb_alloc(DB_OPT_RELEASE_DATA); wis_db = idb_alloc(DB_OPT_RELEASE_DATA);
interServerDb.load(); interServerDb.load();
inter_guild_sql_init(); inter_guild_sql_init();
inter_storage_sql_init(); inter_storage_sql_init();
@@ -1176,7 +1189,7 @@ int mapif_parse_WisRequest(int fd)
safestrncpy(name, RFIFOCP(fd,8+NAME_LENGTH), NAME_LENGTH); //Received name may be too large and not contain \0! [Skotlex] safestrncpy(name, RFIFOCP(fd,8+NAME_LENGTH), NAME_LENGTH); //Received name may be too large and not contain \0! [Skotlex]
Sql_EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH)); 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); Sql_ShowDebug(sql_handle);
// search if character exists before to ask all map-servers // search if character exists before to ask all map-servers

View File

@@ -37,7 +37,17 @@ void mapif_accinfo_ack(bool success, int map_fd, int u_fd, int u_aid, int accoun
int inter_log(const char *fmt,...); int inter_log(const char *fmt,...);
extern unsigned int party_share_level; struct Inter_Config {
unsigned short char_server_port; ///< char-server port
std::string char_server_ip; ///< char-server hostname/ip
std::string char_server_id; ///< char-server username
std::string char_server_pw; ///< char-server password
std::string char_server_db; ///< char-server database
std::string default_codepage; ///< Codepage [irmin]
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* sql_handle;
extern Sql* lsql_handle; extern Sql* lsql_handle;

View File

@@ -5,7 +5,7 @@
#include <algorithm> //min / max #include <algorithm> //min / max
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string>
#include "../common/malloc.hpp" #include "../common/malloc.hpp"
#include "../common/mmo.hpp" #include "../common/mmo.hpp"
@@ -22,18 +22,18 @@
typedef struct AccountDB_SQL { typedef struct AccountDB_SQL {
AccountDB vtable; // public interface AccountDB vtable; // public interface
Sql* accounts; // SQL handle accounts storage Sql* accounts; // SQL handle accounts storage
char db_hostname[64]; // Doubled for long hostnames (bugreport:8003)
uint16 db_port; uint16 db_port;
char db_username[32]; std::string db_hostname;
char db_password[32]; std::string db_username;
char db_database[32]; std::string db_password;
char codepage[32]; std::string db_database;
std::string codepage;
// other settings // other settings
bool case_sensitive; bool case_sensitive;
//table name //table name
char account_db[32]; std::string account_table;
char global_acc_reg_num_table[32]; std::string global_acc_reg_num_table;
char global_acc_reg_str_table[32]; std::string global_acc_reg_str_table;
} AccountDB_SQL; } AccountDB_SQL;
@@ -61,6 +61,9 @@ static AccountDBIterator* account_db_sql_iterator(AccountDB* self);
static void account_db_sql_iter_destroy(AccountDBIterator* self); static void account_db_sql_iter_destroy(AccountDBIterator* self);
static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account* acc); static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account* acc);
static void account_db_init_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_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); static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, bool is_new);
@@ -82,21 +85,13 @@ AccountDB* account_db_sql(void) {
db->vtable.load_num = &account_db_sql_load_num; db->vtable.load_num = &account_db_sql_load_num;
db->vtable.load_str = &account_db_sql_load_str; db->vtable.load_str = &account_db_sql_load_str;
db->vtable.iterator = &account_db_sql_iterator; db->vtable.iterator = &account_db_sql_iterator;
db->vtable.init_conf = &account_db_init_conf;
db->vtable.check_tables = &account_db_check_tables;
// initialize to default values // initialize to default values
db->accounts = NULL; 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, "", sizeof(db->db_password));
safestrncpy(db->db_database, "ragnarok", sizeof(db->db_database));
safestrncpy(db->codepage, "", sizeof(db->codepage));
// other settings // other settings
db->case_sensitive = false; 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; return &db->vtable;
} }
@@ -104,6 +99,57 @@ 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 = "127.0.0.1";
db->db_username = "ragnarok";
db->db_password = std::string("");
db->db_database = "ragnarok";
db->codepage = std::string("");
db->account_table = "login";
db->global_acc_reg_num_table = "global_acc_reg_num";
db->global_acc_reg_str_table = "global_acc_reg_str";
}
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`, "
"`vip_time`, `old_group` "
"FROM `%s`;", db->account_table.c_str()) )
{
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`;", db->global_acc_reg_num_table.c_str()) )
{
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`;", db->global_acc_reg_str_table.c_str()) )
{
Sql_ShowDebug(db->accounts);
return false;
}
return true;
}
/** /**
* Establish the database connection. * Establish the database connection.
@@ -112,38 +158,31 @@ AccountDB* account_db_sql(void) {
static bool account_db_sql_init(AccountDB* self) { static bool account_db_sql_init(AccountDB* self) {
AccountDB_SQL* db = (AccountDB_SQL*)self; AccountDB_SQL* db = (AccountDB_SQL*)self;
Sql* sql_handle; 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(); db->accounts = Sql_Malloc();
sql_handle = db->accounts; sql_handle = db->accounts;
username = db->db_username; if( SQL_ERROR == Sql_Connect(sql_handle, db->db_username.c_str(), db->db_password.c_str(), db->db_hostname.c_str(), db->db_port, db->db_database.c_str()) )
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) )
{ {
ShowError("Couldn't connect with uname='%s',passwd='%s',host='%s',port='%d',database='%s'\n", ShowError("Couldn't connect with uname='%s',passwd='%s',host='%s',port='%d',database='%s'\n",
username, password, hostname, port, database); db->db_username.c_str(), db->db_password.c_str(), db->db_hostname.c_str(), db->db_port, db->db_database.c_str());
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
Sql_Free(db->accounts); Sql_Free(db->accounts);
db->accounts = NULL; db->accounts = NULL;
return false; return false;
} }
if( codepage[0] != '\0' && SQL_ERROR == Sql_SetEncoding(sql_handle, codepage) ) if( !db->codepage.empty() && SQL_ERROR == Sql_SetEncoding(sql_handle, db->codepage.c_str()) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
self->remove_webtokens( self ); self->remove_webtokens( self );
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", db->db_database.c_str(), db->db_hostname.c_str());
return true; return true;
} }
@@ -154,7 +193,7 @@ static bool account_db_sql_init(AccountDB* self) {
static void account_db_sql_destroy(AccountDB* self){ static void account_db_sql_destroy(AccountDB* self){
AccountDB_SQL* db = (AccountDB_SQL*)self; AccountDB_SQL* db = (AccountDB_SQL*)self;
if( SQL_ERROR == Sql_Query( db->accounts, "UPDATE `%s` SET `web_auth_token` = NULL", db->account_db ) ){ if( SQL_ERROR == Sql_Query( db->accounts, "UPDATE `%s` SET `web_auth_token` = NULL", db->account_table.c_str() ) ){
Sql_ShowDebug( db->accounts ); Sql_ShowDebug( db->accounts );
} }
@@ -180,41 +219,33 @@ static bool account_db_sql_get_property(AccountDB* self, const char* key, char*
signature = "login_server_"; signature = "login_server_";
if( strncmpi(key, signature, strlen(signature)) == 0 ) { if( strncmpi(key, signature, strlen(signature)) == 0 ) {
key += strlen(signature); key += strlen(signature);
if( strcmpi(key, "ip") == 0 ) if (strcmpi(key, "ip") == 0)
safesnprintf(buf, buflen, "%s", db->db_hostname); safesnprintf(buf, buflen, "%s", db->db_hostname.c_str());
else else if (strcmpi(key, "port") == 0)
if( strcmpi(key, "port") == 0 )
safesnprintf(buf, buflen, "%d", db->db_port); safesnprintf(buf, buflen, "%d", db->db_port);
else else if (strcmpi(key, "id") == 0)
if( strcmpi(key, "id") == 0 ) safesnprintf(buf, buflen, "%s", db->db_username.c_str());
safesnprintf(buf, buflen, "%s", db->db_username); else if (strcmpi(key, "pw") == 0)
else safesnprintf(buf, buflen, "%s", db->db_password.c_str());
if( strcmpi(key, "pw") == 0 ) else if (strcmpi(key, "db") == 0)
safesnprintf(buf, buflen, "%s", db->db_password); safesnprintf(buf, buflen, "%s", db->db_database.c_str());
else else if (strcmpi(key, "account_table") == 0)
if( strcmpi(key, "db") == 0 ) safesnprintf(buf, buflen, "%s", db->account_table.c_str());
safesnprintf(buf, buflen, "%s", db->db_database); else if (strcmpi(key, "global_acc_reg_num_table") == 0)
else safesnprintf(buf, buflen, "%s", db->global_acc_reg_num_table.c_str());
if( strcmpi(key, "account_db") == 0 ) else if (strcmpi(key, "global_acc_reg_str_table") == 0) {
safesnprintf(buf, buflen, "%s", db->account_db); safesnprintf(buf, buflen, "%s", db->global_acc_reg_str_table.c_str());
else
if( strcmpi(key, "global_acc_reg_str_table") == 0 )
safesnprintf(buf, buflen, "%s", db->global_acc_reg_str_table);
else
if( strcmpi(key, "global_acc_reg_num_table") == 0 )
safesnprintf(buf, buflen, "%s", db->global_acc_reg_num_table);
else
return false;// not found return false;// not found
}
return true; return true;
} }
signature = "login_"; signature = "login_";
if( strncmpi(key, signature, strlen(signature)) == 0 ) { if( strncmpi(key, signature, strlen(signature)) == 0 ) {
key += strlen(signature); key += strlen(signature);
if( strcmpi(key, "codepage") == 0 ) if (strcmpi(key, "codepage") == 0)
safesnprintf(buf, buflen, "%s", db->codepage); safesnprintf(buf, buflen, "%s", db->codepage.c_str());
else else if (strcmpi(key, "case_sensitive") == 0)
if( strcmpi(key, "case_sensitive") == 0 )
safesnprintf(buf, buflen, "%d", (db->case_sensitive ? 1 : 0)); safesnprintf(buf, buflen, "%d", (db->case_sensitive ? 1 : 0));
else else
return false;// not found return false;// not found
@@ -240,28 +271,28 @@ static bool account_db_sql_set_property(AccountDB* self, const char* key, const
if( strncmp(key, signature, strlen(signature)) == 0 ) { if( strncmp(key, signature, strlen(signature)) == 0 ) {
key += strlen(signature); key += strlen(signature);
if( strcmpi(key, "ip") == 0 ) if( strcmpi(key, "ip") == 0 )
safestrncpy(db->db_hostname, value, sizeof(db->db_hostname)); db->db_hostname = value;
else else
if( strcmpi(key, "port") == 0 ) if( strcmpi(key, "port") == 0 )
db->db_port = (uint16)strtoul(value, NULL, 10); db->db_port = (uint16)strtoul(value, NULL, 10);
else else
if( strcmpi(key, "id") == 0 ) if( strcmpi(key, "id") == 0 )
safestrncpy(db->db_username, value, sizeof(db->db_username)); db->db_username = value;
else else
if( strcmpi(key, "pw") == 0 ) if( strcmpi(key, "pw") == 0 )
safestrncpy(db->db_password, value, sizeof(db->db_password)); db->db_password = value;
else else
if( strcmpi(key, "db") == 0 ) if( strcmpi(key, "db") == 0 )
safestrncpy(db->db_database, value, sizeof(db->db_database)); db->db_database = value;
else else
if( strcmpi(key, "account_db") == 0 ) if( strcmpi(key, "account_table") == 0 )
safestrncpy(db->account_db, value, sizeof(db->account_db)); db->account_table = value;
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));
else else
if( strcmpi(key, "global_acc_reg_num_table") == 0 ) if( strcmpi(key, "global_acc_reg_num_table") == 0 )
safestrncpy(db->global_acc_reg_num_table, value, sizeof(db->global_acc_reg_num_table)); db->global_acc_reg_num_table = value;
else
if( strcmpi(key, "global_acc_reg_str_table") == 0 )
db->global_acc_reg_str_table = value;
else else
return false;// not found return false;// not found
return true; return true;
@@ -271,7 +302,7 @@ static bool account_db_sql_set_property(AccountDB* self, const char* key, const
if( strncmpi(key, signature, strlen(signature)) == 0 ) { if( strncmpi(key, signature, strlen(signature)) == 0 ) {
key += strlen(signature); key += strlen(signature);
if( strcmpi(key, "codepage") == 0 ) if( strcmpi(key, "codepage") == 0 )
safestrncpy(db->codepage, value, sizeof(db->codepage)); db->codepage = value;
else else
if( strcmpi(key, "case_sensitive") == 0 ) if( strcmpi(key, "case_sensitive") == 0 )
db->case_sensitive = (config_switch(value)==1); db->case_sensitive = (config_switch(value)==1);
@@ -306,7 +337,7 @@ static bool account_db_sql_create(AccountDB* self, struct mmo_account* acc) {
char* data; char* data;
size_t len; 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`", db->account_table.c_str()) )
{ {
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
return false; return false;
@@ -349,9 +380,9 @@ static bool account_db_sql_remove(AccountDB* self, const uint32 account_id) {
bool result = false; bool result = false;
if( SQL_SUCCESS != Sql_QueryStr(sql_handle, "START TRANSACTION") 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->account_table.c_str(), 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_num_table.c_str(), 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", db->global_acc_reg_str_table.c_str(), account_id) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
else else
result = true; result = true;
@@ -405,7 +436,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 // 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'", 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) ) db->account_table.c_str(), (db->case_sensitive ? "BINARY" : ""), esc_userid) )
{ {
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
return false; return false;
@@ -473,7 +504,7 @@ static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account
// get next account ID // 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", 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) ) db->account_table.c_str(), iter->last_account_id) )
{ {
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
return false; return false;
@@ -514,7 +545,7 @@ static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, uint32
#else #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", "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 #endif
db->account_db, account_id ) db->account_table.c_str(), account_id )
) { ) {
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
return false; return false;
@@ -582,7 +613,7 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo
#else #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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", "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 #endif
db->account_db) db->account_table.c_str())
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_INT, (void*)&acc->account_id, sizeof(acc->account_id)) || 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, 1, SQLDT_STRING, (void*)acc->userid, strlen(acc->userid))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 2, SQLDT_STRING, (void*)acc->pass, strlen(acc->pass)) || SQL_SUCCESS != SqlStmt_BindParam(stmt, 2, SQLDT_STRING, (void*)acc->pass, strlen(acc->pass))
@@ -617,7 +648,7 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo
#else #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'", "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 #endif
db->account_db, acc->account_id) db->account_table.c_str(), acc->account_id)
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, (void*)acc->userid, strlen(acc->userid)) || 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, 1, SQLDT_STRING, (void*)acc->pass, strlen(acc->pass))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 2, SQLDT_ENUM, (void*)&acc->sex, sizeof(acc->sex)) || SQL_SUCCESS != SqlStmt_BindParam(stmt, 2, SQLDT_ENUM, (void*)&acc->sex, sizeof(acc->sex))
@@ -675,7 +706,7 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo
// Retry it for a maximum number of retries // Retry it for a maximum number of retries
do{ do{
if( SQL_SUCCESS == Sql_Query( sql_handle, query, db->account_db, WEB_AUTH_TOKEN_LENGTH - 1, acc->account_id ) ){ if( SQL_SUCCESS == Sql_Query( sql_handle, query, db->account_table.c_str(), WEB_AUTH_TOKEN_LENGTH - 1, acc->account_id ) ){
success = true; success = true;
break; break;
} }
@@ -694,7 +725,7 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo
char* data; char* data;
size_t len; size_t len;
if( SQL_SUCCESS != Sql_Query( sql_handle, "SELECT `web_auth_token` from `%s` WHERE `account_id` = '%d'", db->account_db, acc->account_id ) || if( SQL_SUCCESS != Sql_Query( sql_handle, "SELECT `web_auth_token` from `%s` WHERE `account_id` = '%d'", db->account_table.c_str(), acc->account_id ) ||
SQL_SUCCESS != Sql_NextRow( sql_handle ) || SQL_SUCCESS != Sql_NextRow( sql_handle ) ||
SQL_SUCCESS != Sql_GetData( sql_handle, 0, &data, &len ) SQL_SUCCESS != Sql_GetData( sql_handle, 0, &data, &len )
){ ){
@@ -740,12 +771,12 @@ void mmo_save_global_accreg(AccountDB* self, int fd, uint32 account_id, uint32 c
switch (RFIFOB(fd, cursor++)) { switch (RFIFOB(fd, cursor++)) {
// int // int
case 0: case 0:
if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`account_id`,`key`,`index`,`value`) VALUES ('%" PRIu32 "','%s','%" PRIu32 "','%" PRId64 "')", db->global_acc_reg_num_table, account_id, esc_key, index, RFIFOQ(fd, cursor)) ) if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`account_id`,`key`,`index`,`value`) VALUES ('%" PRIu32 "','%s','%" PRIu32 "','%" PRId64 "')", db->global_acc_reg_num_table.c_str(), account_id, esc_key, index, RFIFOQ(fd, cursor)) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
cursor += 8; cursor += 8;
break; break;
case 1: case 1:
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%" PRIu32 "' AND `key` = '%s' AND `index` = '%" PRIu32 "' LIMIT 1", db->global_acc_reg_num_table, account_id, esc_key, index) ) if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%" PRIu32 "' AND `key` = '%s' AND `index` = '%" PRIu32 "' LIMIT 1", db->global_acc_reg_num_table.c_str(), account_id, esc_key, index) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
break; break;
// str // str
@@ -753,11 +784,11 @@ void mmo_save_global_accreg(AccountDB* self, int fd, uint32 account_id, uint32 c
safestrncpy(sval, RFIFOCP(fd, cursor + 1), RFIFOB(fd, cursor)); safestrncpy(sval, RFIFOCP(fd, cursor + 1), RFIFOB(fd, cursor));
cursor += RFIFOB(fd, cursor) + 1; cursor += RFIFOB(fd, cursor) + 1;
Sql_EscapeString(sql_handle, esc_sval, sval); Sql_EscapeString(sql_handle, esc_sval, sval);
if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`account_id`,`key`,`index`,`value`) VALUES ('%" PRIu32 "','%s','%" PRIu32 "','%s')", db->global_acc_reg_str_table, account_id, esc_key, index, esc_sval) ) if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `%s` (`account_id`,`key`,`index`,`value`) VALUES ('%" PRIu32 "','%s','%" PRIu32 "','%s')", db->global_acc_reg_str_table.c_str(), account_id, esc_key, index, esc_sval) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
break; break;
case 3: case 3:
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%" PRIu32 "' AND `key` = '%s' AND `index` = '%" PRIu32 "' LIMIT 1", db->global_acc_reg_str_table, account_id, esc_key, index) ) if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%" PRIu32 "' AND `key` = '%s' AND `index` = '%" PRIu32 "' LIMIT 1", db->global_acc_reg_str_table.c_str(), account_id, esc_key, index) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
break; break;
default: default:
@@ -775,7 +806,7 @@ void mmo_send_global_accreg(AccountDB* self, int fd, uint32 account_id, uint32 c
int plen = 0; int plen = 0;
size_t len; size_t len;
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `account_id`='%" PRIu32 "'", db->global_acc_reg_str_table, account_id) ) if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `account_id`='%" PRIu32 "'", db->global_acc_reg_str_table.c_str(), account_id) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
WFIFOHEAD(fd, 60000 + 300); WFIFOHEAD(fd, 60000 + 300);
@@ -842,7 +873,7 @@ void mmo_send_global_accreg(AccountDB* self, int fd, uint32 account_id, uint32 c
Sql_FreeResult(sql_handle); Sql_FreeResult(sql_handle);
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `account_id`='%" PRIu32 "'", db->global_acc_reg_num_table, account_id) ) if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `account_id`='%" PRIu32 "'", db->global_acc_reg_num_table.c_str(), account_id) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
WFIFOHEAD(fd, 60000 + 300); WFIFOHEAD(fd, 60000 + 300);
@@ -911,7 +942,7 @@ void mmo_send_global_accreg(AccountDB* self, int fd, uint32 account_id, uint32 c
bool account_db_sql_enable_webtoken( AccountDB* self, const uint32 account_id ){ bool account_db_sql_enable_webtoken( AccountDB* self, const uint32 account_id ){
AccountDB_SQL* db = (AccountDB_SQL*)self; AccountDB_SQL* db = (AccountDB_SQL*)self;
if( SQL_ERROR == Sql_Query( db->accounts, "UPDATE `%s` SET `web_auth_token_enabled` = '1' WHERE `account_id` = '%u'", db->account_db, account_id ) ){ if( SQL_ERROR == Sql_Query( db->accounts, "UPDATE `%s` SET `web_auth_token_enabled` = '1' WHERE `account_id` = '%u'", db->account_table.c_str(), account_id ) ){
Sql_ShowDebug( db->accounts ); Sql_ShowDebug( db->accounts );
return false; return false;
} }
@@ -922,7 +953,7 @@ bool account_db_sql_enable_webtoken( AccountDB* self, const uint32 account_id ){
bool account_db_sql_disable_webtoken( AccountDB* self, const uint32 account_id ){ bool account_db_sql_disable_webtoken( AccountDB* self, const uint32 account_id ){
AccountDB_SQL* db = (AccountDB_SQL*)self; AccountDB_SQL* db = (AccountDB_SQL*)self;
if( SQL_ERROR == Sql_Query( db->accounts, "UPDATE `%s` SET `web_auth_token_enabled` = '0' WHERE `account_id` = '%u'", db->account_db, account_id ) ){ if( SQL_ERROR == Sql_Query( db->accounts, "UPDATE `%s` SET `web_auth_token_enabled` = '0' WHERE `account_id` = '%u'", db->account_table.c_str(), account_id ) ){
Sql_ShowDebug( db->accounts ); Sql_ShowDebug( db->accounts );
return false; return false;
} }
@@ -933,7 +964,7 @@ bool account_db_sql_disable_webtoken( AccountDB* self, const uint32 account_id )
bool account_db_sql_remove_webtokens( AccountDB* self ){ bool account_db_sql_remove_webtokens( AccountDB* self ){
AccountDB_SQL* db = (AccountDB_SQL*)self; AccountDB_SQL* db = (AccountDB_SQL*)self;
if( SQL_ERROR == Sql_Query( db->accounts, "UPDATE `%s` SET `web_auth_token` = NULL, `web_auth_token_enabled` = '0'", db->account_db ) ){ if( SQL_ERROR == Sql_Query( db->accounts, "UPDATE `%s` SET `web_auth_token` = NULL, `web_auth_token_enabled` = '0'", db->account_table.c_str() ) ){
Sql_ShowDebug( db->accounts ); Sql_ShowDebug( db->accounts );
return false; return false;
} }

View File

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

View File

@@ -4,7 +4,7 @@
#include "ipban.hpp" #include "ipban.hpp"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string>
#include "../common/cbasetypes.hpp" #include "../common/cbasetypes.hpp"
#include "../common/showmsg.hpp" #include "../common/showmsg.hpp"
@@ -15,23 +15,64 @@
#include "login.hpp" #include "login.hpp"
#include "loginlog.hpp" #include "loginlog.hpp"
// login sql settings
static char ipban_db_hostname[64] = "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 // globals
static Sql* sql_handle = NULL; 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;
std::string ipban_db_hostname;
std::string ipban_db_username;
std::string ipban_db_password;
std::string ipban_db_database;
std::string ipban_codepage;
std::string ipban_table;
int cleanup_timer_id;
bool ipban_inited;
};
struct Ipban_Config ipban_config;
//early declaration //early declaration
TIMER_FUNC(ipban_cleanup); TIMER_FUNC(ipban_cleanup);
/**
* Initialize default configurations
**/
void ipban_config_init(void) {
ipban_config.ipban_db_port = 3306;
ipban_config.ipban_db_hostname = "127.0.0.1";
ipban_config.ipban_db_username = "ragnarok";
ipban_config.ipban_db_password = "";
ipban_config.ipban_db_database = "ragnarok";
ipban_config.ipban_codepage = "";
ipban_config.ipban_table = "ipbanlist";
ipban_config.cleanup_timer_id = INVALID_TIMER;
ipban_config.ipban_inited = false;
}
/**
* Finalize default configurations
**/
void ipban_config_final(void) {
}
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`;", ipban_config.ipban_table.c_str()) )
{
Sql_ShowDebug(sql_handle);
return false;
}
return true;
}
/** /**
* Check if ip is in the active bans list. * Check if ip is in the active bans list.
* @param ip: ipv4 ip to check if ban * @param ip: ipv4 ip to check if ban
@@ -46,7 +87,7 @@ bool ipban_check(uint32 ip) {
return false;// ipban disabled 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')", 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]) ) ipban_config.ipban_table.c_str(), p[3], p[3], p[2], p[3], p[2], p[1], p[3], p[2], p[1], p[0]) )
{ {
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
// close connection because we can't verify their connectivity. // close connection because we can't verify their connectivity.
@@ -81,7 +122,7 @@ void ipban_log(uint32 ip) {
{ {
uint8* p = (uint8*)&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')", 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) ) ipban_config.ipban_table.c_str(), p[3], p[2], p[1], login_config.dynamic_pass_failure_ban_duration) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
} }
} }
@@ -100,7 +141,7 @@ TIMER_FUNC(ipban_cleanup){
if( !login_config.ipban ) if( !login_config.ipban )
return 0;// ipban disabled return 0;// ipban disabled
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `rtime` <= NOW()", ipban_table) ) if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `rtime` <= NOW()", ipban_config.ipban_table.c_str()) )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
return 0; return 0;
@@ -115,7 +156,7 @@ TIMER_FUNC(ipban_cleanup){
bool ipban_config_read(const char* key, const char* value) { bool ipban_config_read(const char* key, const char* value) {
const char* signature; const char* signature;
if( ipban_inited ) if( ipban_config.ipban_inited )
return false;// settings can only be changed before init return false;// settings can only be changed before init
signature = "ipban_db_"; signature = "ipban_db_";
@@ -123,19 +164,19 @@ bool ipban_config_read(const char* key, const char* value) {
{ {
key += strlen(signature); key += strlen(signature);
if( strcmpi(key, "ip") == 0 ) if( strcmpi(key, "ip") == 0 )
safestrncpy(ipban_db_hostname, value, sizeof(ipban_db_hostname)); ipban_config.ipban_db_hostname = value;
else else
if( strcmpi(key, "port") == 0 ) if( strcmpi(key, "port") == 0 )
ipban_db_port = (uint16)strtoul(value, NULL, 10); ipban_config.ipban_db_port = (uint16)strtoul(value, NULL, 10);
else else
if( strcmpi(key, "id") == 0 ) if( strcmpi(key, "id") == 0 )
safestrncpy(ipban_db_username, value, sizeof(ipban_db_username)); ipban_config.ipban_db_username = value;
else else
if( strcmpi(key, "pw") == 0 ) if( strcmpi(key, "pw") == 0 )
safestrncpy(ipban_db_password, value, sizeof(ipban_db_password)); ipban_config.ipban_db_password = value;
else else
if( strcmpi(key, "db") == 0 ) if( strcmpi(key, "db") == 0 )
safestrncpy(ipban_db_database, value, sizeof(ipban_db_database)); ipban_config.ipban_db_database = value;
else else
return false;// not found return false;// not found
return true; return true;
@@ -146,10 +187,10 @@ bool ipban_config_read(const char* key, const char* value) {
{ {
key += strlen(signature); key += strlen(signature);
if( strcmpi(key, "codepage") == 0 ) if( strcmpi(key, "codepage") == 0 )
safestrncpy(ipban_codepage, value, sizeof(ipban_codepage)); ipban_config.ipban_codepage = value;
else else
if( strcmpi(key, "ipban_table") == 0 ) if( strcmpi(key, "list_table") == 0 )
safestrncpy(ipban_table, value, sizeof(ipban_table)); ipban_config.ipban_table = value;
else else
if( strcmpi(key, "enable") == 0 ) if( strcmpi(key, "enable") == 0 )
login_config.ipban = (config_switch(value) != 0); login_config.ipban = (config_switch(value) != 0);
@@ -181,47 +222,38 @@ bool ipban_config_read(const char* key, const char* value) {
* Launched at login-serv start, create db or other long scope variable here. * Launched at login-serv start, create db or other long scope variable here.
*/ */
void ipban_init(void) { void ipban_init(void) {
const char* username = ipban_db_username; ipban_config.ipban_inited = true;
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;
if( !login_config.ipban ) if( !login_config.ipban )
return;// ipban disabled 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 // establish connections
sql_handle = Sql_Malloc(); sql_handle = Sql_Malloc();
if( SQL_ERROR == Sql_Connect(sql_handle, username, password, hostname, port, database) ) if( SQL_ERROR == Sql_Connect(sql_handle, ipban_config.ipban_db_username.c_str(), ipban_config.ipban_db_password.c_str(), ipban_config.ipban_db_hostname.c_str(), ipban_config.ipban_db_port, ipban_config.ipban_db_database.c_str()) )
{ {
ShowError("Couldn't connect with uname='%s',passwd='%s',host='%s',port='%d',database='%s'\n", ShowError("Couldn't connect with uname='%s',passwd='%s',host='%s',port='%d',database='%s'\n",
username, password, hostname, port, database); ipban_config.ipban_db_username.c_str(), ipban_config.ipban_db_password.c_str(), ipban_config.ipban_db_hostname.c_str(), ipban_config.ipban_db_port, ipban_config.ipban_db_database.c_str());
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
Sql_Free(sql_handle); Sql_Free(sql_handle);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
ShowInfo("Ipban connection made.\n");
ShowInfo("Ipban connection made.\n");
if( codepage[0] != '\0' && SQL_ERROR == Sql_SetEncoding(sql_handle, codepage) )
if( !ipban_config.ipban_codepage.empty() && SQL_ERROR == Sql_SetEncoding(sql_handle, ipban_config.ipban_codepage.c_str()) )
Sql_ShowDebug(sql_handle); 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", ipban_config.ipban_db_database.c_str(), ipban_config.ipban_db_hostname.c_str());
if( login_config.ipban_cleanup_interval > 0 ) if( login_config.ipban_cleanup_interval > 0 )
{ // set up periodic cleanup of connection history and active bans { // set up periodic cleanup of connection history and active bans
add_timer_func_list(ipban_cleanup, "ipban_cleanup"); 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 } else // make sure it gets cleaned up on login-server start regardless of interval-based cleanups
ipban_cleanup(0,0,0,0); ipban_cleanup(0,0,0,0);
} }
@@ -236,7 +268,7 @@ void ipban_final(void) {
if( login_config.ipban_cleanup_interval > 0 ) if( login_config.ipban_cleanup_interval > 0 )
// release data // 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_cleanup(0,0,0,0); // always clean up on login-server stop

View File

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

View File

@@ -5,7 +5,6 @@
#include "login.hpp" #include "login.hpp"
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
@@ -612,7 +611,7 @@ bool login_config_read(const char* cfgName, bool normal) {
} }
else if (strcmpi(w1, "console_msg_log") == 0) else if (strcmpi(w1, "console_msg_log") == 0)
console_msg_log = atoi(w2); console_msg_log = atoi(w2);
else if (strcmpi(w1, "console_log_filepath") == 0) else if (strcmpi(w1, "console_log_filepath") == 0)
safestrncpy(console_log_filepath, w2, sizeof(console_log_filepath)); safestrncpy(console_log_filepath, w2, sizeof(console_log_filepath));
else if(!strcmpi(w1, "log_login")) else if(!strcmpi(w1, "log_login"))
login_config.log_login = (bool)config_switch(w2); login_config.log_login = (bool)config_switch(w2);
@@ -769,8 +768,6 @@ void login_set_defaults() {
} }
/// Constructor destructor and signal handlers /// Constructor destructor and signal handlers
/** /**
@@ -863,11 +860,14 @@ int do_init(int argc, char** argv) {
// initialize engine // initialize engine
accounts = account_db_sql(); accounts = account_db_sql();
accounts->init_conf(accounts);
// read login-server configuration // read login-server configuration
login_set_defaults(); login_set_defaults();
logcnslif_get_options(argc,argv); logcnslif_get_options(argc,argv);
ipban_config_init();
loginlog_config_init();
login_config_read(login_config.loginconf_name, true); login_config_read(login_config.loginconf_name, true);
msg_config_read(login_config.msgconf_name); msg_config_read(login_config.msgconf_name);
login_lan_config_read(login_config.lanconf_name); login_lan_config_read(login_config.lanconf_name);

View File

@@ -4,7 +4,7 @@
#include "loginlog.hpp" #include "loginlog.hpp"
#include <stdlib.h> // exit #include <stdlib.h> // exit
#include <string.h> #include <string>
#include "../common/cbasetypes.hpp" #include "../common/cbasetypes.hpp"
#include "../common/mmo.hpp" #include "../common/mmo.hpp"
@@ -13,25 +13,56 @@
#include "../common/sql.hpp" #include "../common/sql.hpp"
#include "../common/strlib.hpp" #include "../common/strlib.hpp"
// global sql settings (in ipban_sql.cpp)
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 Sql* sql_handle = NULL;
static bool enabled = false;
struct Loginlog_Config {
// local sql settings
uint16 log_db_port;
std::string log_db_hostname;
std::string log_db_username;
std::string log_db_password;
std::string log_db_database;
std::string log_codepage;
std::string log_login_table;
bool enabled;
};
struct Loginlog_Config loginlog_config; /// LoginLog config
/**
* Initialize default configurations
**/
void loginlog_config_init(void) {
loginlog_config.log_db_port = 3306;
loginlog_config.log_db_hostname = "127.0.0.1";
loginlog_config.log_db_username = "ragnarok";
loginlog_config.log_db_password = "";
loginlog_config.log_db_database = "ragnarok";
loginlog_config.log_codepage = "";
loginlog_config.log_login_table = "loginlog";
loginlog_config.enabled = false;;
}
/**
* Finalize default configurations
**/
void loginlog_config_final(void) {
}
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`;", loginlog_config.log_login_table.c_str()) )
{
Sql_ShowDebug(sql_handle);
return false;
}
return true;
}
/** /**
* Get the number of failed login attempts by the ip in the last minutes. * Get the number of failed login attempts by the ip in the last minutes.
@@ -42,11 +73,11 @@ static bool enabled = false;
unsigned long loginlog_failedattempts(uint32 ip, unsigned int minutes) { unsigned long loginlog_failedattempts(uint32 ip, unsigned int minutes) {
unsigned long failures = 0; unsigned long failures = 0;
if( !enabled ) if( !loginlog_config.enabled )
return 0; return 0;
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT count(*) FROM `%s` WHERE `ip` = '%s' AND (`rcode` = '0' OR `rcode` = '1') AND `time` > NOW() - INTERVAL %d MINUTE", if( SQL_ERROR == Sql_Query(sql_handle, "SELECT count(*) FROM `%s` WHERE `ip` = '%s' AND (`rcode` = '0' OR `rcode` = '1') AND `time` > NOW() - INTERVAL %d MINUTE",
log_login_db, ip2str(ip,NULL), minutes) )// how many times failed account? in one ip. loginlog_config.log_login_table.c_str(), ip2str(ip,NULL), minutes) )// how many times failed account? in one ip.
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
if( SQL_SUCCESS == Sql_NextRow(sql_handle) ) if( SQL_SUCCESS == Sql_NextRow(sql_handle) )
@@ -72,7 +103,7 @@ void login_log(uint32 ip, const char* username, int rcode, const char* message)
char esc_message[255*2+1]; char esc_message[255*2+1];
int retcode; int retcode;
if( !enabled ) if( !loginlog_config.enabled )
return; return;
Sql_EscapeStringLen(sql_handle, esc_username, username, strnlen(username, NAME_LENGTH)); Sql_EscapeStringLen(sql_handle, esc_username, username, strnlen(username, NAME_LENGTH));
@@ -80,7 +111,7 @@ void login_log(uint32 ip, const char* username, int rcode, const char* message)
retcode = Sql_Query(sql_handle, retcode = Sql_Query(sql_handle,
"INSERT INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '%s', '%s', '%d', '%s')", "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); loginlog_config.log_login_table.c_str(), ip2str(ip,NULL), esc_username, rcode, esc_message);
if( retcode != SQL_SUCCESS ) if( retcode != SQL_SUCCESS )
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
@@ -93,57 +124,28 @@ void login_log(uint32 ip, const char* username, int rcode, const char* message)
* @return true if successful, false if config not complete or server already running * @return true if successful, false if config not complete or server already running
*/ */
bool loginlog_config_read(const char* key, const char* value) { bool loginlog_config_read(const char* key, const char* value) {
const char* signature;
signature = "sql.";
if( strncmpi(key, signature, strlen(signature)) == 0 )
{
key += strlen(signature);
if( strcmpi(key, "db_hostname") == 0 )
safestrncpy(global_db_hostname, value, sizeof(global_db_hostname));
else
if( strcmpi(key, "db_port") == 0 )
global_db_port = (uint16)strtoul(value, NULL, 10);
else
if( strcmpi(key, "db_username") == 0 )
safestrncpy(global_db_username, value, sizeof(global_db_username));
else
if( strcmpi(key, "db_password") == 0 )
safestrncpy(global_db_password, value, sizeof(global_db_password));
else
if( strcmpi(key, "db_database") == 0 )
safestrncpy(global_db_database, value, sizeof(global_db_database));
else
if( strcmpi(key, "codepage") == 0 )
safestrncpy(global_codepage, value, sizeof(global_codepage));
else
return false;// not found
return true;
}
if( strcmpi(key, "log_db_ip") == 0 ) if( strcmpi(key, "log_db_ip") == 0 )
safestrncpy(log_db_hostname, value, sizeof(log_db_hostname)); loginlog_config.log_db_hostname = value;
else else
if( strcmpi(key, "log_db_port") == 0 ) 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 else
if( strcmpi(key, "log_db_id") == 0 ) if( strcmpi(key, "log_db_id") == 0 )
safestrncpy(log_db_username, value, sizeof(log_db_username)); loginlog_config.log_db_username = value;
else else
if( strcmpi(key, "log_db_pw") == 0 ) if( strcmpi(key, "log_db_pw") == 0 )
safestrncpy(log_db_password, value, sizeof(log_db_password)); loginlog_config.log_db_password = value;
else else
if( strcmpi(key, "log_db_db") == 0 ) if( strcmpi(key, "log_db_db") == 0 )
safestrncpy(log_db_database, value, sizeof(log_db_database)); loginlog_config.log_db_database = value;
else else
if( strcmpi(key, "log_codepage") == 0 ) if( strcmpi(key, "log_codepage") == 0 )
safestrncpy(log_codepage, value, sizeof(log_codepage)); loginlog_config.log_codepage = value;
else else
if( strcmpi(key, "log_login_db") == 0 ) if( strcmpi(key, "log_login_table") == 0 )
safestrncpy(log_login_db, value, sizeof(log_login_db)); loginlog_config.log_login_table = value;
else else
return false; return false;
return true; return true;
} }
@@ -156,48 +158,28 @@ bool loginlog_config_read(const char* key, const char* value) {
* @return true if success else exit execution * @return true if success else exit execution
*/ */
bool loginlog_init(void) { bool loginlog_init(void) {
const char* username;
const char* password;
const char* hostname;
uint16 port;
const char* database;
const char* codepage;
if( log_db_hostname[0] != '\0' )
{// 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;
}
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;
}
sql_handle = Sql_Malloc(); sql_handle = Sql_Malloc();
if( SQL_ERROR == Sql_Connect(sql_handle, username, password, hostname, port, database) ) if( SQL_ERROR == Sql_Connect(sql_handle, loginlog_config.log_db_username.c_str(), loginlog_config.log_db_password.c_str(), loginlog_config.log_db_hostname.c_str(), loginlog_config.log_db_port, loginlog_config.log_db_database.c_str()) )
{ {
ShowError("Couldn't connect with uname='%s',passwd='%s',host='%s',port='%d',database='%s'\n", ShowError("Couldn't connect with uname='%s',passwd='%s',host='%s',port='%d',database='%s'\n",
username, password, hostname, port, database); loginlog_config.log_db_username.c_str(), loginlog_config.log_db_password.c_str(), loginlog_config.log_db_hostname.c_str(), loginlog_config.log_db_port, loginlog_config.log_db_database.c_str());
Sql_ShowDebug(sql_handle); Sql_ShowDebug(sql_handle);
Sql_Free(sql_handle); Sql_Free(sql_handle);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if( codepage[0] != '\0' && SQL_ERROR == Sql_SetEncoding(sql_handle, codepage) ) if( !loginlog_config.log_codepage.empty() && SQL_ERROR == Sql_SetEncoding(sql_handle, loginlog_config.log_codepage.c_str()) )
Sql_ShowDebug(sql_handle); 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", loginlog_config.log_db_database.c_str(), loginlog_config.log_db_hostname.c_str());
return true; return true;
} }
@@ -210,5 +192,6 @@ bool loginlog_init(void) {
bool loginlog_final(void) { bool loginlog_final(void) {
Sql_Free(sql_handle); Sql_Free(sql_handle);
sql_handle = NULL; sql_handle = NULL;
loginlog_config_final();
return true; return true;
} }

View File

@@ -48,4 +48,6 @@ bool loginlog_init(void);
*/ */
bool loginlog_final(void); bool loginlog_final(void);
void loginlog_config_init(void);
#endif /* LOGINLOG_HPP */ #endif /* LOGINLOG_HPP */

View File

@@ -3176,7 +3176,7 @@ ACMD_FUNC(night)
{ {
nullpo_retr(-1, sd); nullpo_retr(-1, sd);
if (night_flag != 1) { if (!map_config.night_flag) {
map_night_timer(night_timer_tid, 0, 0, 1); map_night_timer(night_timer_tid, 0, 0, 1);
} else { } else {
clif_displaymessage(fd, msg_txt(sd,89)); // Night mode is already enabled. clif_displaymessage(fd, msg_txt(sd,89)); // Night mode is already enabled.
@@ -3193,7 +3193,7 @@ ACMD_FUNC(day)
{ {
nullpo_retr(-1, sd); nullpo_retr(-1, sd);
if (night_flag != 0) { if (map_config.night_flag) {
map_day_timer(day_timer_tid, 0, 0, 1); map_day_timer(day_timer_tid, 0, 0, 1);
} else { } else {
clif_displaymessage(fd, msg_txt(sd,90)); // Day mode is already enabled. clif_displaymessage(fd, msg_txt(sd,90)); // Day mode is already enabled.
@@ -3605,13 +3605,13 @@ ACMD_FUNC(agitstart)
{ {
nullpo_retr(-1, sd); nullpo_retr(-1, sd);
if( guild_agit_start() ){ if (guild_agit_start()) {
clif_displaymessage(fd, msg_txt(sd,72)); // War of Emperium has been initiated. clif_displaymessage(fd, msg_txt(sd, 72)); // War of Emperium has been initiated.
return 0; return 0;
}else{ } else
clif_displaymessage(fd, msg_txt(sd,73)); // War of Emperium is currently in progress. clif_displaymessage(fd, msg_txt(sd, 73)); // War of Emperium is currently in progress.
return -1;
} return -1;
} }
/** /**
@@ -3621,13 +3621,13 @@ ACMD_FUNC(agitstart2)
{ {
nullpo_retr(-1, sd); nullpo_retr(-1, sd);
if( guild_agit2_start() ){ if (guild_agit2_start()) {
clif_displaymessage(fd, msg_txt(sd,403)); // "War of Emperium SE has been initiated." clif_displaymessage(fd, msg_txt(sd, 403)); // "War of Emperium SE has been initiated."
return 0; return 0;
}else{ } else
clif_displaymessage(fd, msg_txt(sd,404)); // "War of Emperium SE is currently in progress." clif_displaymessage(fd, msg_txt(sd, 404)); // "War of Emperium SE is currently in progress."
return -1;
} return -1;
} }
/** /**
@@ -3637,13 +3637,13 @@ ACMD_FUNC(agitstart3)
{ {
nullpo_retr(-1, sd); nullpo_retr(-1, sd);
if( guild_agit3_start() ){ if (guild_agit3_start()) {
clif_displaymessage(fd, msg_txt(sd,749)); // "War of Emperium TE has been initiated." clif_displaymessage(fd, msg_txt(sd,749)); // "War of Emperium TE has been initiated."
return 0;
}else{
clif_displaymessage(fd, msg_txt(sd,750)); // "War of Emperium TE is currently in progress."
return -1; return -1;
} } else
clif_displaymessage(fd, msg_txt(sd,750)); // "War of Emperium TE is currently in progress."
return 0;
} }
/** /**
@@ -3653,13 +3653,13 @@ ACMD_FUNC(agitend)
{ {
nullpo_retr(-1, sd); nullpo_retr(-1, sd);
if( guild_agit_end() ){ if (guild_agit_end()) {
clif_displaymessage(fd, msg_txt(sd,74)); // War of Emperium has been ended. clif_displaymessage(fd, msg_txt(sd,74)); // War of Emperium has been ended.
return 0; return 0;
}else{ } else
clif_displaymessage(fd, msg_txt(sd,75)); // War of Emperium is currently not in progress. clif_displaymessage(fd, msg_txt(sd,75)); // War of Emperium is currently not in progress.
return -1;
} return -1;
} }
/** /**
@@ -3669,13 +3669,13 @@ ACMD_FUNC(agitend2)
{ {
nullpo_retr(-1, sd); nullpo_retr(-1, sd);
if( guild_agit2_end() ){ if (guild_agit2_end()) {
clif_displaymessage(fd, msg_txt(sd,405)); // "War of Emperium SE has been ended." clif_displaymessage(fd, msg_txt(sd,405)); // "War of Emperium SE has been ended."
return 0; return 0;
}else{ } else
clif_displaymessage(fd, msg_txt(sd,406)); // "War of Emperium SE is currently not in progress." clif_displaymessage(fd, msg_txt(sd,406)); // "War of Emperium SE is currently not in progress."
return -1;
} return -1;
} }
/** /**
@@ -3685,13 +3685,13 @@ ACMD_FUNC(agitend3)
{ {
nullpo_retr(-1, sd); nullpo_retr(-1, sd);
if( guild_agit3_end() ){ if (guild_agit3_end()) {
clif_displaymessage(fd, msg_txt(sd,751));// War of Emperium TE has been ended. clif_displaymessage(fd, msg_txt(sd,751)); // War of Emperium TE has been ended.
return 0; return 0;
}else{ } else
clif_displaymessage(fd, msg_txt(sd,752));// War of Emperium TE is currently not in progress. clif_displaymessage(fd, msg_txt(sd,752)); // War of Emperium TE is currently not in progress.
return -1;
} return -1;
} }
/*========================================== /*==========================================
@@ -4475,7 +4475,7 @@ ACMD_FUNC(guildspy)
memset(guild_name, '\0', sizeof(guild_name)); memset(guild_name, '\0', sizeof(guild_name));
memset(atcmd_output, '\0', sizeof(atcmd_output)); 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. clif_displaymessage(fd, msg_txt(sd,1125)); // The mapserver has spy command support disabled.
return -1; return -1;
@@ -4516,7 +4516,7 @@ ACMD_FUNC(partyspy)
memset(party_name, '\0', sizeof(party_name)); memset(party_name, '\0', sizeof(party_name));
memset(atcmd_output, '\0', sizeof(atcmd_output)); 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. clif_displaymessage(fd, msg_txt(sd,1125)); // The mapserver has spy command support disabled.
return -1; return -1;
@@ -4554,7 +4554,7 @@ ACMD_FUNC(clanspy){
memset(clan_name, '\0', sizeof(clan_name)); memset(clan_name, '\0', sizeof(clan_name));
memset(atcmd_output, '\0', sizeof(atcmd_output)); 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. clif_displaymessage(fd, msg_txt(sd, 1125)); // The mapserver has spy command support disabled.
return -1; return -1;
} }
@@ -4852,12 +4852,12 @@ ACMD_FUNC(servertime)
clif_displaymessage(fd, temp); clif_displaymessage(fd, temp);
if (battle_config.night_duration == 0 && battle_config.day_duration == 0) { 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. clif_displaymessage(fd, msg_txt(sd,231)); // Game time: The game is in permanent daylight.
else else
clif_displaymessage(fd, msg_txt(sd,232)); // Game time: The game is in permanent night. clif_displaymessage(fd, msg_txt(sd,232)); // Game time: The game is in permanent night.
} else if (battle_config.night_duration == 0) } else if (battle_config.night_duration == 0)
if (night_flag == 1) { // we start with night if (map_config.night_flag == 1) { // we start with night
if ((timer_data = get_timer(day_timer_tid)) != nullptr) { if ((timer_data = get_timer(day_timer_tid)) != nullptr) {
sprintf(temp, msg_txt(sd,233), txt_time(DIFF_TICK(timer_data->tick,gettick())/1000)); // Game time: The game is in night for %s. 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); clif_displaymessage(fd, temp);
@@ -4867,7 +4867,7 @@ ACMD_FUNC(servertime)
} else } else
clif_displaymessage(fd, msg_txt(sd,231)); // Game time: The game is in permanent daylight. clif_displaymessage(fd, msg_txt(sd,231)); // Game time: The game is in permanent daylight.
else if (battle_config.day_duration == 0) else if (battle_config.day_duration == 0)
if (night_flag == 0) { // we start with day if (map_config.night_flag == 0) { // we start with day
if ((timer_data = get_timer(night_timer_tid)) != nullptr) { if ((timer_data = get_timer(night_timer_tid)) != nullptr) {
sprintf(temp, msg_txt(sd,235), txt_time(DIFF_TICK(timer_data->tick,gettick())/1000)); // Game time: The game is in daylight for %s. 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); clif_displaymessage(fd, temp);
@@ -4878,7 +4878,7 @@ ACMD_FUNC(servertime)
clif_displaymessage(fd, msg_txt(sd,232)); // Game time: The game is in permanent night. clif_displaymessage(fd, msg_txt(sd,232)); // Game time: The game is in permanent night.
else { else {
const struct TimerData * timer_data2; const struct TimerData * timer_data2;
if (night_flag == 0) { if (!map_config.night_flag) {
timer_data = get_timer(night_timer_tid); timer_data = get_timer(night_timer_tid);
timer_data2 = get_timer(day_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. sprintf(temp, msg_txt(sd,235), txt_time(DIFF_TICK(timer_data->tick,gettick())/1000)); // Game time: The game is in daylight for %s.
@@ -6100,11 +6100,11 @@ ACMD_FUNC(autotrade) {
sd->state.block_action |= PCBLOCK_IMMUNE; sd->state.block_action |= PCBLOCK_IMMUNE;
if( sd->state.vending ){ if( sd->state.vending ){
if( Sql_Query( mmysql_handle, "UPDATE `%s` SET `autotrade` = 1 WHERE `id` = %d;", vendings_table, 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 ); Sql_ShowDebug( mmysql_handle );
} }
}else if( sd->state.buyingstore ){ }else if( sd->state.buyingstore ){
if( Sql_Query( mmysql_handle, "UPDATE `%s` SET `autotrade` = 1 WHERE `id` = %d;", buyingstores_table, 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 ); Sql_ShowDebug( mmysql_handle );
} }
} }
@@ -7263,7 +7263,7 @@ ACMD_FUNC(gmotd)
{ {
FILE* fp; FILE* fp;
if( ( fp = fopen(motd_txt, "r") ) != NULL ) if( ( fp = fopen(mapserv_file(motd), "r") ) != NULL )
{ {
char buf[CHAT_SIZE_MAX]; char buf[CHAT_SIZE_MAX];
size_t len; size_t len;

View File

@@ -8295,6 +8295,7 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f
case BL_MOB: case BL_MOB:
{ {
struct mob_data *md = BL_CAST(BL_MOB, s_bl); struct mob_data *md = BL_CAST(BL_MOB, s_bl);
if( md->guardian_data && md->guardian_data->guild_id && !mapdata_flag_gvg(mapdata) ) if( md->guardian_data && md->guardian_data->guild_id && !mapdata_flag_gvg(mapdata) )
return 0; // Disable guardians/emperium owned by Guilds on non-woe times. return 0; // Disable guardians/emperium owned by Guilds on non-woe times.

View File

@@ -234,12 +234,12 @@ int8 buyingstore_create( struct map_session_data* sd, int zenylimit, unsigned ch
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`) " 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' );", "VALUES( %d, %d, %d, '%c', '%s', %d, %d, '%s', %d, %d, '%d', '%d', '%d' );",
buyingstores_table, sd->buyer_id, sd->status.account_id, sd->status.char_id, sd->status.sex == 0 ? 'F' : 'M', map_getmapdata(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_getmapdata(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); Sql_ShowDebug(mmysql_handle);
} }
StringBuf_Init(&buf); StringBuf_Init(&buf);
StringBuf_Printf(&buf, "INSERT INTO `%s`(`buyingstore_id`,`index`,`item_id`,`amount`,`price`) VALUES", buyingstore_items_table); 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++){ for (i = 0; i < sd->buyingstore.slots; i++){
StringBuf_Printf(&buf, "(%d,%d,%u,%d,%d)", sd->buyer_id, i, sd->buyingstore.items[i].nameid, sd->buyingstore.items[i].amount, sd->buyingstore.items[i].price); StringBuf_Printf(&buf, "(%d,%d,%u,%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) if (i < sd->buyingstore.slots-1)
@@ -265,8 +265,8 @@ void buyingstore_close(struct map_session_data* sd) {
if( sd->state.buyingstore ) { if( sd->state.buyingstore ) {
if( if(
Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE buyingstore_id = %d;", buyingstore_items_table, 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;", buyingstores_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); Sql_ShowDebug(mmysql_handle);
} }
@@ -453,11 +453,11 @@ void buyingstore_trade( struct map_session_data* sd, uint32 account_id, unsigned
pl_sd->buyingstore.items[listidx].amount -= item->amount; pl_sd->buyingstore.items[listidx].amount -= item->amount;
if( pl_sd->buyingstore.items[listidx].amount > 0 ){ 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_table, 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 ); Sql_ShowDebug( mmysql_handle );
} }
}else{ }else{
if( Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE `buyingstore_id` = %d AND `index` = %d;", buyingstore_items_table, 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 ); Sql_ShowDebug( mmysql_handle );
} }
} }
@@ -472,7 +472,7 @@ void buyingstore_trade( struct map_session_data* sd, uint32 account_id, unsigned
clif_buyingstore_update_item(pl_sd, item->itemId, item->amount, sd->status.char_id, zeny); clif_buyingstore_update_item(pl_sd, item->itemId, item->amount, sd->status.char_id, zeny);
} }
if( save_settings&CHARSAVE_VENDING ) { if( map_config.save_settings&CHARSAVE_BANK ) {
chrif_save(sd, CSAVE_NORMAL|CSAVE_INVENTORY); chrif_save(sd, CSAVE_NORMAL|CSAVE_INVENTORY);
chrif_save(pl_sd, CSAVE_NORMAL|CSAVE_INVENTORY); chrif_save(pl_sd, CSAVE_NORMAL|CSAVE_INVENTORY);
} }
@@ -490,7 +490,7 @@ void buyingstore_trade( struct map_session_data* sd, uint32 account_id, unsigned
} }
else else
{// continue buying {// continue buying
if( Sql_Query( mmysql_handle, "UPDATE `%s` SET `limit` = %d WHERE `id` = %d;", buyingstores_table, 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 ); Sql_ShowDebug( mmysql_handle );
} }
@@ -650,7 +650,7 @@ void do_init_buyingstore_autotrade( void ) {
"FROM `%s` " "FROM `%s` "
"WHERE `autotrade` = 1 AND `limit` > 0 AND (SELECT COUNT(`buyingstore_id`) FROM `%s` WHERE `buyingstore_id` = `id`) > 0 " "WHERE `autotrade` = 1 AND `limit` > 0 AND (SELECT COUNT(`buyingstore_id`) FROM `%s` WHERE `buyingstore_id` = `id`) > 0 "
"ORDER BY `id`;", "ORDER BY `id`;",
buyingstores_table, buyingstore_items_table ) != SQL_SUCCESS ) mapserv_table(buyingstores_table), mapserv_table(buyingstore_items_table) ) != SQL_SUCCESS )
{ {
Sql_ShowDebug(mmysql_handle); Sql_ShowDebug(mmysql_handle);
return; return;
@@ -709,7 +709,7 @@ void do_init_buyingstore_autotrade( void ) {
"FROM `%s` " "FROM `%s` "
"WHERE `buyingstore_id` = %d " "WHERE `buyingstore_id` = %d "
"ORDER BY `index` ASC;", "ORDER BY `index` ASC;",
buyingstore_items_table, at->id ) ) mapserv_table(buyingstore_items_table), at->id ) )
{ {
Sql_ShowDebug(mmysql_handle); Sql_ShowDebug(mmysql_handle);
continue; continue;
@@ -744,8 +744,8 @@ void do_init_buyingstore_autotrade( void ) {
} }
// Everything is loaded fine, their entries will be reinserted once they are loaded // Everything is loaded fine, their entries will be reinserted once they are loaded
if (Sql_Query( mmysql_handle, "DELETE FROM `%s`;", buyingstores_table ) != SQL_SUCCESS || if (Sql_Query( mmysql_handle, "DELETE FROM `%s`;", mapserv_table(buyingstores_table) ) != SQL_SUCCESS ||
Sql_Query( mmysql_handle, "DELETE FROM `%s`;", buyingstore_items_table ) != SQL_SUCCESS) Sql_Query( mmysql_handle, "DELETE FROM `%s`;", mapserv_table(buyingstore_items_table) ) != SQL_SUCCESS)
{ {
Sql_ShowDebug(mmysql_handle); Sql_ShowDebug(mmysql_handle);
} }

View File

@@ -21,10 +21,6 @@ struct sale_item_db sale_items;
#endif #endif
bool cash_shop_defined = false; bool cash_shop_defined = false;
extern char item_cash_table[32];
extern char item_cash2_table[32];
extern char sales_table[32];
/* /*
* Reads one line from database and assigns it to RAM. * Reads one line from database and assigns it to RAM.
* return * return
@@ -106,7 +102,7 @@ static void cashshop_read_db_txt( void ){
* parses line and sends them to parse_dbrow. * parses line and sends them to parse_dbrow.
*/ */
static int cashshop_read_db_sql( void ){ static int cashshop_read_db_sql( void ){
const char* cash_db_name[] = { item_cash_table, item_cash2_table }; const char* cash_db_name[] = { mapserv_table(item_cash_db_table), mapserv_table(item_cash_db2_table) };
int fi; int fi;
for( fi = 0; fi < ARRAYLENGTH( cash_db_name ); ++fi ){ for( fi = 0; fi < ARRAYLENGTH( cash_db_name ); ++fi ){
@@ -202,7 +198,7 @@ static bool sale_parse_dbrow( char* fields[], int columns, int current ){
static void sale_read_db_sql( void ){ static void sale_read_db_sql( void ){
uint32 lines = 0, count = 0; uint32 lines = 0, count = 0;
if( SQL_ERROR == Sql_Query( mmysql_handle, "SELECT `nameid`, UNIX_TIMESTAMP(`start`), UNIX_TIMESTAMP(`end`), `amount` FROM `%s` WHERE `end` > now()", sales_table ) ){ if( SQL_ERROR == Sql_Query( mmysql_handle, "SELECT `nameid`, UNIX_TIMESTAMP(`start`), UNIX_TIMESTAMP(`end`), `amount` FROM `%s` WHERE `end` > now()", mapserv_table(sales_table) ) ){
Sql_ShowDebug(mmysql_handle); Sql_ShowDebug(mmysql_handle);
return; return;
} }
@@ -223,7 +219,7 @@ static void sale_read_db_sql( void ){
} }
if( !sale_parse_dbrow( str, 4, lines ) ){ if( !sale_parse_dbrow( str, 4, lines ) ){
ShowError( "sale_read_db_sql: Cannot process table '%s' at line '%d', skipping...\n", sales_table, lines ); ShowError( "sale_read_db_sql: Cannot process table '%s' at line '%d', skipping...\n", mapserv_table(sales_table), lines );
continue; continue;
} }
@@ -232,7 +228,7 @@ static void sale_read_db_sql( void ){
Sql_FreeResult(mmysql_handle); Sql_FreeResult(mmysql_handle);
ShowStatus( "Done reading '" CL_WHITE "%u" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", count, sales_table ); ShowStatus( "Done reading '" CL_WHITE "%u" CL_RESET "' entries in '" CL_WHITE "%s" CL_RESET "'.\n", count, mapserv_table(sales_table) );
} }
static TIMER_FUNC(sale_end_timer){ static TIMER_FUNC(sale_end_timer){
@@ -299,7 +295,7 @@ enum e_sale_add_result sale_add_item( t_itemid nameid, int32 count, time_t from,
return SALE_ADD_DUPLICATE; return SALE_ADD_DUPLICATE;
} }
if( SQL_ERROR == Sql_Query(mmysql_handle, "INSERT INTO `%s`(`nameid`,`start`,`end`,`amount`) VALUES ( '%u', FROM_UNIXTIME(%d), FROM_UNIXTIME(%d), '%d' )", sales_table, nameid, (uint32)from, (uint32)to, count) ){ if( SQL_ERROR == Sql_Query(mmysql_handle, "INSERT INTO `%s`(`nameid`,`start`,`end`,`amount`) VALUES ( '%u', FROM_UNIXTIME(%d), FROM_UNIXTIME(%d), '%d' )", mapserv_table(sales_table), nameid, (uint32)from, (uint32)to, count) ){
Sql_ShowDebug(mmysql_handle); Sql_ShowDebug(mmysql_handle);
return SALE_ADD_FAILED; return SALE_ADD_FAILED;
} }
@@ -330,7 +326,7 @@ bool sale_remove_item( t_itemid nameid ){
} }
// Delete it from the database // Delete it from the database
if( SQL_ERROR == Sql_Query(mmysql_handle, "DELETE FROM `%s` WHERE `nameid` = '%u'", sales_table, nameid ) ){ if( SQL_ERROR == Sql_Query(mmysql_handle, "DELETE FROM `%s` WHERE `nameid` = '%u'", mapserv_table(sales_table), nameid ) ){
Sql_ShowDebug(mmysql_handle); Sql_ShowDebug(mmysql_handle);
return false; return false;
} }
@@ -431,17 +427,16 @@ static void cashshop_read_db( void ){
time_t now = time(NULL); time_t now = time(NULL);
#endif #endif
if( db_use_sqldbs ){ if (mapserv_schema_config.db_use_sqldbs)
cashshop_read_db_sql(); cashshop_read_db_sql();
} else { else
cashshop_read_db_txt(); cashshop_read_db_txt();
}
#if PACKETVER_SUPPORTS_SALES #if PACKETVER_SUPPORTS_SALES
sale_read_db_sql(); sale_read_db_sql();
// Clean outdated sales // Clean outdated sales
if( SQL_ERROR == Sql_Query(mmysql_handle, "DELETE FROM `%s` WHERE `end` < FROM_UNIXTIME(%d)", sales_table, (uint32)now ) ){ if( SQL_ERROR == Sql_Query(mmysql_handle, "DELETE FROM `%s` WHERE `end` < FROM_UNIXTIME(%d)", mapserv_table(sales_table), (uint32)now ) ){
Sql_ShowDebug(mmysql_handle); Sql_ShowDebug(mmysql_handle);
} }
@@ -615,7 +610,7 @@ bool cashshop_buylist( struct map_session_data* sd, uint32 kafrapoints, int n, s
if( new_amount == 0 ){ if( new_amount == 0 ){
sale_remove_item(sale->nameid); sale_remove_item(sale->nameid);
}else{ }else{
if( SQL_ERROR == Sql_Query( mmysql_handle, "UPDATE `%s` SET `amount` = '%d' WHERE `nameid` = '%u'", sales_table, new_amount, nameid ) ){ if( SQL_ERROR == Sql_Query( mmysql_handle, "UPDATE `%s` SET `amount` = '%d' WHERE `nameid` = '%u'", mapserv_table(sales_table), new_amount, nameid ) ){
Sql_ShowDebug(mmysql_handle); Sql_ShowDebug(mmysql_handle);
} }

View File

@@ -1386,8 +1386,8 @@ void channel_read_config(void) {
config_t channels_conf; config_t channels_conf;
config_setting_t *chan_setting = NULL; config_setting_t *chan_setting = NULL;
if (conf_read_file(&channels_conf, channel_conf)) { if (conf_read_file(&channels_conf, mapserv_file_config.channel.c_str())) {
ShowError("Cannot read file '%s' for channel connfig.\n", channel_conf); ShowError("Cannot read file '%s' for channel connfig.\n", mapserv_file_config.channel.c_str());
return; return;
} }
@@ -1477,7 +1477,7 @@ void channel_read_config(void) {
} }
} }
ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' channels in '" CL_WHITE "%s" CL_RESET "'.\n", db_size(channel_db), channel_conf); ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' channels in '" CL_WHITE "%s" CL_RESET "'.\n", db_size(channel_db), mapserv_file_config.channel.c_str());
config_destroy(&channels_conf); config_destroy(&channels_conf);
} }
} }

View File

@@ -609,8 +609,8 @@ int chrif_sendmapack(int fd) {
} }
// Server name // 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); ShowStatus("Map-server connected to char-server '" CL_WHITE "%s" CL_RESET "'.\n", map_config.wisp_server_name);
// Default map // Default map
memcpy(map_default.mapname, RFIFOP(fd, (offs+=NAME_LENGTH)), MAP_NAME_LENGTH); memcpy(map_default.mapname, RFIFOP(fd, (offs+=NAME_LENGTH)), MAP_NAME_LENGTH);

View File

@@ -571,7 +571,7 @@ int clif_send(const void* buf, int len, struct block_list* bl, enum send_target
memcpy(WFIFOP(fd, 0), buf, len); memcpy(WFIFOP(fd, 0), buf, len);
WFIFOSET(fd, len); WFIFOSET(fd, len);
} }
if (!enable_spy) //Skip unnecessary parsing. [Skotlex] if (!map_config.enable_spy) //Skip unnecessary parsing. [Skotlex]
break; break;
iter = mapit_getallusers(); iter = mapit_getallusers();
@@ -649,7 +649,7 @@ int clif_send(const void* buf, int len, struct block_list* bl, enum send_target
WFIFOSET(fd,len); WFIFOSET(fd,len);
} }
} }
if (!enable_spy) //Skip unnecessary parsing. [Skotlex] if (!map_config.enable_spy) //Skip unnecessary parsing. [Skotlex]
break; break;
iter = mapit_getallusers(); iter = mapit_getallusers();
@@ -705,7 +705,7 @@ int clif_send(const void* buf, int len, struct block_list* bl, enum send_target
WFIFOSET(fd,len); WFIFOSET(fd,len);
} }
if (!enable_spy) //Skip unnecessary parsing. [Skotlex] if (!map_config.enable_spy) //Skip unnecessary parsing. [Skotlex]
break; break;
iter = mapit_getallusers(); iter = mapit_getallusers();
@@ -10689,7 +10689,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
if(hom_is_active(sd->hd)) if(hom_is_active(sd->hd))
hom_init_timers(sd->hd); hom_init_timers(sd->hd);
if (night_flag && mapdata->flag[MF_NIGHTENABLED]) { if (map_config.night_flag && mapdata->flag[MF_NIGHTENABLED]) {
sd->state.night = 1; sd->state.night = 1;
clif_status_load(&sd->bl, EFST_SKE, 1); clif_status_load(&sd->bl, EFST_SKE, 1);
} }
@@ -10767,7 +10767,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
} }
if( night_flag && mapdata->flag[MF_NIGHTENABLED] ) if( map_config.night_flag && mapdata->flag[MF_NIGHTENABLED])
{ //Display night. { //Display night.
if( !sd->state.night ) if( !sd->state.night )
{ {
@@ -11205,7 +11205,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); 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); ShowWarning(gm_msg);
// information is sent to all online GMs // 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; return;
} }
*/ */
@@ -11647,7 +11647,7 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd)
// if player is autotrading // if player is autotrading
if (dstsd->state.autotrade == 1){ if (dstsd->state.autotrade == 1){
safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name); safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0); clif_wis_message(sd, map_config.wisp_server_name, output, strlen(output) + 1, 0);
return; return;
} }
@@ -14643,7 +14643,7 @@ void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
type = RFIFOB(fd,info->pos[1]); type = RFIFOB(fd,info->pos[1]);
if( type == 0 ) { // Add name to ignore list (block) 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 clif_wisexin(sd, type, 1); // fail
return; return;
} }

View File

@@ -2228,11 +2228,11 @@ int guild_castledataloadack(int len, struct guild_castle *gc) {
* Start WoE:FE and triggers all npc OnAgitStart * Start WoE:FE and triggers all npc OnAgitStart
*/ */
bool guild_agit_start(void){ bool guild_agit_start(void){
if( agit_flag ){ if(map_config.agit_flag ){
return false; return false;
} }
agit_flag = true; map_config.agit_flag = true;
npc_event_runall( script_config.agit_start_event_name ); npc_event_runall( script_config.agit_start_event_name );
@@ -2243,11 +2243,11 @@ bool guild_agit_start(void){
* End WoE:FE and triggers all npc OnAgitEnd * End WoE:FE and triggers all npc OnAgitEnd
*/ */
bool guild_agit_end(void){ bool guild_agit_end(void){
if( !agit_flag ){ if( !map_config.agit_flag ){
return false; return false;
} }
agit_flag = false; map_config.agit_flag = false;
npc_event_runall( script_config.agit_end_event_name ); npc_event_runall( script_config.agit_end_event_name );
@@ -2258,11 +2258,11 @@ bool guild_agit_end(void){
* Start WoE:SE and triggers all npc OnAgitStart2 * Start WoE:SE and triggers all npc OnAgitStart2
*/ */
bool guild_agit2_start(void){ bool guild_agit2_start(void){
if( agit2_flag ){ if(map_config.agit2_flag ){
return false; return false;
} }
agit2_flag = true; map_config.agit2_flag = true;
npc_event_runall( script_config.agit_start2_event_name ); npc_event_runall( script_config.agit_start2_event_name );
@@ -2273,11 +2273,11 @@ bool guild_agit2_start(void){
* End WoE:SE and triggers all npc OnAgitEnd2 * End WoE:SE and triggers all npc OnAgitEnd2
*/ */
bool guild_agit2_end(void){ bool guild_agit2_end(void){
if( !agit2_flag ){ if( !map_config.agit2_flag ){
return false; return false;
} }
agit2_flag = false; map_config.agit2_flag = false;
npc_event_runall( script_config.agit_end2_event_name ); npc_event_runall( script_config.agit_end2_event_name );
@@ -2288,11 +2288,11 @@ bool guild_agit2_end(void){
* Start WoE:TE and triggers all npc OnAgitStart3 * Start WoE:TE and triggers all npc OnAgitStart3
*/ */
bool guild_agit3_start(void){ bool guild_agit3_start(void){
if( agit3_flag ){ if(map_config.agit3_flag ){
return false; return false;
} }
agit3_flag = true; map_config.agit3_flag = true;
npc_event_runall( script_config.agit_start3_event_name ); npc_event_runall( script_config.agit_start3_event_name );
@@ -2303,11 +2303,11 @@ bool guild_agit3_start(void){
* End WoE:TE and triggers all npc OnAgitEnd3 * End WoE:TE and triggers all npc OnAgitEnd3
*/ */
bool guild_agit3_end(void){ bool guild_agit3_end(void){
if( !agit3_flag ){ if( !map_config.agit3_flag ){
return false; return false;
} }
agit3_flag = false; map_config.agit3_flag = false;
npc_event_runall( script_config.agit_end3_event_name ); npc_event_runall( script_config.agit_end3_event_name );

View File

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

View File

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

View File

@@ -20,8 +20,6 @@
#include "pc.hpp" #include "pc.hpp"
#include "pet.hpp" #include "pet.hpp"
static char log_timestamp_format[20];
/// filters for item logging /// filters for item logging
typedef enum e_log_filter typedef enum e_log_filter
{ {
@@ -42,10 +40,8 @@ typedef enum e_log_filter
} }
e_log_filter; e_log_filter;
struct Log_Config log_config; struct Log_Config log_config;
#ifdef SQL_INNODB #ifdef SQL_INNODB
// database is using an InnoDB engine so do not use DELAYED // database is using an InnoDB engine so do not use DELAYED
#define LOG_QUERY "INSERT" #define LOG_QUERY "INSERT"
@@ -174,7 +170,7 @@ void log_branch(struct map_session_data* sd)
if( log_config.sql_logs ) { if( log_config.sql_logs ) {
SqlStmt* stmt; SqlStmt* stmt;
stmt = SqlStmt_Malloc(logmysql_handle); 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')", log_config.schema.branch_table.c_str(), 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, 0, SQLDT_STRING, sd->status.name, strnlen(sd->status.name, NAME_LENGTH))
|| SQL_SUCCESS != SqlStmt_Execute(stmt) ) || SQL_SUCCESS != SqlStmt_Execute(stmt) )
{ {
@@ -190,10 +186,10 @@ void log_branch(struct map_session_data* sd)
time_t curtime; time_t curtime;
FILE* logfp; FILE* logfp;
if( ( logfp = fopen(log_config.log_branch, "a") ) == NULL ) if( ( logfp = fopen(log_config.schema.branch_table.c_str(), "a") ) == NULL )
return; return;
time(&curtime); time(&curtime);
strftime(timestring, sizeof(timestring), log_timestamp_format, localtime(&curtime)); strftime(timestring, sizeof(timestring), log_config.log_timestamp.c_str(), localtime(&curtime));
fprintf(logfp,"%s - %s[%d:%d]\t%s\n", timestring, sd->status.name, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex)); fprintf(logfp,"%s - %s[%d:%d]\t%s\n", timestring, sd->status.name, sd->status.account_id, sd->status.char_id, mapindex_id2name(sd->mapindex));
fclose(logfp); fclose(logfp);
} }
@@ -218,7 +214,7 @@ void log_pick(int id, int16 m, e_log_pick_type type, int amount, struct item* it
StringBuf buf; StringBuf buf;
StringBuf_Init(&buf); StringBuf_Init(&buf);
StringBuf_Printf(&buf, "%s INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `map`, `unique_id`, `bound`", LOG_QUERY, log_config.log_pick); StringBuf_Printf(&buf, "%s INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `map`, `unique_id`, `bound`", LOG_QUERY, log_config.schema.pick_table.c_str());
for (i = 0; i < MAX_SLOTS; ++i) for (i = 0; i < MAX_SLOTS; ++i)
StringBuf_Printf(&buf, ", `card%d`", i); StringBuf_Printf(&buf, ", `card%d`", i);
for (i = 0; i < MAX_ITEM_RDM_OPT; ++i) { for (i = 0; i < MAX_ITEM_RDM_OPT; ++i) {
@@ -247,10 +243,10 @@ void log_pick(int id, int16 m, e_log_pick_type type, int amount, struct item* it
time_t curtime; time_t curtime;
FILE* logfp; FILE* logfp;
if( ( logfp = fopen(log_config.log_pick, "a") ) == NULL ) if( ( logfp = fopen(log_config.schema.pick_table.c_str(), "a") ) == NULL )
return; return;
time(&curtime); time(&curtime);
strftime(timestring, sizeof(timestring), log_timestamp_format, localtime(&curtime)); strftime(timestring, sizeof(timestring), log_config.log_timestamp.c_str(), localtime(&curtime));
fprintf(logfp,"%s - %d\t%c\t%u,%d,%d,%u,%u,%u,%u,%s,'%" PRIu64 "',%d\n", timestring, id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], map_getmapdata(m)->name[0]?map_getmapdata(m)->name:"", itm->unique_id, itm->bound); fprintf(logfp,"%s - %d\t%c\t%u,%d,%d,%u,%u,%u,%u,%s,'%" PRIu64 "',%d\n", timestring, id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], map_getmapdata(m)->name[0]?map_getmapdata(m)->name:"", itm->unique_id, itm->bound);
fclose(logfp); fclose(logfp);
} }
@@ -282,7 +278,7 @@ void log_zeny(struct map_session_data* sd, e_log_pick_type type, struct map_sess
if( log_config.sql_logs ) if( log_config.sql_logs )
{ {
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')", 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)) ) log_config.schema.zeny_table.c_str(), sd->status.char_id, src_sd->status.char_id, log_picktype2char(type), amount, mapindex_id2name(sd->mapindex)) )
{ {
Sql_ShowDebug(logmysql_handle); Sql_ShowDebug(logmysql_handle);
return; return;
@@ -294,10 +290,10 @@ void log_zeny(struct map_session_data* sd, e_log_pick_type type, struct map_sess
time_t curtime; time_t curtime;
FILE* logfp; FILE* logfp;
if( ( logfp = fopen(log_config.log_zeny, "a") ) == NULL ) if( ( logfp = fopen(log_config.schema.zeny_table.c_str(), "a") ) == NULL )
return; return;
time(&curtime); time(&curtime);
strftime(timestring, sizeof(timestring), log_timestamp_format, localtime(&curtime)); strftime(timestring, sizeof(timestring), log_config.log_timestamp.c_str(), localtime(&curtime));
fprintf(logfp, "%s - %s[%d]\t%s[%d]\t%d\t\n", timestring, src_sd->status.name, src_sd->status.account_id, sd->status.name, sd->status.account_id, amount); fprintf(logfp, "%s - %s[%d]\t%s[%d]\t%d\t\n", timestring, src_sd->status.name, src_sd->status.account_id, sd->status.name, sd->status.account_id, amount);
fclose(logfp); fclose(logfp);
} }
@@ -315,7 +311,7 @@ void log_mvpdrop(struct map_session_data* sd, int monster_id, t_itemid nameid, t
if( log_config.sql_logs ) if( log_config.sql_logs )
{ {
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', '%u', '%" PRIu64 "', '%s') ", 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', '%u', '%" PRIu64 "', '%s') ",
log_config.log_mvpdrop, sd->status.char_id, monster_id, nameid, exp, mapindex_id2name(sd->mapindex)) ) log_config.schema.mvpdrop_table.c_str(), sd->status.char_id, monster_id, nameid, exp, mapindex_id2name(sd->mapindex)) )
{ {
Sql_ShowDebug(logmysql_handle); Sql_ShowDebug(logmysql_handle);
return; return;
@@ -327,10 +323,10 @@ void log_mvpdrop(struct map_session_data* sd, int monster_id, t_itemid nameid, t
time_t curtime; time_t curtime;
FILE* logfp; FILE* logfp;
if( ( logfp = fopen(log_config.log_mvpdrop,"a") ) == NULL ) if( ( logfp = fopen(log_config.schema.mvpdrop_table.c_str(),"a") ) == NULL )
return; return;
time(&curtime); time(&curtime);
strftime(timestring, sizeof(timestring), log_timestamp_format, localtime(&curtime)); strftime(timestring, sizeof(timestring), log_config.log_timestamp.c_str(), localtime(&curtime));
fprintf(logfp,"%s - %s[%d:%d]\t%d\t%u,%" PRIu64 "\n", timestring, sd->status.name, sd->status.account_id, sd->status.char_id, monster_id, nameid, exp); fprintf(logfp,"%s - %s[%d:%d]\t%d\t%u,%" PRIu64 "\n", timestring, sd->status.name, sd->status.account_id, sd->status.char_id, monster_id, nameid, exp);
fclose(logfp); fclose(logfp);
} }
@@ -351,7 +347,7 @@ void log_atcommand(struct map_session_data* sd, const char* message)
SqlStmt* stmt; SqlStmt* stmt;
stmt = SqlStmt_Malloc(logmysql_handle); 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', ?)", log_config.schema.command_table.c_str(), 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, 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_BindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, 255))
|| SQL_SUCCESS != SqlStmt_Execute(stmt) ) || SQL_SUCCESS != SqlStmt_Execute(stmt) )
@@ -368,10 +364,10 @@ void log_atcommand(struct map_session_data* sd, const char* message)
time_t curtime; time_t curtime;
FILE* logfp; FILE* logfp;
if( ( logfp = fopen(log_config.log_gm, "a") ) == NULL ) if( ( logfp = fopen(log_config.schema.command_table.c_str(), "a") ) == NULL )
return; return;
time(&curtime); time(&curtime);
strftime(timestring, sizeof(timestring), log_timestamp_format, localtime(&curtime)); strftime(timestring, sizeof(timestring), log_config.log_timestamp.c_str(), localtime(&curtime));
fprintf(logfp, "%s - %s[%d]: %s\n", timestring, sd->status.name, sd->status.account_id, message); fprintf(logfp, "%s - %s[%d]: %s\n", timestring, sd->status.name, sd->status.account_id, message);
fclose(logfp); fclose(logfp);
} }
@@ -388,7 +384,7 @@ void log_npc( struct npc_data* nd, const char* message ){
{ {
SqlStmt* stmt; SqlStmt* stmt;
stmt = SqlStmt_Malloc(logmysql_handle); stmt = SqlStmt_Malloc(logmysql_handle);
if( SQL_SUCCESS != SqlStmt_Prepare(stmt, LOG_QUERY " INTO `%s` (`npc_date`, `char_name`, `map`, `mes`) VALUES (NOW(), ?, '%s', ?)", log_config.log_npc, map_mapid2mapname(nd->bl.m) ) if( SQL_SUCCESS != SqlStmt_Prepare(stmt, LOG_QUERY " INTO `%s` (`npc_date`, `char_name`, `map`, `mes`) VALUES (NOW(), ?, '%s', ?)", log_config.schema.npc_table.c_str(), map_mapid2mapname(nd->bl.m) )
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, nd->name, strnlen(nd->name, NAME_LENGTH)) || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, nd->name, strnlen(nd->name, NAME_LENGTH))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, 255)) || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, 255))
|| SQL_SUCCESS != SqlStmt_Execute(stmt) ) || SQL_SUCCESS != SqlStmt_Execute(stmt) )
@@ -405,10 +401,10 @@ void log_npc( struct npc_data* nd, const char* message ){
time_t curtime; time_t curtime;
FILE* logfp; FILE* logfp;
if( ( logfp = fopen(log_config.log_npc, "a") ) == NULL ) if( ( logfp = fopen(log_config.schema.npc_table.c_str(), "a") ) == NULL )
return; return;
time(&curtime); time(&curtime);
strftime(timestring, sizeof(timestring), log_timestamp_format, localtime(&curtime)); strftime(timestring, sizeof(timestring), log_config.log_timestamp.c_str(), localtime(&curtime));
fprintf(logfp, "%s - %s: %s\n", timestring, nd->name, message); fprintf(logfp, "%s - %s: %s\n", timestring, nd->name, message);
fclose(logfp); fclose(logfp);
} }
@@ -426,7 +422,7 @@ void log_npc(struct map_session_data* sd, const char* message)
{ {
SqlStmt* stmt; SqlStmt* stmt;
stmt = SqlStmt_Malloc(logmysql_handle); 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', ?)", log_config.schema.npc_table.c_str(), 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, 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_BindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, 255))
|| SQL_SUCCESS != SqlStmt_Execute(stmt) ) || SQL_SUCCESS != SqlStmt_Execute(stmt) )
@@ -443,10 +439,10 @@ void log_npc(struct map_session_data* sd, const char* message)
time_t curtime; time_t curtime;
FILE* logfp; FILE* logfp;
if( ( logfp = fopen(log_config.log_npc, "a") ) == NULL ) if( ( logfp = fopen(log_config.schema.npc_table.c_str(), "a") ) == NULL )
return; return;
time(&curtime); time(&curtime);
strftime(timestring, sizeof(timestring), log_timestamp_format, localtime(&curtime)); strftime(timestring, sizeof(timestring), log_config.log_timestamp.c_str(), localtime(&curtime));
fprintf(logfp, "%s - %s[%d]: %s\n", timestring, sd->status.name, sd->status.account_id, message); fprintf(logfp, "%s - %s[%d]: %s\n", timestring, sd->status.name, sd->status.account_id, message);
fclose(logfp); fclose(logfp);
} }
@@ -470,7 +466,7 @@ void log_chat(e_log_chat_type type, int type_id, int src_charid, int src_accid,
SqlStmt* stmt; SqlStmt* stmt;
stmt = SqlStmt_Malloc(logmysql_handle); 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', ?, ?)", log_config.schema.chat_table.c_str(), 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, 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_BindParam(stmt, 1, SQLDT_STRING, (char*)message, safestrnlen(message, CHAT_SIZE_MAX))
|| SQL_SUCCESS != SqlStmt_Execute(stmt) ) || SQL_SUCCESS != SqlStmt_Execute(stmt) )
@@ -487,10 +483,10 @@ void log_chat(e_log_chat_type type, int type_id, int src_charid, int src_accid,
time_t curtime; time_t curtime;
FILE* logfp; FILE* logfp;
if( ( logfp = fopen(log_config.log_chat, "a") ) == NULL ) if( ( logfp = fopen(log_config.schema.chat_table.c_str(), "a") ) == NULL )
return; return;
time(&curtime); time(&curtime);
strftime(timestring, sizeof(timestring), log_timestamp_format, localtime(&curtime)); strftime(timestring, sizeof(timestring), log_config.log_timestamp.c_str(), localtime(&curtime));
fprintf(logfp, "%s - %c,%d,%d,%d,%s,%d,%d,%s,%s\n", timestring, log_chattype2char(type), type_id, src_charid, src_accid, mapname, x, y, dst_charname, message); fprintf(logfp, "%s - %c,%d,%d,%d,%s,%d,%d,%s,%s\n", timestring, log_chattype2char(type), type_id, src_charid, src_accid, mapname, x, y, dst_charname, message);
fclose(logfp); fclose(logfp);
} }
@@ -505,7 +501,7 @@ void log_cash( struct map_session_data* sd, e_log_pick_type type, e_log_cash_typ
if( log_config.sql_logs ){ if( log_config.sql_logs ){
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' )", 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 ) ) ) log_config.schema.cash_table.c_str(), sd->status.char_id, log_picktype2char( type ), log_cashtype2char( cash_type ), amount, mapindex_id2name( sd->mapindex ) ) )
{ {
Sql_ShowDebug( logmysql_handle ); Sql_ShowDebug( logmysql_handle );
return; return;
@@ -515,10 +511,10 @@ void log_cash( struct map_session_data* sd, e_log_pick_type type, e_log_cash_typ
time_t curtime; time_t curtime;
FILE* logfp; FILE* logfp;
if( ( logfp = fopen( log_config.log_cash, "a" ) ) == NULL ) if( ( logfp = fopen( log_config.schema.cash_table.c_str(), "a" ) ) == NULL )
return; return;
time( &curtime ); time( &curtime );
strftime( timestring, sizeof( timestring ), log_timestamp_format, localtime( &curtime ) ); strftime(timestring, sizeof(timestring), log_config.log_timestamp.c_str(), localtime(&curtime));
fprintf( logfp, "%s - %s[%d]\t%d(%c)\t\n", timestring, sd->status.name, sd->status.account_id, amount, log_cashtype2char( cash_type ) ); fprintf( logfp, "%s - %s[%d]\t%d(%c)\t\n", timestring, sd->status.name, sd->status.account_id, amount, log_cashtype2char( cash_type ) );
fclose( logfp ); fclose( logfp );
} }
@@ -558,7 +554,7 @@ void log_feeding(struct map_session_data *sd, e_log_feeding_type type, t_itemid
if (log_config.sql_logs) { if (log_config.sql_logs) {
if (SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `target_id`, `target_class`, `type`, `intimacy`, `item_id`, `map`, `x`, `y`) VALUES ( NOW(), '%" PRIu32 "', '%" PRIu32 "', '%hu', '%c', '%" PRIu32 "', '%u', '%s', '%hu', '%hu' )", if (SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `target_id`, `target_class`, `type`, `intimacy`, `item_id`, `map`, `x`, `y`) VALUES ( NOW(), '%" PRIu32 "', '%" PRIu32 "', '%hu', '%c', '%" PRIu32 "', '%u', '%s', '%hu', '%hu' )",
log_config.log_feeding, sd->status.char_id, target_id, target_class, log_feedingtype2char(type), intimacy, nameid, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y)) log_config.schema.feeding_table.c_str(), sd->status.char_id, target_id, target_class, log_feedingtype2char(type), intimacy, nameid, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y))
{ {
Sql_ShowDebug(logmysql_handle); Sql_ShowDebug(logmysql_handle);
return; return;
@@ -568,10 +564,10 @@ void log_feeding(struct map_session_data *sd, e_log_feeding_type type, t_itemid
time_t curtime; time_t curtime;
FILE* logfp; FILE* logfp;
if ((logfp = fopen(log_config.log_feeding, "a")) == NULL) if ((logfp = fopen(log_config.schema.feeding_table.c_str(), "a")) == NULL)
return; return;
time(&curtime); time(&curtime);
strftime(timestring, sizeof(timestring), log_timestamp_format, localtime(&curtime)); strftime(timestring, sizeof(timestring), log_config.log_timestamp.c_str(), localtime(&curtime));
fprintf(logfp, "%s - %s[%d]\t%d\t%d(%c)\t%d\t%u\t%s\t%hu,%hu\n", timestring, sd->status.name, sd->status.char_id, target_id, target_class, log_feedingtype2char(type), intimacy, nameid, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y); fprintf(logfp, "%s - %s[%d]\t%d\t%d(%c)\t%d\t%u\t%s\t%hu,%hu\n", timestring, sd->status.name, sd->status.char_id, target_id, target_class, log_feedingtype2char(type), intimacy, nameid, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y);
fclose(logfp); fclose(logfp);
} }
@@ -579,27 +575,208 @@ void log_feeding(struct map_session_data *sd, e_log_feeding_type type, t_itemid
void log_set_defaults(void) 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 // Logging
log_config.refine_items_log = 5; // log refined items, with refine >= +5 log_config.cash = true;
log_config.rare_items_log = 100; // log rare items. drop chance <= 1% log_config.branch = 0;
log_config.price_items_log = 1000; // 1000z log_config.mvpdrop = 0;
log_config.amount_items_log = 100; 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
}
/**
* Initialize default configurations
**/
void log_config_init(void) {
log_set_defaults();
log_config.log_path = "log/";
log_config.log_ext = ".log";
log_config.log_timestamp = "%m/%d/%Y %H:%M:%S";
log_config.schema.branch_table = "branchlog";
log_config.schema.cash_table = "cashlog";
log_config.schema.chat_table = "chatlog";
log_config.schema.command_table = "atcommandlog";
log_config.schema.mvpdrop_table = "mvplog";
log_config.schema.npc_table = "npclog";
log_config.schema.pick_table = "picklog";
log_config.schema.zeny_table = "zenylog";
log_config.schema.feeding_table = "feedinglog";
} }
/**
* Finalize default configurations
**/
void log_config_final(void) {
}
/**
* Report final logging state
**/
void log_config_read_done(void) {
#define LOG_CONFIG_PATH(log) {\
log_config.schema.log = log_config.log_path; \
log_config.schema.log.append(log_config.schema.log); \
log_config.schema.log.append((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, log_config.schema.pick_table.c_str());
}
if (log_config.branch) {
ShowInfo("Logging monster summon item usage to %s: '%s'.\n", target, log_config.schema.branch_table.c_str());
}
if (log_config.chat) {
ShowInfo("Logging chat to %s: '%s'.\n", target, log_config.schema.chat_table.c_str());
}
if (log_config.commands) {
ShowInfo("Logging commands to %s: '%s'.\n", target, log_config.schema.command_table.c_str());
}
if (log_config.mvpdrop) {
ShowInfo("Logging MVP monster rewards to %s: '%s'.\n", target, log_config.schema.mvpdrop_table.c_str());
}
if (log_config.npc) {
ShowInfo("Logging 'logmes' messages to %s: '%s'.\n", target, log_config.schema.npc_table.c_str());
}
if (log_config.zeny) {
ShowInfo("Logging Zeny transactions to %s: '%s'.\n", target, log_config.schema.zeny_table.c_str());
}
if (log_config.cash) {
ShowInfo("Logging Cash transactions to %s: '%s'.\n", target, log_config.schema.cash_table.c_str());
}
if (log_config.feeding) {
ShowInfo("Logging Feeding items to %s: '%s'.\n", target, log_config.schema.feeding_table.c_str());
}
#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`;", log_config.schema.branch_table.c_str()) )
{
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`;", log_config.schema.cash_table.c_str()) )
{
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`;", log_config.schema.chat_table.c_str()) )
{
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`;", log_config.schema.command_table.c_str()) )
{
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`;", log_config.schema.mvpdrop_table.c_str()) )
{
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`;", log_config.schema.npc_table.c_str()) )
{
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`;", log_config.schema.pick_table.c_str()) )
{
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`;", log_config.schema.zeny_table.c_str()) )
{
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`;", log_config.schema.feeding_table.c_str()) )
{
Sql_ShowDebug(logmysql_handle);
return false;
}
return true;
}
int log_config_read(const char* cfgName) int log_config_read(const char* cfgName)
{ {
static int count = 0; char line[1024];
char line[1024], w1[1024], w2[1024];
FILE *fp; FILE *fp;
if( count++ == 0 )
log_set_defaults();
if( ( fp = fopen(cfgName, "r") ) == NULL ) if( ( fp = fopen(cfgName, "r") ) == NULL )
{ {
ShowError("Log configuration file not found at: %s\n", cfgName); ShowError("Log configuration file not found at: %s\n", cfgName);
@@ -608,6 +785,7 @@ int log_config_read(const char* cfgName)
while( fgets(line, sizeof(line), fp) ) while( fgets(line, sizeof(line), fp) )
{ {
char w1[32], w2[32];
if( line[0] == '/' && line[1] == '/' ) if( line[0] == '/' && line[1] == '/' )
continue; continue;
@@ -628,46 +806,49 @@ int log_config_read(const char* cfgName)
log_config.amount_items_log = atoi(w2); log_config.amount_items_log = atoi(w2);
//end of common filter settings //end of common filter settings
else if( strcmpi(w1, "log_branch") == 0 ) else if( strcmpi(w1, "log_branch") == 0 )
log_config.branch = config_switch(w2); log_config.branch = config_switch(w2) ? true : false;
else if( strcmpi(w1, "log_filter") == 0 ) 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 ) else if( strcmpi(w1, "log_zeny") == 0 )
log_config.zeny = config_switch(w2); log_config.zeny = config_switch(w2);
else if( strcmpi( w1, "log_cash" ) == 0 ) else if( strcmpi( w1, "log_cash" ) == 0 )
log_config.cash = config_switch( w2 ) > 0; log_config.cash = config_switch( w2 ) > 0;
else if( strcmpi(w1, "log_commands") == 0 ) else if( strcmpi(w1, "log_commands") == 0 )
log_config.commands = config_switch(w2); log_config.commands = config_switch(w2) ? true : false;
else if( strcmpi(w1, "log_npc") == 0 ) else if( strcmpi(w1, "log_npc") == 0 )
log_config.npc = config_switch(w2); log_config.npc = config_switch(w2) ? true : false;
else if( strcmpi(w1, "log_chat") == 0 ) 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 ) else if( strcmpi(w1, "log_mvpdrop") == 0 )
log_config.mvpdrop = config_switch(w2); log_config.mvpdrop = config_switch(w2) ? true : false;
else if( strcmpi(w1, "log_feeding") == 0 ) else if( strcmpi(w1, "log_feeding") == 0 )
log_config.feeding = config_switch(w2); log_config.feeding = config_switch(w2);
else if( strcmpi(w1, "log_chat_woe_disable") == 0 ) else if( strcmpi(w1, "log_chat_woe_disable") == 0 )
log_config.log_chat_woe_disable = config_switch(w2) > 0; log_config.log_chat_woe_disable = config_switch(w2) ? true : false;
else if( strcmpi(w1, "log_branch_db") == 0 ) else if( strcmpi(w1, "log_branch_table") == 0 )
safestrncpy(log_config.log_branch, w2, sizeof(log_config.log_branch)); log_config.schema.branch_table = w2;
else if( strcmpi(w1, "log_pick_db") == 0 ) else if( strcmpi(w1, "log_pick_table") == 0 )
safestrncpy(log_config.log_pick, w2, sizeof(log_config.log_pick)); log_config.schema.pick_table = w2;
else if( strcmpi(w1, "log_zeny_db") == 0 ) else if( strcmpi(w1, "log_zeny_table") == 0 )
safestrncpy(log_config.log_zeny, w2, sizeof(log_config.log_zeny)); log_config.schema.zeny_table = w2;
else if( strcmpi(w1, "log_mvpdrop_db") == 0 ) else if( strcmpi(w1, "log_mvpdrop_table") == 0 )
safestrncpy(log_config.log_mvpdrop, w2, sizeof(log_config.log_mvpdrop)); log_config.schema.mvpdrop_table = w2;
else if( strcmpi(w1, "log_gm_db") == 0 ) else if( strcmpi(w1, "log_gm_table") == 0 )
safestrncpy(log_config.log_gm, w2, sizeof(log_config.log_gm)); log_config.schema.command_table = w2;
else if( strcmpi(w1, "log_npc_db") == 0 ) else if( strcmpi(w1, "log_npc_table") == 0 )
safestrncpy(log_config.log_npc, w2, sizeof(log_config.log_npc)); log_config.schema.npc_table = w2;
else if( strcmpi(w1, "log_chat_db") == 0 ) else if( strcmpi(w1, "log_chat_table") == 0 )
safestrncpy(log_config.log_chat, w2, sizeof(log_config.log_chat)); log_config.schema.chat_table = w2;
else if( strcmpi( w1, "log_cash_db" ) == 0 ) else if( strcmpi( w1, "log_cash_table" ) == 0 )
safestrncpy( log_config.log_cash, w2, sizeof( log_config.log_cash ) ); log_config.schema.cash_table = w2;
else if( strcmpi( w1, "log_feeding_db" ) == 0 ) else if( strcmpi( w1, "log_feeding_table" ) == 0 )
safestrncpy( log_config.log_feeding, w2, sizeof( log_config.log_feeding ) ); log_config.schema.feeding_table = w2;
// log file timestamp format else if( strcmpi( w1, "log_path" ) == 0 )
log_config.log_path = w2;
else if( strcmpi( w1, "log_extension" ) == 0 )
log_config.log_ext = w2;
else if( strcmpi( w1, "log_timestamp_format" ) == 0 ) else if( strcmpi( w1, "log_timestamp_format" ) == 0 )
safestrncpy(log_timestamp_format, w2, sizeof(log_timestamp_format)); log_config.log_timestamp = w2;
//support the import command, just like any other config //support the import command, just like any other config
else if( strcmpi(w1,"import") == 0 ) else if( strcmpi(w1,"import") == 0 )
log_config_read(w2); log_config_read(w2);
@@ -677,46 +858,5 @@ int log_config_read(const char* cfgName)
} }
fclose(fp); 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; return 0;
} }

View File

@@ -4,6 +4,8 @@
#ifndef LOG_HPP #ifndef LOG_HPP
#define LOG_HPP #define LOG_HPP
#include <string>
#include "../common/cbasetypes.hpp" #include "../common/cbasetypes.hpp"
#include "../common/mmo.hpp" #include "../common/mmo.hpp"
@@ -14,6 +16,7 @@ struct item;
enum e_log_chat_type : uint8 enum e_log_chat_type : uint8
{ {
LOG_CHAT_NONE = 0,
LOG_CHAT_GLOBAL = 0x01, LOG_CHAT_GLOBAL = 0x01,
LOG_CHAT_WHISPER = 0x02, LOG_CHAT_WHISPER = 0x02,
LOG_CHAT_PARTY = 0x04, LOG_CHAT_PARTY = 0x04,
@@ -86,18 +89,50 @@ void log_mvpdrop(struct map_session_data* sd, int monster_id, t_itemid nameid, t
int log_config_read(const char* cfgName); int log_config_read(const char* cfgName);
extern struct Log_Config /// Log Config structure
{ struct Log_Config {
e_log_pick_type enable_logs; uint32 enable_logs; ///< Values @see e_log_pick_type
int filter; uint16 filter; ///< Values @see e_log_filter
bool sql_logs; bool sql_logs; ///< Enable SQL log instead of file log
bool log_chat_woe_disable; bool log_chat_woe_disable; ///< Disable chat logging on WOE
bool cash;
int rare_items_log,refine_items_log,price_items_log,amount_items_log; //for filter bool cash; ///< Log cash usage
int branch, mvpdrop, zeny, commands, npc, chat; bool branch; ///< Log item branch usage
unsigned feeding : 2; bool mvpdrop; ///< Log MVP Drop
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]; uint32 zeny; ///< Log Zeny usage if zeny spent is more than 'zeny'
char log_feeding[64]; bool commands; ///< Log Comman usage
} log_config; 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'
std::string log_path; ///< Path to log file (Used if 'sql_logs' is no)
std::string log_ext; ///< Log file extension (Used if 'sql_logs' is no)
std::string log_timestamp; ///< Time Stamp format for logs
struct s_log_schema_config {
std::string branch_table; ///< Branch log table/file with path
std::string cash_table; ///< Cash log table/file with path
std::string chat_table; ///< Chat log table/file with path
std::string command_table; ///< Command log table/file with path
std::string mvpdrop_table; ///< MVP Drop log table/file with path
std::string npc_table; ///< NPC log table/file with path
std::string pick_table; ///< Pick log table/file with path
std::string zeny_table; ///< Zeny log table/file with path
std::string 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);
#endif /* LOG_HPP */ #endif /* LOG_HPP */

View File

@@ -52,50 +52,21 @@
using namespace rathena; using namespace rathena;
char default_codepage[32] = ""; Sql* mmysql_handle; /// Map-server handle
int map_server_port = 3306;
char map_server_ip[64] = "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* qsmysql_handle; /// For query_sql Sql* qsmysql_handle; /// For query_sql
Sql* logmysql_handle; /// Log database handle
int db_use_sqldbs = 0; struct Map_Config map_config; /// Map configurations
char buyingstores_table[32] = "buyingstores"; static void map_inter_config_init(void);
char buyingstore_items_table[32] = "buyingstore_items"; static void map_inter_config_final(void);
char item_cash_table[32] = "item_cash_db";
char item_cash2_table[32] = "item_cash_db2";
#ifdef RENEWAL
char item_table[32] = "item_db_re";
char item2_table[32] = "item_db2_re";
char mob_table[32] = "mob_db_re";
char mob2_table[32] = "mob_db2_re";
char mob_skill_table[32] = "mob_skill_db_re";
char mob_skill2_table[32] = "mob_skill_db2_re";
#else
char item_table[32] = "item_db";
char item2_table[32] = "item_db2";
char mob_table[32] = "mob_db";
char mob2_table[32] = "mob_db2";
char mob_skill_table[32] = "mob_skill_db";
char mob_skill2_table[32] = "mob_skill_db2";
#endif
char sales_table[32] = "sales";
char vendings_table[32] = "vendings";
char vending_items_table[32] = "vending_items";
char market_table[32] = "market";
char roulette_table[32] = "db_roulette";
char guild_storage_log_table[32] = "guild_storage_log";
// log database struct MapServer_Schema mapserv_schema_config; /// map-server tables
char log_db_ip[64] = "127.0.0.1"; static void map_schema_init(void);
int log_db_port = 3306; static void map_schema_final(void);
char log_db_id[32] = "ragnarok";
char log_db_pw[32] = ""; struct MapServer_File mapserv_file_config; /// Sub files needed for map-server
char log_db_db[32] = "log"; static void map_file_init(void);
Sql* logmysql_handle; static void map_file_final(void);
// DBMap declaration // DBMap declaration
static DBMap* id_db=NULL; /// int id -> struct block_list* static DBMap* id_db=NULL; /// int id -> struct block_list*
@@ -128,13 +99,7 @@ int map_num = 0;
int map_port=0; int map_port=0;
int autosave_interval = DEFAULT_AUTOSAVE_INTERVAL; struct eri *map_skill_damage_ers = NULL;
int minsave_interval = 100;
int16 save_settings = CHARSAVE_ALL;
bool agit_flag = false;
bool agit2_flag = false;
bool agit3_flag = false;
int night_flag = 0; // 0=day, 1=night [Yor]
struct charid_request { struct charid_request {
struct charid_request* next; struct charid_request* next;
@@ -159,10 +124,6 @@ struct map_cache_map_info {
int32 len; int32 len;
}; };
char motd_txt[256] = "conf/motd.txt";
char charhelp_txt[256] = "conf/charhelp.txt";
char channel_conf[256] = "conf/channels.conf";
const char *MSG_CONF_NAME_RUS; const char *MSG_CONF_NAME_RUS;
const char *MSG_CONF_NAME_SPN; const char *MSG_CONF_NAME_SPN;
const char *MSG_CONF_NAME_GRM; const char *MSG_CONF_NAME_GRM;
@@ -173,14 +134,8 @@ const char *MSG_CONF_NAME_FRN;
const char *MSG_CONF_NAME_POR; const char *MSG_CONF_NAME_POR;
const char *MSG_CONF_NAME_THA; const char *MSG_CONF_NAME_THA;
char wisp_server_name[NAME_LENGTH] = "Server"; // can be modified in char-server configuration file
struct s_map_default map_default; 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]
/** /**
* Get the map data * Get the map data
* @param mapid: Map ID to lookup * @param mapid: Map ID to lookup
@@ -3801,7 +3756,7 @@ int map_readallmaps (void)
}; };
char map_cache_decode_buffer[MAX_MAP_SIZE]; char map_cache_decode_buffer[MAX_MAP_SIZE];
if( enable_grf ) if( map_config.enable_grf )
ShowStatus("Loading maps (using GRF files)...\n"); ShowStatus("Loading maps (using GRF files)...\n");
else { else {
const char* mapcachefilepath[] = { const char* mapcachefilepath[] = {
@@ -3845,7 +3800,7 @@ int map_readallmaps (void)
// show progress // show progress
ShowStatus("Loading maps [%i/%i]: %s" CL_CLL "\r", i, map_num, mapdata->name); ShowStatus("Loading maps [%i/%i]: %s" CL_CLL "\r", i, map_num, mapdata->name);
if( enable_grf ){ if( map_config.enable_grf ){
// try to load the map // try to load the map
success = map_readgat(mapdata) != 0; success = map_readgat(mapdata) != 0;
}else{ }else{
@@ -3904,7 +3859,7 @@ int map_readallmaps (void)
// intialization and configuration-dependent adjustments of mapflags // intialization and configuration-dependent adjustments of mapflags
map_flags_init(); map_flags_init();
if( !enable_grf ) { if( !map_config.enable_grf ) {
// The cache isn't needed anymore, so free it. [Shinryo] // The cache isn't needed anymore, so free it. [Shinryo]
if( map_cache_buffer[1] != NULL ){ if( map_cache_buffer[1] != NULL ){
aFree(map_cache_buffer[1]); aFree(map_cache_buffer[1]);
@@ -3997,6 +3952,51 @@ int parse_console(const char* buf){
return 0; 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))) {\
mapserv_schema_config.var = w2;\
return true;\
}\
if (strcmpi(w1,"use_sql_db")==0) {
mapserv_schema_config.db_use_sqldbs = config_switch(w2) ? true : false;
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(guild_storage_log_table, "guild_storage_log_table")
SCHEMA_CONF(mapreg_table, "mapreg_table")
SCHEMA_CONF(market_table, "market_table")
SCHEMA_CONF(roulette_table, "roulette_table")
SCHEMA_CONF(sales_table, "sales_table")
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...) * Read map server configuration files (conf/map_athena.conf...)
*------------------------------------------*/ *------------------------------------------*/
@@ -4029,15 +4029,16 @@ int map_config_read(const char *cfgName)
ptr++; ptr++;
*ptr = '\0'; *ptr = '\0';
if(strcmpi(w1,"timestamp_format")==0) if (strcmpi(w1, "timestamp_format") == 0)
safestrncpy(timestamp_format, w2, 20); safestrncpy(timestamp_format, w2, 20);
else if(strcmpi(w1,"stdout_with_ansisequence")==0) else if (strcmpi(w1, "stdout_with_ansisequence") == 0)
stdout_with_ansisequence = config_switch(w2); stdout_with_ansisequence = config_switch(w2);
else if(strcmpi(w1,"console_silent")==0) { else if (strcmpi(w1, "console_silent") == 0) {
msg_silent = atoi(w2); msg_silent = atoi(w2);
if( msg_silent ) // only bother if its actually enabled if (msg_silent) // only bother if its actually enabled
ShowInfo("Console Silent Setting: %d\n", atoi(w2)); ShowInfo("Console Silent Setting: %d\n", atoi(w2));
} else if (strcmpi(w1, "userid")==0) }
else if (strcmpi(w1, "userid") == 0)
chrif_setuserid(w2); chrif_setuserid(w2);
else if (strcmpi(w1, "passwd") == 0) else if (strcmpi(w1, "passwd") == 0)
chrif_setpasswd(w2); chrif_setpasswd(w2);
@@ -4052,7 +4053,8 @@ int map_config_read(const char *cfgName)
else if (strcmpi(w1, "map_port") == 0) { else if (strcmpi(w1, "map_port") == 0) {
clif_setport(atoi(w2)); clif_setport(atoi(w2));
map_port = (atoi(w2)); map_port = (atoi(w2));
} else if (strcmpi(w1, "map") == 0) }
else if (strcmpi(w1, "map") == 0)
map_addmap(w2); map_addmap(w2);
else if (strcmpi(w1, "delmap") == 0) else if (strcmpi(w1, "delmap") == 0)
map_delmap(w2); map_delmap(w2);
@@ -4061,37 +4063,45 @@ int map_config_read(const char *cfgName)
else if (strcmpi(w1, "delnpc") == 0) else if (strcmpi(w1, "delnpc") == 0)
npc_delsrcfile(w2); npc_delsrcfile(w2);
else if (strcmpi(w1, "autosave_time") == 0) { else if (strcmpi(w1, "autosave_time") == 0) {
autosave_interval = atoi(w2); map_config.autosave_interval = atoi(w2);
if (autosave_interval < 1) //Revert to default saving. if (map_config.autosave_interval < 1) //Revert to default saving.
autosave_interval = DEFAULT_AUTOSAVE_INTERVAL; map_config.autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
else 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); else if (strcmpi(w1, "minsave_time") == 0) {
if (minsave_interval < 1) map_config.minsave_interval = atoi(w2);
minsave_interval = 1; if (map_config.minsave_interval < 1)
} else if (strcmpi(w1, "save_settings") == 0) map_config.minsave_interval = 1;
save_settings = cap_value(atoi(w2),CHARSAVE_NONE,CHARSAVE_ALL); }
else if (strcmpi(w1, "save_settings") == 0)
map_config.save_settings = cap_value(static_cast<e_save_settings_type>(atoi(w2)), CHARSAVE_NONE, CHARSAVE_ALL);
else if (strcmpi(w1, "motd_txt") == 0) else if (strcmpi(w1, "motd_txt") == 0)
safestrncpy(motd_txt, w2, sizeof(motd_txt)); mapserv_file_config.motd = w2;
else if (strcmpi(w1, "charhelp_txt") == 0) else if (strcmpi(w1, "group_conf_file") == 0)
safestrncpy(charhelp_txt, w2, sizeof(charhelp_txt)); mapserv_file_config.group = w2;
else if (strcmpi(w1, "channel_conf") == 0) else if (strcmpi(w1, "atcommand_conf_file") == 0)
safestrncpy(channel_conf, w2, sizeof(channel_conf)); mapserv_file_config.atcommand = w2;
else if (strcmpi(w1, "channel_conf_file") == 0)
mapserv_file_config.channel = w2;
else if(strcmpi(w1,"db_path") == 0) else if(strcmpi(w1,"db_path") == 0)
safestrncpy(db_path,w2,ARRAYLENGTH(db_path)); safestrncpy(db_path,w2,ARRAYLENGTH(db_path));
else if (strcmpi(w1, "console") == 0) { else if (strcmpi(w1, "console") == 0) {
console = config_switch(w2); map_config.console = config_switch(w2) ? true : false;
if (console) if (map_config.console)
ShowNotice("Console Commands are enabled.\n"); ShowNotice("Console Commands are enabled.\n");
} else if (strcmpi(w1, "enable_spy") == 0) } else if (strcmpi(w1, "enable_spy") == 0)
enable_spy = config_switch(w2); map_config.enable_spy = config_switch(w2) ? true : false;
else if (strcmpi(w1, "use_grf") == 0) else if (strcmpi(w1, "use_grf") == 0)
enable_grf = config_switch(w2); map_config.enable_grf = config_switch(w2) ? true : false;
else if (strcmpi(w1, "console_msg_log") == 0) else if (strcmpi(w1, "console_msg_log") == 0)
console_msg_log = atoi(w2);//[Ind] console_msg_log = atoi(w2);//[Ind]
else if (strcmpi(w1, "console_log_filepath") == 0) else if (strcmpi(w1, "console_log_filepath") == 0)
safestrncpy(console_log_filepath, w2, sizeof(console_log_filepath)); safestrncpy(console_log_filepath, w2, sizeof(console_log_filepath));
else if (strcmpi(w1,"check_tables") == 0)
map_config.check_tables = config_switch(w2) ? true : false;
else if (map_schema_read_conf(w1, w2))
continue;
else if (strcmpi(w1, "import") == 0) else if (strcmpi(w1, "import") == 0)
map_config_read(w2); map_config_read(w2);
else else
@@ -4156,9 +4166,257 @@ void map_reloadnpc(bool clear)
#endif #endif
} }
int inter_config_read(const char *cfgName) /**
* Initialize default configurations
**/
static void map_inter_config_init(void) {
map_config.map_server_port = 3306;
map_config.map_server_ip = "127.0.0.1";
map_config.map_server_id = "ragnarok";
map_config.map_server_pw = "";
map_config.map_server_db = "ragnarok";
map_config.default_codepage = "";
map_config.log_db_port = 3306;
map_config.log_db_ip = "127.0.0.1";
map_config.log_db_id = "ragnarok";
map_config.log_db_pw = "";
map_config.log_db_db = "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) {
}
/**
* Initialize default map-server tables
**/
static void map_schema_init(void) {
mapserv_schema_config.db_use_sqldbs = false;
mapserv_schema_config.buyingstores_table = "buyingstores";
mapserv_schema_config.buyingstore_items_table = "buyingstore_items";
mapserv_schema_config.guild_storage_log_table = "guildstorage_log";
mapserv_schema_config.item_db_table = "item_db";
mapserv_schema_config.item_db2_table = "item_db2";
mapserv_schema_config.item_db_re_table = "item_db_re";
mapserv_schema_config.item_cash_db_table = "item_cash_db";
mapserv_schema_config.item_cash_db2_table = "item_cash_db2";
mapserv_schema_config.mapreg_table = "mapreg";
mapserv_schema_config.market_table = "market";
mapserv_schema_config.mob_db_table = "mob_db";
mapserv_schema_config.mob_db_re_table = "mob_db_re";
mapserv_schema_config.mob_db2_table = "mob_db2";
mapserv_schema_config.mob_skill_db_table = "mob_skill_db";
mapserv_schema_config.mob_skill_db_re_table = "mob_skill_db_re";
mapserv_schema_config.mob_skill_db2_table = "mob_skill_db2";
mapserv_schema_config.roulette_table = "db_roulette";
mapserv_schema_config.sales_table = "sales";
mapserv_schema_config.vendings_table = "vendings";
mapserv_schema_config.vending_items_table = "vending_items";
}
/**
* Finalize map-server tables
**/
static void map_schema_final(void) {
}
/**
* Initialize default map-server files
**/
static void map_file_init(void) {
mapserv_file_config.group = "conf/groups.conf";
mapserv_file_config.atcommand = "conf/atcommand_athena.conf";
mapserv_file_config.channel = "conf/channels.conf";
mapserv_file_config.motd = "conf/motd.txt";
}
/**
* Finalize map-server files
**/
static void map_file_final(void) {
}
/**
* 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(const char *cfgName)
{ {
char line[1024],w1[1024],w2[1024]; char line[1024];
FILE *fp; FILE *fp;
fp=fopen(cfgName,"r"); fp=fopen(cfgName,"r");
@@ -4168,100 +4426,39 @@ int inter_config_read(const char *cfgName)
} }
while(fgets(line, sizeof(line), fp)) while(fgets(line, sizeof(line), fp))
{ {
char w1[32],w2[32];
if(line[0] == '/' && line[1] == '/') if(line[0] == '/' && line[1] == '/')
continue; continue;
if( sscanf(line,"%1023[^:]: %1023[^\r\n]",w1,w2) < 2 ) if( sscanf(line,"%31[^:]: %31[^\r\n]",w1,w2) < 2 )
continue; continue;
#define RENEWALPREFIX "renewal-"
if (!strncmpi(w1, RENEWALPREFIX, strlen(RENEWALPREFIX))) {
#ifdef RENEWAL
// Move the original name to the beginning of the string
memmove(w1, w1 + strlen(RENEWALPREFIX), strlen(w1) - strlen(RENEWALPREFIX) + 1);
#else
// In Pre-Renewal the Renewal specific configurations can safely be ignored
continue;
#endif
}
#undef RENEWALPREFIX
if( strcmpi( w1, "buyingstore_db" ) == 0 )
safestrncpy( buyingstores_table, w2, sizeof(buyingstores_table) );
else if( strcmpi( w1, "buyingstore_items_table" ) == 0 )
safestrncpy( buyingstore_items_table, w2, sizeof(buyingstore_items_table) );
else if(strcmpi(w1,"item_table")==0)
safestrncpy(item_table,w2,sizeof(item_table));
else if(strcmpi(w1,"item2_table")==0)
safestrncpy(item2_table,w2,sizeof(item2_table));
else if(strcmpi(w1,"mob_table")==0)
safestrncpy(mob_table,w2,sizeof(mob_table));
else if(strcmpi(w1,"mob2_table")==0)
safestrncpy(mob2_table,w2,sizeof(mob2_table));
else if(strcmpi(w1,"mob_skill_table")==0)
safestrncpy(mob_skill_table,w2,sizeof(mob_skill_table));
else if(strcmpi(w1,"mob_skill2_table")==0)
safestrncpy(mob_skill2_table,w2,sizeof(mob_skill2_table));
else if( strcmpi( w1, "item_cash_table" ) == 0 )
safestrncpy( item_cash_table, w2, sizeof(item_cash_table) );
else if( strcmpi( w1, "item_cash2_table" ) == 0 )
safestrncpy( item_cash2_table, w2, sizeof(item_cash2_table) );
else if( strcmpi( w1, "vending_db" ) == 0 )
safestrncpy( vendings_table, w2, sizeof(vendings_table) );
else if( strcmpi( w1, "vending_items_table" ) == 0 )
safestrncpy(vending_items_table, w2, sizeof(vending_items_table));
else if( strcmpi(w1, "roulette_table") == 0)
safestrncpy(roulette_table, w2, sizeof(roulette_table));
else if (strcmpi(w1, "market_table") == 0)
safestrncpy(market_table, w2, sizeof(market_table));
else if (strcmpi(w1, "sales_table") == 0)
safestrncpy(sales_table, w2, sizeof(sales_table));
else if (strcmpi(w1, "guild_storage_log") == 0)
safestrncpy(guild_storage_log_table, w2, sizeof(guild_storage_log_table));
else
//Map Server SQL DB //Map Server SQL DB
if(strcmpi(w1,"map_server_ip")==0) else if(strcmpi(w1,"map_server_ip")==0)
safestrncpy(map_server_ip, w2, sizeof(map_server_ip)); map_config.map_server_ip = w2;
else else if(strcmpi(w1,"map_server_port")==0)
if(strcmpi(w1,"map_server_port")==0) map_config.map_server_port = atoi(w2);
map_server_port=atoi(w2); else if(strcmpi(w1,"map_server_id")==0)
else map_config.map_server_id = w2;
if(strcmpi(w1,"map_server_id")==0) else if(strcmpi(w1,"map_server_pw")==0)
safestrncpy(map_server_id, w2, sizeof(map_server_id)); map_config.map_server_pw = w2;
else else if(strcmpi(w1,"map_server_db")==0)
if(strcmpi(w1,"map_server_pw")==0) map_config.map_server_db = w2;
safestrncpy(map_server_pw, w2, sizeof(map_server_pw)); else if(strcmpi(w1,"default_codepage")==0)
else map_config.default_codepage = w2;
if(strcmpi(w1,"map_server_db")==0) else if(strcmpi(w1,"log_db_ip")==0)
safestrncpy(map_server_db, w2, sizeof(map_server_db)); map_config.log_db_ip = w2;
else else if(strcmpi(w1,"log_db_id")==0)
if(strcmpi(w1,"default_codepage")==0) map_config.log_db_id = w2;
safestrncpy(default_codepage, w2, sizeof(default_codepage)); else if(strcmpi(w1,"log_db_pw")==0)
else map_config.log_db_pw = w2;
if(strcmpi(w1,"use_sql_db")==0) { else if(strcmpi(w1,"log_db_port")==0)
db_use_sqldbs = config_switch(w2); map_config.log_db_port = atoi(w2);
ShowStatus ("Using SQL dbs: %s\n",w2); else if(strcmpi(w1,"log_db_db")==0)
} else map_config.log_db_db = w2;
if(strcmpi(w1,"log_db_ip")==0)
safestrncpy(log_db_ip, w2, sizeof(log_db_ip));
else
if(strcmpi(w1,"log_db_id")==0)
safestrncpy(log_db_id, w2, sizeof(log_db_id));
else
if(strcmpi(w1,"log_db_pw")==0)
safestrncpy(log_db_pw, w2, sizeof(log_db_pw));
else
if(strcmpi(w1,"log_db_port")==0)
log_db_port = atoi(w2);
else
if(strcmpi(w1,"log_db_db")==0)
safestrncpy(log_db_db, w2, sizeof(log_db_db));
else
if( mapreg_config_read(w1,w2) )
continue;
//support the import command, just like any other config //support the import command, just like any other config
else else if(strcmpi(w1,"import")==0)
if(strcmpi(w1,"import")==0) map_inter_config_read(w2);
inter_config_read(w2);
} }
fclose(fp); fclose(fp);
@@ -4278,11 +4475,11 @@ int map_sql_init(void)
qsmysql_handle = Sql_Malloc(); qsmysql_handle = Sql_Malloc();
ShowInfo("Connecting to the Map DB Server....\n"); 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) || 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) ) 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", 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_ShowDebug(mmysql_handle);
Sql_Free(mmysql_handle); Sql_Free(mmysql_handle);
Sql_ShowDebug(qsmysql_handle); Sql_ShowDebug(qsmysql_handle);
@@ -4291,12 +4488,19 @@ int map_sql_init(void)
} }
ShowStatus("Connect success! (Map Server Connection)\n"); ShowStatus("Connect success! (Map Server Connection)\n");
if( strlen(default_codepage) > 0 ) { if( map_server_codepage_len() > 0 ) {
if ( SQL_ERROR == Sql_SetEncoding(mmysql_handle, default_codepage) ) if ( SQL_ERROR == Sql_SetEncoding(mmysql_handle, map_server_codepage()) )
Sql_ShowDebug(mmysql_handle); 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); 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; return 0;
} }
@@ -4323,20 +4527,26 @@ int log_sql_init(void)
// log db connection // log db connection
logmysql_handle = Sql_Malloc(); 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); 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) ){ 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", 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_ShowDebug(logmysql_handle);
Sql_Free(logmysql_handle); Sql_Free(logmysql_handle);
exit(EXIT_FAILURE); 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( map_server_codepage_len() > 0 )
if ( SQL_ERROR == Sql_SetEncoding(logmysql_handle, default_codepage) ) if ( SQL_ERROR == Sql_SetEncoding(logmysql_handle, map_server_codepage()) )
Sql_ShowDebug(logmysql_handle); 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);
}
return 0; return 0;
} }
@@ -4943,7 +5153,7 @@ void do_final(void){
} }
mapindex_final(); mapindex_final();
if(enable_grf) if(map_config.enable_grf)
grfio_final(); grfio_final();
id_db->destroy(id_db, NULL); id_db->destroy(id_db, NULL);
@@ -4955,6 +5165,12 @@ void do_final(void){
iwall_db->destroy(iwall_db, NULL); iwall_db->destroy(iwall_db, NULL);
regen_db->destroy(regen_db, NULL); regen_db->destroy(regen_db, NULL);
ers_destroy(map_skill_damage_ers);
map_inter_config_final();
map_schema_final();
map_file_final();
log_config_final();
map_sql_close(); map_sql_close();
ShowStatus("Finished.\n"); ShowStatus("Finished.\n");
@@ -5158,10 +5374,15 @@ int do_init(int argc, char *argv[])
cli_get_options(argc,argv); cli_get_options(argc,argv);
rnd_init(); rnd_init();
map_inter_config_init();
map_schema_init();
map_file_init();
log_config_init();
map_config_read(MAP_CONF_NAME); map_config_read(MAP_CONF_NAME);
if (save_settings == CHARSAVE_NONE) if (map_config.save_settings == CHARSAVE_NONE)
ShowWarning("Value of 'save_settings' is not set, player's data only will be saved every 'autosave_time' (%d seconds).\n", autosave_interval/1000); ShowWarning("Value of 'save_settings' is not set, player's data only will be saved every 'autosave_time' (%d seconds).\n", map_config.autosave_interval/1000);
// loads npcs // loads npcs
map_reloadnpc(false); map_reloadnpc(false);
@@ -5192,8 +5413,10 @@ int do_init(int argc, char *argv[])
battle_config_read(BATTLE_CONF_FILENAME); battle_config_read(BATTLE_CONF_FILENAME);
script_config_read(SCRIPT_CONF_NAME); 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(LOG_CONF_NAME);
log_config_read_done();
id_db = idb_alloc(DB_OPT_BASE); id_db = idb_alloc(DB_OPT_BASE);
pc_db = idb_alloc(DB_OPT_BASE); //Added for reliable map_id2sd() use. [Skotlex] pc_db = idb_alloc(DB_OPT_BASE); //Added for reliable map_id2sd() use. [Skotlex]
@@ -5210,7 +5433,7 @@ int do_init(int argc, char *argv[])
log_sql_init(); log_sql_init();
mapindex_init(); mapindex_init();
if(enable_grf) if(map_config.enable_grf)
grfio_init(GRF_PATH_FILENAME); grfio_init(GRF_PATH_FILENAME);
map_readallmaps(); map_readallmaps();
@@ -5265,7 +5488,7 @@ int do_init(int argc, char *argv[])
runflag = MAPSERVER_ST_RUNNING; runflag = MAPSERVER_ST_RUNNING;
} }
if( console ){ //start listening if( map_config.console ){ //start listening
add_timer_func_list(parse_console_timer, "parse_console_timer"); 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 add_timer_interval(gettick()+1000, parse_console_timer, 0, 0, 1000); //start in 1s each 1sec
} }

View File

@@ -16,7 +16,6 @@
#include "../common/mmo.hpp" #include "../common/mmo.hpp"
#include "../common/msg_conf.hpp" #include "../common/msg_conf.hpp"
#include "../common/timer.hpp" #include "../common/timer.hpp"
#include "../config/core.hpp"
#include "script.hpp" #include "script.hpp"
@@ -57,6 +56,120 @@ void map_msg_reload(void);
#define MAX_VENDING 12 #define MAX_VENDING 12
#define MAX_MAP_SIZE 512*512 // Wasn't there something like this already? Can't find it.. [Shinryo] #define MAX_MAP_SIZE 512*512 // Wasn't there something like this already? Can't find it.. [Shinryo]
/// Type of 'save_settings'
enum e_save_settings_type : uint16 {
CHARSAVE_NONE = 0x000, /// Never
CHARSAVE_TRADE = 0x001, /// After trading
CHARSAVE_VENDING = 0x002, /// After vending (open/transaction)
CHARSAVE_STORAGE = 0x004, /// After closing storage/guild storage.
CHARSAVE_PET = 0x008, /// After hatching/returning to egg a pet.
CHARSAVE_MAIL = 0x010, /// After successfully sending a mail with attachment
CHARSAVE_AUCTION = 0x020, /// After successfully submitting an item for auction
CHARSAVE_QUEST = 0x040, /// After successfully get/delete/complete a quest
CHARSAVE_BANK = 0x080, /// After every bank transaction (deposit/withdraw)
CHARSAVE_ATTENDANCE = 0x100, /// After every attendence reward
CHARSAVE_ALL = 0xFFF, /// Always
};
struct MapServer_Schema {
bool db_use_sqldbs;
std::string buyingstores_table; ///< Buyingstore table (buyer & autotrader)
std::string buyingstore_items_table; ///< Buyingstore items table (buyer & autotrader)
std::string guild_storage_log_table; ///< Guild Storage Log table
std::string item_cash_db_table; ///< Item cash table
std::string item_cash_db2_table; ///< Item cash table
std::string item_db_table; ///< Item DB table
std::string item_db2_table; ///< Item DB table
std::string item_db_re_table; ///< Item DB table
std::string mapreg_table; ///< Mapreg table, used in mapreg.cpp
std::string market_table; ///< Market table
std::string mob_db_table; ///< Mob DB table
std::string mob_db_re_table; ///< Mob DB table
std::string mob_db2_table; ///< Mob DB table
std::string mob_skill_db_table; ///< Mob Skill table
std::string mob_skill_db_re_table; ///< Mob Skill table
std::string mob_skill_db2_table; ///< Mob Skill table
std::string roulette_table; ///< Roulette table
std::string sales_table; ///< Sales table
std::string vendings_table; ///< Vending table (vendor & autotrader)
std::string 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) ( mapserv_schema_config.table.c_str() )
struct MapServer_File {
std::string group; ///< Prefered file for groups.conf
std::string atcommand; ///< Prefered file for atcommand_athena.conf
std::string channel; ///< Prefered file for channels.conf
std::string motd; ///< Prefered file for MOTD
};
extern struct MapServer_File mapserv_file_config;
/// Get file name
#define mapserv_file(filename) ( mapserv_file_config.filename.c_str() )
struct Map_Config {
// Map-server
uint16 map_server_port;
std::string map_server_ip;
std::string map_server_id;
std::string map_server_pw;
std::string map_server_db;
std::string default_codepage;
// Log Database
uint16 log_db_port;
std::string log_db_ip;
std::string log_db_id;
std::string log_db_pw;
std::string log_db_db;
char wisp_server_name[NAME_LENGTH]; // can be modified in char-server configuration file
uint32 autosave_interval;
uint32 minsave_interval;
e_save_settings_type save_settings;
bool agit_flag;
bool agit2_flag;
bool agit3_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() ( map_config.map_server_ip.c_str() )
/// Getter of map_server_id Username
#define map_server_id() ( map_config.map_server_id.c_str() )
/// Getter of map_server_pw Password
#define map_server_pw() ( map_config.map_server_pw.c_str() )
/// Getter of map_server_db Database
#define map_server_db() ( map_config.map_server_db.c_str() )
/// Getter of map's default_codepage
#define map_server_codepage() ( map_config.default_codepage.c_str() )
/// Get map's default_codepage length
#define map_server_codepage_len() ( map_config.default_codepage.size() )
/// Getter of log_db_port
#define log_db_port() ( map_config.log_db_port )
/// Getter of log_db_ip Hostname
#define log_db_ip() ( map_config.log_db_ip.c_str() )
/// Getter of log_db_id Username
#define log_db_id() ( map_config.log_db_id.c_str() )
/// Getter of log_db_pw Password
#define log_db_pw() ( map_config.log_db_pw.c_str() )
/// Getter of log_db_db Database
#define log_db_db() ( map_config.log_db_db.c_str() )
//The following system marks a different job ID system used by the map server, //The following system marks a different job ID system used by the map server,
//which makes a lot more sense than the normal one. [Skotlex] //which makes a lot more sense than the normal one. [Skotlex]
// //
@@ -787,17 +900,8 @@ void map_setgatcell(int16 m, int16 x, int16 y, int gat);
extern struct map_data map[]; extern struct map_data map[];
extern int map_num; extern int map_num;
extern int autosave_interval;
extern int minsave_interval;
extern int16 save_settings;
extern int night_flag; // 0=day, 1=night [Yor]
extern int enable_spy; //Determines if @spy commands are active.
// Agit Flags // Agit Flags
extern bool agit_flag; #define is_agit_start() (map_config.agit_flag || map_config.agit2_flag || map_config.agit3_flag)
extern bool agit2_flag;
extern bool agit3_flag;
#define is_agit_start() (agit_flag || agit2_flag || agit3_flag)
/** /**
* Specifies maps where players may hit each other * Specifies maps where players may hit each other
@@ -808,7 +912,7 @@ inline bool mapdata_flag_vs(struct map_data *mapdata) {
if (mapdata == nullptr) if (mapdata == nullptr)
return false; return false;
if (mapdata->flag[MF_PVP] || mapdata->flag[MF_GVG_DUNGEON] || mapdata->flag[MF_GVG] || ((agit_flag || agit2_flag) && mapdata->flag[MF_GVG_CASTLE]) || mapdata->flag[MF_GVG_TE] || (agit3_flag && mapdata->flag[MF_GVG_TE_CASTLE]) || mapdata->flag[MF_BATTLEGROUND]) if (mapdata->flag[MF_PVP] || mapdata->flag[MF_GVG_DUNGEON] || mapdata->flag[MF_GVG] || ((map_config.agit_flag || map_config.agit2_flag) && mapdata->flag[MF_GVG_CASTLE]) || mapdata->flag[MF_GVG_TE] || (map_config.agit3_flag && mapdata->flag[MF_GVG_TE_CASTLE]) || mapdata->flag[MF_BATTLEGROUND])
return true; return true;
return false; return false;
@@ -838,7 +942,7 @@ inline bool mapdata_flag_gvg(struct map_data *mapdata) {
if (mapdata == nullptr) if (mapdata == nullptr)
return false; return false;
if (mapdata->flag[MF_GVG] || ((agit_flag || agit2_flag) && mapdata->flag[MF_GVG_CASTLE]) || mapdata->flag[MF_GVG_TE] || (agit3_flag && mapdata->flag[MF_GVG_TE_CASTLE])) if (mapdata->flag[MF_GVG] || ((map_config.agit_flag || map_config.agit2_flag) && mapdata->flag[MF_GVG_CASTLE]) || mapdata->flag[MF_GVG_TE] || (map_config.agit3_flag && mapdata->flag[MF_GVG_TE_CASTLE]))
return true; return true;
return false; return false;
@@ -970,12 +1074,6 @@ inline bool map_flag_gvg2_no_te(int16 m) {
return mapdata_flag_gvg2_no_te(mapdata); return mapdata_flag_gvg2_no_te(mapdata);
} }
extern char motd_txt[];
extern char charhelp_txt[];
extern char channel_conf[];
extern char wisp_server_name[];
struct s_map_default { struct s_map_default {
char mapname[MAP_NAME_LENGTH]; char mapname[MAP_NAME_LENGTH];
unsigned short x; unsigned short x;
@@ -983,21 +1081,6 @@ struct s_map_default {
}; };
extern struct s_map_default map_default; extern struct s_map_default map_default;
/// Type of 'save_settings'
enum save_settings_type {
CHARSAVE_NONE = 0x000, /// Never
CHARSAVE_TRADE = 0x001, /// After trading
CHARSAVE_VENDING = 0x002, /// After vending (open/transaction)
CHARSAVE_STORAGE = 0x004, /// After closing storage/guild storage.
CHARSAVE_PET = 0x008, /// After hatching/returning to egg a pet.
CHARSAVE_MAIL = 0x010, /// After successfully sending a mail with attachment
CHARSAVE_AUCTION = 0x020, /// After successfully submitting an item for auction
CHARSAVE_QUEST = 0x040, /// After successfully get/delete/complete a quest
CHARSAVE_BANK = 0x080, /// After every bank transaction (deposit/withdraw)
CHARSAVE_ATTENDANCE = 0x100, /// After every attendence reward
CHARSAVE_ALL = 0xFFF, /// Always
};
// users // users
void map_setusers(int); void map_setusers(int);
int map_getusers(void); int map_getusers(void);
@@ -1175,26 +1258,10 @@ typedef struct elemental_data TBL_ELEM;
#include "../common/sql.hpp" #include "../common/sql.hpp"
extern int db_use_sqldbs;
extern Sql* mmysql_handle; extern Sql* mmysql_handle;
extern Sql* qsmysql_handle; extern Sql* qsmysql_handle;
extern Sql* logmysql_handle; extern Sql* logmysql_handle;
extern char buyingstores_table[32];
extern char buyingstore_items_table[32];
extern char item_table[32];
extern char item2_table[32];
extern char mob_table[32];
extern char mob2_table[32];
extern char mob_skill_table[32];
extern char mob_skill2_table[32];
extern char vendings_table[32];
extern char vending_items_table[32];
extern char market_table[32];
extern char roulette_table[32];
extern char guild_storage_log_table[32];
void do_shutdown(void); void do_shutdown(void);
#endif /* MAP_HPP */ #endif /* MAP_HPP */

View File

@@ -20,9 +20,7 @@
static struct eri *mapreg_ers; static struct eri *mapreg_ers;
bool skip_insert = false; bool skip_insert = false;
static bool mapreg_dirty = false;
static char mapreg_table[32] = "mapreg";
static bool mapreg_dirty = false; // Whether there are modified regs to be saved
struct reg_db regs; struct reg_db regs;
#define MAPREG_AUTOSAVE_INTERVAL (300*1000) #define MAPREG_AUTOSAVE_INTERVAL (300*1000)
@@ -87,7 +85,7 @@ bool mapreg_setreg(int64 uid, int64 val)
if (name[1] != '@' && !skip_insert) {// write new variable to database if (name[1] != '@' && !skip_insert) {// write new variable to database
char esc_name[32 * 2 + 1]; char esc_name[32 * 2 + 1];
Sql_EscapeStringLen(mmysql_handle, esc_name, name, strnlen(name, 32)); Sql_EscapeStringLen(mmysql_handle, esc_name, name, strnlen(name, 32));
if (SQL_ERROR == Sql_Query(mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%" PRIu32 "','%" PRId64 "')", mapreg_table, esc_name, i, val)) if (SQL_ERROR == Sql_Query(mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%" PRIu32 "','%" PRId64 "')", mapserv_table(mapreg_table), esc_name, i, val))
Sql_ShowDebug(mmysql_handle); Sql_ShowDebug(mmysql_handle);
} }
i64db_put(regs.vars, uid, m); i64db_put(regs.vars, uid, m);
@@ -103,7 +101,7 @@ bool mapreg_setreg(int64 uid, int64 val)
if (name[1] != '@') {// Remove from database because it is unused. if (name[1] != '@') {// Remove from database because it is unused.
char esc_name[32 * 2 + 1]; char esc_name[32 * 2 + 1];
Sql_EscapeStringLen(mmysql_handle, esc_name, name, strnlen(name, 32)); Sql_EscapeStringLen(mmysql_handle, esc_name, name, strnlen(name, 32));
if (SQL_ERROR == Sql_Query(mmysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%" PRIu32 "'", mapreg_table, esc_name, i)) if (SQL_ERROR == Sql_Query(mmysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%" PRIu32 "'", mapserv_table(mapreg_table), esc_name, i))
Sql_ShowDebug(mmysql_handle); Sql_ShowDebug(mmysql_handle);
} }
} }
@@ -131,7 +129,7 @@ bool mapreg_setregstr(int64 uid, const char* str)
if (name[1] != '@') { if (name[1] != '@') {
char esc_name[32 * 2 + 1]; char esc_name[32 * 2 + 1];
Sql_EscapeStringLen(mmysql_handle, esc_name, name, strnlen(name, 32)); Sql_EscapeStringLen(mmysql_handle, esc_name, name, strnlen(name, 32));
if (SQL_ERROR == Sql_Query(mmysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%" PRIu32 "'", mapreg_table, esc_name, i)) if (SQL_ERROR == Sql_Query(mmysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%" PRIu32 "'", mapserv_table(mapreg_table), esc_name, i))
Sql_ShowDebug(mmysql_handle); Sql_ShowDebug(mmysql_handle);
} }
if ((m = static_cast<mapreg_save *>(i64db_get(regs.vars, uid)))) { if ((m = static_cast<mapreg_save *>(i64db_get(regs.vars, uid)))) {
@@ -165,7 +163,7 @@ bool mapreg_setregstr(int64 uid, const char* str)
char esc_str[255 * 2 + 1]; char esc_str[255 * 2 + 1];
Sql_EscapeStringLen(mmysql_handle, esc_name, name, strnlen(name, 32)); Sql_EscapeStringLen(mmysql_handle, esc_name, name, strnlen(name, 32));
Sql_EscapeStringLen(mmysql_handle, esc_str, str, strnlen(str, 255)); Sql_EscapeStringLen(mmysql_handle, esc_str, str, strnlen(str, 255));
if (SQL_ERROR == Sql_Query(mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%" PRIu32 "','%s')", mapreg_table, esc_name, i, esc_str)) if (SQL_ERROR == Sql_Query(mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%" PRIu32 "','%s')", mapserv_table(mapreg_table), esc_name, i, esc_str))
Sql_ShowDebug(mmysql_handle); Sql_ShowDebug(mmysql_handle);
} }
i64db_put(regs.vars, uid, m); i64db_put(regs.vars, uid, m);
@@ -192,7 +190,7 @@ static void script_load_mapreg(void)
char value[255+1]; char value[255+1];
uint32 length; uint32 length;
if ( SQL_ERROR == SqlStmt_Prepare(stmt, "SELECT `varname`, `index`, `value` FROM `%s`", mapreg_table) if ( SQL_ERROR == SqlStmt_Prepare(stmt, "SELECT `varname`, `index`, `value` FROM `%s`", mapserv_table(mapreg_table))
|| SQL_ERROR == SqlStmt_Execute(stmt) || SQL_ERROR == SqlStmt_Execute(stmt)
) { ) {
SqlStmt_ShowDebug(stmt); SqlStmt_ShowDebug(stmt);
@@ -243,14 +241,14 @@ static void script_save_mapreg(void)
if (!m->is_string) { if (!m->is_string) {
char esc_name[32 * 2 + 1]; char esc_name[32 * 2 + 1];
Sql_EscapeStringLen(mmysql_handle, esc_name, name, strnlen(name, 32)); Sql_EscapeStringLen(mmysql_handle, esc_name, name, strnlen(name, 32));
if (SQL_ERROR == Sql_Query(mmysql_handle, "UPDATE `%s` SET `value`='%" PRId64 "' WHERE `varname`='%s' AND `index`='%" PRIu32 "' LIMIT 1", mapreg_table, m->u.i, esc_name, i)) if (SQL_ERROR == Sql_Query(mmysql_handle, "UPDATE `%s` SET `value`='%" PRId64 "' WHERE `varname`='%s' AND `index`='%" PRIu32 "' LIMIT 1", mapserv_table(mapreg_table), m->u.i, esc_name, i))
Sql_ShowDebug(mmysql_handle); Sql_ShowDebug(mmysql_handle);
} else { } else {
char esc_str[2 * 255 + 1]; char esc_str[2 * 255 + 1];
char esc_name[32 * 2 + 1]; char esc_name[32 * 2 + 1];
Sql_EscapeStringLen(mmysql_handle, esc_name, name, strnlen(name, 32)); Sql_EscapeStringLen(mmysql_handle, esc_name, name, strnlen(name, 32));
Sql_EscapeStringLen(mmysql_handle, esc_str, m->u.str, safestrnlen(m->u.str, 255)); Sql_EscapeStringLen(mmysql_handle, esc_str, m->u.str, safestrnlen(m->u.str, 255));
if (SQL_ERROR == Sql_Query(mmysql_handle, "UPDATE `%s` SET `value`='%s' WHERE `varname`='%s' AND `index`='%" PRIu32 "' LIMIT 1", mapreg_table, esc_str, esc_name, i)) if (SQL_ERROR == Sql_Query(mmysql_handle, "UPDATE `%s` SET `value`='%s' WHERE `varname`='%s' AND `index`='%" PRIu32 "' LIMIT 1", mapserv_table(mapreg_table), esc_str, esc_name, i))
Sql_ShowDebug(mmysql_handle); Sql_ShowDebug(mmysql_handle);
} }
m->save = false; m->save = false;
@@ -343,16 +341,3 @@ void mapreg_init(void)
add_timer_func_list(script_autosave_mapreg, "script_autosave_mapreg"); add_timer_func_list(script_autosave_mapreg, "script_autosave_mapreg");
add_timer_interval(gettick() + MAPREG_AUTOSAVE_INTERVAL, script_autosave_mapreg, 0, 0, MAPREG_AUTOSAVE_INTERVAL); add_timer_interval(gettick() + MAPREG_AUTOSAVE_INTERVAL, script_autosave_mapreg, 0, 0, MAPREG_AUTOSAVE_INTERVAL);
} }
/**
* Loads the mapreg configuration file.
*/
bool mapreg_config_read(const char* w1, const char* w2)
{
if(!strcmpi(w1, "mapreg_table"))
safestrncpy(mapreg_table, w2, sizeof(mapreg_table));
else
return false;
return true;
}

View File

@@ -23,7 +23,6 @@ extern bool skip_insert;
void mapreg_reload(void); void mapreg_reload(void);
void mapreg_final(void); void mapreg_final(void);
void mapreg_init(void); void mapreg_init(void);
bool mapreg_config_read(const char* w1, const char* w2);
int64 mapreg_readreg(int64 uid); int64 mapreg_readreg(int64 uid);
char* mapreg_readregstr(int64 uid); char* mapreg_readregstr(int64 uid);

View File

@@ -4335,8 +4335,13 @@ static bool mob_readdb_sub(char* fields[], int columns, int current)
static int mob_read_sqldb(void) static int mob_read_sqldb(void)
{ {
const char* mob_db_name[] = { const char* mob_db_name[] = {
mob_table, #ifndef RENEWAL
mob2_table }; mapserv_table(mob_db_table),
#else
mapserv_table(mob_db_re_table),
#endif
mapserv_table(mob_db2_table)
};
int fi; int fi;
for( fi = 0; fi < ARRAYLENGTH(mob_db_name); ++fi ) { for( fi = 0; fi < ARRAYLENGTH(mob_db_name); ++fi ) {
@@ -5063,8 +5068,13 @@ static void mob_readskilldb(const char* basedir, bool silent) {
static int mob_read_sqlskilldb(void) static int mob_read_sqlskilldb(void)
{ {
const char* mob_skill_db_name[] = { const char* mob_skill_db_name[] = {
mob_skill_table, #ifndef RENEWAL
mob_skill2_table }; mapserv_table(mob_skill_db_table),
#else
mapserv_table(mob_skill_db_re_table),
#endif
mapserv_table(mob_skill_db2_table)
};
int fi; int fi;
if( battle_config.mob_skill_rate == 0 ) { if( battle_config.mob_skill_rate == 0 ) {
@@ -5539,7 +5549,7 @@ static void mob_load(void)
}; };
// First we parse all the possible monsters to add additional data in the second loop // First we parse all the possible monsters to add additional data in the second loop
if( db_use_sqldbs ) if( mapserv_schema_config.db_use_sqldbs )
mob_read_sqldb(); mob_read_sqldb();
else { else {
for(int i = 0; i < ARRAYLENGTH(dbsubpath); i++){ for(int i = 0; i < ARRAYLENGTH(dbsubpath); i++){
@@ -5577,9 +5587,7 @@ static void mob_load(void)
sv_readdb(dbsubpath1, "mob_chat_db.txt", '#', 3, 3, -1, &mob_parse_row_chatdb, silent); sv_readdb(dbsubpath1, "mob_chat_db.txt", '#', 3, 3, -1, &mob_parse_row_chatdb, silent);
if( db_use_sqldbs && i == 0 ) if( mapserv_schema_config.db_use_sqldbs && i == 0 )
mob_read_sqlskilldb();
else
mob_readskilldb(dbsubpath2, silent); mob_readskilldb(dbsubpath2, silent);
sv_readdb(dbsubpath2, "mob_race2_db.txt", ',', 2, MAX_RACE2_MOBS, -1, &mob_readdb_race2, silent); sv_readdb(dbsubpath2, "mob_race2_db.txt", ',', 2, MAX_RACE2_MOBS, -1, &mob_readdb_race2, silent);

View File

@@ -3628,7 +3628,7 @@ int npc_instancedestroy(struct npc_data* nd)
void npc_market_tosql(const char *exname, struct npc_item_list *list) { void npc_market_tosql(const char *exname, struct npc_item_list *list) {
SqlStmt* stmt = SqlStmt_Malloc(mmysql_handle); SqlStmt* stmt = SqlStmt_Malloc(mmysql_handle);
if (SQL_ERROR == SqlStmt_Prepare(stmt, "REPLACE INTO `%s` (`name`,`nameid`,`price`,`amount`,`flag`) VALUES ('%s','%u','%d','%hu','%" PRIu8 "')", if (SQL_ERROR == SqlStmt_Prepare(stmt, "REPLACE INTO `%s` (`name`,`nameid`,`price`,`amount`,`flag`) VALUES ('%s','%u','%d','%hu','%" PRIu8 "')",
market_table, exname, list->nameid, list->value, list->qty, list->flag) || mapserv_table(market_table), exname, list->nameid, list->value, list->qty, list->flag) ||
SQL_ERROR == SqlStmt_Execute(stmt)) SQL_ERROR == SqlStmt_Execute(stmt))
SqlStmt_ShowDebug(stmt); SqlStmt_ShowDebug(stmt);
SqlStmt_Free(stmt); SqlStmt_Free(stmt);
@@ -3643,11 +3643,11 @@ void npc_market_tosql(const char *exname, struct npc_item_list *list) {
void npc_market_delfromsql_(const char *exname, t_itemid nameid, bool clear) { void npc_market_delfromsql_(const char *exname, t_itemid nameid, bool clear) {
SqlStmt* stmt = SqlStmt_Malloc(mmysql_handle); SqlStmt* stmt = SqlStmt_Malloc(mmysql_handle);
if (clear) { if (clear) {
if( SQL_ERROR == SqlStmt_Prepare(stmt, "DELETE FROM `%s` WHERE `name`='%s'", market_table, exname) || if( SQL_ERROR == SqlStmt_Prepare(stmt, "DELETE FROM `%s` WHERE `name`='%s'", mapserv_table(market_table), exname) ||
SQL_ERROR == SqlStmt_Execute(stmt)) SQL_ERROR == SqlStmt_Execute(stmt))
SqlStmt_ShowDebug(stmt); SqlStmt_ShowDebug(stmt);
} else { } else {
if (SQL_ERROR == SqlStmt_Prepare(stmt, "DELETE FROM `%s` WHERE `name`='%s' AND `nameid`='%u' LIMIT 1", market_table, exname, nameid) || if (SQL_ERROR == SqlStmt_Prepare(stmt, "DELETE FROM `%s` WHERE `name`='%s' AND `nameid`='%u' LIMIT 1", mapserv_table(market_table), exname, nameid) ||
SQL_ERROR == SqlStmt_Execute(stmt)) SQL_ERROR == SqlStmt_Execute(stmt))
SqlStmt_ShowDebug(stmt); SqlStmt_ShowDebug(stmt);
} }
@@ -3754,7 +3754,7 @@ static void npc_market_checkall(void) {
static void npc_market_fromsql(void) { static void npc_market_fromsql(void) {
uint32 count = 0; uint32 count = 0;
if (SQL_ERROR == Sql_Query(mmysql_handle, "SELECT `name`,`nameid`,`price`,`amount`,`flag` FROM `%s` ORDER BY `name`", market_table)) { if (SQL_ERROR == Sql_Query(mmysql_handle, "SELECT `name`,`nameid`,`price`,`amount`,`flag` FROM `%s` ORDER BY `name`", mapserv_table(market_table))) {
Sql_ShowDebug(mmysql_handle); Sql_ShowDebug(mmysql_handle);
return; return;
} }
@@ -3784,7 +3784,7 @@ static void npc_market_fromsql(void) {
} }
Sql_FreeResult(mmysql_handle); Sql_FreeResult(mmysql_handle);
ShowStatus("Done loading '" CL_WHITE "%d" CL_RESET "' entries for '" CL_WHITE "%d" CL_RESET "' NPC Markets from '" CL_WHITE "%s" CL_RESET "' table.\n", count, db_size(NPCMarketDB), market_table); ShowStatus("Done loading '" CL_WHITE "%d" CL_RESET "' entries for '" CL_WHITE "%d" CL_RESET "' NPC Markets from '" CL_WHITE "%s" CL_RESET "' table.\n", count, db_size(NPCMarketDB), mapserv_table(market_table));
} }
#endif #endif

View File

@@ -11405,9 +11405,9 @@ static TIMER_FUNC(pc_autosave){
} }
mapit_free(iter); mapit_free(iter);
interval = autosave_interval/(map_usercount()+1); interval = map_config.autosave_interval/(map_usercount()+1);
if(interval < minsave_interval) if(interval < map_config.minsave_interval)
interval = minsave_interval; interval = map_config.minsave_interval;
add_timer(gettick()+interval,pc_autosave,0,0); add_timer(gettick()+interval,pc_autosave,0,0);
return 0; return 0;
@@ -11415,10 +11415,10 @@ static TIMER_FUNC(pc_autosave){
static int pc_daynight_timer_sub(struct map_session_data *sd,va_list ap) static int pc_daynight_timer_sub(struct map_session_data *sd,va_list ap)
{ {
if (sd->state.night != night_flag && map_getmapflag(sd->bl.m, MF_NIGHTENABLED)) if (sd->state.night != map_config.night_flag && map_getmapflag(sd->bl.m, MF_NIGHTENABLED))
{ //Night/day state does not match. { //Night/day state does not match.
clif_status_load(&sd->bl, EFST_SKE, night_flag); //New night effect by dynamix [Skotlex] clif_status_load(&sd->bl, EFST_SKE, map_config.night_flag); //New night effect by dynamix [Skotlex]
sd->state.night = night_flag; sd->state.night = map_config.night_flag;
return 1; return 1;
} }
return 0; return 0;
@@ -11433,10 +11433,10 @@ TIMER_FUNC(map_day_timer){
if (data == 0 && battle_config.day_duration <= 0) // if we want a day if (data == 0 && battle_config.day_duration <= 0) // if we want a day
return 0; return 0;
if (!night_flag) if (!map_config.night_flag)
return 0; //Already day. 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); map_foreachpc(pc_daynight_timer_sub);
strcpy(tmp_soutput, (data == 0) ? msg_txt(NULL,502) : msg_txt(NULL,60)); // The day has arrived! 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); intif_broadcast(tmp_soutput, strlen(tmp_soutput) + 1, BC_DEFAULT);
@@ -11453,10 +11453,10 @@ TIMER_FUNC(map_night_timer){
if (data == 0 && battle_config.night_duration <= 0) // if we want a night if (data == 0 && battle_config.night_duration <= 0) // if we want a night
return 0; return 0;
if (night_flag) if (map_config.night_flag)
return 0; //Already nigth. 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); map_foreachpc(pc_daynight_timer_sub);
strcpy(tmp_soutput, (data == 0) ? msg_txt(NULL,503) : msg_txt(NULL,59)); // The night has fallen... 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); intif_broadcast(tmp_soutput, strlen(tmp_soutput) + 1, BC_DEFAULT);
@@ -12369,11 +12369,12 @@ void pc_readdb(void) {
int pc_read_motd(void) int pc_read_motd(void)
{ {
FILE* fp; FILE* fp;
const char *motd_file = mapserv_file(motd);
// clear old MOTD // clear old MOTD
memset(motd_text, 0, sizeof(motd_text)); memset(motd_text, 0, sizeof(motd_text));
// read current MOTD // read current MOTD
if( ( fp = fopen(motd_txt, "r") ) != NULL ) if( ( fp = fopen(motd_file, "r") ) != NULL )
{ {
unsigned int entries = 0; unsigned int entries = 0;
char buf[CHAT_SIZE_MAX]; char buf[CHAT_SIZE_MAX];
@@ -12392,7 +12393,7 @@ int pc_read_motd(void)
char * ptr; char * ptr;
buf[len] = 0; buf[len] = 0;
if( ( ptr = strstr(buf, " :") ) != NULL && ptr-buf >= NAME_LENGTH ) // crashes newer clients 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 else {// empty line
buf[0] = ' '; buf[0] = ' ';
@@ -12402,10 +12403,10 @@ int pc_read_motd(void)
entries++; entries++;
} }
fclose(fp); 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 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; return 0;
} }
@@ -12637,7 +12638,7 @@ void pc_check_expiration(struct map_session_data *sd) {
char tmpstr[1024]; 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." 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,wisp_server_name,tmpstr,strlen(tmpstr) + 1,0); clif_wis_message(sd,map_config.wisp_server_name,tmpstr,strlen(tmpstr) + 1,0);
pc_expire_check(sd); pc_expire_check(sd);
} }
@@ -12733,7 +12734,7 @@ enum e_BANKING_DEPOSIT_ACK pc_bank_deposit(struct map_session_data *sd, int mone
sd->bank_vault += money; sd->bank_vault += money;
pc_setreg2(sd, BANK_VAULT_VAR, sd->bank_vault); pc_setreg2(sd, BANK_VAULT_VAR, sd->bank_vault);
if( save_settings&CHARSAVE_BANK ) if( map_config.save_settings&CHARSAVE_BANK )
chrif_save(sd, CSAVE_NORMAL); chrif_save(sd, CSAVE_NORMAL);
return BDA_SUCCESS; return BDA_SUCCESS;
} }
@@ -12761,7 +12762,7 @@ enum e_BANKING_WITHDRAW_ACK pc_bank_withdraw(struct map_session_data *sd, int mo
sd->bank_vault -= money; sd->bank_vault -= money;
pc_setreg2(sd, BANK_VAULT_VAR, sd->bank_vault); pc_setreg2(sd, BANK_VAULT_VAR, sd->bank_vault);
if( save_settings&CHARSAVE_BANK ) if( map_config.save_settings&CHARSAVE_BANK )
chrif_save(sd, CSAVE_NORMAL); chrif_save(sd, CSAVE_NORMAL);
return BWA_SUCCESS; return BWA_SUCCESS;
} }
@@ -13506,7 +13507,7 @@ void pc_attendance_claim_reward( struct map_session_data* sd ){
pc_setreg2( sd, ATTENDANCE_DATE_VAR, date_get(DT_YYYYMMDD) ); pc_setreg2( sd, ATTENDANCE_DATE_VAR, date_get(DT_YYYYMMDD) );
pc_setreg2( sd, ATTENDANCE_COUNT_VAR, attendance_counter ); pc_setreg2( sd, ATTENDANCE_COUNT_VAR, attendance_counter );
if( save_settings&CHARSAVE_ATTENDANCE ) if( map_config.save_settings&CHARSAVE_ATTENDANCE )
chrif_save(sd, CSAVE_NORMAL); chrif_save(sd, CSAVE_NORMAL);
std::shared_ptr<s_attendance_reward> reward = period->rewards[attendance_counter - 1]; std::shared_ptr<s_attendance_reward> reward = period->rewards[attendance_counter - 1];
@@ -13569,10 +13570,10 @@ void do_init_pc(void) {
add_timer_func_list(pc_autotrade_timer, "pc_autotrade_timer"); add_timer_func_list(pc_autotrade_timer, "pc_autotrade_timer");
add_timer_func_list(pc_on_expire_active, "pc_on_expire_active"); add_timer_func_list(pc_on_expire_active, "pc_on_expire_active");
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] // 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) { if (battle_config.day_duration > 0 && battle_config.night_duration > 0) {
int day_duration = battle_config.day_duration; int day_duration = battle_config.day_duration;
@@ -13581,8 +13582,8 @@ void do_init_pc(void) {
add_timer_func_list(map_day_timer, "map_day_timer"); add_timer_func_list(map_day_timer, "map_day_timer");
add_timer_func_list(map_night_timer, "map_night_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); 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 + (night_flag ? night_duration : 0), map_night_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(); do_init_pc_groups();

View File

@@ -62,9 +62,9 @@ static inline GroupSettings* name2group(const char* group_name)
static void read_config(void) static void read_config(void)
{ {
config_setting_t *groups = NULL; config_setting_t *groups = NULL;
const char *config_filename = "conf/groups.conf"; // FIXME hardcoded name const char *config_filename = mapserv_file(group);
int group_count = 0; int group_count = 0;
if (conf_read_file(&pc_group_config, config_filename)) if (conf_read_file(&pc_group_config, config_filename))
return; return;

View File

@@ -1100,7 +1100,7 @@ int pet_birth_process(struct map_session_data *sd, struct s_pet *pet)
intif_save_petdata(sd->status.account_id,pet); intif_save_petdata(sd->status.account_id,pet);
if (save_settings&CHARSAVE_PET) if (map_config.save_settings&CHARSAVE_PET)
chrif_save(sd, CSAVE_INVENTORY); //is it REALLY Needed to save the char for hatching a pet? [Skotlex] chrif_save(sd, CSAVE_INVENTORY); //is it REALLY Needed to save the char for hatching a pet? [Skotlex]
if(sd->bl.prev != NULL) { if(sd->bl.prev != NULL) {
@@ -2278,7 +2278,7 @@ void pet_evolution(struct map_session_data *sd, int16 pet_id) {
// Save the pet and inventory data // Save the pet and inventory data
intif_save_petdata(sd->status.account_id, &sd->pd->pet); intif_save_petdata(sd->status.account_id, &sd->pd->pet);
if (save_settings&CHARSAVE_PET) if (map_config.save_settings&CHARSAVE_PET)
chrif_save(sd, CSAVE_INVENTORY); chrif_save(sd, CSAVE_INVENTORY);
// Spawn it // Spawn it

View File

@@ -538,7 +538,7 @@ int quest_add(struct map_session_data *sd, int quest_id)
clif_quest_add(sd, &sd->quest_log[n]); clif_quest_add(sd, &sd->quest_log[n]);
clif_quest_update_objective(sd, &sd->quest_log[n]); clif_quest_update_objective(sd, &sd->quest_log[n]);
if( save_settings&CHARSAVE_QUEST ) if( map_config.save_settings&CHARSAVE_QUEST )
chrif_save(sd, CSAVE_NORMAL); chrif_save(sd, CSAVE_NORMAL);
return 0; return 0;
@@ -588,7 +588,7 @@ int quest_change(struct map_session_data *sd, int qid1, int qid2)
clif_quest_add(sd, &sd->quest_log[i]); clif_quest_add(sd, &sd->quest_log[i]);
clif_quest_update_objective(sd, &sd->quest_log[i]); clif_quest_update_objective(sd, &sd->quest_log[i]);
if( save_settings&CHARSAVE_QUEST ) if( map_config.save_settings&CHARSAVE_QUEST )
chrif_save(sd, CSAVE_NORMAL); chrif_save(sd, CSAVE_NORMAL);
return 0; return 0;
@@ -627,7 +627,7 @@ int quest_delete(struct map_session_data *sd, int quest_id)
clif_quest_delete(sd, quest_id); clif_quest_delete(sd, quest_id);
if( save_settings&CHARSAVE_QUEST ) if( map_config.save_settings&CHARSAVE_QUEST )
chrif_save(sd, CSAVE_NORMAL); chrif_save(sd, CSAVE_NORMAL);
return 0; return 0;
@@ -786,7 +786,7 @@ int quest_update_status(struct map_session_data *sd, int quest_id, e_quest_state
clif_quest_delete(sd, quest_id); clif_quest_delete(sd, quest_id);
if (save_settings&CHARSAVE_QUEST) if( map_config.save_settings&CHARSAVE_QUEST )
chrif_save(sd, CSAVE_NORMAL); chrif_save(sd, CSAVE_NORMAL);
return 0; return 0;

View File

@@ -13124,7 +13124,7 @@ BUILDIN_FUNC(agitend3)
*/ */
BUILDIN_FUNC(agitcheck) BUILDIN_FUNC(agitcheck)
{ {
script_pushint(st, agit_flag); script_pushint(st, map_config.agit_flag);
return SCRIPT_CMD_SUCCESS; return SCRIPT_CMD_SUCCESS;
} }
@@ -13134,7 +13134,7 @@ BUILDIN_FUNC(agitcheck)
*/ */
BUILDIN_FUNC(agitcheck2) BUILDIN_FUNC(agitcheck2)
{ {
script_pushint(st, agit2_flag); script_pushint(st, map_config.agit2_flag);
return SCRIPT_CMD_SUCCESS; return SCRIPT_CMD_SUCCESS;
} }
@@ -13144,7 +13144,7 @@ BUILDIN_FUNC(agitcheck2)
*/ */
BUILDIN_FUNC(agitcheck3) BUILDIN_FUNC(agitcheck3)
{ {
script_pushint(st, agit3_flag); script_pushint(st, map_config.agit3_flag);
return SCRIPT_CMD_SUCCESS; return SCRIPT_CMD_SUCCESS;
} }
@@ -14815,6 +14815,7 @@ BUILDIN_FUNC(dispbottom)
else else
clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], message, false, SELF); clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], message, false, SELF);
} }
return SCRIPT_CMD_SUCCESS; return SCRIPT_CMD_SUCCESS;
} }
@@ -15584,21 +15585,6 @@ BUILDIN_FUNC(summon)
return SCRIPT_CMD_SUCCESS; return SCRIPT_CMD_SUCCESS;
} }
/*==========================================
* Checks whether it is daytime/nighttime
*------------------------------------------*/
BUILDIN_FUNC(isnight)
{
script_pushint(st,(night_flag == 1));
return SCRIPT_CMD_SUCCESS;
}
BUILDIN_FUNC(isday)
{
script_pushint(st,(night_flag == 0));
return SCRIPT_CMD_SUCCESS;
}
/*================================================ /*================================================
* Check how many items/cards in the list are * Check how many items/cards in the list are
* equipped - used for 2/15's cards patch [celest] * equipped - used for 2/15's cards patch [celest]
@@ -15800,17 +15786,32 @@ BUILDIN_FUNC(getrefine)
return SCRIPT_CMD_SUCCESS; return SCRIPT_CMD_SUCCESS;
} }
/*==========================================
* Checks whether it is daytime/nighttime
*------------------------------------------*/
BUILDIN_FUNC(isnight)
{
script_pushint(st, (map_config.night_flag ? 1 : 0));
return SCRIPT_CMD_SUCCESS;
}
BUILDIN_FUNC(isday)
{
script_pushint(st, (map_config.night_flag ? 1 : 0));
return SCRIPT_CMD_SUCCESS;
}
/*======================================================= /*=======================================================
* Day/Night controls * Day/Night controls
*-------------------------------------------------------*/ *-------------------------------------------------------*/
BUILDIN_FUNC(night) 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; return SCRIPT_CMD_SUCCESS;
} }
BUILDIN_FUNC(day) 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; return SCRIPT_CMD_SUCCESS;
} }

View File

@@ -506,7 +506,7 @@ void storage_storageclose(struct map_session_data *sd)
nullpo_retv(sd); nullpo_retv(sd);
if (sd->storage.dirty) { if (sd->storage.dirty) {
if (save_settings&CHARSAVE_STORAGE) if (map_config.save_settings&CHARSAVE_STORAGE)
chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART); chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART);
else else
storage_storagesave(sd); storage_storagesave(sd);
@@ -530,7 +530,7 @@ void storage_storage_quit(struct map_session_data* sd, int flag)
{ {
nullpo_retv(sd); nullpo_retv(sd);
if (save_settings&CHARSAVE_STORAGE) if (map_config.save_settings&CHARSAVE_STORAGE)
chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART); chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART);
else else
storage_storagesave(sd); storage_storagesave(sd);
@@ -645,7 +645,7 @@ void storage_guild_log( struct map_session_data* sd, struct item* item, int16 am
StringBuf buf; StringBuf buf;
StringBuf_Init(&buf); StringBuf_Init(&buf);
StringBuf_Printf(&buf, "INSERT INTO `%s` (`time`, `guild_id`, `char_id`, `name`, `nameid`, `amount`, `identify`, `refine`, `attribute`, `unique_id`, `bound`", guild_storage_log_table); StringBuf_Printf(&buf, "INSERT INTO `%s` (`time`, `guild_id`, `char_id`, `name`, `nameid`, `amount`, `identify`, `refine`, `attribute`, `unique_id`, `bound`", mapserv_table(guild_storage_log_table));
for (i = 0; i < MAX_SLOTS; ++i) for (i = 0; i < MAX_SLOTS; ++i)
StringBuf_Printf(&buf, ", `card%d`", i); StringBuf_Printf(&buf, ", `card%d`", i);
for (i = 0; i < MAX_ITEM_RDM_OPT; ++i) { for (i = 0; i < MAX_ITEM_RDM_OPT; ++i) {
@@ -684,7 +684,7 @@ enum e_guild_storage_log storage_guild_log_read_sub( struct map_session_data* sd
StringBuf_Printf(&buf, ", `option_val%d`", j); StringBuf_Printf(&buf, ", `option_val%d`", j);
StringBuf_Printf(&buf, ", `option_parm%d`", j); StringBuf_Printf(&buf, ", `option_parm%d`", j);
} }
StringBuf_Printf(&buf, " FROM `%s` WHERE `guild_id`='%u'", guild_storage_log_table, sd->status.guild_id ); StringBuf_Printf(&buf, " FROM `%s` WHERE `guild_id`='%u'", mapserv_table(guild_storage_log_table), sd->status.guild_id );
StringBuf_Printf(&buf, " ORDER BY `time` DESC LIMIT %u", max); StringBuf_Printf(&buf, " ORDER BY `time` DESC LIMIT %u", max);
SqlStmt* stmt = SqlStmt_Malloc(mmysql_handle); SqlStmt* stmt = SqlStmt_Malloc(mmysql_handle);
@@ -1095,7 +1095,7 @@ void storage_guild_storageclose(struct map_session_data* sd)
clif_storageclose(sd); clif_storageclose(sd);
if (stor->status) { if (stor->status) {
if (save_settings&CHARSAVE_STORAGE) if (map_config.save_settings&CHARSAVE_STORAGE)
chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART); //This one also saves the storage. [Skotlex] chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART); //This one also saves the storage. [Skotlex]
else else
storage_guild_storagesave(sd->status.account_id, sd->status.guild_id,0); storage_guild_storagesave(sd->status.account_id, sd->status.guild_id,0);
@@ -1121,7 +1121,7 @@ void storage_guild_storage_quit(struct map_session_data* sd, int flag)
if (flag) { //Only during a guild break flag is 1 (don't save storage) if (flag) { //Only during a guild break flag is 1 (don't save storage)
clif_storageclose(sd); clif_storageclose(sd);
if (save_settings&CHARSAVE_STORAGE) if (map_config.save_settings&CHARSAVE_STORAGE)
chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART); chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART);
sd->state.storage_flag = 0; sd->state.storage_flag = 0;
@@ -1130,7 +1130,7 @@ void storage_guild_storage_quit(struct map_session_data* sd, int flag)
} }
if (stor->status) { if (stor->status) {
if (save_settings&CHARSAVE_STORAGE) if (map_config.save_settings&CHARSAVE_STORAGE)
chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART); chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART);
else else
storage_guild_storagesave(sd->status.account_id,sd->status.guild_id,1); storage_guild_storagesave(sd->status.account_id,sd->status.guild_id,1);
@@ -1224,7 +1224,7 @@ void storage_premiumStorage_close(struct map_session_data *sd) {
nullpo_retv(sd); nullpo_retv(sd);
if (sd->premiumStorage.dirty) { if (sd->premiumStorage.dirty) {
if (save_settings&CHARSAVE_STORAGE) if (map_config.save_settings&CHARSAVE_STORAGE)
chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART); chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART);
else else
storage_premiumStorage_save(sd); storage_premiumStorage_save(sd);
@@ -1245,7 +1245,7 @@ void storage_premiumStorage_close(struct map_session_data *sd) {
void storage_premiumStorage_quit(struct map_session_data *sd) { void storage_premiumStorage_quit(struct map_session_data *sd) {
nullpo_retv(sd); nullpo_retv(sd);
if (save_settings&CHARSAVE_STORAGE) if (map_config.save_settings&CHARSAVE_STORAGE)
chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART); chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART);
else else
storage_premiumStorage_save(sd); storage_premiumStorage_save(sd);

View File

@@ -206,9 +206,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 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. 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: %u), and try to trade %d of them. 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: %u), 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 we block people
if (battle_config.ban_hack_trade < 0) { 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 chrif_req_login_operation(-1, sd->status.name, CHRIF_OP_LOGIN_BLOCK, 0, 0, 0); // type: 1 - block
@@ -225,7 +225,7 @@ int impossible_trade_check(struct map_session_data *sd)
// message about the ban // message about the ban
strcpy(message_to_gm, msg_txt(sd,508)); // This player hasn't been banned (Ban option is disabled). 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; return 1;
} }
@@ -657,7 +657,7 @@ void trade_tradecommit(struct map_session_data *sd)
clif_tradecompleted(tsd, 0); clif_tradecompleted(tsd, 0);
// save both player to avoid crash: they always have no advantage/disadvantage between the 2 players // 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, CSAVE_INVENTORY|CSAVE_CART); chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART);
chrif_save(tsd, CSAVE_INVENTORY|CSAVE_CART); chrif_save(tsd, CSAVE_INVENTORY|CSAVE_CART);
} }

View File

@@ -60,8 +60,8 @@ void vending_closevending(struct map_session_data* sd)
nullpo_retv(sd); nullpo_retv(sd);
if( sd->state.vending ) { if( sd->state.vending ) {
if( Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE vending_id = %d;", vending_items_table, 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;", vendings_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); Sql_ShowDebug(mmysql_handle);
} }
@@ -230,11 +230,11 @@ void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const ui
z += ((double)vsd->vending[i].value * (double)amount); z += ((double)vsd->vending[i].value * (double)amount);
if( vsd->vending[vend_list[i]].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_table, vsd->vending[vend_list[i]].amount, vsd->vender_id, vsd->cart.u.items_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->cart.u.items_cart[idx].id ) != SQL_SUCCESS ) {
Sql_ShowDebug( mmysql_handle ); Sql_ShowDebug( mmysql_handle );
} }
} else { } else {
if( Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE `vending_id` = %d and `cartinventory_id` = %d", vending_items_table, vsd->vender_id, vsd->cart.u.items_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->cart.u.items_cart[idx].id ) != SQL_SUCCESS ) {
Sql_ShowDebug( mmysql_handle ); Sql_ShowDebug( mmysql_handle );
} }
} }
@@ -268,7 +268,7 @@ void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const ui
vsd->vend_num = cursor; vsd->vend_num = cursor;
//Always save BOTH: customer (buyer) and vender //Always save BOTH: customer (buyer) and vender
if( save_settings&CHARSAVE_VENDING ) { if( map_config.save_settings&CHARSAVE_VENDING ) {
chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART); chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART);
chrif_save(vsd, CSAVE_INVENTORY|CSAVE_CART); chrif_save(vsd, CSAVE_INVENTORY|CSAVE_CART);
} }
@@ -322,7 +322,7 @@ int8 vending_openvending(struct map_session_data* sd, const char* message, const
return 3; 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, CSAVE_INVENTORY|CSAVE_CART); chrif_save(sd, CSAVE_INVENTORY|CSAVE_CART);
// filter out invalid items // filter out invalid items
@@ -372,12 +372,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`) " 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' );", "VALUES( %d, %d, %d, '%c', '%s', %d, %d, '%s', %d, '%d', '%d', '%d' );",
vendings_table, sd->vender_id, sd->status.account_id, sd->status.char_id, sd->status.sex == SEX_FEMALE ? 'F' : 'M', map_getmapdata(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 == SEX_FEMALE ? 'F' : 'M', map_getmapdata(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); Sql_ShowDebug(mmysql_handle);
} }
StringBuf_Init(&buf); StringBuf_Init(&buf);
StringBuf_Printf(&buf, "INSERT INTO `%s`(`vending_id`,`index`,`cartinventory_id`,`amount`,`price`) VALUES", vending_items_table); StringBuf_Printf(&buf, "INSERT INTO `%s`(`vending_id`,`index`,`cartinventory_id`,`amount`,`price`) VALUES", mapserv_table(vending_items_table));
for (j = 0; j < i; j++) { for (j = 0; j < i; j++) {
StringBuf_Printf(&buf, "(%d,%d,%d,%d,%d)", sd->vender_id, j, sd->cart.u.items_cart[sd->vending[j].index].id, sd->vending[j].amount, sd->vending[j].value); StringBuf_Printf(&buf, "(%d,%d,%d,%d,%d)", sd->vender_id, j, sd->cart.u.items_cart[sd->vending[j].index].id, sd->vending[j].amount, sd->vending[j].value);
if (j < i-1) if (j < i-1)
@@ -563,7 +563,7 @@ void do_init_vending_autotrade(void)
"FROM `%s` " "FROM `%s` "
"WHERE `autotrade` = 1 AND (SELECT COUNT(`vending_id`) FROM `%s` WHERE `vending_id` = `id`) > 0 " "WHERE `autotrade` = 1 AND (SELECT COUNT(`vending_id`) FROM `%s` WHERE `vending_id` = `id`) > 0 "
"ORDER BY `id`;", "ORDER BY `id`;",
vendings_table, vending_items_table ) != SQL_SUCCESS ) mapserv_table(vendings_table), mapserv_table(vending_items_table) ) != SQL_SUCCESS )
{ {
Sql_ShowDebug(mmysql_handle); Sql_ShowDebug(mmysql_handle);
return; return;
@@ -621,7 +621,7 @@ void do_init_vending_autotrade(void)
"FROM `%s` " "FROM `%s` "
"WHERE `vending_id` = %d " "WHERE `vending_id` = %d "
"ORDER BY `index` ASC;", "ORDER BY `index` ASC;",
vending_items_table, at->id ) ) mapserv_table(vending_items_table), at->id ) )
{ {
Sql_ShowDebug(mmysql_handle); Sql_ShowDebug(mmysql_handle);
continue; continue;
@@ -656,8 +656,8 @@ void do_init_vending_autotrade(void)
} }
// Everything is loaded fine, their entries will be reinserted once they are loaded // Everything is loaded fine, their entries will be reinserted once they are loaded
if (Sql_Query( mmysql_handle, "DELETE FROM `%s`;", vendings_table ) != SQL_SUCCESS || if (Sql_Query( mmysql_handle, "DELETE FROM `%s`;", mapserv_table(vendings_table) ) != SQL_SUCCESS ||
Sql_Query( mmysql_handle, "DELETE FROM `%s`;", vending_items_table ) != SQL_SUCCESS) { Sql_Query( mmysql_handle, "DELETE FROM `%s`;", mapserv_table(vending_items_table) ) != SQL_SUCCESS) {
Sql_ShowDebug(mmysql_handle); Sql_ShowDebug(mmysql_handle);
} }
} }