From c84a4473cc0491edbf6ac3e7efd062d8c57e5a2c Mon Sep 17 00:00:00 2001 From: Haru Date: Sun, 6 Sep 2015 18:08:14 +0200 Subject: Ported char-server.conf to libconfig Fixed issue: 8115, now start items can be equipped as well Ported to modern Hercules and cleaned up from Panikon's commits: c6482e9870645ffe59a6a059b819574d4ac79fd9, 832fb27d4f767e4bc8b68c432d0da00b7cb7a4f9, f81b579899e3a15bd472ca8c6a6e0116c43bec92, e23723725499b617def03d05661eca637edaeabd, 0b783a83d82e588efd760f7f4baec0c8074a6fd1, 1b7de91308a57ea07b158ed95a2515a3c8cc36bd, 677d3430cbda0962b320a60cf499e9dadf637d00 Signed-off-by: Haru --- conf/char-server.conf | 188 ------------------------------ conf/char/char-server.conf | 233 ++++++++++++++++++++++++++++++++++++++ conf/global/console.conf | 59 ++++++++++ conf/import-tmpl/char-server.conf | 32 ++++++ conf/import-tmpl/char_conf.txt | 0 5 files changed, 324 insertions(+), 188 deletions(-) delete mode 100644 conf/char-server.conf create mode 100644 conf/char/char-server.conf create mode 100644 conf/global/console.conf create mode 100644 conf/import-tmpl/char-server.conf delete mode 100644 conf/import-tmpl/char_conf.txt (limited to 'conf') diff --git a/conf/char-server.conf b/conf/char-server.conf deleted file mode 100644 index eb2b9a63d..000000000 --- a/conf/char-server.conf +++ /dev/null @@ -1,188 +0,0 @@ -// Character Server configuration file. - -// Note: "Comments" are all text on the right side of a double slash "//" -// Whatever text is commented will not be parsed by the servers, and serves -// only as information/reference. - -// Server Communication username and password. -userid: s1 -passwd: p1 - -// Server name, use alternative character such as ASCII 160 for spaces. -// NOTE: Do not use spaces or any of these characters which are not allowed in -// Windows filenames \/:*?"<>| -// ... or else guild emblems won't work client-side! -server_name: Hercules - -// Wisp name for server: used to send wisp from server to players (between 4 to 23 characters) -wisp_server_name: Server - -// Login Server IP -// The character server connects to the login server using this IP address. -// NOTE: This is useful when you are running behind a firewall or are on -// a machine with multiple interfaces. -//login_ip: 127.0.0.1 - -// The character server listens on the interface with this IP address. -// NOTE: This allows you to run multiple servers on multiple interfaces -// while using the same ports for each server. -//bind_ip: 127.0.0.1 - -// Login Server Port -login_port: 6900 - -// Character Server IP -// The IP address which clients will use to connect. -// Set this to what your server's public IP address is. -//char_ip: 127.0.0.1 - -// Character Server Port -char_port: 6121 - -//Time-stamp format which will be printed before all messages. -//Can at most be 20 characters long. -//Common formats: -// %I:%M:%S %p (hour:minute:second 12 hour, AM/PM format) -// %H:%M:%S (hour:minute:second, 24 hour format) -// %d/%b/%Y (day/Month/year) -//For full format information, consult the strftime() manual. -//timestamp_format: [%d/%b %H:%M] - -//If redirected output contains escape sequences (color codes) -stdout_with_ansisequence: no - -//Makes server output more silent by ommitting certain types of messages: -//1: Hide Information messages -//2: Hide Status messages -//4: Hide Notice Messages -//8: Hide Warning Messages -//16: Hide Error and SQL Error messages. -//32: Hide Debug Messages -//Example: "console_silent: 7" Hides information, status and notice messages (1+2+4) -console_silent: 0 - -// Type of server. -// No functional side effects at the moment. -// Displayed next to the server name in the client. -// 0=normal, 1=maintenance, 2=over 18, 3=paying, 4=F2P -char_server_type: 0 - -// Minimum Group ID to join char server when it is on char_server_type 1 (maintenance) -char_maintenance_min_group_id: 99 - -// Enable or disable creation of new characters. -// Now it is actually supported [Kevin] -char_new: 1 - -// Display (New) in the server list. -char_new_display: 0 - -// Maximum users able to connect to the server. -// Set to 0 to disable users to log-in. (-1 means unlimited) -max_connect_user: -1 - -// Group ID that is allowed to bypass the server limit of users. -// Default: -1 = nobody (there are no groups with ID < 0) -// See: conf/groups.conf -gm_allow_group: -1 - -// How often should the server save all files? (In seconds) -// Note: Applies to all data files on TXT servers. -// On SQL servers, it applies to guilds (character save interval is defined on the map config) -autosave_time: 60 - -// Display information on the console whenever characters/guilds/parties/pets are loaded/saved? -save_log: yes - -// Start point, Map name followed by coordinates (x,y) -start_point_re: iz_int,97,90 -start_point_pre: new_1-1,53,111 - -// Starting items for new characters -// Format is: id1,quantity1,stackable1,idN,quantityN,stackableN -// stackable: -// 0 - Not stackable (weapon, armor, egg, pet armor) -// 1 - Stackable -start_items: 1201,1,0,2301,1,0 - -// Starting zeny for new characters -start_zeny: 0 - -// Size for the fame-lists -fame_list_alchemist: 10 -fame_list_blacksmith: 10 -fame_list_taekwon: 10 - -// Guild earned exp modifier. -// Adjusts taxed exp before adding it to the guild's exp. For example, if set -// to 200, the guild receives double the player's taxed exp. -guild_exp_rate: 100 - -// Name used for unknown characters -unknown_char_name: Unknown - -// To log the character server? -log_char: 1 - -// Allow or not identical name for characters but with a different case (upper/lower): -// example: Test-test-TEST-TesT; Value: 0 not allowed (default), 1 allowed -name_ignoring_case: no - -// Manage possible letters/symbol in the name of charater. Control character (0x00-0x1f) are never accepted. Possible values are: -// NOTE: Applies to character, party and guild names. -// 0: no restriction (default) -// 1: only letters/symbols in 'char_name_letters' option. -// 2: Letters/symbols in 'char_name_letters' option are forbidden. All others are possibles. -char_name_option: 1 - -// Set the letters/symbols that you want use with the 'char_name_option' option. -// Note: Don't add spaces unless you mean to add 'space' to the list. -char_name_letters: abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 - -// Restrict character deletion by BaseLevel -// 0: no restriction (players can delete characters of any level) -// -X: you can't delete chars with BaseLevel <= X -// Y: you can't delete chars with BaseLevel >= Y -// e.g. char_del_level: 80 (players can't delete characters with 80+ BaseLevel) -char_del_level: 0 - -// Amount of time in seconds by which the character deletion is delayed. -// Default: 86400 (24 hours) -// NOTE: Requires client 2010-08-03aragexeRE or newer. -char_del_delay: 86400 - -// Block deletion if character is inside a guild or a party? (BOOL) -// default: 0 official: 1 -// !!This check is imposed by Aegis to avoid dead entries in databases and _is_not_needed_ as we clear data properly!! -char_aegis_delete: 0 - -// What folder the DB files are in (item_db.conf, etc.) -db_path: db - -//================================================================== -// Pincode system -//================================================================== - -// A window is opened before you can select your character and you will have to enter a pincode by using only your mouse -// NOTE: Requires client 2011-03-09aragexeRE or newer. -// 0: disabled -// 1: enabled -pincode_enabled: 1 - -// Request Pincode only on login or on everytime char select is accessed? -// 0: only on login (default) -// 1: everytime the char select window is accessed -pincode_charselect: 0 - -// How often does a user have to change his pincode? -// Default: 0 -// 0: never -// X: every X minutes -pincode_changetime: 0 - -// How often can a user enter the wrong password? -// Default: 3 -// NOTE: The maximum on clientside is 3 -pincode_maxtry: 3 - -import: conf/import/char_conf.txt diff --git a/conf/char/char-server.conf b/conf/char/char-server.conf new file mode 100644 index 000000000..576925872 --- /dev/null +++ b/conf/char/char-server.conf @@ -0,0 +1,233 @@ +//================= Hercules Configuration ================================ +//= _ _ _ +//= | | | | | | +//= | |_| | ___ _ __ ___ _ _| | ___ ___ +//= | _ |/ _ \ '__/ __| | | | |/ _ \/ __| +//= | | | | __/ | | (__| |_| | | __/\__ \ +//= \_| |_/\___|_| \___|\__,_|_|\___||___/ +//================= License =============================================== +//= This file is part of Hercules. +//= http://herc.ws - http://github.com/HerculesWS/Hercules +//= +//= Copyright (C) 2014-2016 Hercules Dev Team +//= +//= Hercules is free software: you can redistribute it and/or modify +//= it under the terms of the GNU General Public License as published by +//= the Free Software Foundation, either version 3 of the License, or +//= (at your option) any later version. +//= +//= This program is distributed in the hope that it will be useful, +//= but WITHOUT ANY WARRANTY; without even the implied warranty of +//= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//= GNU General Public License for more details. +//= +//= You should have received a copy of the GNU General Public License +//= along with this program. If not, see . +//========================================================================= +//= Character Server configuration file. +//========================================================================= + +char_configuration: { + @include "conf/global/console.conf" + + // Server name, use alternative character such as ASCII 160 for spaces. + // NOTE: Do not use spaces or any of these characters which are not allowed in + // Windows filenames \/:*?"<>| + // ... or else guild emblems won't work client-side! + server_name: "Hercules" + + // Wisp name for server: used to send wisp from server to players (between 4 to 23 characters) + wisp_server_name: "Server" + + // Guild earned exp modifier. + // Adjusts taxed exp before adding it to the guild's exp. For example, + // if set to 200, the guild receives double the player's taxed exp. + guild_exp_rate: 100 + + // Information related to inter-server behavior + inter: { + // Server Communication username and password. + userid: "s1" + passwd: "p1" + // Login Server IP + // The character server connects to the login server using this IP address. + // NOTE: This is useful when you are running behind a firewall or are on + // a machine with multiple interfaces. + //login_ip: "127.0.0.1" + + // The character server listens on the interface with this IP address. + // NOTE: This allows you to run multiple servers on multiple interfaces + // while using the same ports for each server. + //bind_ip: "127.0.0.1" + + // Login Server Port + login_port: 6900 + + // Character Server IP + // The IP address which clients will use to connect. + // Set this to what your server's public IP address is. + //char_ip: "127.0.0.1" + + // Character Server Port + char_port: 6121 + } + + // Connection permission + permission: { + // Enable or disable creation of new characters. + enable_char_creation: true + + // Display (New) in the server list. + display_new: false + + // Maximum users able to connect to the server. + // Set to 0 to disable users to log-in. (-1 means unlimited) + max_connect_user: -1 + + // Group ID that is allowed to bypass the server limit of users. + // Default: -1 = nobody (there are no groups with ID < 0) + // See: conf/groups.conf + gm_allow_group: -1 + + // Type of server. + // No functional side effects at the moment. + // Displayed next to the server name in the client. + // 0=normal, 1=maintenance, 2=over 18, 3=paying, 4=F2P + server_type: 0 + + // Minimum Group ID to join char server when it is on char_server_type 1 (maintenance) + maintenance_min_group_id: 99 + } + + // Player-related configuration + player: { + new: { + // Start point (Renewal) + start_point_re: { + map: "iz_int" + x: 97 + y: 90 + } + // Start point (Pre-Renewal) + start_point_pre: { + map: "new_1-1" + x: 53 + y: 111 + } + + // Starting items for new characters + //{ + // id: Item id + // amount: Item amount + // loc: Item position, same as in item_db if you want the item to be equipped, otherwise 0 (optional) + // stackable: Is stackable? (not stackable item types: weapon, armor, egg, pet armor) + //}, + start_items: ( + { + id: 1201 // Knife + amount: 1 + loc: 2 + stackable: false + }, + { + id: 2301 // Cotton_Shirt + amount: 1 + loc: 16 + stackable: false + }, + ) + + // Starting zeny + zeny: 0 + } + + // Character name configuration + name: { + // Name used for unknown characters + unknown_char_name: "Unknown" + + // Allow or not identical name for characters but with a different case (upper/lower): + // example: Test-test-TEST-TesT; Value: 0 not allowed (default), 1 allowed + name_ignoring_case: false + + // Manage possible letters/symbol in the name of charater. Control character (0x00-0x1f) are never accepted. Possible values are: + // NOTE: Applies to character, party and guild names. + // 0: no restriction (default) + // 1: only letters/symbols in 'name_letters' option. + // 2: Letters/symbols in 'name_letters' option are forbidden. All others are possibles. + name_option: 1 + + // Set the letters/symbols that you want use with the 'char_name_option' option. + // Note: Don't add spaces unless you mean to add 'space' to the list. + name_letters: "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" + } + + deletion: { + // Restrict character deletion by BaseLevel + // 0: no restriction (players can delete characters of any level) + // -X: you can't delete chars with BaseLevel <= X + // Y: you can't delete chars with BaseLevel >= Y + // e.g. char_del_level: 80 (players can't delete characters with 80+ BaseLevel) + level: 0 + + // Amount of time in seconds by which the character deletion is delayed. + // Default: 86400 (24 hours) + // NOTE: Requires client 2010-08-03aragexeRE or newer. + delay: 86400 + + // Block deletion if character is inside a guild or a party? (BOOL) + // default: false official: true + // !!This check is imposed by Aegis to avoid dead entries in databases and _is_not_needed_ as we clear data properly!! + use_aegis_delete: false + } + + // Size for the fame-lists + fame: { + alchemist: 10 + blacksmith: 10 + taekwon: 10 + } + } + + database: { + // How often should server save all guild related information? (character save interval is defined on the map config) + // (in seconds) + autosave_time: 60 + + // What folder the DB files are in (abra_db.txt, etc.) + db_path: "db" + + // To log the character server? + log_char: true + } + + //================================================================== + // Pincode system + //================================================================== + pincode: { + // A window is opened before you can select your character and you will have to enter a pincode by using only your mouse + // NOTE: Requires client 2011-03-09aragexeRE or newer. + // 0: disabled + // 1: enabled + enabled: true + + // Request Pincode only on login or on everytime char select is accessed? + // 0: only on login (default) + // 1: everytime the char select window is accessed + request: 0 + + // How often does a user have to change his pincode? + // Default: 0 + // 0: never + // X: every X minutes + change_time: 0 + + // How often can a user enter the wrong password? + // Default: 3 + // Maximum allowed by clientside: 3 + max_tries: 3 + } + +} + +import: "conf/import/char-server.conf" diff --git a/conf/global/console.conf b/conf/global/console.conf new file mode 100644 index 000000000..d26c48352 --- /dev/null +++ b/conf/global/console.conf @@ -0,0 +1,59 @@ +//================= Hercules Configuration ================================ +//= _ _ _ +//= | | | | | | +//= | |_| | ___ _ __ ___ _ _| | ___ ___ +//= | _ |/ _ \ '__/ __| | | | |/ _ \/ __| +//= | | | | __/ | | (__| |_| | | __/\__ \ +//= \_| |_/\___|_| \___|\__,_|_|\___||___/ +//================= License =============================================== +//= This file is part of Hercules. +//= http://herc.ws - http://github.com/HerculesWS/Hercules +//= +//= Copyright (C) 2014-2016 Hercules Dev Team +//= +//= Hercules is free software: you can redistribute it and/or modify +//= it under the terms of the GNU General Public License as published by +//= the Free Software Foundation, either version 3 of the License, or +//= (at your option) any later version. +//= +//= This program is distributed in the hope that it will be useful, +//= but WITHOUT ANY WARRANTY; without even the implied warranty of +//= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//= GNU General Public License for more details. +//= +//= You should have received a copy of the GNU General Public License +//= along with this program. If not, see . +//========================================================================= +//= Server Console configuration file. +//========================================================================= +// This file affects how ALL server consoles work, unless explictly defined +// so in the server configuration file (See doc/global_configuration.txt +// for more information). +//========================================================================= + +console: { + //Time-stamp format which will be printed before all messages. + //Can at most be 20 characters long. + //Common formats: + // %I:%M:%S %p (hour:minute:second 12 hour, AM/PM format) + // %H:%M:%S (hour:minute:second, 24 hour format) + // %d/%b/%Y (day/Month/year) + //For full format information, consult the strftime() manual. + //timestamp_format: "[%d/%b %H:%M]" + + //If redirected output contains escape sequences (color codes) + stdout_with_ansisequence: false + + //Makes server output more silent by omitting certain types of messages: + //1: Hide Information messages + //2: Hide Status messages + //4: Hide Notice Messages + //8: Hide Warning Messages + //16: Hide Error and SQL Error messages. + //32: Hide Debug Messages + //Example: "console_silent: 7" Hides information, status and notice messages (1+2+4) + console_silent: 0 + + // [CHAR] Display information on the console whenever characters/guilds/parties/pets are loaded/saved? + save_log: true +} diff --git a/conf/import-tmpl/char-server.conf b/conf/import-tmpl/char-server.conf new file mode 100644 index 000000000..6bfb308b5 --- /dev/null +++ b/conf/import-tmpl/char-server.conf @@ -0,0 +1,32 @@ +//================= Hercules Configuration ================================ +//= _ _ _ +//= | | | | | | +//= | |_| | ___ _ __ ___ _ _| | ___ ___ +//= | _ |/ _ \ '__/ __| | | | |/ _ \/ __| +//= | | | | __/ | | (__| |_| | | __/\__ \ +//= \_| |_/\___|_| \___|\__,_|_|\___||___/ +//================= License =============================================== +//= This file is part of Hercules. +//= http://herc.ws - http://github.com/HerculesWS/Hercules +//= +//= Copyright (C) 2014-2016 Hercules Dev Team +//= +//= Hercules is free software: you can redistribute it and/or modify +//= it under the terms of the GNU General Public License as published by +//= the Free Software Foundation, either version 3 of the License, or +//= (at your option) any later version. +//= +//= This program is distributed in the hope that it will be useful, +//= but WITHOUT ANY WARRANTY; without even the implied warranty of +//= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//= GNU General Public License for more details. +//= +//= You should have received a copy of the GNU General Public License +//= along with this program. If not, see . +//========================================================================= +//= Character Server local configuration file. +//========================================================================= + +char_configuration: { + // See conf/char/char-server.conf for details +} diff --git a/conf/import-tmpl/char_conf.txt b/conf/import-tmpl/char_conf.txt deleted file mode 100644 index e69de29bb..000000000 -- cgit v1.2.3-70-g09d2 From ea9ceb17bdf4ea4acf28dca84508b62bd7e94fd4 Mon Sep 17 00:00:00 2001 From: Haru Date: Mon, 7 Sep 2015 01:42:31 +0200 Subject: Ported inter-server.conf to libconfig Ported to modern Hercules and cleaned up from Panikon's commits: 40f9ec33868e2240cab013308897898ed252b3e0, a9d646da19e25ab6fcf44dbd1ae7d90c30f6686c, 1aa8581a0aecbfd53e877686c399ffb731dcd75e, 72c645b015ae6130ca7d4309d0fb1413340e7f23, f8c906a0496b9acdae1d8244b1544fa03592061e, 51d88a58983c9552dfd1a0f059e5a031742aed61, 443684b3c77f4c32fe7877a7f8d62debf73b1e93, cf93eafef1f322cd1583226272b7d4008f562da4 Signed-off-by: Haru --- .gitignore | 1 - conf/char/char-server.conf | 1 + conf/common/inter-server.conf | 119 ++++++++++++++++ conf/global/sql_connection.conf | 49 +++++++ conf/import-tmpl/inter-server.conf | 32 +++++ conf/import-tmpl/inter_conf.txt | 0 conf/inter-server.conf | 125 ----------------- src/char/char.c | 279 ++++++++++++++++++++++++------------- src/char/char.h | 5 +- src/char/inter.c | 114 +++++++++------ src/char/inter.h | 6 +- src/common/sql.c | 96 +++++++------ src/common/sql.h | 2 +- src/map/map.c | 174 +++++++++++++++-------- src/map/map.h | 7 +- src/map/mapreg.h | 6 +- src/map/mapreg_sql.c | 21 ++- tools/configconverter.pl | 77 ++++++++++ 18 files changed, 738 insertions(+), 376 deletions(-) create mode 100644 conf/common/inter-server.conf create mode 100644 conf/global/sql_connection.conf create mode 100644 conf/import-tmpl/inter-server.conf delete mode 100644 conf/import-tmpl/inter_conf.txt delete mode 100644 conf/inter-server.conf (limited to 'conf') diff --git a/.gitignore b/.gitignore index 5eccd9969..3302e44cf 100644 --- a/.gitignore +++ b/.gitignore @@ -61,7 +61,6 @@ Thumbs.db # /conf/ /conf/import/*.conf /conf/import/battle_conf.txt -/conf/import/inter_conf.txt /conf/import/log_conf.txt /conf/import/login_conf.txt /conf/import/map_conf.txt diff --git a/conf/char/char-server.conf b/conf/char/char-server.conf index 576925872..4c6ef0348 100644 --- a/conf/char/char-server.conf +++ b/conf/char/char-server.conf @@ -29,6 +29,7 @@ char_configuration: { @include "conf/global/console.conf" + @include "conf/global/sql_connection.conf" // Server name, use alternative character such as ASCII 160 for spaces. // NOTE: Do not use spaces or any of these characters which are not allowed in diff --git a/conf/common/inter-server.conf b/conf/common/inter-server.conf new file mode 100644 index 000000000..fd55b27e5 --- /dev/null +++ b/conf/common/inter-server.conf @@ -0,0 +1,119 @@ +//================= Hercules Configuration ================================ +//= _ _ _ +//= | | | | | | +//= | |_| | ___ _ __ ___ _ _| | ___ ___ +//= | _ |/ _ \ '__/ __| | | | |/ _ \/ __| +//= | | | | __/ | | (__| |_| | | __/\__ \ +//= \_| |_/\___|_| \___|\__,_|_|\___||___/ +//================= License =============================================== +//= This file is part of Hercules. +//= http://herc.ws - http://github.com/HerculesWS/Hercules +//= +//= Copyright (C) 2014-2016 Hercules Dev Team +//= +//= Hercules is free software: you can redistribute it and/or modify +//= it under the terms of the GNU General Public License as published by +//= the Free Software Foundation, either version 3 of the License, or +//= (at your option) any later version. +//= +//= This program is distributed in the hope that it will be useful, +//= but WITHOUT ANY WARRANTY; without even the implied warranty of +//= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//= GNU General Public License for more details. +//= +//= You should have received a copy of the GNU General Public License +//= along with this program. If not, see . +//========================================================================= +//= Hercules Inter Server configuration file. +//========================================================================= +// Settings that are shared by more than one of the main servers +//========================================================================= + +inter_configuration: { + // Level range for sharing within a party + party_share_level: 15 // FIXME: Split RE and pre-RE + + // Log configuration + log: { + // Log Inter Connections, etc.? + log_inter: true + + // Inter Log Filename + inter_log_filename: "log/inter.log" + + // Log database SQL connection + @include "conf/global/sql_connection.conf" + } + + mysql_reconnect: { + // == MySQL Reconnect Settings + // =========================== + // - mysql_reconnect_type + // - 1: when mysql disconnects during runtime, the server tries to reconnect mysql_reconnect_count times and, + // -- if unsuccessful, the server is shut down + // - 2: when mysql disconnects during runtime it tries to reconnect indefinitely + type: 2 + + // - mysql_reconnect_count + // - number of reconnect attempts the server should do when the database disconnects during runtime + // - only used when mysql_reconnect_type is 1 + count: 1 + } + + // ALL MySQL Database Table names + // 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] + database_names: { + char_db: "char" + interlog_db: "interlog" + ragsrvinfo_db: "ragsrvinfo" + registry: { + acc_reg_num_db: "acc_reg_num_db" + acc_reg_str_db: "acc_reg_str_db" + char_reg_str_db: "char_reg_str_db" + char_reg_num_db: "char_reg_num_db" + + global_acc_reg_num_db: "global_acc_reg_num_db" + global_acc_reg_str_db: "global_acc_reg_str_db" + } + pc: { + hotkey_db: "hotkey" + scdata_db: "sc_data" + cart_db: "cart_inventory" + inventory_db: "inventory" + charlog_db: "charlog" + storage_db: "storage" + skill_db: "skill" + memo_db: "memo" + party_db: "party" + pet_db: "pet" + friend_db: "friends" + mail_db: "mail" + auction_db: "auction" + quest_db: "quest" + homunculus_db: "homunculus" + skill_homunculus_db: "skill_homunculus" + mercenary_db: "mercenary" + mercenary_owner_db: "mercenary_owner" + elemental_db: "elemental" + account_data_db: "account_data" + } + guild: { + main_db: "guild" + alliance_db: "guild_alliance" + castle_db: "guild_castle" + expulsion_db: "guild_expulsion" + member_db: "guild_member" + skill_db: "guild_skill" + position_db: "guild_position" + storage_db: "guild_storage" + } + mapreg_db: "mapreg" + autotrade_merchants_db: "autotrade_merchants" + autotrade_data_db: "autotrade_data" + npc_market_data_db: "npc_market_data" + } +} + +import: "conf/import/inter-server.conf" diff --git a/conf/global/sql_connection.conf b/conf/global/sql_connection.conf new file mode 100644 index 000000000..58c9e6d08 --- /dev/null +++ b/conf/global/sql_connection.conf @@ -0,0 +1,49 @@ +//================= Hercules Configuration ================================ +//= _ _ _ +//= | | | | | | +//= | |_| | ___ _ __ ___ _ _| | ___ ___ +//= | _ |/ _ \ '__/ __| | | | |/ _ \/ __| +//= | | | | __/ | | (__| |_| | | __/\__ \ +//= \_| |_/\___|_| \___|\__,_|_|\___||___/ +//================= License =============================================== +//= This file is part of Hercules. +//= http://herc.ws - http://github.com/HerculesWS/Hercules +//= +//= Copyright (C) 2014-2016 Hercules Dev Team +//= +//= Hercules is free software: you can redistribute it and/or modify +//= it under the terms of the GNU General Public License as published by +//= the Free Software Foundation, either version 3 of the License, or +//= (at your option) any later version. +//= +//= This program is distributed in the hope that it will be useful, +//= but WITHOUT ANY WARRANTY; without even the implied warranty of +//= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//= GNU General Public License for more details. +//= +//= You should have received a copy of the GNU General Public License +//= along with this program. If not, see . +//========================================================================= +//= SQL connection configuration file. +//========================================================================= +// This file affects how ALL server sql connections work, unless explictly +// defined so in the server configuration file (See +// doc/global_configuration.txt for more information). +//========================================================================= + +sql_connection: { + // [INTER] You can specify the codepage to use in your mySQL tables here. + // (Note that this feature requires MySQL 4.1+) + //default_codepage: "" + + // For IPs, ideally under linux, you want to use localhost instead of 127.0.0.1. + // Under windows, you want to use 127.0.0.1. If you see a message like + // "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)" + // and you have localhost, switch it to 127.0.0.1 + db_hostname: "127.0.0.1" + db_port: 3306 + db_username: "ragnarok" + db_password: "ragnarok" + db_database: "ragnarok" + //codepage:"" +} diff --git a/conf/import-tmpl/inter-server.conf b/conf/import-tmpl/inter-server.conf new file mode 100644 index 000000000..243dda4ea --- /dev/null +++ b/conf/import-tmpl/inter-server.conf @@ -0,0 +1,32 @@ +//================= Hercules Configuration ================================ +//= _ _ _ +//= | | | | | | +//= | |_| | ___ _ __ ___ _ _| | ___ ___ +//= | _ |/ _ \ '__/ __| | | | |/ _ \/ __| +//= | | | | __/ | | (__| |_| | | __/\__ \ +//= \_| |_/\___|_| \___|\__,_|_|\___||___/ +//================= License =============================================== +//= This file is part of Hercules. +//= http://herc.ws - http://github.com/HerculesWS/Hercules +//= +//= Copyright (C) 2014-2016 Hercules Dev Team +//= +//= Hercules is free software: you can redistribute it and/or modify +//= it under the terms of the GNU General Public License as published by +//= the Free Software Foundation, either version 3 of the License, or +//= (at your option) any later version. +//= +//= This program is distributed in the hope that it will be useful, +//= but WITHOUT ANY WARRANTY; without even the implied warranty of +//= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//= GNU General Public License for more details. +//= +//= You should have received a copy of the GNU General Public License +//= along with this program. If not, see . +//========================================================================= +//= Hercules Inter Server local configuration file. +//========================================================================= + +inter_configuration: { + // See conf/common/inter-server.conf +} diff --git a/conf/import-tmpl/inter_conf.txt b/conf/import-tmpl/inter_conf.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/conf/inter-server.conf b/conf/inter-server.conf deleted file mode 100644 index 704d5fc12..000000000 --- a/conf/inter-server.conf +++ /dev/null @@ -1,125 +0,0 @@ -// Hercules InterServer (settings shared/used by more than 1 server) configuration. - -// Options for both versions - -// Log Inter Connections, etc.? -log_inter: 1 - -// Inter Log Filename -inter_log_filename: log/inter.log - -// Level range for sharing within a party -party_share_level: 15 - -// SQL version options only - -// You can specify the codepage to use in your mySQL tables here. -// (Note that this feature requires MySQL 4.1+) -//default_codepage: - - -// For IPs, ideally under linux, you want to use localhost instead of 127.0.0.1 -// Under windows, you want to use 127.0.0.1. If you see a message like -// "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)" -// and you have localhost, switch it to 127.0.0.1 - -// Global SQL settings -// overridden by local settings when the hostname is defined there -// (currently only the login-server reads/obeys these settings) -sql.db_hostname: 127.0.0.1 -sql.db_port: 3306 -sql.db_username: ragnarok -sql.db_password: ragnarok -sql.db_database: ragnarok -sql.codepage: - -// MySQL Character SQL server -char_server_ip: 127.0.0.1 -char_server_port: 3306 -char_server_id: ragnarok -char_server_pw: ragnarok -char_server_db: ragnarok - -// MySQL Map SQL Server -map_server_ip: 127.0.0.1 -map_server_port: 3306 -map_server_id: ragnarok -map_server_pw: ragnarok -map_server_db: ragnarok - -// MySQL Log SQL Database -log_db_ip: 127.0.0.1 -log_db_port: 3306 -log_db_id: ragnarok -log_db_pw: ragnarok -log_db_db: ragnarok -log_codepage: -log_login_db: loginlog - -// == MySQL Reconnect Settings -// =========================== -// - mysql_reconnect_type -// - 1: when mysql disconnects during runtime, the server tries to reconnect mysql_reconnect_count times and, -// -- if unsuccessful, the server is shut down -// - 2: when mysql disconnects during runtime it tries to reconnect indefinitely -mysql_reconnect_type:2 -// - mysql_reconnect_count -// - number of reconnect attempts the server should do when the database disconnects during runtime -// - only used when mysql_reconnect_type is 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 - -//Shared -interreg_db: interreg -global_acc_reg_num_db: global_acc_reg_num_db -global_acc_reg_str_db: global_acc_reg_str_db - -// Char Database Tables -char_db: char -hotkey_db: hotkey -scdata_db: sc_data -cart_db: cart_inventory -inventory_db: inventory -charlog_db: charlog -storage_db: storage -skill_db: skill -interlog_db: interlog -memo_db: memo -guild_db: guild -guild_alliance_db: guild_alliance -guild_castle_db: guild_castle -guild_expulsion_db: guild_expulsion -guild_member_db: guild_member -guild_skill_db: guild_skill -guild_position_db: guild_position -guild_storage_db: guild_storage -party_db: party -pet_db: pet -friend_db: friends -mail_db: mail -auction_db: auction -quest_db: quest -homunculus_db: homunculus -skill_homunculus_db: skill_homunculus -mercenary_db: mercenary -mercenary_owner_db: mercenary_owner -ragsrvinfo_db: ragsrvinfo -elemental_db: elemental -account_data_db: account_data -acc_reg_num_db: acc_reg_num_db -acc_reg_str_db: acc_reg_str_db -char_reg_str_db: char_reg_str_db -char_reg_num_db: char_reg_num_db - -// Map Database Tables -mapreg_db: mapreg -autotrade_merchants_db: autotrade_merchants -autotrade_data_db: autotrade_data -npc_market_data_db: npc_market_data - -import: conf/import/inter_conf.txt diff --git a/src/char/char.c b/src/char/char.c index 2b5c837c5..62b1d8f4c 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -5350,102 +5350,171 @@ static int char_online_data_cleanup(int tid, int64 tick, int id, intptr_t data) return 0; } -void char_sql_config_read(const char* cfgName) +/** + * Reads the 'inter_configuration' config file and initializes required variables. + * + * @param filename Path to configuration file + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool char_sql_config_read(const char *filename, bool imported) { - char line[1024], w1[1024], w2[1024]; - FILE* fp; + struct config_t config; + const struct config_setting_t *setting = NULL; + const char *import = NULL; + bool retval = true; - if ((fp = fopen(cfgName, "r")) == NULL) { - ShowError("File not found: %s\n", cfgName); - return; + nullpo_retr(false, filename); + + if (!libconfig->load_file(&config, filename)) + return false; // Error message is already shown by libconfig->load_file + + if ((setting = libconfig->lookup(&config, "inter_configuration/database_names")) == NULL) { + libconfig->destroy(&config); + if (imported) + return true; + ShowError("sql_config_read: inter_configuration/database_names was not found in %s!\n", filename); + return false; } + libconfig->setting_lookup_mutable_string(setting, "char_db", char_db, sizeof(char_db)); + libconfig->setting_lookup_mutable_string(setting, "interlog_db", interlog_db, sizeof(interlog_db)); + libconfig->setting_lookup_mutable_string(setting, "ragsrvinfo_db", ragsrvinfo_db, sizeof(ragsrvinfo_db)); - while(fgets(line, sizeof(line), fp)) - { - if(line[0] == '/' && line[1] == '/') - continue; + if (!chr->sql_config_read_registry(filename, &config, imported)) + retval = false; + if (!chr->sql_config_read_pc(filename, &config, imported)) + retval = false; + if (!chr->sql_config_read_guild(filename, &config, imported)) + retval = false; - if (sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2) != 2) - continue; + ShowInfo("Done reading %s.\n", filename); + // import should overwrite any previous configuration, so it should be called last + if (libconfig->lookup_string(&config, "import", &import) == CONFIG_TRUE) { + if (strcmp(import, filename) == 0 || strcmp(import, chr->SQL_CONF_NAME) == 0) { + ShowWarning("sql_config_read: Loop detected in %s! Skipping 'import'...\n", filename); + } else { + if (!chr->sql_config_read(import, true)) + retval = false; + } + } - if(!strcmpi(w1,"char_db")) - safestrncpy(char_db, w2, sizeof(char_db)); - else if(!strcmpi(w1,"scdata_db")) - safestrncpy(scdata_db, w2, sizeof(scdata_db)); - else if(!strcmpi(w1,"cart_db")) - safestrncpy(cart_db, w2, sizeof(cart_db)); - else if(!strcmpi(w1,"inventory_db")) - safestrncpy(inventory_db, w2, sizeof(inventory_db)); - else if(!strcmpi(w1,"charlog_db")) - safestrncpy(charlog_db, w2, sizeof(charlog_db)); - else if(!strcmpi(w1,"storage_db")) - safestrncpy(storage_db, w2, sizeof(storage_db)); - else if(!strcmpi(w1,"skill_db")) - safestrncpy(skill_db, w2, sizeof(skill_db)); - else if(!strcmpi(w1,"interlog_db")) - safestrncpy(interlog_db, w2, sizeof(interlog_db)); - else if(!strcmpi(w1,"memo_db")) - safestrncpy(memo_db, w2, sizeof(memo_db)); - else if(!strcmpi(w1,"guild_db")) - safestrncpy(guild_db, w2, sizeof(guild_db)); - else if(!strcmpi(w1,"guild_alliance_db")) - safestrncpy(guild_alliance_db, w2, sizeof(guild_alliance_db)); - else if(!strcmpi(w1,"guild_castle_db")) - safestrncpy(guild_castle_db, w2, sizeof(guild_castle_db)); - else if(!strcmpi(w1,"guild_expulsion_db")) - safestrncpy(guild_expulsion_db, w2, sizeof(guild_expulsion_db)); - else if(!strcmpi(w1,"guild_member_db")) - safestrncpy(guild_member_db, w2, sizeof(guild_member_db)); - else if(!strcmpi(w1,"guild_skill_db")) - safestrncpy(guild_skill_db, w2, sizeof(guild_skill_db)); - else if(!strcmpi(w1,"guild_position_db")) - safestrncpy(guild_position_db, w2, sizeof(guild_position_db)); - else if(!strcmpi(w1,"guild_storage_db")) - safestrncpy(guild_storage_db, w2, sizeof(guild_storage_db)); - else if(!strcmpi(w1,"party_db")) - safestrncpy(party_db, w2, sizeof(party_db)); - else if(!strcmpi(w1,"pet_db")) - safestrncpy(pet_db, w2, sizeof(pet_db)); - else if(!strcmpi(w1,"mail_db")) - safestrncpy(mail_db, w2, sizeof(mail_db)); - else if(!strcmpi(w1,"auction_db")) - safestrncpy(auction_db, w2, sizeof(auction_db)); - else if(!strcmpi(w1,"friend_db")) - safestrncpy(friend_db, w2, sizeof(friend_db)); - else if(!strcmpi(w1,"hotkey_db")) - safestrncpy(hotkey_db, w2, sizeof(hotkey_db)); - else if(!strcmpi(w1,"quest_db")) - safestrncpy(quest_db,w2,sizeof(quest_db)); - else if(!strcmpi(w1,"homunculus_db")) - safestrncpy(homunculus_db,w2,sizeof(homunculus_db)); - else if(!strcmpi(w1,"skill_homunculus_db")) - safestrncpy(skill_homunculus_db,w2,sizeof(skill_homunculus_db)); - else if(!strcmpi(w1,"mercenary_db")) - safestrncpy(mercenary_db,w2,sizeof(mercenary_db)); - else if(!strcmpi(w1,"mercenary_owner_db")) - safestrncpy(mercenary_owner_db,w2,sizeof(mercenary_owner_db)); - else if(!strcmpi(w1,"ragsrvinfo_db")) - safestrncpy(ragsrvinfo_db,w2,sizeof(ragsrvinfo_db)); - else if(!strcmpi(w1,"elemental_db")) - safestrncpy(elemental_db,w2,sizeof(elemental_db)); - else if(!strcmpi(w1,"account_data_db")) - safestrncpy(account_data_db,w2,sizeof(account_data_db)); - else if(!strcmpi(w1,"char_reg_num_db")) - safestrncpy(char_reg_num_db, w2, sizeof(char_reg_num_db)); - else if(!strcmpi(w1,"char_reg_str_db")) - safestrncpy(char_reg_str_db, w2, sizeof(char_reg_str_db)); - else if(!strcmpi(w1,"acc_reg_str_db")) - safestrncpy(acc_reg_str_db, w2, sizeof(acc_reg_str_db)); - else if(!strcmpi(w1,"acc_reg_num_db")) - safestrncpy(acc_reg_num_db, w2, sizeof(acc_reg_num_db)); - //support the import command, just like any other config - else if(!strcmpi(w1,"import")) - chr->sql_config_read(w2); - else - HPM->parseConf(w1, w2, HPCT_CHAR_INTER); + // TODO HPM->parseConf(w1, w2, HPCT_CHAR_INTER); + + libconfig->destroy(&config); + return retval; +} + +/** + * Reads the 'inter_configuration/database_names/registry' config entry and initializes required variables. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool char_sql_config_read_registry(const char *filename, const struct config_t *config, bool imported) +{ + const struct config_setting_t *setting = NULL; + + nullpo_retr(false, filename); + nullpo_retr(false, config); + + if ((setting = libconfig->lookup(config, "inter_configuration/database_names/registry")) == NULL) { + if (imported) + return true; + ShowError("sql_config_read: inter_configuration/database_names/registry was not found in %s!\n", filename); + return false; } - fclose(fp); - ShowInfo("Done reading %s.\n", cfgName); + // Not all registries are read by char-server + libconfig->setting_lookup_mutable_string(setting, "char_reg_num_db", char_reg_num_db, sizeof(char_reg_num_db)); + libconfig->setting_lookup_mutable_string(setting, "char_reg_str_db", char_reg_str_db, sizeof(char_reg_str_db)); + libconfig->setting_lookup_mutable_string(setting, "acc_reg_str_db", acc_reg_str_db, sizeof(acc_reg_str_db)); + libconfig->setting_lookup_mutable_string(setting, "acc_reg_num_db", acc_reg_num_db, sizeof(acc_reg_num_db)); + + return true; +} + +/** + * Reads the 'inter_configuration/database_names/pc' config entry and initializes required variables. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool char_sql_config_read_pc(const char *filename, const struct config_t *config, bool imported) +{ + const struct config_setting_t *setting = NULL; + + nullpo_retr(false, filename); + nullpo_retr(false, config); + + if ((setting = libconfig->lookup(config, "inter_configuration/database_names/pc")) == NULL) { + if (imported) + return true; + ShowError("sql_config_read: inter_configuration/database_names/pc was not found in %s!\n", filename); + return false; + } + libconfig->setting_lookup_mutable_string(setting, "hotkey_db", hotkey_db, sizeof(hotkey_db)); + libconfig->setting_lookup_mutable_string(setting, "scdata_db", scdata_db, sizeof(scdata_db)); + libconfig->setting_lookup_mutable_string(setting, "inventory_db", inventory_db, sizeof(inventory_db)); + libconfig->setting_lookup_mutable_string(setting, "cart_db", cart_db, sizeof(cart_db)); + libconfig->setting_lookup_mutable_string(setting, "charlog_db", charlog_db, sizeof(charlog_db)); + libconfig->setting_lookup_mutable_string(setting, "storage_db", storage_db, sizeof(storage_db)); + libconfig->setting_lookup_mutable_string(setting, "skill_db", skill_db, sizeof(skill_db)); + libconfig->setting_lookup_mutable_string(setting, "memo_db", memo_db, sizeof(memo_db)); + libconfig->setting_lookup_mutable_string(setting, "party_db", party_db, sizeof(party_db)); + libconfig->setting_lookup_mutable_string(setting, "pet_db", pet_db, sizeof(pet_db)); + libconfig->setting_lookup_mutable_string(setting, "friend_db", friend_db, sizeof(friend_db)); + libconfig->setting_lookup_mutable_string(setting, "mail_db", mail_db, sizeof(mail_db)); + libconfig->setting_lookup_mutable_string(setting, "auction_db", auction_db, sizeof(auction_db)); + libconfig->setting_lookup_mutable_string(setting, "quest_db", quest_db, sizeof(quest_db)); + libconfig->setting_lookup_mutable_string(setting, "homunculus_db", homunculus_db, sizeof(homunculus_db)); + libconfig->setting_lookup_mutable_string(setting, "skill_homunculus_db", skill_homunculus_db, sizeof(skill_homunculus_db)); + libconfig->setting_lookup_mutable_string(setting, "mercenary_db", mercenary_db, sizeof(mercenary_db)); + libconfig->setting_lookup_mutable_string(setting, "mercenary_owner_db", mercenary_owner_db, sizeof(mercenary_owner_db)); + libconfig->setting_lookup_mutable_string(setting, "elemental_db", elemental_db, sizeof(elemental_db)); + libconfig->setting_lookup_mutable_string(setting, "account_data_db", account_data_db, sizeof(account_data_db)); + + return true; +} + +/** + * Reads the 'inter_configuration/database_names/guild' config entry and initializes required variables. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool char_sql_config_read_guild(const char *filename, const struct config_t *config, bool imported) +{ + const struct config_setting_t *setting = NULL; + + nullpo_retr(false, filename); + nullpo_retr(false, config); + + if ((setting = libconfig->lookup(config, "inter_configuration/database_names/guild")) == NULL) { + if (imported) + return true; + ShowError("sql_config_read: inter_configuration/database_names/guild was not found in %s!\n", filename); + return false; + } + + libconfig->setting_lookup_mutable_string(setting, "main_db", guild_db, sizeof(guild_db)); + libconfig->setting_lookup_mutable_string(setting, "alliance_db", guild_alliance_db, sizeof(guild_alliance_db)); + libconfig->setting_lookup_mutable_string(setting, "castle_db", guild_castle_db, sizeof(guild_castle_db)); + libconfig->setting_lookup_mutable_string(setting, "expulsion_db", guild_expulsion_db, sizeof(guild_expulsion_db)); + libconfig->setting_lookup_mutable_string(setting, "member_db", guild_member_db, sizeof(guild_member_db)); + libconfig->setting_lookup_mutable_string(setting, "skill_db", guild_skill_db, sizeof(guild_skill_db)); + libconfig->setting_lookup_mutable_string(setting, "position_db", guild_position_db, sizeof(guild_position_db)); + libconfig->setting_lookup_mutable_string(setting, "storage_db", guild_storage_db, sizeof(guild_storage_db)); + + return true; } /** @@ -5479,6 +5548,8 @@ bool char_config_read(const char *filename, bool imported) retval = false; if (!chr->config_read_database(filename, &config, imported)) retval = false; + if (!inter->config_read_connection(filename, &config, imported)) + retval = false; if (!pincode->config_read(filename, &config, imported)) retval = false; @@ -6095,8 +6166,8 @@ int do_init(int argc, char **argv) { chr->CHAR_CONF_NAME = aStrdup("conf/char/char-server.conf"); chr->NET_CONF_NAME = aStrdup("conf/network.conf"); - chr->SQL_CONF_NAME = aStrdup("conf/inter-server.conf"); - chr->INTER_CONF_NAME = aStrdup("conf/inter-server.conf"); + chr->SQL_CONF_NAME = aStrdup("conf/common/inter-server.conf"); + chr->INTER_CONF_NAME = aStrdup("conf/common/inter-server.conf"); VECTOR_INIT(start_items); @@ -6123,18 +6194,25 @@ int do_init(int argc, char **argv) { cmdline->exec(argc, argv, CMDLINE_OPT_NORMAL); chr->config_read(chr->CHAR_CONF_NAME, false); sockt->net_config_read(chr->NET_CONF_NAME); - chr->sql_config_read(chr->SQL_CONF_NAME); + chr->sql_config_read(chr->SQL_CONF_NAME, false); { // TODO: Remove this when no longer needed. +#define CHECK_OLD_LOCAL_CONF(oldname, newname) do { \ + if (stat((oldname), &fileinfo) == 0 && fileinfo.st_size > 0) { \ + ShowWarning("An old configuration file \"%s\" was found.\n", (oldname)); \ + ShowWarning("If it contains settings you wish to keep, please merge them into \"%s\".\n", (newname)); \ + ShowWarning("Otherwise, just delete it.\n"); \ + ShowInfo("Resuming in 10 seconds...\n"); \ + HSleep(10); \ + } \ +} while (0) struct stat fileinfo; - if (stat("conf/import/char_conf.txt", &fileinfo) == 0 && fileinfo.st_size > 0) { - ShowWarning("An old configuration file \"conf/import/char_conf.txt\" was found.\n"); - ShowWarning("If it contains settings you wish to keep, please merge them into \"conf/import/char-server_local.conf\".\n"); - ShowWarning("Otherwise, just delete it.\n"); - ShowInfo("Resuming in 10 seconds...\n"); - HSleep(10); - } + + CHECK_OLD_LOCAL_CONF("conf/import/char_conf.txt", "conf/import/char-server.conf"); + CHECK_OLD_LOCAL_CONF("conf/import/inter_conf.txt", "conf/import/inter-server.conf"); + +#undef CHECK_OLD_LOCAL_CONF } #ifndef BUILDBOT @@ -6425,6 +6503,9 @@ void char_defaults(void) chr->online_data_cleanup_sub = char_online_data_cleanup_sub; chr->online_data_cleanup = char_online_data_cleanup; chr->sql_config_read = char_sql_config_read; + chr->sql_config_read_registry = char_sql_config_read_registry; + chr->sql_config_read_pc = char_sql_config_read_pc; + chr->sql_config_read_guild = char_sql_config_read_guild; chr->config_read = char_config_read; chr->config_read_database = char_config_read_database; chr->config_read_console = char_config_read_console; diff --git a/src/char/char.h b/src/char/char.h index 74478b747..4dbdfd9db 100644 --- a/src/char/char.h +++ b/src/char/char.h @@ -279,8 +279,11 @@ struct char_interface { int (*check_connect_login_server) (int tid, int64 tick, int id, intptr_t data); int (*online_data_cleanup_sub) (union DBKey key, struct DBData *data, va_list ap); int (*online_data_cleanup) (int tid, int64 tick, int id, intptr_t data); - void (*sql_config_read) (const char* cfgName); + bool (*sql_config_read) (const char *filename, bool imported); + bool (*sql_config_read_registry) (const char *filename, const struct config_t *config, bool imported); + bool (*sql_config_read_pc) (const char *filename, const struct config_t *config, bool imported); + bool (*sql_config_read_guild) (const char *filename, const struct config_t *config, bool imported); bool (*config_read) (const char *filename, bool imported); bool (*config_read_database) (const char *filename, const struct config_t *config, bool imported); bool (*config_read_console) (const char *filename, const struct config_t *config, bool imported); diff --git a/src/char/inter.c b/src/char/inter.c index d1b885eed..4c5eb05e5 100644 --- a/src/char/inter.c +++ b/src/char/inter.c @@ -36,6 +36,7 @@ #include "char/int_storage.h" #include "char/mapif.h" #include "common/cbasetypes.h" +#include "common/conf.h" #include "common/db.h" #include "common/memmgr.h" #include "common/mmo.h" @@ -62,7 +63,7 @@ char char_server_pw[100] = "ragnarok"; char char_server_db[32] = "ragnarok"; char default_codepage[32] = ""; //Feature by irmin. -unsigned int party_share_level = 10; +int party_share_level = 10; // recv. packet list int inter_recv_packet_length[] = { @@ -791,50 +792,84 @@ int inter_accreg_fromsql(int account_id,int char_id, int fd, int type) return 1; } -/*========================================== - * read config file - *------------------------------------------*/ -static int inter_config_read(const char* cfgName) +/** + * Reads the 'char_configuration/sql_connection' config entry and initializes required variables. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool inter_config_read_connection(const char *filename, const struct config_t *config, bool imported) { - char line[1024], w1[1024], w2[1024]; - FILE* fp; + const struct config_setting_t *setting = NULL; - nullpo_retr(1, cfgName); - fp = fopen(cfgName, "r"); - if(fp == NULL) { - ShowError("File not found: %s\n", cfgName); - return 1; + nullpo_retr(false, filename); + nullpo_retr(false, config); + + if ((setting = libconfig->lookup(config, "char_configuration/sql_connection")) == NULL) { + if (imported) + return true; + ShowError("char_config_read: char_configuration/sql_connection was not found in %s!\n", filename); + ShowWarning("inter_config_read_connection: Defaulting sql_connection...\n"); + return false; } - while (fgets(line, sizeof(line), fp)) { - int i = sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2); - if(i != 2) - continue; + libconfig->setting_lookup_int(setting, "db_port", &char_server_port); + libconfig->setting_lookup_mutable_string(setting, "db_hostname", char_server_ip, sizeof(char_server_ip)); + libconfig->setting_lookup_mutable_string(setting, "db_username", char_server_id, sizeof(char_server_id)); + libconfig->setting_lookup_mutable_string(setting, "db_password", char_server_pw, sizeof(char_server_pw)); + libconfig->setting_lookup_mutable_string(setting, "db_database", char_server_db, sizeof(char_server_db)); + libconfig->setting_lookup_mutable_string(setting, "default_codepage", default_codepage, sizeof(default_codepage)); + + return true; +} - if(!strcmpi(w1,"char_server_ip")) { - safestrncpy(char_server_ip, w2, sizeof(char_server_ip)); - } else if(!strcmpi(w1,"char_server_port")) { - char_server_port = atoi(w2); - } else if(!strcmpi(w1,"char_server_id")) { - safestrncpy(char_server_id, w2, sizeof(char_server_id)); - } else if(!strcmpi(w1,"char_server_pw")) { - safestrncpy(char_server_pw, w2, sizeof(char_server_pw)); - } else if(!strcmpi(w1,"char_server_db")) { - safestrncpy(char_server_db, w2, sizeof(char_server_db)); - } else if(!strcmpi(w1,"default_codepage")) { - safestrncpy(default_codepage, w2, sizeof(default_codepage)); - } else if(!strcmpi(w1,"party_share_level")) - party_share_level = atoi(w2); - else if(!strcmpi(w1,"log_inter")) - inter->enable_logs = atoi(w2) ? true : false; - else if(!strcmpi(w1,"import")) - inter->config_read(w2); +/** + * Reads the 'inter_configuration' config file and initializes required variables. + * + * @param filename Path to configuration file + * @param imported Whether the current config is from an imported file. + * + * @retval false in case of error. + */ +bool inter_config_read(const char *filename, bool imported) +{ + struct config_t config; + const struct config_setting_t *setting = NULL; + const char *import = NULL; + bool retval = true; + + nullpo_retr(false, filename); + + if (!libconfig->load_file(&config, filename)) + return false; + + if ((setting = libconfig->lookup(&config, "inter_configuration")) == NULL) { + libconfig->destroy(&config); + if (imported) + return true; + ShowError("inter_config_read: inter_configuration was not found in %s!\n", filename); + return false; } - fclose(fp); + libconfig->setting_lookup_int(setting, "party_share_level", &party_share_level); + libconfig->setting_lookup_bool_real(setting, "log_inter", &inter->enable_logs); - ShowInfo ("Done reading %s.\n", cfgName); + ShowInfo("Done reading %s.\n", filename); - return 0; + // import should overwrite any previous configuration, so it should be called last + if (libconfig->lookup_string(&config, "import", &import) == CONFIG_TRUE) { + if (strcmp(import, filename) == 0 || strcmp(import, chr->INTER_CONF_NAME) == 0) { + ShowWarning("inter_config_read: Loop detected in %s! Skipping 'import'...\n", filename); + } else { + if (!inter->config_read(import, true)) + retval = false; + } + } + + libconfig->destroy(&config); + return retval; } /** @@ -879,9 +914,7 @@ int inter_log(char* fmt, ...) // initialize int inter_init_sql(const char *file) { - //int i; - - inter->config_read(file); + inter->config_read(file, false); //DB connection initialized inter->sql_handle = SQL->Malloc(); @@ -1385,4 +1418,5 @@ void inter_defaults(void) inter->check_length = inter_check_length; inter->parse_frommap = inter_parse_frommap; inter->final = inter_final; + inter->config_read_connection = inter_config_read_connection; } diff --git a/src/char/inter.h b/src/char/inter.h index db50fd645..57d1db86c 100644 --- a/src/char/inter.h +++ b/src/char/inter.h @@ -28,6 +28,7 @@ /* Forward Declarations */ struct Sql; // common/sql.h +struct config_t; // common/conf.h /** * inter interface @@ -43,7 +44,6 @@ struct inter_interface { void (*msg_to_fd) (int fd, int u_fd, int aid, char *msg, ...) __attribute__((format(printf, 4, 5))); void (*savereg) (int account_id, int char_id, const char *key, unsigned int index, intptr_t val, bool is_string); int (*accreg_fromsql) (int account_id,int char_id, int fd, int type); - int (*config_read) (const char* cfgName); int (*vlog) (char* fmt, va_list ap); int (*log) (char* fmt, ...); int (*init_sql) (const char *file); @@ -53,10 +53,12 @@ struct inter_interface { int (*check_length) (int fd, int length); int (*parse_frommap) (int fd); void (*final) (void); + bool (*config_read) (const char *filename, bool imported); + bool (*config_read_connection) (const char *filename, const struct config_t *config, bool imported); }; #ifdef HERCULES_CORE -extern unsigned int party_share_level; +extern int party_share_level; ///< Share range for parties. void inter_defaults(void); #endif // HERCULES_CORE diff --git a/src/common/sql.c b/src/common/sql.c index 9a90f9807..be0bd43e3 100644 --- a/src/common/sql.c +++ b/src/common/sql.c @@ -2,7 +2,7 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2012-2015 Hercules Dev Team + * Copyright (C) 2012-2016 Hercules Dev Team * Copyright (C) Athena Dev Teams * * Hercules is free software: you can redistribute it and/or modify @@ -23,7 +23,9 @@ #include "sql.h" #include "common/cbasetypes.h" +#include "common/conf.h" #include "common/memmgr.h" +#include "common/nullpo.h" #include "common/showmsg.h" #include "common/strlib.h" #include "common/timer.h" @@ -37,8 +39,8 @@ void hercules_mysql_error_handler(unsigned int ecode); -int mysql_reconnect_type; -unsigned int mysql_reconnect_count; +int mysql_reconnect_type = 2; +int mysql_reconnect_count = 1; struct sql_interface sql_s; struct sql_interface *SQL; @@ -868,55 +870,67 @@ void hercules_mysql_error_handler(unsigned int ecode) { switch( ecode ) { case 2003:/* Can't connect to MySQL (this error only happens here when failing to reconnect) */ if( mysql_reconnect_type == 1 ) { - static unsigned int retry = 1; + static int retry = 1; if( ++retry > mysql_reconnect_count ) { - ShowFatalError("MySQL has been unreachable for too long, %u reconnects were attempted. Shutting Down\n", retry); + ShowFatalError("MySQL has been unreachable for too long, %d reconnects were attempted. Shutting Down\n", retry); exit(EXIT_FAILURE); } } break; } } -void Sql_inter_server_read(const char* cfgName, bool first) { - char line[1024], w1[1024], w2[1024]; - FILE* fp; - - fp = fopen(cfgName, "r"); - if(fp == NULL) { - if( first ) { - ShowFatalError("File not found: %s\n", cfgName); - exit(EXIT_FAILURE); - } else - ShowError("File not found: %s\n", cfgName); - return; + +/** + * Parses mysql_reconnect from inter_configuration. + * + * @param filename Path to configuration file. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool Sql_inter_server_read(const char *filename, bool imported) +{ + struct config_t config; + const struct config_setting_t *setting = NULL; + const char *import = NULL; + bool retval = true; + + nullpo_retr(false, filename); + + if (!libconfig->load_file(&config, filename)) + return false; + + if ((setting = libconfig->lookup(&config, "inter_configuration/mysql_reconnect")) == NULL) { + config_destroy(&config); + if (imported) + return true; + ShowError("Sql_inter_server_read: inter_configuration/mysql_reconnect was not found in %s!\n", filename); + return false; } - while (fgets(line, sizeof(line), fp)) { - int i = sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2); - if (i != 2) - continue; + if (libconfig->setting_lookup_int(setting, "type", &mysql_reconnect_type) == CONFIG_TRUE) { + if (mysql_reconnect_type != 1 && mysql_reconnect_type != 2) { + ShowError("%s::inter_configuration/mysql_reconnect/type is set to %d which is not valid, defaulting to 1...\n", filename, mysql_reconnect_type); + mysql_reconnect_type = 1; + } + } + if (libconfig->setting_lookup_int(setting, "count", &mysql_reconnect_count) == CONFIG_TRUE) { + if (mysql_reconnect_count < 1) + mysql_reconnect_count = 1; + } - if(!strcmpi(w1,"mysql_reconnect_type")) { - mysql_reconnect_type = atoi(w2); - switch( mysql_reconnect_type ) { - case 1: - case 2: - break; - default: - ShowError("%s::mysql_reconnect_type is set to %d which is not valid, defaulting to 1...\n", cfgName, mysql_reconnect_type); - mysql_reconnect_type = 1; - break; - } - } else if(!strcmpi(w1,"mysql_reconnect_count")) { - mysql_reconnect_count = atoi(w2); - if( mysql_reconnect_count < 1 ) - mysql_reconnect_count = 1; - } else if(!strcmpi(w1,"import")) - Sql_inter_server_read(w2,false); + // import should overwrite any previous configuration, so it should be called last + if (libconfig->lookup_string(&config, "import", &import) == CONFIG_TRUE) { + if (strcmp(import, filename) == 0 || strcmp(import, "conf/common/inter-server.conf") == 0) { // FIXME: Hardcoded path + ShowWarning("Sql_inter_server_read: Loop detected in %s! Skipping 'import'...\n", filename); + } else { + if (!Sql_inter_server_read(import, true)) + retval = false; + } } - fclose(fp); - return; + libconfig->destroy(&config); + return retval; } void Sql_HerculesUpdateCheck(struct Sql *self) @@ -1019,7 +1033,7 @@ void Sql_HerculesUpdateSkip(struct Sql *self, const char *filename) } void Sql_Init(void) { - Sql_inter_server_read("conf/inter-server.conf",true); + Sql_inter_server_read("conf/common/inter-server.conf", false); // FIXME: Hardcoded path } void sql_defaults(void) { SQL = &sql_s; diff --git a/src/common/sql.h b/src/common/sql.h index 07be829fc..4d9a12cc1 100644 --- a/src/common/sql.h +++ b/src/common/sql.h @@ -2,7 +2,7 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2012-2015 Hercules Dev Team + * Copyright (C) 2012-2016 Hercules Dev Team * Copyright (C) Athena Dev Teams * * Hercules is free software: you can redistribute it and/or modify diff --git a/src/map/map.c b/src/map/map.c index d6425b94e..56af8113b 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -3997,63 +3997,125 @@ void map_reloadnpc(bool clear) { } } -int inter_config_read(char *cfgName) { - char line[1024],w1[1024],w2[1024]; - FILE *fp; +/** + * Reads inter-server.conf and initializes required variables. + * + * @param filename Path to configuration file + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool inter_config_read(const char *filename, bool imported) +{ + struct config_t config; + const struct config_setting_t *setting = NULL; + const char *import = NULL; + bool retval = true; - nullpo_retr(1, cfgName); - if (!(fp = fopen(cfgName,"r"))) { - ShowError("File not found: %s\n",cfgName); - return 1; + nullpo_retr(false, filename); + + if (!libconfig->load_file(&config, filename)) + return false; + + if ((setting = libconfig->lookup(&config, "inter_configuration")) == NULL) { + libconfig->destroy(&config); + if (imported) + return true; + ShowError("inter_config_read: inter_configuration was not found in %s!\n", filename); + return false; } - while (fgets(line, sizeof(line), fp)) { - if (line[0] == '/' && line[1] == '/') - continue; - if (sscanf(line,"%1023[^:]: %1023[^\r\n]", w1, w2) < 2) - continue; - /* map sql stuff */ - if(strcmpi(w1,"map_server_ip")==0) - safestrncpy(map->server_ip, w2, sizeof(map->server_ip)); - else if(strcmpi(w1,"map_server_port")==0) - map->server_port=atoi(w2); - else if(strcmpi(w1,"map_server_id")==0) - safestrncpy(map->server_id, w2, sizeof(map->server_id)); - else if(strcmpi(w1,"map_server_pw")==0) - safestrncpy(map->server_pw, w2, sizeof(map->server_pw)); - else if(strcmpi(w1,"map_server_db")==0) - safestrncpy(map->server_db, w2, sizeof(map->server_db)); - else if(strcmpi(w1,"default_codepage")==0) - safestrncpy(map->default_codepage, w2, sizeof(map->default_codepage)); - else if(strcmpi(w1,"autotrade_merchants_db")==0) - safestrncpy(map->autotrade_merchants_db, w2, sizeof(map->autotrade_merchants_db)); - else if(strcmpi(w1,"autotrade_data_db")==0) - safestrncpy(map->autotrade_data_db, w2, sizeof(map->autotrade_data_db)); - else if(strcmpi(w1,"npc_market_data_db")==0) - safestrncpy(map->npc_market_data_db, w2, sizeof(map->npc_market_data_db)); - /* sql log db */ - else if(strcmpi(w1,"log_db_ip")==0) - safestrncpy(logs->db_ip, w2, sizeof(logs->db_ip)); - else if(strcmpi(w1,"log_db_id")==0) - safestrncpy(logs->db_id, w2, sizeof(logs->db_id)); - else if(strcmpi(w1,"log_db_pw")==0) - safestrncpy(logs->db_pw, w2, sizeof(logs->db_pw)); - else if(strcmpi(w1,"log_db_port")==0) - logs->db_port = atoi(w2); - else if(strcmpi(w1,"log_db_db")==0) - safestrncpy(logs->db_name, w2, sizeof(logs->db_name)); - /* mapreg */ - else if( mapreg->config_read(w1,w2) ) - continue; - /* import */ - else if(strcmpi(w1,"import")==0) - map->inter_config_read(w2); - else - HPM->parseConf(w1, w2, HPCT_MAP_INTER); + if (!map->inter_config_read_database_names(filename, &config, imported)) + retval = false; + if (!map->inter_config_read_connection(filename, &config, imported)) + retval = false; + + // TODO HPM->parseConf(w1, w2, HPCT_MAP_INTER); + + // import should overwrite any previous configuration, so it should be called last + if (libconfig->lookup_string(&config, "import", &import) == CONFIG_TRUE) { + if (strcmp(import, filename) == 0 || strcmp(import, map->INTER_CONF_NAME) == 0) { + ShowWarning("inter_config_read: Loop detected in %s! Skipping 'import'...\n", filename); + } else { + if (!map->inter_config_read(import, true)) + retval = false; + } } - fclose(fp); - return 0; + libconfig->destroy(&config); + return retval; +} + +/** + * Reads the 'inter_configuration/log/sql_connection' config entry and initializes required variables. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool inter_config_read_connection(const char *filename, const struct config_t *config, bool imported) +{ + const struct config_setting_t *setting = NULL; + + nullpo_retr(false, filename); + nullpo_retr(false, config); + + if ((setting = libconfig->lookup(config, "inter_configuration/log/sql_connection")) == NULL) { + if (imported) + return true; + ShowError("inter_config_read: inter_configuration/log/sql_connection was not found in %s!\n", filename); + return false; + } + + libconfig->setting_lookup_int(setting, "port", &logs->db_port); + libconfig->setting_lookup_mutable_string(setting, "db_hostname", logs->db_ip, sizeof(logs->db_ip)); + libconfig->setting_lookup_mutable_string(setting, "db_username", logs->db_id, sizeof(logs->db_id)); + libconfig->setting_lookup_mutable_string(setting, "db_password", logs->db_pw, sizeof(logs->db_pw)); + libconfig->setting_lookup_mutable_string(setting, "db_database", logs->db_name, sizeof(logs->db_name)); + + return true; +} + +/** + * Reads the 'inter_configuration/database_names' config entry and initializes required variables. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool inter_config_read_database_names(const char *filename, const struct config_t *config, bool imported) +{ + const struct config_setting_t *setting = NULL; + bool retval = true; + + nullpo_retr(false, filename); + nullpo_retr(false, config); + + if ((setting = libconfig->lookup(config, "inter_configuration/database_names")) == NULL) { + if (imported) + return true; + ShowError("inter_config_read: inter_configuration/database_names was not found in %s!\n", filename); + return false; + } + + libconfig->setting_lookup_mutable_string(setting, "autotrade_merchants_db", map->autotrade_merchants_db, sizeof(map->autotrade_merchants_db)); + libconfig->setting_lookup_mutable_string(setting, "autotrade_data_db", map->autotrade_data_db, sizeof(map->autotrade_data_db)); + libconfig->setting_lookup_mutable_string(setting, "npc_market_data_db", map->npc_market_data_db, sizeof(map->npc_market_data_db)); + + if (!mapreg->config_read(filename, setting, imported)) + retval = false; + + if ((setting = libconfig->lookup(config, "inter_configuration/database_names/registry")) == NULL) { + if (imported) + return retval; + ShowError("inter_config_read: inter_configuration/database_names/registry was not found in %s!\n", filename); + return false; + } + return retval; } /*======================================= @@ -6077,7 +6139,7 @@ int do_init(int argc, char *argv[]) map_load_defaults(); - map->INTER_CONF_NAME = aStrdup("conf/inter-server.conf"); + map->INTER_CONF_NAME = aStrdup("conf/common/inter-server.conf"); map->LOG_CONF_NAME = aStrdup("conf/logs.conf"); map->MAP_CONF_NAME = aStrdup("conf/map-server.conf"); map->BATTLE_CONF_FILENAME = aStrdup("conf/battle.conf"); @@ -6128,7 +6190,7 @@ int do_init(int argc, char *argv[]) battle->config_read(map->BATTLE_CONF_FILENAME); atcommand->msg_read(map->MSG_CONF_NAME, false); - map->inter_config_read(map->INTER_CONF_NAME); + map->inter_config_read(map->INTER_CONF_NAME, false); logs->config_read(map->LOG_CONF_NAME); } script->config_read(map->SCRIPT_CONF_NAME); @@ -6288,7 +6350,7 @@ void map_defaults(void) { map->night_flag = 0; // 0=day, 1=night [Yor] map->enable_spy = 0; //To enable/disable @spy commands, which consume too much cpu time when sending packets. [Skotlex] - map->INTER_CONF_NAME="conf/inter-server.conf"; + map->INTER_CONF_NAME="conf/common/inter-server.conf"; map->LOG_CONF_NAME="conf/logs.conf"; map->MAP_CONF_NAME = "conf/map-server.conf"; map->BATTLE_CONF_FILENAME = "conf/battle.conf"; @@ -6502,6 +6564,8 @@ void map_defaults(void) { map->config_read_sub = map_config_read_sub; map->reloadnpc_sub = map_reloadnpc_sub; map->inter_config_read = inter_config_read; + map->inter_config_read_database_names = inter_config_read_database_names; + map->inter_config_read_connection = inter_config_read_connection; map->sql_init = map_sql_init; map->sql_close = map_sql_close; map->zone_mf_cache = map_zone_mf_cache; diff --git a/src/map/map.h b/src/map/map.h index dbd30febf..f98e1cb7f 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -2,7 +2,7 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2012-2015 Hercules Dev Team + * Copyright (C) 2012-2016 Hercules Dev Team * Copyright (C) Athena Dev Teams * * Hercules is free software: you can redistribute it and/or modify @@ -33,6 +33,7 @@ /* Forward Declarations */ struct Sql; // common/sql.h +struct config_t; // common/conf.h struct mob_data; struct npc_data; struct channel_data; @@ -1190,7 +1191,9 @@ END_ZEROED_BLOCK; int (*config_read) (char *cfgName); int (*config_read_sub) (char *cfgName); void (*reloadnpc_sub) (char *cfgName); - int (*inter_config_read) (char *cfgName); + bool (*inter_config_read) (const char *filename, bool imported); + bool (*inter_config_read_database_names) (const char *filename, const struct config_t *config, bool imported); + bool (*inter_config_read_connection) (const char *filename, const struct config_t *config, bool imported); int (*sql_init) (void); int (*sql_close) (void); bool (*zone_mf_cache) (int m, char *flag, char *params); diff --git a/src/map/mapreg.h b/src/map/mapreg.h index d19b2bb80..642bce48e 100644 --- a/src/map/mapreg.h +++ b/src/map/mapreg.h @@ -2,7 +2,7 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2012-2015 Hercules Dev Team + * Copyright (C) 2012-2016 Hercules Dev Team * Copyright (C) Athena Dev Teams * * Hercules is free software: you can redistribute it and/or modify @@ -25,6 +25,8 @@ #include "common/hercules.h" #include "common/db.h" +/* Forward Declarations */ +struct config_setting_t; // common/conf.h struct eri; /** Container for a mapreg value */ @@ -61,7 +63,7 @@ struct mapreg_interface { int (*save_timer) (int tid, int64 tick, int id, intptr_t data); int (*destroyreg) (union DBKey key, struct DBData *data, va_list ap); void (*reload) (void); - bool (*config_read) (const char *w1, const char *w2); + bool (*config_read) (const char *filename, const struct config_setting_t *config, bool imported); }; #ifdef HERCULES_CORE diff --git a/src/map/mapreg_sql.c b/src/map/mapreg_sql.c index 82ce39d64..4cdb91b21 100644 --- a/src/map/mapreg_sql.c +++ b/src/map/mapreg_sql.c @@ -2,7 +2,7 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2012-2015 Hercules Dev Team + * Copyright (C) 2012-2016 Hercules Dev Team * Copyright (C) Athena Dev Teams * * Hercules is free software: you can redistribute it and/or modify @@ -25,6 +25,7 @@ #include "map/map.h" // map-"mysql_handle #include "map/script.h" #include "common/cbasetypes.h" +#include "common/conf.h" #include "common/db.h" #include "common/ers.h" #include "common/memmgr.h" @@ -349,13 +350,19 @@ void mapreg_init(void) { /** * Loads the mapreg configuration file. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. */ -bool mapreg_config_read(const char* w1, const char* w2) { - nullpo_retr(false, w1); - nullpo_retr(false, w2); - if(!strcmpi(w1, "mapreg_db")) - safestrncpy(mapreg->table, w2, sizeof(mapreg->table)); - else +bool mapreg_config_read(const char *filename, const struct config_setting_t *config, bool imported) +{ + nullpo_retr(false, filename); + nullpo_retr(false, config); + + if (libconfig->setting_lookup_mutable_string(config, "mapreg_db", mapreg->table, sizeof(mapreg->table)) != CONFIG_TRUE) return false; return true; diff --git a/tools/configconverter.pl b/tools/configconverter.pl index 2849270de..c49dc95d9 100755 --- a/tools/configconverter.pl +++ b/tools/configconverter.pl @@ -263,6 +263,83 @@ my @defaults = ( import => {parse => \&parsecfg_string, print => \&printcfg_nil, path => "", default => "conf/import/char_conf.txt"}, } }, + { + files => ['inter-server.conf', 'import/inter_conf.txt'], + settings => { + party_share_level => {parse => \&parsecfg_int, print => \&printcfg_int, path => "inter-server:inter_configuration/", default => 15}, + log_inter => {parse => \&parsecfg_bool, print => \&printcfg_bool, path => "inter-server:inter_configuration/log/", default => "true"}, + inter_log_filename => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/log/", default => "log/inter.log"}, + mysql_reconnect_type => {parse => \&parsecfg_int, print => \&printcfg_int, path => "inter-server:inter_configuration/mysql_reconnect/type", default => 2}, + mysql_reconnect_count => {parse => \&parsecfg_int, print => \&printcfg_int, path => "inter-server:inter_configuration/mysql_reconnect/count", default => 1}, + log_login_db => {parse => \&parsecfg_string, print => \&printcfg_nil, path => "inter-server:inter_configuration/database_names/login_db", default => "loginlog"}, + char_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/", default => "char"}, + interlog_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/", default => "interlog"}, + ragsrvinfo_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/", default => "ragsrvinfo"}, + acc_reg_num_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/registry/", default => "acc_reg_num_db"}, + acc_reg_str_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/registry/", default => "acc_reg_str_db"}, + char_reg_num_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/registry/", default => "char_reg_num_db"}, + char_reg_str_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/registry/", default => "char_reg_str_db"}, + global_acc_reg_num_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/registry/", default => "global_acc_reg_num_db"}, + global_acc_reg_str_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/registry/", default => "global_acc_reg_str_db"}, + hotkey_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/pc/", default => "hotkey"}, + scdata_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/pc/", default => "sc_data"}, + cart_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/pc/", default => "cart_inventory"}, + inventory_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/pc/", default => "inventory"}, + charlog_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/pc/", default => "charlog"}, + storage_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/pc/", default => "storage"}, + skill_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/pc/", default => "skill"}, + memo_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/pc/", default => "memo"}, + party_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/pc/", default => "party"}, + pet_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/pc/", default => "pet"}, + friend_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/pc/", default => "friends"}, + mail_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/pc/", default => "mail"}, + auction_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/pc/", default => "auction"}, + quest_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/pc/", default => "quest"}, + homunculus_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/pc/", default => "homunculus"}, + skill_homunculus_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/pc/", default => "skill_homunculus"}, + mercenary_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/pc/", default => "mercenary"}, + mercenary_owner_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/pc/", default => "mercenary_owner"}, + elemental_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/pc/", default => "elemental"}, + account_data_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/pc/", default => "account_data"}, + guild_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/guild/main_db", default => "guild"}, + guild_alliance_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/guild/alliance_db", default => "guild_alliance"}, + guild_castle_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/guild/castle_db", default => "guild_castle"}, + guild_expulsion_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/guild/expulsion_db", default => "guild_expulsion"}, + guild_member_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/guild/member_db", default => "guild_member"}, + guild_skill_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/guild/skill_db", default => "guild_skill"}, + guild_position_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/guild/position_db", default => "guild_position"}, + guild_storage_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/guild/storage_db", default => "guild_storage"}, + mapreg_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/", default => "mapreg"}, + autotrade_merchants_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/", default => "autotrade_merchants"}, + autotrade_data_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/", default => "autotrade_data"}, + npc_market_data_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/", default => "npc_market_data"}, + default_codepage => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/", default => ""}, + 'sql.db_hostname' => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/db_hostname", default => "127.0.0.1"}, + char_server_ip => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/db_hostname", default => "127.0.0.1"}, + map_server_ip => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/db_hostname", default => "127.0.0.1"}, + log_db_ip => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/db_hostname", default => "127.0.0.1"}, + 'sql.db_port' => {parse => \&parsecfg_int, print => \&printcfg_int, path => "sql_connection:sql_connection/db_port", default => 3306}, + char_server_port => {parse => \&parsecfg_int, print => \&printcfg_int, path => "sql_connection:sql_connection/db_port", default => 3306}, + map_server_port => {parse => \&parsecfg_int, print => \&printcfg_int, path => "sql_connection:sql_connection/db_port", default => 3306}, + log_db_port => {parse => \&parsecfg_int, print => \&printcfg_int, path => "sql_connection:sql_connection/db_port", default => 3306}, + 'sql.db_username' => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/db_username", default => "ragnarok"}, + char_server_id => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/db_username", default => "ragnarok"}, + map_server_id => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/db_username", default => "ragnarok"}, + log_db_id => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/db_username", default => "ragnarok"}, + 'sql.db_password' => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/db_password", default => "ragnarok"}, + char_server_pw => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/db_password", default => "ragnarok"}, + map_server_pw => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/db_password", default => "ragnarok"}, + log_db_pw => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/db_password", default => "ragnarok"}, + 'sql.db_database' => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/db_database", default => "ragnarok"}, + char_server_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/db_database", default => "ragnarok"}, + map_server_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/db_database", default => "ragnarok"}, + log_db_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/db_database", default => "ragnarok"}, + 'sql.codepage' => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/codepage", default => ""}, + log_codepage => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/codepage", default => ""}, + interreg_db => {parse => \&parsecfg_string, print => \&printcfg_nil, path => "", default => "interreg"}, + import => {parse => \&parsecfg_string, print => \&printcfg_nil, path => "", default => "conf/import/inter_conf.txt"}, + } + }, ); for (@ARGV) { -- cgit v1.2.3-70-g09d2 From f56264d23d9cc86a87331401496e206639cdd6e3 Mon Sep 17 00:00:00 2001 From: Haru Date: Thu, 11 Feb 2016 00:41:54 +0100 Subject: Ported login-server.conf to libconfig Ported to modern Hercules and cleaned up from Panikon's commits: ceb8a486ac47c2ed9aae4baa1ec39a11f31e9368, c1049123a4ea6ae6f0992ffe766db8aed7435ab5, 6feb097046355610d2288670a569ccc175358580, 9f6e27a96d655f2b4555310786d9d10898754404, 21fa5d24255ba026f96b1dbedf74ac5ef831d3ae, e22a56ad4def8ca22e94d44377a5364b9db1a425, f753a754923140bfec02057c16e6e8429b863d0e, 25dde7e46524ace330b83cb4bf0255cc4d796792 Signed-off-by: Haru --- .gitignore | 1 - conf/common/inter-server.conf | 3 + conf/global/sql_connection.conf | 3 + conf/import-tmpl/login-server.conf | 32 +++ conf/import-tmpl/login_conf.txt | 0 conf/login-server.conf | 156 ----------- conf/login/login-server.conf | 187 +++++++++++++ doc/md5_hashcheck.txt | 24 +- src/login/account.h | 10 +- src/login/account_sql.c | 243 +++++++--------- src/login/ipban.h | 9 +- src/login/ipban_sql.c | 281 ++++++++++--------- src/login/login.c | 547 ++++++++++++++++++++++++++++--------- src/login/login.h | 17 +- src/login/loginlog.h | 4 +- src/login/loginlog_sql.c | 198 +++++++------- tools/configconverter.pl | 110 +++++++- 17 files changed, 1142 insertions(+), 683 deletions(-) create mode 100644 conf/import-tmpl/login-server.conf delete mode 100644 conf/import-tmpl/login_conf.txt delete mode 100644 conf/login-server.conf create mode 100644 conf/login/login-server.conf (limited to 'conf') diff --git a/.gitignore b/.gitignore index 3302e44cf..bd33fac60 100644 --- a/.gitignore +++ b/.gitignore @@ -62,7 +62,6 @@ Thumbs.db /conf/import/*.conf /conf/import/battle_conf.txt /conf/import/log_conf.txt -/conf/import/login_conf.txt /conf/import/map_conf.txt /conf/import/msg_conf.txt /conf/import/packet_conf.txt diff --git a/conf/common/inter-server.conf b/conf/common/inter-server.conf index fd55b27e5..888d4ad80 100644 --- a/conf/common/inter-server.conf +++ b/conf/common/inter-server.conf @@ -65,6 +65,9 @@ inter_configuration: { // this is meant for people who KNOW their stuff, and for some reason want to change their // database layout. [CLOWNISIUS] database_names: { + account_db: "login" + login_db: "loginlog" + ipban_table: "ipbanlist" char_db: "char" interlog_db: "interlog" ragsrvinfo_db: "ragsrvinfo" diff --git a/conf/global/sql_connection.conf b/conf/global/sql_connection.conf index 58c9e6d08..60fea5656 100644 --- a/conf/global/sql_connection.conf +++ b/conf/global/sql_connection.conf @@ -36,6 +36,9 @@ sql_connection: { // (Note that this feature requires MySQL 4.1+) //default_codepage: "" + // [LOGIN] Is `userid` in account_db case sensitive? + //case_sensitive: false + // For IPs, ideally under linux, you want to use localhost instead of 127.0.0.1. // Under windows, you want to use 127.0.0.1. If you see a message like // "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)" diff --git a/conf/import-tmpl/login-server.conf b/conf/import-tmpl/login-server.conf new file mode 100644 index 000000000..feadef976 --- /dev/null +++ b/conf/import-tmpl/login-server.conf @@ -0,0 +1,32 @@ +//================= Hercules Configuration ================================ +//= _ _ _ +//= | | | | | | +//= | |_| | ___ _ __ ___ _ _| | ___ ___ +//= | _ |/ _ \ '__/ __| | | | |/ _ \/ __| +//= | | | | __/ | | (__| |_| | | __/\__ \ +//= \_| |_/\___|_| \___|\__,_|_|\___||___/ +//================= License =============================================== +//= This file is part of Hercules. +//= http://herc.ws - http://github.com/HerculesWS/Hercules +//= +//= Copyright (C) 2014-2016 Hercules Dev Team +//= +//= Hercules is free software: you can redistribute it and/or modify +//= it under the terms of the GNU General Public License as published by +//= the Free Software Foundation, either version 3 of the License, or +//= (at your option) any later version. +//= +//= This program is distributed in the hope that it will be useful, +//= but WITHOUT ANY WARRANTY; without even the implied warranty of +//= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//= GNU General Public License for more details. +//= +//= You should have received a copy of the GNU General Public License +//= along with this program. If not, see . +//========================================================================= +//= Login Server local configuration file. +//========================================================================= + +login_configuration: { + // See conf/login/login-server.conf for details +} diff --git a/conf/import-tmpl/login_conf.txt b/conf/import-tmpl/login_conf.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/conf/login-server.conf b/conf/login-server.conf deleted file mode 100644 index 620fae327..000000000 --- a/conf/login-server.conf +++ /dev/null @@ -1,156 +0,0 @@ -// Hercules Login Server configuration file. -// Translated by Peter Kieser - -// Note: "Comments" are all text on the right side of a double slash "//" -// Whatever text is commented will not be parsed by the servers, and serves -// only as information/reference. - -// The login server listens on the interface with this IP address. -// NOTE: This allows you to run multiple servers on multiple interfaces -// while using the same ports for each server. -//bind_ip: 127.0.0.1 - -// Login Server Port -login_port: 6900 - -//Time-stamp format which will be printed before all messages. -//Can at most be 20 characters long. -//Common formats: -// %I:%M:%S %p (hour:minute:second 12 hour, AM/PM format) -// %H:%M:%S (hour:minute:second, 24 hour format) -// %d/%b/%Y (day/Month/year) -//For full format information, consult the strftime() manual. -//timestamp_format: [%d/%b %H:%M] - -//If redirected output contains escape sequences (color codes) -stdout_with_ansisequence: no - -//Makes server output more silent by omitting certain types of messages: -//1: Hide Information messages -//2: Hide Status messages -//4: Hide Notice Messages -//8: Hide Warning Messages -//16: Hide Error and SQL Error messages. -//32: Hide Debug Messages -//Example: "console_silent: 7" Hides information, status and notice messages (1+2+4) -console_silent: 0 - -// Can you use _M/_F to make new accounts on the server? -new_account: yes - -//If new_account is enabled, minimum length to userid and passwords should be 4? -//Must be 'Yes' unless your client uses both 'Disable 4 LetterUserID/Password' Diffs -new_acc_length_limit: yes - -// Account registration flood protection system -// allowed_regs is the number of registrations allowed in time_allowed (in seconds) -allowed_regs: 1 -time_allowed: 10 - -// To log the login server? -// NOTE: The login-sql server needs the login logs to enable dynamic pass failure bans. -log_login: yes - -// Indicate how to display date in logs, to players, etc. -date_format: %Y-%m-%d %H:%M:%S - -// Required account group id to connect to server. -// -1: disabled -// 0 or more: group id -group_id_to_connect: -1 - -// Minimum account group id required to connect to server. -// Will not function if group_id_to_connect config is enabled. -// -1: disabled -// 0 or more: group id -min_group_id_to_connect: -1 - -// Starting additional sec from now for the limited time at creation of account -// -1: new account are created with UNlimited time (default value) -// 0 or more: new accounts was created by addition of the value (in sec) to the actual time (to set first limited time) -start_limited_time: -1 - -// Check The clientversion set in the clientinfo ? -check_client_version: no - -// What version we would allow to connect? (if the options above is enabled..) -client_version_to_connect: 20 - -// Store passwords as MD5 hashes instead of plaintext ? -// NOTE: Will not work with clients that use -use_MD5_passwords: no - -// Ipban features (SQL only) -ipban.enable: yes -//ipban.sql.db_hostname: 127.0.0.1 -//ipban.sql.db_port: 3306 -//ipban.sql.db_username: ragnarok -//ipban.sql.db_password: ragnarok -//ipban.sql.db_database: ragnarok -//ipban.sql.codepage: -//ipban.sql.ipban_table: ipbanlist -// Dynamic password failure ipban system -ipban.dynamic_pass_failure_ban: yes -ipban.dynamic_pass_failure_ban_interval: 5 -ipban.dynamic_pass_failure_ban_limit: 7 -ipban.dynamic_pass_failure_ban_duration: 5 - -// Interval (in seconds) to clean up expired IP bans. 0 = disabled. default = 60. -// NOTE: Even if this is disabled, expired IP bans will be cleaned up on login server start/stop. -// Players will still be able to login if an ipban entry exists but the expiration time has already passed. -ipban_cleanup_interval: 60 - -// Interval (in minutes) to execute a DNS/IP update. Disabled by default. -// Enable it if your server uses a dynamic IP which changes with time. -//ip_sync_interval: 10 - -// DNS Blacklist Blocking -// If enabled, each incoming connection will be tested against the blacklists -// on the specified dnsbl_servers (comma-separated list) -use_dnsbl: no -dnsbl_servers: bl.blocklist.de, socks.dnsbl.sorbs.net -// Here are some free DNS Blacklist Services: http://en.wikipedia.org/wiki/Comparison_of_DNS_blacklists -//============================================================================== -// dnsbl_servers Description -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// bl.blocklist.de IP-Addresses who attack other servers/honeypots over SSH, FTP, IMAP, etc. -// ircbl.ahbl.org AHBL (open proxies, compromised machines, comment spammers) -// safe.dnsbl.sorbs.net All zones in dnsbl.sorbs.net except "recent" and "escalations" -// sbl-xbl.spamhaus.org Spamhaus blacklist (spammers, open proxies) -// socks.dnsbl.sorbs.net Open SOCKS proxy servers -// tor.ahbl.org Current tor relay and exit nodes - - -// Account data storage configuration -// SQL -//account.sql.db_hostname: 127.0.0.1 -//account.sql.db_port: 3306 -//account.sql.db_username: ragnarok -//account.sql.db_password: ragnarok -//account.sql.db_database: ragnarok -//account.sql.codepage: -//account.sql.case_sensitive: no -//account.sql.account_db: login -//account.sql.accreg_db: global_reg_value - -// Client MD5 hash check -// If turned on, the login server will check if the client's hash matches -// the value below, and will not connect tampered clients. -// Note: see doc/md5_hashcheck.txt for more details. -client_hash_check: off - -// Client MD5 hashes -// The client with the specified hash can be used to log in by players with -// a group_id equal to or greater than the given value. -// If you specify 'disabled' as hash, players with a group_id greater than or -// equal to the given value will be able to log in regardless of hash (and even -// if their client does not send a hash at all.) -// Format: group_id, hash -// Note: see doc/md5_hashcheck.txt for more details. -//client_hash: 0, 113e195e6c051bb1cfb12a644bb084c5 -//client_hash: 10, cb1ea78023d337c38e8ba5124e2338ae -//client_hash: 99, disabled - - -import: conf/inter-server.conf -import: conf/import/login_conf.txt diff --git a/conf/login/login-server.conf b/conf/login/login-server.conf new file mode 100644 index 000000000..71928e3d0 --- /dev/null +++ b/conf/login/login-server.conf @@ -0,0 +1,187 @@ +//================= Hercules Configuration ================================ +//= _ _ _ +//= | | | | | | +//= | |_| | ___ _ __ ___ _ _| | ___ ___ +//= | _ |/ _ \ '__/ __| | | | |/ _ \/ __| +//= | | | | __/ | | (__| |_| | | __/\__ \ +//= \_| |_/\___|_| \___|\__,_|_|\___||___/ +//================= License =============================================== +//= This file is part of Hercules. +//= http://herc.ws - http://github.com/HerculesWS/Hercules +//= +//= Copyright (C) 2014-2016 Hercules Dev Team +//= +//= Hercules is free software: you can redistribute it and/or modify +//= it under the terms of the GNU General Public License as published by +//= the Free Software Foundation, either version 3 of the License, or +//= (at your option) any later version. +//= +//= This program is distributed in the hope that it will be useful, +//= but WITHOUT ANY WARRANTY; without even the implied warranty of +//= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//= GNU General Public License for more details. +//= +//= You should have received a copy of the GNU General Public License +//= along with this program. If not, see . +//========================================================================= +//= Login Server configuration file. +//========================================================================= + +login_configuration: { + // Login-server's console configuration + @include "conf/global/console.conf" + + inter: { + // The login server listens on the interface with this IP address. + // NOTE: This allows you to run multiple servers on multiple interfaces + // while using the same ports for each server. + //bind_ip: "127.0.0.1" + + // Login Server Port + login_port: 6900 + + // Interval (in minutes) to execute a DNS/IP update. Disabled by default. + // Enable it if your server uses a dynamic IP which changes with time. + //ip_sync_interval: 10 + } + + log: { + // To log the login server? + // NOTE: The login-sql server needs the login logs to enable dynamic pass failure bans. + log_login: true + + // Indicate how to display date in logs, to players, etc. + date_format: "%Y-%m-%d %H:%M:%S" + } + + // Account engine configuration + account: { + // Can you use _M/_F to make new accounts on the server? + new_account: true + + //If new_account is enabled, minimum length to userid and passwords should be 4? + //Must be 'true' unless your client uses both 'Disable 4 LetterUserID/Password' Diffs + new_acc_length_limit: true + + // Account registration flood protection system + // allowed_regs is the number of registrations allowed in time_allowed (in seconds) + allowed_regs: 1 + time_allowed: 10 + + // Starting additional sec from now for the limited time at creation of account + // -1: new account are created with UNlimited time (default value) + // 0 or more: new accounts was created by addition of the value (in sec) to the actual time (to set first limited time) + start_limited_time: -1 + + // Store passwords as MD5 hashes instead of plaintext ? + // NOTE: Will not work with clients that use + use_MD5_passwords: false + + // Account data engine storage configuration + @include "conf/global/sql_connection.conf" + + //================================================================== + // IP banning system + //================================================================== + ipban: { + enabled: true + + // Interval (in seconds) to clean up expired IP bans. 0 = disabled. default = 60. + // NOTE: Even if this is disabled, expired IP bans will be cleaned up on login server start/stop. + // Players will still be able to login if an ipban entry exists but the expiration time has already passed. + cleanup_interval: 60 + + // SQL connection settings + @include "conf/global/sql_connection.conf" + + // Dynamic password failure ipban system + dynamic_pass_failure: { + enabled: true + + // Interval in minutes between failed tries + // Only failed tries between this interval will be accounted when banning + ban_interval: 5 + + // How many failures before adding a temporary ban entry? + ban_limit: 7 + + // Duration of the ban in minutes + ban_duration: 5 + } + } // login_configuration.account.ipban + } // login_configuration.account + + permission: { + // Required account group id to connect to server. + // -1: disabled + // 0 or more: group id + group_id_to_connect: -1 + + // Minimum account group id required to connect to server. + // Will not function if group_id_to_connect config is enabled. + // -1: disabled + // 0 or more: group id + min_group_id_to_connect: -1 + + // Check The clientversion set in the clientinfo ? + check_client_version: false + + // What version we would allow to connect? (if check_client_version is enabled) + client_version_to_connect: 20 + + //================================================================== + // Client hash checking system + //================================================================== + // Note: see doc/md5_hashcheck.txt for more details. + hash: { + // Client MD5 hash check + // If turned on, the login server will check if the client's hash matches + // the value below, and will not connect tampered clients. + enabled: false + + // Client MD5 hashes + // The client with the specified hash can be used to log in by players with + // a group_id equal to or greater than the given value. + // If you specify 'disabled' as hash, players with a group_id greater than or + // equal to the given value will be able to log in regardless of hash (and even + // if their client does not send a hash at all.) + MD5_hashes: ( + //{ + // group_id: group id + // hash: client hash + //}, + //{ + // group_id: 0 + // hash: "113e195e6c051bb1cfb12a644bb084c5" + //}, + //{ + // group_id: 10 + // hash: "cb1ea78023d337c38e8ba5124e2338ae" + //}, + //{ + // group_id: 99 + // hash: "disabled" + //}, + ) + } // login_configuration.permission.hash + + DNS_blacklist: { + // DNS Blacklist Blocking + // If enabled, each incoming connection will be tested against the blacklists + // on the specified dnsbl_servers + enabled: false + + dnsbl_servers: ( + // Here are some free DNS Blacklist Services: http://en.wikipedia.org/wiki/Comparison_of_DNS_blacklists + "bl.blocklist.de", // IP-Addresses who attack other servers/honeypots over SSH, FTP, IMAP, etc. + //"ircbl.ahbl.org", // AHBL (open proxies, compromised machines, comment spammers) + //"safe.dnsbl.sorbs.net", // All zones in dnsbl.sorbs.net except "recent" and "escalations" + //"sbl-xbl.spamhaus.org", // Spamhaus blacklist (spammers, open proxies) + "socks.dnsbl.sorbs.net", // Open SOCKS proxy servers + //"tor.ahbl.org", // Current tor relay and exit nodes + ) + } // login_configuration.DNS_blacklist + } // login_configuration.permission +} + +import: "conf/import/login-server.conf" diff --git a/doc/md5_hashcheck.txt b/doc/md5_hashcheck.txt index d9064b1ab..b386559b5 100644 --- a/doc/md5_hashcheck.txt +++ b/doc/md5_hashcheck.txt @@ -3,7 +3,7 @@ //===== By: ================================================== //= Hercules Dev Team //===== Current Version: ===================================== -//= 20140208 +//= 20160210 //===== Description: ========================================= //= This file outlines the login server's MD5 hash check. //============================================================ @@ -20,27 +20,9 @@ Please refer to your client diff tool manual for the appropriate patch tools or diffs it may have similar names.) The serverside settings for the hash check are located in -conf/login.conf: +conf/login.conf::login_configuration.permission.hash -// Client MD5 hash check -// If turned on, the login server will check if the client's hash matches -// the value below, and will not connect tampered clients. -// Note: see doc/md5_hashcheck.txt for more details. -client_hash_check: off - -// Client MD5 hashes -// The client with the specified hash can be used to log in by players with -// a group_id equal to or greater than the given value. -// If you specify 'disabled' as hash, players with a group_id greater than or -// equal to the given value will be able to log in regardless of hash (and even -// if their client does not send a hash at all.) -// Format: group_id, hash -// Note: see doc/md5_hashcheck.txt for more details. -client_hash: 0, 113e195e6c051bb1cfb12a644bb084c5 -client_hash: 10, cb1ea78023d337c38e8ba5124e2338ae -client_hash: 99, disabled - -To enable MD5 hash checks, set 'client_hash_check' to 'on' and add one +To enable MD5 hash checks, set 'client_hash_check' to 'true' and add one 'client_hash' entry for each client you want to use. The group_id can be any of the groups in conf/groups.conf, and it is useful in case if you want to allow GMs to use a different client diff --git a/src/login/account.h b/src/login/account.h index 7e1930ad4..9bb07fda3 100644 --- a/src/login/account.h +++ b/src/login/account.h @@ -2,7 +2,7 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2012-2015 Hercules Dev Team + * Copyright (C) 2012-2016 Hercules Dev Team * Copyright (C) Athena Dev Teams * * Hercules is free software: you can redistribute it and/or modify @@ -27,6 +27,9 @@ /* Forward declarations */ struct Sql; // common/sql.h +/* Forward Declarations */ +struct config_t; // common/conf.h + typedef struct AccountDB AccountDB; typedef struct AccountDBIterator AccountDBIterator; @@ -107,10 +110,9 @@ struct AccountDB /// Sets a property in this database. /// /// @param self Database - /// @param key Property name - /// @param value Property value + /// @param config Configuration node /// @return true if successful - bool (*set_property)(AccountDB* self, const char* key, const char* value); + bool (*set_property)(AccountDB* self, struct config_t *config, bool imported); /// Creates a new account in this database. /// If acc->account_id is not -1, the provided value will be used. diff --git a/src/login/account_sql.c b/src/login/account_sql.c index 2e128e8bf..70d4f3dfb 100644 --- a/src/login/account_sql.c +++ b/src/login/account_sql.c @@ -2,7 +2,7 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2012-2015 Hercules Dev Team + * Copyright (C) 2012-2016 Hercules Dev Team * Copyright (C) Athena Dev Teams * * Hercules is free software: you can redistribute it and/or modify @@ -24,6 +24,7 @@ #include "account.h" #include "common/cbasetypes.h" +#include "common/conf.h" #include "common/console.h" #include "common/memmgr.h" #include "common/mmo.h" @@ -45,14 +46,7 @@ typedef struct AccountDB_SQL struct Sql *accounts; // SQL accounts storage - // global sql settings - char global_db_hostname[32]; - uint16 global_db_port; - char global_db_username[32]; - char global_db_password[100]; - char global_db_database[32]; - char global_codepage[32]; - // local sql settings + // Sql settings char db_hostname[32]; uint16 db_port; char db_username[32]; @@ -81,7 +75,7 @@ typedef struct AccountDBIterator_SQL static bool account_db_sql_init(AccountDB* self); static void account_db_sql_destroy(AccountDB* self); static bool account_db_sql_get_property(AccountDB* self, const char* key, char* buf, size_t buflen); -static bool account_db_sql_set_property(AccountDB* self, const char* option, const char* value); +static bool account_db_sql_set_property(AccountDB* self, struct config_t *config, bool imported); static bool account_db_sql_create(AccountDB* self, struct mmo_account* acc); static bool account_db_sql_remove(AccountDB* self, const int account_id); static bool account_db_sql_save(AccountDB* self, const struct mmo_account* acc); @@ -113,19 +107,12 @@ AccountDB* account_db_sql(void) // initialize to default values db->accounts = NULL; - // global sql settings - safestrncpy(db->global_db_hostname, "127.0.0.1", sizeof(db->global_db_hostname)); - db->global_db_port = 3306; - safestrncpy(db->global_db_username, "ragnarok", sizeof(db->global_db_username)); - safestrncpy(db->global_db_password, "ragnarok", sizeof(db->global_db_password)); - safestrncpy(db->global_db_database, "ragnarok", sizeof(db->global_db_database)); - safestrncpy(db->global_codepage, "", sizeof(db->global_codepage)); - // local sql settings - safestrncpy(db->db_hostname, "", sizeof(db->db_hostname)); + // Sql settings + safestrncpy(db->db_hostname, "127.0.0.1", sizeof(db->db_hostname)); db->db_port = 3306; - safestrncpy(db->db_username, "", sizeof(db->db_username)); - safestrncpy(db->db_password, "", sizeof(db->db_password)); - safestrncpy(db->db_database, "", sizeof(db->db_database)); + safestrncpy(db->db_username, "ragnarok", sizeof(db->db_username)); + safestrncpy(db->db_password, "ragnarok", sizeof(db->db_password)); + safestrncpy(db->db_database, "ragnarok", sizeof(db->db_database)); safestrncpy(db->codepage, "", sizeof(db->codepage)); // other settings db->case_sensitive = false; @@ -144,46 +131,22 @@ AccountDB* account_db_sql(void) static bool account_db_sql_init(AccountDB* self) { AccountDB_SQL* db = (AccountDB_SQL*)self; - struct Sql *sql_handle; - const char* username; - const char* password; - const char* hostname; - uint16 port; - const char* database; - const char* codepage; + struct Sql *sql_handle = NULL; nullpo_ret(db); + db->accounts = SQL->Malloc(); sql_handle = db->accounts; - if( db->db_hostname[0] != '\0' ) - {// local settings - username = db->db_username; - password = db->db_password; - hostname = db->db_hostname; - port = db->db_port; - database = db->db_database; - codepage = db->codepage; - } - else - {// global settings - username = db->global_db_username; - password = db->global_db_password; - hostname = db->global_db_hostname; - port = db->global_db_port; - database = db->global_db_database; - codepage = db->global_codepage; - } - - if( SQL_ERROR == SQL->Connect(sql_handle, username, password, hostname, port, database) ) - { + if (SQL_ERROR == SQL->Connect(sql_handle, db->db_username, db->db_password, + db->db_hostname, db->db_port, db->db_database)) { Sql_ShowDebug(sql_handle); SQL->Free(db->accounts); db->accounts = NULL; return false; } - if( codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, codepage) ) + if (db->codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, db->codepage)) Sql_ShowDebug(sql_handle); Sql_HerculesUpdateCheck(db->accounts); @@ -207,6 +170,15 @@ static void account_db_sql_destroy(AccountDB* self) /// Gets a property from this database. static bool account_db_sql_get_property(AccountDB* self, const char* key, char* buf, size_t buflen) { + /* TODO: + * This functionality is not being used as of now, it was removed in + * commit 5479f9631f8579d03fbfd14d8a49c7976226a156, it is meant to get + * engine properties when more than one engine is available. I'll + * re-add it as soon as I can, following the new standards. If anyone + * is interested in this functionality you can contact me in our boards + * and I'll try to add it sooner (Pan) [Panikon] + */ +#if 0 AccountDB_SQL* db = (AccountDB_SQL*)self; const char* signature; @@ -230,32 +202,6 @@ static bool account_db_sql_get_property(AccountDB* self, const char* key, char* return true; } - signature = "sql."; - if( strncmpi(key, signature, strlen(signature)) == 0 ) - { - key += strlen(signature); - if( strcmpi(key, "db_hostname") == 0 ) - safesnprintf(buf, buflen, "%s", db->global_db_hostname); - else - if( strcmpi(key, "db_port") == 0 ) - safesnprintf(buf, buflen, "%d", db->global_db_port); - else - if( strcmpi(key, "db_username") == 0 ) - safesnprintf(buf, buflen, "%s", db->global_db_username); - else - if( strcmpi(key, "db_password") == 0 ) - safesnprintf(buf, buflen, "%s", db->global_db_password); - else - if( strcmpi(key, "db_database") == 0 ) - safesnprintf(buf, buflen, "%s", db->global_db_database); - else - if( strcmpi(key, "codepage") == 0 ) - safesnprintf(buf, buflen, "%s", db->global_codepage); - else - return false;// not found - return true; - } - signature = "account.sql."; if( strncmpi(key, signature, strlen(signature)) == 0 ) { @@ -295,82 +241,91 @@ static bool account_db_sql_get_property(AccountDB* self, const char* key, char* } return false;// not found +#endif // 0 + return false; } -/// if the option is supported, adjusts the internal state -static bool account_db_sql_set_property(AccountDB* self, const char* key, const char* value) +/** + * Reads the 'inter_configuration' config file and initializes required variables. + * + * @param db Self. + * @param filename Path to configuration file + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool account_db_read_inter(AccountDB_SQL *db, const char *filename, bool imported) +{ + struct config_t config; + struct config_setting_t *setting = NULL; + + nullpo_retr(false, db); + nullpo_retr(false, filename); + + if (!libconfig->load_file(&config, filename)) + return false; // Error message is already shown by libconfig->load_file + + if ((setting = libconfig->lookup(&config, "inter_configuration/database_names")) == NULL) { + libconfig->destroy(&config); + if (imported) + return true; + ShowError("account_db_sql_set_property: inter_configuration/database_names was not found!\n"); + return false; + } + libconfig->setting_lookup_mutable_string(setting, "account_db", db->account_db, sizeof(db->account_db)); + + if ((setting = libconfig->lookup(&config, "inter_configuration/database_names/registry")) == NULL) { + libconfig->destroy(&config); + if (imported) + return true; + ShowError("account_db_sql_set_property: inter_configuration/database_names/registry was not found!\n"); + return false; + } + libconfig->setting_lookup_mutable_string(setting, "global_acc_reg_str_db", db->global_acc_reg_str_db, sizeof(db->global_acc_reg_str_db)); + libconfig->setting_lookup_mutable_string(setting, "global_acc_reg_num_db", db->global_acc_reg_num_db, sizeof(db->global_acc_reg_num_db)); + + // TODO: Proper import mechanism for this file + + libconfig->destroy(&config); + return true; +} + +/** + * Loads the sql configuration. + * + * @param self Self. + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +static bool account_db_sql_set_property(AccountDB* self, struct config_t *config, bool imported) { AccountDB_SQL* db = (AccountDB_SQL*)self; - const char* signature; + struct config_setting_t *setting = NULL; nullpo_ret(db); - nullpo_ret(key); - nullpo_ret(value); - signature = "sql."; - if( strncmp(key, signature, strlen(signature)) == 0 ) - { - key += strlen(signature); - if( strcmpi(key, "db_hostname") == 0 ) - safestrncpy(db->global_db_hostname, value, sizeof(db->global_db_hostname)); - else - if( strcmpi(key, "db_port") == 0 ) - db->global_db_port = (uint16)strtoul(value, NULL, 10); - else - if( strcmpi(key, "db_username") == 0 ) - safestrncpy(db->global_db_username, value, sizeof(db->global_db_username)); - else - if( strcmpi(key, "db_password") == 0 ) - safestrncpy(db->global_db_password, value, sizeof(db->global_db_password)); - else - if( strcmpi(key, "db_database") == 0 ) - safestrncpy(db->global_db_database, value, sizeof(db->global_db_database)); - else - if( strcmpi(key, "codepage") == 0 ) - safestrncpy(db->global_codepage, value, sizeof(db->global_codepage)); - else - return false;// not found - return true; - } + nullpo_ret(config); - signature = "account.sql."; - if( strncmp(key, signature, strlen(signature)) == 0 ) - { - key += strlen(signature); - if( strcmpi(key, "db_hostname") == 0 ) - safestrncpy(db->db_hostname, value, sizeof(db->db_hostname)); - else - if( strcmpi(key, "db_port") == 0 ) - db->db_port = (uint16)strtoul(value, NULL, 10); - else - if( strcmpi(key, "db_username") == 0 ) - safestrncpy(db->db_username, value, sizeof(db->db_username)); - else - if( strcmpi(key, "db_password") == 0 ) - safestrncpy(db->db_password, value, sizeof(db->db_password)); - else - if( strcmpi(key, "db_database") == 0 ) - safestrncpy(db->db_database, value, sizeof(db->db_database)); - else - if( strcmpi(key, "codepage") == 0 ) - safestrncpy(db->codepage, value, sizeof(db->codepage)); - else - if( strcmpi(key, "case_sensitive") == 0 ) - db->case_sensitive = (bool)config_switch(value); - else - if( strcmpi(key, "account_db") == 0 ) - safestrncpy(db->account_db, value, sizeof(db->account_db)); - else - if( strcmpi(key, "global_acc_reg_str_db") == 0 ) - safestrncpy(db->global_acc_reg_str_db, value, sizeof(db->global_acc_reg_str_db)); - else - if( strcmpi(key, "global_acc_reg_num_db") == 0 ) - safestrncpy(db->global_acc_reg_num_db, value, sizeof(db->global_acc_reg_num_db)); - else - return false;// not found - return true; + if ((setting = libconfig->lookup(config, "login_configuration/account/sql_connection")) == NULL) { + if (imported) + return true; + ShowError("account_db_sql_set_property: login_configuration/account/sql_connection was not found!\n"); + ShowWarning("account_db_sql_set_property: Defaulting sql_connection...\n"); + return false; } - return false;// not found + libconfig->setting_lookup_mutable_string(setting, "db_hostname", db->db_hostname, sizeof(db->db_hostname)); + libconfig->setting_lookup_mutable_string(setting, "db_username", db->db_username, sizeof(db->db_username)); + libconfig->setting_lookup_mutable_string(setting, "db_password", db->db_password, sizeof(db->db_password)); + libconfig->setting_lookup_mutable_string(setting, "db_database", db->db_database, sizeof(db->db_database)); + libconfig->setting_lookup_mutable_string(setting, "codepage", db->codepage, sizeof(db->codepage)); // FIXME: Why do we need both codepage and default_codepage? + libconfig->setting_lookup_uint16(setting, "db_port", &db->db_port); + libconfig->setting_lookup_bool_real(setting, "case_sensitive", &db->case_sensitive); + + account_db_read_inter(db, "conf/common/inter-server.conf", imported); + + return true; } /// create a new account entry diff --git a/src/login/ipban.h b/src/login/ipban.h index 85cf3873c..104e3a8a3 100644 --- a/src/login/ipban.h +++ b/src/login/ipban.h @@ -2,7 +2,7 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2012-2015 Hercules Dev Team + * Copyright (C) 2012-2016 Hercules Dev Team * Copyright (C) Athena Dev Teams * * Hercules is free software: you can redistribute it and/or modify @@ -23,6 +23,9 @@ #include "common/cbasetypes.h" +/* Forward Declarations */ +struct config_t; // common/conf.h + #ifdef HERCULES_CORE // TODO: Interface // initialize @@ -37,8 +40,8 @@ bool ipban_check(uint32 ip); // increases failure count for the specified IP void ipban_log(uint32 ip); -// parses configuration option -bool ipban_config_read(const char *key, const char* value); +// parses configuration options +bool ipban_config_read(const char *filename, struct config_t *config, bool imported); #endif // HERCULES_CORE #endif /* LOGIN_IPBAN_H */ diff --git a/src/login/ipban_sql.c b/src/login/ipban_sql.c index bec0217f4..d74e6c4fa 100644 --- a/src/login/ipban_sql.c +++ b/src/login/ipban_sql.c @@ -2,7 +2,7 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2012-2015 Hercules Dev Team + * Copyright (C) 2012-2016 Hercules Dev Team * Copyright (C) Athena Dev Teams * * Hercules is free software: you can redistribute it and/or modify @@ -25,26 +25,21 @@ #include "login/login.h" #include "login/loginlog.h" #include "common/cbasetypes.h" +#include "common/conf.h" #include "common/nullpo.h" +#include "common/showmsg.h" #include "common/sql.h" #include "common/strlib.h" #include "common/timer.h" #include -// global sql settings -static char global_db_hostname[32] = "127.0.0.1"; -static uint16 global_db_port = 3306; -static char global_db_username[32] = "ragnarok"; -static char global_db_password[100] = "ragnarok"; -static char global_db_database[32] = "ragnarok"; -static char global_codepage[32] = ""; -// local sql settings -static char ipban_db_hostname[32] = ""; -static uint16 ipban_db_port = 0; -static char ipban_db_username[32] = ""; -static char ipban_db_password[100] = ""; -static char ipban_db_database[32] = ""; +// Sql settings +static char ipban_db_hostname[32] = "127.0.0.1"; +static uint16 ipban_db_port = 3306; +static char ipban_db_username[32] = "ragnarok"; +static char ipban_db_password[100] = "ragnarok"; +static char ipban_db_database[32] = "ragnarok"; static char ipban_codepage[32] = ""; static char ipban_table[32] = "ipbanlist"; @@ -59,54 +54,30 @@ int ipban_cleanup(int tid, int64 tick, int id, intptr_t data); // initialize void ipban_init(void) { - const char* username; - const char* password; - const char* hostname; - uint16 port; - const char* database; - const char* codepage; - ipban_inited = true; if (!login->config->ipban) return;// ipban disabled - if( ipban_db_hostname[0] != '\0' ) - {// local settings - username = ipban_db_username; - password = ipban_db_password; - hostname = ipban_db_hostname; - port = ipban_db_port; - database = ipban_db_database; - codepage = ipban_codepage; - } - 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; - } - // establish connections sql_handle = SQL->Malloc(); - if( SQL_ERROR == SQL->Connect(sql_handle, username, password, hostname, port, database) ) - { + if (SQL_ERROR == SQL->Connect(sql_handle, ipban_db_username, ipban_db_password, + ipban_db_hostname, ipban_db_port, ipban_db_database)) { Sql_ShowDebug(sql_handle); SQL->Free(sql_handle); exit(EXIT_FAILURE); } - if( codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, codepage) ) + if (ipban_codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, ipban_codepage)) Sql_ShowDebug(sql_handle); - if (login->config->ipban_cleanup_interval > 0) - { // set up periodic cleanup of connection history and active bans + if (login->config->ipban_cleanup_interval > 0) { + // set up periodic cleanup of connection history and active bans timer->add_func_list(ipban_cleanup, "ipban_cleanup"); cleanup_timer_id = timer->add_interval(timer->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); + } } // finalize @@ -126,95 +97,153 @@ void ipban_final(void) sql_handle = NULL; } -// load configuration options -bool ipban_config_read(const char* key, const char* value) +/** + * Reads 'inter_configuration' and initializes required variables/Sets global + * configuration. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + + */ +bool ipban_config_read_inter(const char *filename, bool imported) { - const char* signature; + struct config_t config; + struct config_setting_t *setting = NULL; + const char *import = NULL; + bool retval = true; - nullpo_ret(key); - nullpo_ret(value); - if( ipban_inited ) - return false;// settings can only be changed before init + nullpo_retr(false, filename); - 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 (!libconfig->load_file(&config, filename)) + return false; // Error message is already shown by libconfig->read_file + + if ((setting = libconfig->lookup(&config, "inter_configuration/database_names")) == NULL) { + libconfig->destroy(&config); + if (imported) + return true; + ShowError("ipban_config_read: inter_configuration/database_names was not found!\n"); + return false; + } + libconfig->setting_lookup_mutable_string(setting, "ipban_table", ipban_table, sizeof(ipban_table)); + + // import should overwrite any previous configuration, so it should be called last + if (libconfig->lookup_string(&config, "import", &import) == CONFIG_TRUE) { + if (strcmp(import, filename) == 0 || strcmp(import, "conf/common/inter-server.conf") == 0) { + ShowWarning("ipban_config_read_inter: Loop detected! Skipping 'import'...\n"); + } else { + if (!ipban_config_read_inter(import, true)) + retval = false; + } } - signature = "ipban.sql."; - if( strncmpi(key, signature, strlen(signature)) == 0 ) - { - key += strlen(signature); - if( strcmpi(key, "db_hostname") == 0 ) - safestrncpy(ipban_db_hostname, value, sizeof(ipban_db_hostname)); - else - if( strcmpi(key, "db_port") == 0 ) - ipban_db_port = (uint16)strtoul(value, NULL, 10); - else - if( strcmpi(key, "db_username") == 0 ) - safestrncpy(ipban_db_username, value, sizeof(ipban_db_username)); - else - if( strcmpi(key, "db_password") == 0 ) - safestrncpy(ipban_db_password, value, sizeof(ipban_db_password)); - else - if( strcmpi(key, "db_database") == 0 ) - safestrncpy(ipban_db_database, value, sizeof(ipban_db_database)); - else - if( strcmpi(key, "codepage") == 0 ) - safestrncpy(ipban_codepage, value, sizeof(ipban_codepage)); - else - if( strcmpi(key, "ipban_table") == 0 ) - safestrncpy(ipban_table, value, sizeof(ipban_table)); - else - return false;// not found - return true; + libconfig->destroy(&config); + return retval; +} + +/** + * Reads login_configuration/account/ipban/sql_connection and loads configuration options. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool ipban_config_read_connection(const char *filename, struct config_t *config, bool imported) +{ + struct config_setting_t *setting = NULL; + + nullpo_retr(false, filename); + nullpo_retr(false, config); + + if ((setting = libconfig->lookup(config, "login_configuration/account/ipban/sql_connection")) == NULL) { + if (imported) + return true; + ShowError("account_db_sql_set_property: login_configuration/account/ipban/sql_connection was not found in %s!\n", filename); + return false; } - signature = "ipban."; - if( strncmpi(key, signature, strlen(signature)) == 0 ) - { - key += strlen(signature); - if( strcmpi(key, "enable") == 0 ) - login->config->ipban = (bool)config_switch(value); - else - if( strcmpi(key, "dynamic_pass_failure_ban") == 0 ) - login->config->dynamic_pass_failure_ban = (bool)config_switch(value); - else - if( strcmpi(key, "dynamic_pass_failure_ban_interval") == 0 ) - login->config->dynamic_pass_failure_ban_interval = atoi(value); - else - if( strcmpi(key, "dynamic_pass_failure_ban_limit") == 0 ) - login->config->dynamic_pass_failure_ban_limit = atoi(value); - else - if( strcmpi(key, "dynamic_pass_failure_ban_duration") == 0 ) - login->config->dynamic_pass_failure_ban_duration = atoi(value); - else - return false;// not found - return true; + libconfig->setting_lookup_mutable_string(setting, "db_hostname", ipban_db_hostname, sizeof(ipban_db_hostname)); + libconfig->setting_lookup_mutable_string(setting, "db_database", ipban_db_database, sizeof(ipban_db_database)); + + libconfig->setting_lookup_mutable_string(setting, "db_username", ipban_db_username, sizeof(ipban_db_username)); + libconfig->setting_lookup_mutable_string(setting, "db_password", ipban_db_password, sizeof(ipban_db_password)); + libconfig->setting_lookup_mutable_string(setting, "codepage", ipban_codepage, sizeof(ipban_codepage)); + libconfig->setting_lookup_uint16(setting, "db_port", &ipban_db_port); + + return true; +} + +/** + * Reads login_configuration/account/ipban/dynamic_pass_failure and loads configuration options. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool ipban_config_read_dynamic(const char *filename, struct config_t *config, bool imported) +{ + struct config_setting_t *setting = NULL; + + nullpo_retr(false, filename); + nullpo_retr(false, config); + + if ((setting = libconfig->lookup(config, "login_configuration/account/ipban/dynamic_pass_failure")) == NULL) { + if (imported) + return true; + ShowError("account_db_sql_set_property: login_configuration/account/ipban/dynamic_pass_failure was not found in %s!\n", filename); + return false; + } + + libconfig->setting_lookup_bool_real(setting, "enabled", &login->config->dynamic_pass_failure_ban); + libconfig->setting_lookup_uint32(setting, "ban_interval", &login->config->dynamic_pass_failure_ban_interval); + libconfig->setting_lookup_uint32(setting, "ban_limit", &login->config->dynamic_pass_failure_ban_limit); + libconfig->setting_lookup_uint32(setting, "ban_duration", &login->config->dynamic_pass_failure_ban_duration); + + return true; +} + +/** + * Reads login_configuration.account.ipban and loads configuration options. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool ipban_config_read(const char *filename, struct config_t *config, bool imported) +{ + struct config_setting_t *setting = NULL; + bool retval = true; + + nullpo_retr(false, filename); + nullpo_retr(false, config); + + if (ipban_inited) + return false; // settings can only be changed before init + + if ((setting = libconfig->lookup(config, "login_configuration/account/ipban")) == NULL) { + if (!imported) + ShowError("login_config_read: login_configuration/log was not found in %s!\n", filename); + return false; } - return false;// not found + libconfig->setting_lookup_bool_real(setting, "enabled", &login->config->ipban); + libconfig->setting_lookup_uint32(setting, "cleanup_interval", &login->config->ipban_cleanup_interval); + + if (!ipban_config_read_inter("conf/common/inter-server.conf", imported)) + retval = false; + if (!ipban_config_read_connection(filename, config, imported)) + retval = false; + if (!ipban_config_read_dynamic(filename, config, imported)) + retval = false; + + return retval; } // check ip against active bans list diff --git a/src/login/login.c b/src/login/login.c index 6b422eef2..f1302b673 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -29,6 +29,7 @@ #include "login/lclif.h" #include "common/HPM.h" #include "common/cbasetypes.h" +#include "common/conf.h" #include "common/core.h" #include "common/db.h" #include "common/memmgr.h" @@ -43,6 +44,7 @@ #include #include +#include // stat() /** @file * Implementation of the login interface. @@ -1064,13 +1066,14 @@ int login_mmo_auth(struct login_session_data* sd, bool isServer) { if (login->config->use_dnsbl) { char r_ip[16]; char ip_dnsbl[256]; - char* dnsbl_serv; uint8* sin_addr = (uint8*)&sockt->session[sd->fd]->client_addr; + int i; sprintf(r_ip, "%u.%u.%u.%u", sin_addr[0], sin_addr[1], sin_addr[2], sin_addr[3]); - for (dnsbl_serv = strtok(login->config->dnsbl_servs,","); dnsbl_serv != NULL; dnsbl_serv = strtok(NULL,",")) { - sprintf(ip_dnsbl, "%s.%s", r_ip, trim(dnsbl_serv)); + for (i = 0; i < VECTOR_LENGTH(login->config->dnsbl_servers); i++) { + char *dnsbl_server = VECTOR_INDEX(login->config->dnsbl_servers, i); + sprintf(ip_dnsbl, "%s.%s", r_ip, trim(dnsbl_server)); if (sockt->host2ip(ip_dnsbl)) { ShowInfo("DNSBL: (%s) Blacklisted. User Kicked.\n", r_ip); return 3; @@ -1450,150 +1453,431 @@ void login_config_set_defaults(void) login->config->dynamic_pass_failure_ban_limit = 7; login->config->dynamic_pass_failure_ban_duration = 5; login->config->use_dnsbl = false; - safestrncpy(login->config->dnsbl_servs, "", sizeof(login->config->dnsbl_servs)); + VECTOR_INIT(login->config->dnsbl_servers); login->config->client_hash_check = 0; login->config->client_hash_nodes = NULL; } -//----------------------------------- -// Reading main configuration file -//----------------------------------- -int login_config_read(const char *cfgName) +/** + * Reads 'login_configuration/inter' and initializes required variables. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool login_config_read_inter(const char *filename, struct config_t *config, bool imported) { - char line[1024], w1[1024], w2[1024]; - FILE* fp; - nullpo_retr(1, cfgName); - fp = fopen(cfgName, "r"); - if (fp == NULL) { - ShowError("Configuration file (%s) not found.\n", cfgName); - return 1; + struct config_setting_t *setting = NULL; + const char *str = NULL; + + nullpo_retr(false, filename); + nullpo_retr(false, config); + + if ((setting = libconfig->lookup(config, "login_configuration/inter")) == NULL) { + if (imported) + return true; + ShowError("login_config_read: login_configuration/inter was not found in %s!\n", filename); + return false; } - while(fgets(line, sizeof(line), fp)) { - if (line[0] == '/' && line[1] == '/') - continue; - if (sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2) < 2) + libconfig->setting_lookup_uint16(setting, "login_port", &login->config->login_port); + + if (libconfig->setting_lookup_uint32(setting, "ip_sync_interval", &login->config->ip_sync_interval) == CONFIG_TRUE) + login->config->ip_sync_interval *= 1000*60; // In minutes + + if (libconfig->setting_lookup_string(setting, "bind_ip", &str) == CONFIG_TRUE) { + char old_ip_str[16]; + sockt->ip2str(login->config->login_ip, old_ip_str); + + if ((login->config->login_ip = sockt->host2ip(str)) != 0) + ShowStatus("Login server binding IP address : %s -> %s\n", old_ip_str, str); + } + + return true; +} + +/** + * Reads 'login_configuration.console' and initializes required variables. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool login_config_read_console(const char *filename, struct config_t *config, bool imported) +{ + struct config_setting_t *setting = NULL; + + nullpo_retr(false, filename); + nullpo_retr(false, config); + + if ((setting = libconfig->lookup(config, "login_configuration/console")) == NULL) { + if (imported) + return true; + ShowError("login_config_read: login_configuration/console was not found in %s!\n", filename); + return false; + } + + libconfig->setting_lookup_bool_real(setting, "stdout_with_ansisequence", &showmsg->stdout_with_ansisequence); + if (libconfig->setting_lookup_int(setting, "console_silent", &showmsg->silent) == CONFIG_TRUE) { + if (showmsg->silent) // only bother if its actually enabled + ShowInfo("Console Silent Setting: %d\n", showmsg->silent); + } + libconfig->setting_lookup_mutable_string(setting, "timestamp_format", showmsg->timestamp_format, sizeof(showmsg->timestamp_format)); + + return true; +} + +/** + * Reads 'login_configuration.log' and initializes required variables. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool login_config_read_log(const char *filename, struct config_t *config, bool imported) +{ + struct config_setting_t *setting = NULL; + + nullpo_retr(false, filename); + nullpo_retr(false, config); + + if ((setting = libconfig->lookup(config, "login_configuration/log")) == NULL) { + if (imported) + return true; + ShowError("login_config_read: login_configuration/log was not found in %s!\n", filename); + return false; + } + + libconfig->setting_lookup_bool_real(setting, "log_login", &login->config->log_login); + libconfig->setting_lookup_mutable_string(setting, "date_format", login->config->date_format, sizeof(login->config->date_format)); + return true; +} + +/** + * Reads 'login_configuration.account' and initializes required variables. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool login_config_read_account(const char *filename, struct config_t *config, bool imported) +{ + struct config_setting_t *setting = NULL; + AccountDB *db = account_engine[0].db; + bool retval = true; + + nullpo_retr(false, filename); + nullpo_retr(false, config); + + if ((setting = libconfig->lookup(config, "login_configuration/account")) == NULL) { + if (imported) + return true; + ShowError("login_config_read: login_configuration/account was not found in %s!\n", filename); + return false; + } + + libconfig->setting_lookup_bool_real(setting, "new_account", &login->config->new_account_flag); + libconfig->setting_lookup_bool_real(setting, "new_acc_length_limit", &login->config->new_acc_length_limit); + + libconfig->setting_lookup_int(setting, "allowed_regs", &login->config->allowed_regs); + libconfig->setting_lookup_int(setting, "time_allowed", &login->config->time_allowed); + libconfig->setting_lookup_int(setting, "start_limited_time", &login->config->start_limited_time); + libconfig->setting_lookup_bool_real(setting, "use_MD5_passwords", &login->config->use_md5_passwds); + + if (!db->set_property(db, config, imported)) + retval = false; + if (!ipban_config_read(filename, config, imported)) + retval = false; + + return retval; +} + +/** + * Frees login->config->client_hash_nodes + **/ +void clear_client_hash_nodes(void) +{ + struct client_hash_node *node = login->config->client_hash_nodes; + + while (node != NULL) { + struct client_hash_node *next = node->next; + aFree(node); + node = next; + } + + login->config->client_hash_nodes = NULL; +} + +/** + * Reads information from login_configuration.permission.hash.md5_hashes. + * + * @param setting The setting to read from. + */ +void login_config_set_md5hash(struct config_setting_t *setting) +{ + int i; + int count = libconfig->setting_length(setting); + + clear_client_hash_nodes(); + + // There's no need to parse if it's disabled or if there's no list + if (count <= 0 || !login->config->client_hash_check) + return; + + for (i = 0; i < count; i++) { + int j; + int group_id = 0; + char md5hash[33]; + struct client_hash_node *nnode = NULL; + struct config_setting_t *item = libconfig->setting_get_elem(setting, i); + + if (item == NULL) continue; - if(!strcmpi(w1,"timestamp_format")) - safestrncpy(showmsg->timestamp_format, w2, 20); - else if(!strcmpi(w1,"stdout_with_ansisequence")) - showmsg->stdout_with_ansisequence = config_switch(w2) ? true : false; - else if(!strcmpi(w1,"console_silent")) { - showmsg->silent = atoi(w2); - if (showmsg->silent) /* only bother if we actually have this enabled */ - ShowInfo("Console Silent Setting: %d\n", atoi(w2)); - } - else if( !strcmpi(w1, "bind_ip") ) { - login->config->login_ip = sockt->host2ip(w2); - if (login->config->login_ip) { - char ip_str[16]; - ShowStatus("Login server binding IP address : %s -> %s\n", w2, sockt->ip2str(login->config->login_ip, ip_str)); - } + if (libconfig->setting_lookup_int(item, "group_id", &group_id) != CONFIG_TRUE) { + ShowWarning("login_config_set_md5hash: entry (%d) is missing group_id! Ignoring...\n", i); + continue; } - else if( !strcmpi(w1, "login_port") ) { - login->config->login_port = (uint16)atoi(w2); + + if (libconfig->setting_lookup_mutable_string(item, "hash", md5hash, sizeof(md5hash)) != CONFIG_TRUE) { + ShowWarning("login_config_set_md5hash: entry (%d) is missing hash! Ignoring...\n", i); + continue; } - else if(!strcmpi(w1, "log_login")) - login->config->log_login = (bool)config_switch(w2); - - else if(!strcmpi(w1, "new_account")) - login->config->new_account_flag = (bool)config_switch(w2); - else if(!strcmpi(w1, "new_acc_length_limit")) - login->config->new_acc_length_limit = (bool)config_switch(w2); - else if(!strcmpi(w1, "start_limited_time")) - login->config->start_limited_time = atoi(w2); - else if(!strcmpi(w1, "check_client_version")) - login->config->check_client_version = (bool)config_switch(w2); - else if(!strcmpi(w1, "client_version_to_connect")) - login->config->client_version_to_connect = (unsigned int)strtoul(w2, NULL, 10); - else if(!strcmpi(w1, "use_MD5_passwords")) - login->config->use_md5_passwds = (bool)config_switch(w2); - else if(!strcmpi(w1, "group_id_to_connect")) - login->config->group_id_to_connect = atoi(w2); - else if(!strcmpi(w1, "min_group_id_to_connect")) - login->config->min_group_id_to_connect = atoi(w2); - else if(!strcmpi(w1, "date_format")) - safestrncpy(login->config->date_format, w2, sizeof(login->config->date_format)); - else if(!strcmpi(w1, "allowed_regs")) //account flood protection system - login->config->allowed_regs = atoi(w2); - else if(!strcmpi(w1, "time_allowed")) - login->config->time_allowed = atoi(w2); - else if(!strcmpi(w1, "use_dnsbl")) - login->config->use_dnsbl = (bool)config_switch(w2); - else if(!strcmpi(w1, "dnsbl_servers")) - safestrncpy(login->config->dnsbl_servs, w2, sizeof(login->config->dnsbl_servs)); - else if(!strcmpi(w1, "ipban_cleanup_interval")) - login->config->ipban_cleanup_interval = (unsigned int)atoi(w2); - else if(!strcmpi(w1, "ip_sync_interval")) - login->config->ip_sync_interval = (unsigned int)1000*60*atoi(w2); //w2 comes in minutes. - else if(!strcmpi(w1, "client_hash_check")) - login->config->client_hash_check = config_switch(w2); - else if(!strcmpi(w1, "client_hash")) { - int group = 0; - char md5hash[33]; - memset(md5hash, '\0', 33); - - if (sscanf(w2, "%d, %32s", &group, md5hash) == 2) { - struct client_hash_node *nnode; - CREATE(nnode, struct client_hash_node, 1); - - if (strcmpi(md5hash, "disabled") == 0) { - nnode->hash[0] = '\0'; - } else { - int i; - for (i = 0; i < 32; i += 2) { - char buf[3]; - unsigned int byte; - - memcpy(buf, &md5hash[i], 2); - buf[2] = 0; - - sscanf(buf, "%x", &byte); - nnode->hash[i / 2] = (uint8)(byte & 0xFF); - } - } - - nnode->group_id = group; - nnode->next = login->config->client_hash_nodes; - - login->config->client_hash_nodes = nnode; + + CREATE(nnode, struct client_hash_node, 1); + if (strcmpi(md5hash, "disabled") == 0) { + nnode->hash[0] = '\0'; + } else { + for (j = 0; j < 32; j += 2) { + char buf[3]; + unsigned int byte; + + memcpy(buf, &md5hash[j], 2); + buf[2] = 0; + + sscanf(buf, "%x", &byte); + nnode->hash[j / 2] = (uint8)(byte & 0xFF); } } - else if(!strcmpi(w1, "import")) - login_config_read(w2); - else - { - AccountDB* db = account_engine[0].db; - if (db) - db->set_property(db, w1, w2); - ipban_config_read(w1, w2); - loginlog_config_read(w1, w2); - HPM->parseConf(w1, w2, HPCT_LOGIN); + nnode->group_id = group_id; + nnode->next = login->config->client_hash_nodes; // login->config->client_hash_nodes is initialized before calling this function + login->config->client_hash_nodes = nnode; + } + + return; +} + +/** + * Reads 'login_configuration/permission/hash' and initializes required variables. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool login_config_read_permission_hash(const char *filename, struct config_t *config, bool imported) +{ + struct config_setting_t *setting = NULL; + + nullpo_retr(false, filename); + nullpo_retr(false, config); + + if ((setting = libconfig->lookup(config, "login_configuration/permission/hash")) == NULL) { + if (imported) + return true; + ShowError("login_config_read: login_configuration/permission/hash was not found in %s!\n", filename); + return false; + } + + libconfig->setting_lookup_bool_real(setting, "enabled", &login->config->client_hash_check); + + if ((setting = libconfig->lookup(config, "login_configuration/permission/hash/MD5_hashes")) != NULL) + login_config_set_md5hash(setting); + + return true; +} + +/** + * Clears login->config->dnsbl_servers, freeing any allocated memory. + */ +void clear_dnsbl_servers(void) +{ + while (VECTOR_LENGTH(login->config->dnsbl_servers) > 0) { + aFree(&VECTOR_POP(login->config->dnsbl_servers)); + } + VECTOR_CLEAR(login->config->dnsbl_servers); +} + +/** + * Reads information from login_config/permission/DNS_blacklist/dnsbl_servers. + * + * @param setting The configuration setting to read from. + */ +void login_config_set_dnsbl_servers(struct config_setting_t *setting) +{ + int i; + int count = libconfig->setting_length(setting); + + clear_dnsbl_servers(); + + // There's no need to parse if it's disabled + if (count <= 0 || !login->config->use_dnsbl) + return; + + VECTOR_ENSURE(login->config->dnsbl_servers, count, 1); + + for (i = 0; i < count; i++) { + const char *string = libconfig->setting_get_string_elem(setting, i); + + if (string == NULL || string[0] == '\0') + continue; + + VECTOR_PUSH(login->config->dnsbl_servers, aStrdup(string)); + } +} + +/** + * Reads 'login_configuration/permission/DNS_blacklist' and initializes required variables. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool login_config_read_permission_blacklist(const char *filename, struct config_t *config, bool imported) +{ + struct config_setting_t *setting = NULL; + + nullpo_retr(false, filename); + nullpo_retr(false, config); + + if ((setting = libconfig->lookup(config, "login_configuration/permission/DNS_blacklist")) == NULL) { + if (imported) + return true; + ShowError("login_config_read: login_configuration/permission/DNS_blacklist was not found in %s!\n", filename); + return false; + } + + libconfig->setting_lookup_bool_real(setting, "enabled", &login->config->use_dnsbl); + + if ((setting = libconfig->lookup(config, "login_configuration/permission/DNS_blacklist/dnsbl_servers")) != NULL) + login_config_set_dnsbl_servers(setting); + + return true; +} + +/** + * Reads 'login_configuration.permission' and initializes required variables. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool login_config_read_permission(const char *filename, struct config_t *config, bool imported) +{ + struct config_setting_t *setting = NULL; + bool retval = true; + + nullpo_retr(false, filename); + nullpo_retr(false, config); + + if ((setting = libconfig->lookup(config, "login_configuration/permission")) == NULL) { + if (imported) + return true; + ShowError("login_config_read: login_configuration/permission was not found in %s!\n", filename); + return false; + } + + libconfig->setting_lookup_int(setting, "group_id_to_connect", &login->config->group_id_to_connect); + libconfig->setting_lookup_int(setting, "min_group_id_to_connect", &login->config->min_group_id_to_connect); + libconfig->setting_lookup_bool_real(setting, "check_client_version", &login->config->check_client_version); + libconfig->setting_lookup_uint32(setting, "client_version_to_connect", &login->config->client_version_to_connect); + + if (!login_config_read_permission_hash(filename, config, imported)) + retval = false; + if (!login_config_read_permission_blacklist(filename, config, imported)) + retval = false; + + return retval; +} + +/** + * Reads the 'login-config' configuration file and initializes required variables. + * + * @param filename Path to configuration file. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + **/ +bool login_config_read(const char *filename, bool imported) +{ + struct config_t config; + const char *import = NULL; + bool retval = true; + + nullpo_retr(false, filename); + + if (!libconfig->load_file(&config, filename)) + return false; // Error message is already shown by libconfig->load_file + + if (!login_config_read_inter(filename, &config, imported)) + retval = false; + if (!login_config_read_console(filename, &config, imported)) + retval = false; + if (!login_config_read_log(filename, &config, imported)) + retval = false; + if (!login_config_read_account(filename, &config, imported)) + retval = false; + if (!login_config_read_permission(filename, &config, imported)) + retval = false; + + if (!loginlog_config_read("conf/common/inter-server.conf", imported)) // Only inter-server + retval = false; + + // TODO HPM->parseConf(w1, w2, HPCT_LOGIN); + + ShowInfo("Finished reading %s.\n", filename); + + // import should overwrite any previous configuration, so it should be called last + if (libconfig->lookup_string(&config, "import", &import) == CONFIG_TRUE) { + if (strcmp(import, filename) == 0 || strcmp(import, login->LOGIN_CONF_NAME) == 0) { + ShowWarning("login_config_read: Loop detected in %s! Skipping 'import'...\n", filename); + } else { + if (!login->config_read(import, true)) + retval = false; } } - fclose(fp); - ShowInfo("Finished reading %s.\n", cfgName); - return 0; + + config_destroy(&config); + return retval; } //-------------------------------------- // Function called at exit of the server //-------------------------------------- -int do_final(void) { +int do_final(void) +{ int i; - struct client_hash_node *hn = login->config->client_hash_nodes; ShowStatus("Terminating...\n"); HPM->event(HPET_FINAL); - while (hn) { - struct client_hash_node *tmp = hn; - hn = hn->next; - aFree(tmp); - } + clear_client_hash_nodes(); + clear_dnsbl_servers(); login_log(0, "login server", 100, "login server shutdown"); @@ -1730,9 +2014,28 @@ int do_init(int argc, char** argv) // read login-server configuration login->config_set_defaults(); - login->LOGIN_CONF_NAME = aStrdup("conf/login-server.conf"); + login->LOGIN_CONF_NAME = aStrdup("conf/login/login-server.conf"); login->NET_CONF_NAME = aStrdup("conf/network.conf"); + { + // TODO: Remove this when no longer needed. +#define CHECK_OLD_LOCAL_CONF(oldname, newname) do { \ + if (stat((oldname), &fileinfo) == 0 && fileinfo.st_size > 0) { \ + ShowWarning("An old configuration file \"%s\" was found.\n", (oldname)); \ + ShowWarning("If it contains settings you wish to keep, please merge them into \"%s\".\n", (newname)); \ + ShowWarning("Otherwise, just delete it.\n"); \ + ShowInfo("Resuming in 10 seconds...\n"); \ + HSleep(10); \ + } \ +} while (0) + struct stat fileinfo; + + CHECK_OLD_LOCAL_CONF("conf/import/login_conf.txt", "conf/import/login-server.conf"); + CHECK_OLD_LOCAL_CONF("conf/import/inter_conf.txt", "conf/import/inter-server.conf"); + +#undef CHECK_OLD_LOCAL_CONF + } + lclif->init(); HPM_login_do_init(); @@ -1741,7 +2044,7 @@ int do_init(int argc, char** argv) HPM->event(HPET_PRE_INIT); cmdline->exec(argc, argv, CMDLINE_OPT_NORMAL); - login_config_read(login->LOGIN_CONF_NAME); + login->config_read(login->LOGIN_CONF_NAME, false); sockt->net_config_read(login->NET_CONF_NAME); for( i = 0; i < ARRAYLENGTH(server); ++i ) diff --git a/src/login/login.h b/src/login/login.h index 36085ae91..5632e6529 100644 --- a/src/login/login.h +++ b/src/login/login.h @@ -97,8 +97,8 @@ struct Login_Config { uint32 login_ip; ///< the address to bind to uint16 login_port; ///< the port to bind to - unsigned int ipban_cleanup_interval; ///< interval (in seconds) to clean up expired IP bans - unsigned int ip_sync_interval; ///< interval (in minutes) to execute a DNS/IP update (for dynamic IPs) + uint32 ipban_cleanup_interval; ///< interval (in seconds) to clean up expired IP bans + uint32 ip_sync_interval; ///< interval (in minutes) to execute a DNS/IP update (for dynamic IPs) bool log_login; ///< whether to log login server actions or not char date_format[32]; ///< date format used in messages bool new_account_flag,new_acc_length_limit; ///< auto-registration via _M/_F ? / if yes minimum length is 4? @@ -113,13 +113,14 @@ struct Login_Config { bool ipban; ///< perform IP blocking (via contents of `ipbanlist`) ? bool dynamic_pass_failure_ban; ///< automatic IP blocking due to failed login attemps ? - unsigned int dynamic_pass_failure_ban_interval; ///< how far to scan the loginlog for password failures - unsigned int dynamic_pass_failure_ban_limit; ///< number of failures needed to trigger the ipban - unsigned int dynamic_pass_failure_ban_duration; ///< duration of the ipban + uint32 dynamic_pass_failure_ban_interval; ///< how far to scan the loginlog for password failures + uint32 dynamic_pass_failure_ban_limit; ///< number of failures needed to trigger the ipban + uint32 dynamic_pass_failure_ban_duration; ///< duration of the ipban bool use_dnsbl; ///< dns blacklist blocking ? - char dnsbl_servs[1024]; ///< comma-separated list of dnsbl servers + VECTOR_DECL(char *) dnsbl_servers; ///< dnsbl servers - int client_hash_check; ///< flags for checking client md5 + bool client_hash_check; ///< flags for checking client md5 + // TODO: VECTOR candidate struct client_hash_node *client_hash_nodes; ///< linked list containg md5 hash for each gm group }; @@ -207,7 +208,7 @@ struct login_interface { void (*char_server_connection_status) (int fd, struct login_session_data* sd, uint8 status); void (*parse_request_connection) (int fd, struct login_session_data* sd, const char *ip, uint32 ipl); void (*config_set_defaults) (void); - int (*config_read) (const char *cfgName); + bool (*config_read) (const char *filename, bool included); char *LOGIN_CONF_NAME; char *NET_CONF_NAME; ///< Network configuration filename }; diff --git a/src/login/loginlog.h b/src/login/loginlog.h index efb0873bd..589bc4fa1 100644 --- a/src/login/loginlog.h +++ b/src/login/loginlog.h @@ -2,7 +2,7 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2012-2015 Hercules Dev Team + * Copyright (C) 2012-2016 Hercules Dev Team * Copyright (C) Athena Dev Teams * * Hercules is free software: you can redistribute it and/or modify @@ -29,7 +29,7 @@ unsigned long loginlog_failedattempts(uint32 ip, unsigned int minutes); void login_log(uint32 ip, const char* username, int rcode, const char* message); bool loginlog_init(void); bool loginlog_final(void); -bool loginlog_config_read(const char* w1, const char* w2); +bool loginlog_config_read(const char *filename, bool imported); #endif // HERCULES_CORE #endif /* LOGIN_LOGINLOG_H */ diff --git a/src/login/loginlog_sql.c b/src/login/loginlog_sql.c index 16accfada..7dff14990 100644 --- a/src/login/loginlog_sql.c +++ b/src/login/loginlog_sql.c @@ -2,7 +2,7 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2012-2015 Hercules Dev Team + * Copyright (C) 2012-2016 Hercules Dev Team * Copyright (C) Athena Dev Teams * * Hercules is free software: you can redistribute it and/or modify @@ -23,27 +23,22 @@ #include "loginlog.h" #include "common/cbasetypes.h" +#include "common/conf.h" #include "common/mmo.h" #include "common/nullpo.h" +#include "common/showmsg.h" #include "common/socket.h" #include "common/sql.h" #include "common/strlib.h" #include // exit -// global sql settings (in ipban_sql.c) -static char global_db_hostname[32] = "127.0.0.1"; -static uint16 global_db_port = 3306; -static char global_db_username[32] = "ragnarok"; -static char global_db_password[100] = "ragnarok"; -static char global_db_database[32] = "ragnarok"; -static char global_codepage[32] = ""; -// local sql settings -static char log_db_hostname[32] = ""; -static uint16 log_db_port = 0; -static char log_db_username[32] = ""; -static char log_db_password[100] = ""; -static char log_db_database[32] = ""; +// Sql settings +static char log_db_hostname[32] = "127.0.0.1"; +static uint16 log_db_port = 3306; +static char log_db_username[32] = "ragnarok"; +static char log_db_password[100] = "ragnarok"; +static char log_db_database[32] = "ragnarok"; static char log_codepage[32] = ""; static char log_login_db[256] = "loginlog"; @@ -102,42 +97,16 @@ void login_log(uint32 ip, const char* username, int rcode, const char* message) 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(); - if( SQL_ERROR == SQL->Connect(sql_handle, username, password, hostname, port, database) ) - { + if (SQL_ERROR == SQL->Connect(sql_handle, log_db_username, log_db_password, + log_db_hostname, log_db_port, log_db_database)) { Sql_ShowDebug(sql_handle); SQL->Free(sql_handle); exit(EXIT_FAILURE); } - if( codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, codepage) ) + if (log_codepage[0] != '\0' && SQL_ERROR == SQL->SetEncoding(sql_handle, log_codepage)) Sql_ShowDebug(sql_handle); enabled = true; @@ -152,60 +121,105 @@ bool loginlog_final(void) return true; } -bool loginlog_config_read(const char* key, const char* value) +/** + * Reads 'inter_configuration/database_names' and initializes required + * variables/Sets global configuration. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool loginlog_config_read_names(const char *filename, struct config_t *config, bool imported) { - const char* signature; + struct config_setting_t *setting = NULL; - nullpo_ret(key); - nullpo_ret(value); - 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; + nullpo_retr(false, filename); + nullpo_retr(false, config); + + if ((setting = libconfig->lookup(config, "inter_configuration/database_names")) == NULL) { + if (imported) + return true; + ShowError("loginlog_config_read: inter_configuration/database_names was not found in %s!\n", filename); + return false; } - if( strcmpi(key, "log_db_ip") == 0 ) - safestrncpy(log_db_hostname, value, sizeof(log_db_hostname)); - else - if( strcmpi(key, "log_db_port") == 0 ) - log_db_port = (uint16)strtoul(value, NULL, 10); - else - if( strcmpi(key, "log_db_id") == 0 ) - safestrncpy(log_db_username, value, sizeof(log_db_username)); - else - if( strcmpi(key, "log_db_pw") == 0 ) - safestrncpy(log_db_password, value, sizeof(log_db_password)); - else - if( strcmpi(key, "log_db_db") == 0 ) - safestrncpy(log_db_database, value, sizeof(log_db_database)); - else - if( strcmpi(key, "log_codepage") == 0 ) - safestrncpy(log_codepage, value, sizeof(log_codepage)); - else - if( strcmpi(key, "log_login_db") == 0 ) - safestrncpy(log_login_db, value, sizeof(log_login_db)); - else + libconfig->setting_lookup_mutable_string(setting, "login_db", log_login_db, sizeof(log_login_db)); + + return true; +} + +/** + * Reads 'inter_configuration.log' and initializes required variables/Sets + * global configuration. + * + * @param filename Path to configuration file (used in error and warning messages). + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool loginlog_config_read_log(const char *filename, struct config_t *config, bool imported) +{ + struct config_setting_t *setting = NULL; + + nullpo_retr(false, filename); + nullpo_retr(false, config); + + if ((setting = libconfig->lookup(config, "inter_configuration/log/sql_connection")) == NULL) { + if (imported) + return true; + ShowError("loginlog_config_read: inter_configuration/log/sql_connection was not found in %s!\n", filename); return false; + } + + libconfig->setting_lookup_mutable_string(setting, "db_hostname", log_db_hostname, sizeof(log_db_hostname)); + libconfig->setting_lookup_mutable_string(setting, "db_database", log_db_database, sizeof(log_db_database)); + libconfig->setting_lookup_mutable_string(setting, "db_username", log_db_username, sizeof(log_db_username)); + libconfig->setting_lookup_mutable_string(setting, "db_password", log_db_password, sizeof(log_db_password)); + + libconfig->setting_lookup_uint16(setting, "db_port", &log_db_port); + libconfig->setting_lookup_mutable_string(setting, "codepage", log_codepage, sizeof(log_codepage)); return true; } + +/** + * Reads 'inter_configuration' and initializes required variables/Sets global + * configuration. + * + * @param filename Path to configuration file. + * @param config The current config being parsed. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + **/ +bool loginlog_config_read(const char *filename, bool imported) +{ + struct config_t config; + const char *import = NULL; + bool retval = true; + + nullpo_retr(false, filename); + + if (!libconfig->load_file(&config, filename)) + return false; // Error message is already shown by libconfig->load_file + + if (!loginlog_config_read_names(filename, &config, imported)) + retval = false; + if (!loginlog_config_read_log(filename, &config, imported)) + retval = false; + + if (libconfig->lookup_string(&config, "import", &import) == CONFIG_TRUE) { + if (strcmp(import, filename) == 0 || strcmp(import, "conf/common/inter-server.conf") == 0) { + ShowWarning("inter_config_read: Loop detected! Skipping 'import'...\n"); + } else { + if (!loginlog_config_read(import, true)) + retval = false; + } + } + + libconfig->destroy(&config); + return retval; +} diff --git a/tools/configconverter.pl b/tools/configconverter.pl index c49dc95d9..435e4b246 100755 --- a/tools/configconverter.pl +++ b/tools/configconverter.pl @@ -57,18 +57,37 @@ sub cfg_add($$$$) { $output->{$variable} = {value => $value, print => $default->{print}, path => $default->{path}} unless $value eq $default->{default}; } -sub parsecfg_string($$$$) { +sub cfg_append($$$$) { my ($variable, $value, $default, $output) = @_; + for my $default_value (@{$default->{default}}) { + return if $value eq $default_value; + } + $output->{$variable} = {value => [], print => $default->{print}, path => $default->{path}} unless $output->{$variable}; + push(@{$output->{$variable}->{value}}, $value); +} + +sub parsecfg_string_sub($$$$$) { + my ($variable, $value, $default, $output, $func) = @_; if ($value =~ m{\s*"((?:\\"|.)*)"\s*(?://.*)?$}i) { - cfg_add($variable, $1, $default, $output); + $func->($variable, $1, $default, $output); return 1; } elsif ($value =~ m{\s*((?:\\"|.)*)\s*(?://.*)?$}i) { - cfg_add($variable, $1, $default, $output); + $func->($variable, $1, $default, $output); return 1; } return 0; } +sub parsecfg_string($$$$) { + my ($variable, $value, $default, $output) = @_; + return parsecfg_string_sub($variable, $value, $default, $output, \&cfg_add); +} + +sub parsecfg_stringarr($$$$) { + my ($variable, $value, $default, $output) = @_; + return parsecfg_string_sub($variable, $value, $default, $output, \&cfg_append); +} + sub parsecfg_int($$$$) { my ($variable, $value, $default, $output) = @_; if ($value =~ m{\s*(-?[0-9]+)\s*(?://.*)?$}) { @@ -189,6 +208,39 @@ sub printcfg_items($$$) { indent(")\n", $nestlevel); } +sub printcfg_md5hash($$$) { + my ($variable, $value, $nestlevel) = @_; + + indent("$variable: (\n", $nestlevel); + + for (@$value) { + my ($group_id, $hash) = split(/,/, $_, 2); + $group_id =~ s/\s*$//; $group_id =~ s/^\s*//; + $hash =~ s/\s*$//; $hash =~ s/^\s*//; + + indent("{\n", $nestlevel); + indent("group_id: $group_id\n", $nestlevel + 1); + indent("hash: \"$hash\"\n", $nestlevel + 1); + indent("},\n", $nestlevel); + } + + indent(")\n", $nestlevel); +} + +sub printcfg_strlist($$$) { + my ($variable, $value, $nestlevel) = @_; + + indent("$variable: (\n", $nestlevel); + + for my $string (split(/,/, $value)) { + $string =~ s/\s*$//; $string =~ s/^\s*//; + + indent("\"$string\",\n", $nestlevel + 1); + } + + indent(")\n", $nestlevel); +} + sub process_conf($$) { my ($files, $defaults) = @_; my $found = 0; @@ -271,7 +323,7 @@ my @defaults = ( inter_log_filename => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/log/", default => "log/inter.log"}, mysql_reconnect_type => {parse => \&parsecfg_int, print => \&printcfg_int, path => "inter-server:inter_configuration/mysql_reconnect/type", default => 2}, mysql_reconnect_count => {parse => \&parsecfg_int, print => \&printcfg_int, path => "inter-server:inter_configuration/mysql_reconnect/count", default => 1}, - log_login_db => {parse => \&parsecfg_string, print => \&printcfg_nil, path => "inter-server:inter_configuration/database_names/login_db", default => "loginlog"}, + log_login_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/login_db", default => "loginlog"}, char_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/", default => "char"}, interlog_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/", default => "interlog"}, ragsrvinfo_db => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/", default => "ragsrvinfo"}, @@ -340,6 +392,56 @@ my @defaults = ( import => {parse => \&parsecfg_string, print => \&printcfg_nil, path => "", default => "conf/import/inter_conf.txt"}, } }, + { + files => ['login-server.conf', 'import/login_conf.txt'], + settings => { + bind_ip => {parse => \&parsecfg_string, print => \&printcfg_string, path => "login-server:login_configuration/inter/", default => "127.0.0.1"}, + login_port => {parse => \&parsecfg_int, print => \&printcfg_int, path => "login-server:login_configuration/inter/", default => 6900}, + timestamp_format => {parse => \&parsecfg_string, print => \&printcfg_string, path => "console:console/", default => "[%d/%b %H:%M]"}, + stdout_with_ansisequence => {parse => \&parsecfg_bool, print => \&printcfg_bool, path => "console:console/", default => "false"}, + console_silent => {parse => \&parsecfg_int, print => \&printcfg_int, path => "console:console/", default => 0}, + new_account => {parse => \&parsecfg_bool, print => \&printcfg_bool, path => "login-server:login_configuration/account/", default => "true"}, + new_acc_length_limit => {parse => \&parsecfg_bool, print => \&printcfg_bool, path => "login-server:login_configuration/account/", default => "true"}, + allowed_regs => {parse => \&parsecfg_int, print => \&printcfg_int, path => "login-server:login_configuration/account/", default => 1}, + time_allowed => {parse => \&parsecfg_int, print => \&printcfg_int, path => "login-server:login_configuration/account/", default => 10}, + log_login => {parse => \&parsecfg_bool, print => \&printcfg_bool, path => "login-server:login_configuration/log/", default => "true"}, + date_format => {parse => \&parsecfg_string, print => \&printcfg_string, path => "login-server:login_configuration/log/", default => "%Y-%m-%d %H:%M:%S"}, + group_id_to_connect => {parse => \&parsecfg_int, print => \&printcfg_int, path => "login-server:login_configuration/permission/", default => -1}, + min_group_id_to_connect => {parse => \&parsecfg_int, print => \&printcfg_int, path => "login-server:login_configuration/permission/", default => -1}, + start_limited_time => {parse => \&parsecfg_int, print => \&printcfg_int, path => "login-server:login_configuration/account/", default => -1}, + check_client_version => {parse => \&parsecfg_bool, print => \&printcfg_bool, path => "login-server:login_configuration/permission/", default => "false"}, + client_version_to_connect => {parse => \&parsecfg_int, print => \&printcfg_int, path => "login-server:login_configuration/permission/", default => 20}, + use_MD5_passwords => {parse => \&parsecfg_bool, print => \&printcfg_bool, path => "login-server:login_configuration/account/", default => "false"}, + 'ipban.enable' => {parse => \&parsecfg_bool, print => \&printcfg_bool, path => "login-server:login_configuration/account/ipban/enabled", default => "true"}, + 'ipban.sql.db_hostname' => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/db_hostname", default => "127.0.0.1"}, + 'ipban.sql.db_port' => {parse => \&parsecfg_int, print => \&printcfg_int, path => "sql_connection:sql_connection/db_port", default => 3306}, + 'ipban.sql.db_username' => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/db_username", default => "ragnarok"}, + 'ipban.sql.db_password' => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/db_password", default => "ragnarok"}, + 'ipban.sql.db_database' => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/db_database", default => "ragnarok"}, + 'ipban.sql.codepage' => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/codepage", default => ""}, + 'ipban.sql.ipban_table' => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/ipban_table", default => "ipbanlist"}, + 'ipban.dynamic_pass_failure_ban' => {parse => \&parsecfg_bool, print => \&printcfg_bool, path => "login-server:login_configuration/account/ipban/dynamic_pass_failure/enabled", default => "true"}, + 'ipban.dynamic_pass_failure_ban_interval' => {parse => \&parsecfg_int, print => \&printcfg_int, path => "login-server:login_configuration/account/ipban/dynamic_pass_failure/ban_interval", default => 5}, + 'ipban.dynamic_pass_failure_ban_limit' => {parse => \&parsecfg_int, print => \&printcfg_int, path => "login-server:login_configuration/account/ipban/dynamic_pass_failure/ban_limit", default => 7}, + 'ipban.dynamic_pass_failure_ban_duration' => {parse => \&parsecfg_int, print => \&printcfg_int, path => "login-server:login_configuration/account/ipban/dynamic_pass_failure/ban_duration", default => 5}, + ipban_cleanup_interval => {parse => \&parsecfg_int, print => \&printcfg_int, path => "login-server:login_configuration/account/ipban/cleanup_interval", default => 60}, + ip_sync_interval => {parse => \&parsecfg_int, print => \&printcfg_int, path => "login-server:login_configuration/inter/ip_sync_interval", default => 10}, + use_dnsbl => {parse => \&parsecfg_bool, print => \&printcfg_bool, path => "login-server:login_configuration/permission/DNS_blacklist/enabled", default => "false"}, + dnsbl_servers => {parse => \&parsecfg_string, print => \&printcfg_strlist, path => "login-server:login_configuration/permission/DNS_blacklist/dnsbl_servers", default => "bl.blocklist.de, socks.dnsbl.sorbs.net"}, + 'account.sql.db_hostname' => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/db_hostname", default => "127.0.0.1"}, + 'account.sql.db_port' => {parse => \&parsecfg_int, print => \&printcfg_int, path => "sql_connection:sql_connection/db_port", default => 3306}, + 'account.sql.db_username' => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/db_username", default => "ragnarok"}, + 'account.sql.db_password' => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/db_password", default => "ragnarok"}, + 'account.sql.db_database' => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/db_database", default => "ragnarok"}, + 'account.sql.codepage' => {parse => \&parsecfg_string, print => \&printcfg_string, path => "sql_connection:sql_connection/codepage", default => ""}, + 'account.sql.case_sensitive' => {parse => \&parsecfg_bool, print => \&printcfg_bool, path => "sql_connection:sql_connection/case_sensitive", default => "false"}, + 'account.sql.account_db' => {parse => \&parsecfg_string, print => \&printcfg_string, path => "inter-server:inter_configuration/database_names/account_db", default => "login"}, + client_hash_check => {parse => \&parsecfg_bool, print => \&printcfg_bool, path => "login-server:login_configuration/permission/hash/enabled", default => "false"}, + client_hash => {parse => \&parsecfg_stringarr, print => \&printcfg_md5hash, path => "login-server:login_configuration/permission/hash/MD5_hashes", default => []}, + 'account.sql.accreg_db' => {parse => \&parsecfg_string, print => \&printcfg_nil, path => "", default => "global_reg_value"}, + import => {parse => \&parsecfg_stringarr, print => \&printcfg_nil, path => "", default => ["conf/inter-server.conf", "conf/import/login_conf.txt"]}, + } + } ); for (@ARGV) { -- cgit v1.2.3-70-g09d2 From 85d10885379bbe52930c233f02bf1c94ec86ac30 Mon Sep 17 00:00:00 2001 From: Haru Date: Thu, 11 Feb 2016 13:28:18 +0100 Subject: Ported map-server.conf to libconfig Ported to modern Hercules and cleaned up from Panikon's commits: ee48838b12d15902fc14738cfa46d58b39080d11, 55498ebb7ac5d28444d0b01506c88ef6874f6055, 6d1f8f50b0e7349bdab2c53bb172d0b036e47c04, 25dde7e46524ace330b83cb4bf0255cc4d796792 Signed-off-by: Haru --- .gitignore | 1 - conf/atcommand.conf | 2 +- conf/charhelp.txt | 28 - conf/global/console.conf | 8 + conf/help.txt | 307 ---------- conf/import-tmpl/map-server.conf | 32 + conf/import-tmpl/map_conf.txt | 0 conf/map-server.conf | 119 ---- conf/map/charhelp.txt | 28 + conf/map/help.txt | 307 ++++++++++ conf/map/map-server.conf | 117 ++++ conf/map/maps.conf | 1252 ++++++++++++++++++++++++++++++++++++++ conf/maps.conf | 1225 ------------------------------------- src/map/map.c | 449 ++++++++++---- src/map/map.h | 7 +- tools/configconverter.pl | 35 +- 16 files changed, 2111 insertions(+), 1806 deletions(-) delete mode 100644 conf/charhelp.txt delete mode 100644 conf/help.txt create mode 100644 conf/import-tmpl/map-server.conf delete mode 100644 conf/import-tmpl/map_conf.txt delete mode 100644 conf/map-server.conf create mode 100644 conf/map/charhelp.txt create mode 100644 conf/map/help.txt create mode 100644 conf/map/map-server.conf create mode 100644 conf/map/maps.conf delete mode 100644 conf/maps.conf (limited to 'conf') diff --git a/.gitignore b/.gitignore index bd33fac60..eaf7a3aa3 100644 --- a/.gitignore +++ b/.gitignore @@ -62,7 +62,6 @@ Thumbs.db /conf/import/*.conf /conf/import/battle_conf.txt /conf/import/log_conf.txt -/conf/import/map_conf.txt /conf/import/msg_conf.txt /conf/import/packet_conf.txt /conf/import/script_conf.txt diff --git a/conf/atcommand.conf b/conf/atcommand.conf index df4972067..175286eb0 100644 --- a/conf/atcommand.conf +++ b/conf/atcommand.conf @@ -68,5 +68,5 @@ nolog: { /* Commands help file */ help: { - @include "conf/help.txt" + @include "conf/map/help.txt" } diff --git a/conf/charhelp.txt b/conf/charhelp.txt deleted file mode 100644 index e3acddbb4..000000000 --- a/conf/charhelp.txt +++ /dev/null @@ -1,28 +0,0 @@ - 40:--- CHARACTER CMD --- - 40:#statsall - Set all stats of a player to maximum. - 40:#itemlist - Displays all items of a player. - 40:#storagelist - Displays all items of a player's storage. - 40:#stats - Displays a characters stats. - 60:#option - Like @option command but only to target character. - 50:#mountpeco - Give/remove to a player a peco (Class is required, but not skill). - 50:#petrename - Re-enable pet rename to a player. - 60:#save - Changes the target players respawn point. - 60:#baselvl/#blvl <#> - Change a characters base level. - 60:#joblvl/#jlvl <#> - Change a characters job level. - 60:#job/#jobchange - Changes target characters job. - 60:#zeny - Give/take a players Zeny - 60:#cash - Give/take a player cash points - 60:#points - Give/take a player Kafra points - 60:#stpoint - Give/take a players stat points - 60:#skpoint - give/take a players skill points - 60:#skreset - Reset skills of a character. - 60:#streset - Reset stats of a character. - 60:#reset - Reset stats AND skills of a character. - 60:#questskill <#> - Gives to a player the specified quest skill. - 60:#lostskill <#> - Takes away the specified quest skill from the player. - 60:#delitem - Remove items from a character - 50:#model - Changes a player's model - 60:#disguise - Changes disguise of a player - 60:#undisguise - Cancels disguise of a player - 60:#changesex - Changes sex of a player (all characters of the account) - 60:#warp/#rura+ - Warps character to location of choice diff --git a/conf/global/console.conf b/conf/global/console.conf index d26c48352..21ee46bd0 100644 --- a/conf/global/console.conf +++ b/conf/global/console.conf @@ -56,4 +56,12 @@ console: { // [CHAR] Display information on the console whenever characters/guilds/parties/pets are loaded/saved? save_log: true + + // [MAP] Makes server log selected message types to a file in the /log/ folder + //1: Log Warning Messages + //2: Log Error and SQL Error messages. + //4: Log Debug Messages + //Example: "console_msg_log: 7" logs all 3 kinds + //Messages logged by this overrides console_silent setting + console_msg_log: 0 } diff --git a/conf/help.txt b/conf/help.txt deleted file mode 100644 index a65c7de70..000000000 --- a/conf/help.txt +++ /dev/null @@ -1,307 +0,0 @@ -// This is help file that contains help messages for atcommands/charcommands. - -// Format: -// : "" - -// This file uses libconfig syntax. - -help: "Params: \n" "Shows help for specified command." -noask: "Auto rejects deals/invites." -me: "Params: \n" "Displays normal text as a message in this format: *name message* (like /me in mIRC)." -fakename: "Params: \n" "Changes your name to your choice temporarily." -npctalk: "Params: \n" "Forces a NPC to display a message in normal chat." -broadcast: "Params: \n" "Broadcasts a message with your name (in yellow)." -kami: "Params: \n" "Broadcasts a message without your name (in yellow)." -kamib: "Params: \n" "Broadcasts a message without your name (in blue)." -localbroadcast: "Params: \n" "Broadcasts a message with your name (in yellow) only on your map." -commands: "Displays a list of commands that you can use." -rates: "Displays the server's current rates." -uptime: "Displays how long the server has been online." -showdelay: "Shows/hides the \"There is a delay after this skill\" message." -exp: "Displays current levels and % progress." -mobinfo: "Params: \n" "Shows monster info (stats, exp, drops etc)." -iteminfo: "Params: \n" "Shows item info (type, price etc)." -whodrops: "Params: \n" "Shows who drops an item (monster with highest drop rates)." -version: "Displays SVN version of the server." -email: "Params: \n" "Changes your account e-mail address." -where: "Params: \n" "Tells you the location of a character." -time: "Shows the date and time of the server." -showexp: "Displays/hides experience gained." -showzeny: "Displays/hides Zeny gained." -mobsearch: "Params: \n" "Shows the location of a certain mob on the current map." -who: "Params: []\n" "Shows a list of online players and their party and guild." -who2: "Params: []\n" "Shows a list of online players and their job." -who3: "Params: []\n" "Shows a list of online players and their location." -whomap: "@whomap/@whomap2/@whomap3 [map] - like @who/@who2/@who3 but only for specified map." -whogm: "Params: [match_text] - Like @who+@who2+who3, but only for GM." -guildspy: "Params: - You will receive all messages of the guild channel (Chat logging must be enabled)" -partyspy: "@partyspy - You will receive all messages of the party channel (Chat logging must be enabled)" -mapinfo: "Params: [<0-3> [map]] - Give information about a map (general info +: 0: no more, 1: players, 2: NPC, 3: shops/chat)." -go: "Params: \n" "Warps you to a city.\n" - " -3: (Memo point 2) 14: louyang 31: mora\n" - " -2: (Memo point 1) 15: start point 32: dewata\n" - " -1: (Memo point 0) 16: prison/jail 33: malangdo island\n" - " 0: prontera 17: jawaii 34: malaya port\n" - " 1: morocc 18: ayothaya 35: eclage\n" - " 2: geffen 19: einbroch\n" - " 3: payon 20: lighthalzen\n" - " 4: alberta 21: einbech\n" - " 5: izlude 22: hugel\n" - " 6: aldebaran 23: rachel\n" - " 7: xmas (lutie) 24: veins\n" - " 8: comodo 25: moscovia\n" - " 9: yuno 26: midgard camp\n" - " 10: amatsu 27: manuk\n" - " 11: gonryun 28: splendide\n" - " 12: umbala 29: brasilis\n" - " 13: niflheim 30: el dicastes\n" -jumpto: "Params: \n" "Warps you to selected character." -follow: "Params: \n" "Follow a player." -mount: "Give/remove you a peco (Class is required, but not skill)" -disguise: "Params: \n" "Change your appearence to other players to a mob." -undisguise: "Restore your normal appearance." -disguiseguild: "Disguises all online characters of a guild." -undisguiseguild: "Restore the normal appearance of all characters of a guild." -model: "Params: - Changes your characters appearence." -size: "Params: <1-3> Changes your size (1-Smallest 2-Biggest 3-Normal)" -sizeall: "Changes the size of all players." -sizeguild: "Changes the size of all online characters of a guild." -hide: "Makes you character invisible (GM invisibility). Type again to become visible." -save: "Sets respawn point to current spot." -load: "Warps you to your save point." -warp: "Params: [ ]\n" "Warps you to the selected map and position." -jump: "Params: [ []]\n" "Randomly warps you like a flywing." -jobchange: "Params: \n" "Changes your job.\n" - "----- Novice / 1st Class -----\n" - " 0 Novice 1 Swordman 2 Magician 3 Archer\n" - " 4 Acolyte 5 Merchant 6 Thief\n" - "----- 2nd Class -----\n" - " 7 Knight 8 Priest 9 Wizard 10 Blacksmith\n" - " 11 Hunter 12 Assassin 14 Crusader 15 Monk\n" - " 16 Sage 17 Rogue 18 Alchemist 19 Bard\n" - " 20 Dancer\n" - "----- High Novice / High 1st Class -----\n" - "4001 Novice High 4002 Swordman High 4003 Magician High 4004 Archer High\n" - "4005 Acolyte High 4006 Merchant High 4007 Thief High\n" - "----- Transcendent 2nd Class -----\n" - "4008 Lord Knight 4009 High Priest 4010 High Wizard 4011 Whitesmith\n" - "4012 Sniper 4013 Assassin Cross 4015 Paladin 4016 Champion\n" - "4017 Professor 4018 Stalker 4019 Creator 4020 Clown\n" - "4021 Gypsy\n" - "----- 3rd Class (Regular) -----\n" - "4054 Rune Knight 4055 Warlock 4056 Ranger 4057 Arch Bishop\n" - "4058 Mechanic 4059 Guillotine Cross 4066 Royal Guard 4067 Sorcerer\n" - "4068 Minstrel 4069 Wanderer 4070 Sura 4071 Genetic\n" - "4072 Shadow Chaser\n" - "----- 3rd Class (Transcendent) -----\n" - "4060 Rune Knight 4061 Warlock 4062 Ranger 4063 Arch Bishop\n" - "4064 Mechanic 4065 Guillotine Cross 4073 Royal Guard 4074 Sorcerer\n" - "4075 Minstrel 4076 Wanderer 4077 Sura 4078 Genetic\n" - "4079 Shadow Chaser\n" - "----- Expanded Class -----\n" - " 23 Super Novice 24 Gunslinger 25 Ninja 4045 Super Baby\n" - "4046 Taekwon 4047 Star Gladiator 4049 Soul Linker 4050 Gangsi\n" - "4051 Death Knight 4052 Dark Collector 4190 Ex. Super Novice 4191 Ex. Super Baby\n" - "4211 Kagerou 4212 Oboro 4215 Rebellion\n" - "----- Baby Novice And Baby 1st Class -----\n" - "4023 Baby Novice 4024 Baby Swordman 4025 Baby Magician 4026 Baby Archer\n" - "4027 Baby Acolyte 4028 Baby Merchant 4029 Baby Thief\n" - "---- Baby 2nd Class ----\n" - "4030 Baby Knight 4031 Baby Priest 4032 Baby Wizard 4033 Baby Blacksmith\n" - "4034 Baby Hunter 4035 Baby Assassin 4037 Baby Crusader 4038 Baby Monk\n" - "4039 Baby Sage 4040 Baby Rogue 4041 Baby Alchemist 4042 Baby Bard\n" - "4043 Baby Dancer\n" - "---- Baby 3rd Class ----\n" - "4096 Baby Rune Knight 4097 Baby Warlock 4098 Baby Ranger 4099 Baby Arch Bishop\n" - "4100 Baby Mechanic 4101 Baby Glt. Cross 4102 Baby Royal Guard 4103 Baby Sorcerer\n" - "4104 Baby Minstrel 4105 Baby Wanderer 4106 Baby Sura 4107 Baby Genetic\n" - "4108 Baby Shadow Chaser\n" - "---- Modes And Others ----\n" - " 22 Wedding 26 Christmas 27 Summer 4048 Star Gladiator (Union)\n" -option: "Params: (stackable) (stackable)\n" "Adds different visual effects on or around your character.\n" -" \n" -"01: Stone 01: Sight 01: Sight 512: Cart Lv. 4\n" -"02: Frozen 02: Curse 02: Hiding 1024: Cart Lv. 5\n" -"03: Stun 04: Silence 04: Cloaking 2048: Orc Head\n" -"04: Sleep 08: Signum 08: Cart Lv. 1 4096: Wedding\n" -"06: Petrify 16: Blind 16: Falcon 8192: Ruwach\n" -"07: Burning 32: Angelus 32: Riding 16384: Chasewalk\n" -"08: Imprison 64: Bleeding 64: Invisible\n" -"16: (Nothing) 128: D. Poison 128: Cart Lv. 2\n" -"32: (Nothing) 256: Fear 256: Cart Lv. 3" -heal: "Params: [ ]\n" "Heals the desired amount of HP and SP. No value specified will do a full heal." -dye: "Params: \n" "Changes your characters clothes color." -hairstyle: "Params: \n" "Changes your hair style." -haircolor: "Params \n" "Changes your hair color." -speed: "Params: <1-1000>\n" "Changes you walking speed. 1 being the fastest and 1000 the slowest. Default is 150." -effect: "Params: []\n" "Give an effect to your character." -dropall: "Throws all your possession on the ground." -storeall: "Puts all your possessions in storage." -killable: "Make your character killable." -memo: "Params: [memo position]\n" "Set/change a memo location (no position: display memo points)." -spiritball: "Params: <1-100>\n" "Gives you \"spirit spheres\" like from the skill \"Call Spirits\".\n" -questskill: "Params: <#>\n" "Gives you the specified quest skill\n" -"Novice = 142: First Aid, 143: Act Dead\n" -"Archer = 147: Create Arrow, 148: Charge Arrow\n" -"Swordman = 144: Moving HP Recovery, 145: Attack Weak Point, 146: Auto Berserk\n" -"Acolyte = 156: Holy Light\n" -"Thief = 149: Throw Sand, 150: Back Sliding, 151: Take Stone, 152: Throw Stone\n" -"Merchant = 153: Cart Revolution, 154: Change Cart, 155: Crazy Uproar, 2535: Open Buying Store\n" -"Magician = 157: Energy Coat\n" -"Hunter = 1009: Phantasmic Arrow\n" -"Bard = 1010: Pang Voice\n" -"Dancer = 1011: Wink of Charm\n" -"Knight = 1001: Charge Attack\n" -"Crusader = 1002: Shrink\n" -"Priest = 1014: Redemptio\n" -"Monk = 1015: Ki Translation, 1016: Ki Explosio\n" -"Assassin = 1003: Sonic Acceleration, 1004: Throw Venom Knife\n" -"Rogue = 1005: Close Confine\n" -"Blacksmith = 1012: Unfair Trick, 1013: Greed\n" -"Alchemist = 238: Basis of Life\n" -"Wizard = 1006: Sight Blaster\n" -"Sage = 1007: Create Elemental Converter, 1008: Elemental Change (Water), 1017: Elemental Change (Earth), 1018: Elemental Change (Fire), 1019: Elemental Change (Wind)" -lostskill: "Params: <#>\n" "Takes away the specified quest skill from you\n" -"Novice = 142: First Aid, 143: Act Dead\n" -"Archer = 147: Create Arrow, 148: Charge Arrow\n" -"Swordman = 144: Moving HP Recovery, 145: Attack Weak Point, 146: Auto Berserk\n" -"Acolyte = 156: Holy Light\n" -"Thief = 149: Throw Sand, 150: Back Sliding, 151: Take Stone, 152: Throw Stone\n" -"Merchant = 153: Cart Revolution, 154: Change Cart, 155: Crazy Uproar, 2535: Open Buying Store\n" -"Magician = 157: Energy Coat\n" -"Hunter = 1009: Phantasmic Arrow\n" -"Bard = 1010: Pang Voice\n" -"Dancer = 1011: Wink of Charm\n" -"Knight = 1001: Charge Attack\n" -"Crusader = 1002: Shrink\n" -"Priest = 1014: Redemptio\n" -"Monk = 1015: Ki Translation, 1016: Ki Explosio\n" -"Assassin = 1003: Sonic Acceleration, 1004: Throw Venom Knife\n" -"Rogue = 1005: Close Confine\n" -"Blacksmith = 1012: Unfair Trick, 1013: Greed\n" -"Alchemist = 238: Basis of Life\n" -"Wizard = 1006: Sight Blaster\n" -"Sage = 1007: Create Elemental Converter, 1008: Elemental Change (Water), 1017: Elemental Change (Earth), 1018: Elemental Change (Fire), 1019: Elemental Change (Wind)" -skillid: "Params: \n" "Look up a skill by name" -useskill: "Params: \n" "Use a skill on target" -skilltree: "Params: \n" "Prints the skill tree needed to get a skill for the target player." -marry: "Params: \n" "Marry another player." -divorce: "Divorce player." -alive: "Revives yourself from death." -blvl: "Params: \n" "Raises your base level the desired number of levels." -jlvl: "Params: \n" "Raises your job level the desired number of levels." -allskill: "Give you all skills." -stpoint: "Params: - Gives you the desired number of stat points." -skpoint: "Params: - Gives you the desired number of skill points." -zeny: "Params: - Gives you desired amount of Zeny." -cash: "Params: - Gives you the specified amount of cash points." -points: "Params: - Gives you the specified amount of Kafra Points." -str: "Params: \n" "Raises STR by given amount." -agi: "Params: \n" "Raises AGI by given amount." -dex: "Params: \n" "Raises DEX by given amount." -vit: "Params: \n" "Raises VIT by given amount." -int: "Params: \n" "Raises INT by given amount." -luk: "Params: \n" "Raises LUK by given amount." -allstats: "Params: \n" "Adds value in all stats (maximum if no value)." -addwarp: "Params: \n" -killmonster2: "Kills all monsters of your map (without drops)." -monster: "Params: [ [ [ []]]]\n" - "@monster2 [ [ []]]\n" -"@spawn/@monster/@summon/@monster2 \"desired monster name\" [ [ []]]\n" -"@spawn/@monster/@summon/@monster2 \"desired monster name\" [ [ []]]\n" -" Spawns the desired monster with any desired name." -monstersmall: "Params: \n" "Spawns a smaller version of a monster." -monsterbig: "Params: \n" "Spawns a larger version of a monster." -killmonster: "Params: \n" "Kill all monsters of the map (they drop)" -autoloot: "Params: \n" "Makes items go straight into your inventory." -autotrade: "Allows you to vend while you are offline." -changegm: "Params: \n" "Changes the leader of your guild (You must be guild leader)" -changeleader: "Params: \n" "Changes the leader of your party (You must be party leader)" -request: "Params: \n" "Sends a message to all connected GMs (via the gm whisper system)" -sound: "Params: \n" "Plays a sound from the data folder or GRF file located on the client." -clone: "Params: \n" "Spawns a supportive clone of the given player." -slaveclone: "Params: \n" "Spawns a supportive clone of the given player that follows the creator around." -evilclone: "Params: \n" "Spawns an aggressive clone of the given player." -changesex: "Changes your gender." -duel: "Starts a duel." -invite: "Invites a player to a duel." -accept: "Accepts an invitation to a duel." -reject: "Rejects an invitation to a duel." -leave: "Leaves a duel." -mail: "Open mail box." -storage: "Opens storage." -itemreset: "Remove all your items." -guildstorage: "Opens guild storage." -idsearch: "Params: \n" "Search all items that name have part_of_item_name" -refine: "Params: <+/- amount>" -produce: "Params: <# of very's>\n" -" Element: 0=None 1=Ice 2=Earth 3=Fire 4=Wind\n" -" You can add up to 3 Star Crumbs and 1 element\n" -repairall: "Repair all items of your inventory" -item: "Params: \n" "Gives you the desired item." -item2: "Params: \n" "Gives you the desired item." -pvpon: "Turns pvp on on the current map" -pvpoff: "Turns pvp off on the current map" -gvgon: "Turns gvg on on the current map" -gvgoff: "Turns gvg off on the current map" -agitstart: "Starts War of Emperium" -agitend: "End War of Emperium" -party: "Params: \n" "Create a party." -guild: "Params: \n" "Create a guild." -glvl: "Params: <# of levels>\n" "Raise Guild by desired number of levels" -guildrecall: "Params: \n" "Warps all online characters of a guild to you." -partyrecall: "Params: \n" "Warps all online characters of a party to you." -petrename: "Re-enable pet rename" -pettalk: "Params: \n" "Makes your pet say a message." -petfriendly: "Params: <#>\n" "Set pet friendly amount (0-1000) 1000 = Max" -pethungry: "Params: <#>\n" "Set pet hungry amount (0-100) 100 = Max" -hatch: "Create a pet from your inventory eggs list." -makeegg: "Params: \n" "Gives pet egg for monster number in pet DB" -kick: "Params: \n" "Kicks specified character off the server" -unjail: "Params: \n" "Discharges specified character/prisoner" -kill: "Params: \n" "Kills player." -recall: "Params: \n" "Warps target character to you." -raise: "Params: \n" "Revives target character." -block: "Params: \n" "Permanently blocks an account." -unblock: "Params: \n" "Unblocks an account." -ban: "Params: