summaryrefslogtreecommitdiff
path: root/src/char
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2014-01-25 09:43:09 -0800
committerBen Longbons <b.r.longbons@gmail.com>2014-01-25 10:14:44 -0800
commit34f0540da418b01dd4d49f6ecf72569d3cfecfdf (patch)
treebf7c4623b0d794e4db8c72b0906bb40807d62ba8 /src/char
parent9a4c3a44476f3306a8deed8a836e8fbc25ceb55f (diff)
downloadtmwa-34f0540da418b01dd4d49f6ecf72569d3cfecfdf.tar.gz
tmwa-34f0540da418b01dd4d49f6ecf72569d3cfecfdf.tar.bz2
tmwa-34f0540da418b01dd4d49f6ecf72569d3cfecfdf.tar.xz
tmwa-34f0540da418b01dd4d49f6ecf72569d3cfecfdf.zip
Implement unified config parsing (mostly)
Diffstat (limited to 'src/char')
-rw-r--r--src/char/char.cpp156
-rw-r--r--src/char/char.hpp4
-rw-r--r--src/char/int_party.cpp7
-rw-r--r--src/char/int_party.hpp2
-rw-r--r--src/char/int_storage.cpp6
-rw-r--r--src/char/int_storage.hpp2
-rw-r--r--src/char/inter.cpp43
-rw-r--r--src/char/inter.hpp5
8 files changed, 90 insertions, 135 deletions
diff --git a/src/char/char.cpp b/src/char/char.cpp
index 5c5179d..cb159c3 100644
--- a/src/char/char.cpp
+++ b/src/char/char.cpp
@@ -24,6 +24,7 @@
#include "../io/lock.hpp"
#include "../io/read.hpp"
+#include "../common/config_parse.hpp"
#include "../common/core.hpp"
#include "../common/db.hpp"
#include "../common/extract.hpp"
@@ -80,9 +81,9 @@ static
FString char_log_filename = "log/char.log";
//Added for lan support
static
-IP4Address lan_map_ip;
+IP4Address lan_map_ip = IP4_LOCALHOST;
static
-IP4Mask lan_subnet;
+IP4Mask lan_subnet = IP4Mask(IP4_LOCALHOST, IP4_BROADCAST);
static
int char_name_option = 0; // Option to know which letters/symbols are authorised in the name of a character (0: all, 1: only those in char_name_letters, 2: all EXCEPT those in char_name_letters) by [Yor]
static
@@ -451,7 +452,7 @@ int mmo_char_init(void)
{
line_count++;
- if (line.startswith("//"))
+ if (is_comment(line))
continue;
{
@@ -2536,32 +2537,11 @@ void check_connect_login_server(TimerData *, tick_t)
// Reading Lan Support configuration by [Yor]
//-------------------------------------------
static
-int lan_config_read(ZString lancfgName)
+bool char_lan_config(XString w1, ZString w2)
{
struct hostent *h = NULL;
- // set default configuration
- lan_map_ip = IP4_LOCALHOST;
- lan_subnet = IP4Mask(IP4_LOCALHOST, IP4_BROADCAST);
-
- io::ReadFile in(lancfgName);
-
- if (!in.is_open())
- {
- PRINTF("LAN support configuration file not found: %s\n", lancfgName);
- return 1;
- }
-
- PRINTF("---start reading of Lan Support configuration...\n");
-
- FString line;
- while (in.getline(line))
{
- XString w1;
- ZString w2;
- if (!split_key_value(line, &w1, &w2))
- continue;
-
if (w1 == "lan_map_ip")
{
// Read map-server Lan IP Address
@@ -2577,8 +2557,8 @@ int lan_config_read(ZString lancfgName)
}
else
{
- PRINTF("Bad IP value: %s\n", line);
- abort();
+ PRINTF("Bad IP value: %s\n", w2);
+ return false;
}
PRINTF("LAN IP of map-server: %s.\n", lan_map_ip);
}
@@ -2587,54 +2567,42 @@ int lan_config_read(ZString lancfgName)
{
if (!extract(w2, &lan_subnet))
{
- PRINTF("Bad IP mask: %s\n", line);
- abort();
+ PRINTF("Bad IP mask: %s\n", w2);
+ return false;
}
PRINTF("Sub-network of the map-server: %s.\n",
lan_subnet);
}
else
{
- FString w1z = w1;
- PRINTF("WARNING: unknown lan config key: %s\n", w1z);
+ return false;
}
}
+ return true;
+}
+static
+bool lan_check()
+{
// sub-network check of the map-server
{
PRINTF("LAN test of LAN IP of the map-server: ");
if (!lan_ip_check(lan_map_ip))
{
PRINTF("\033[1;31m***ERROR: LAN IP of the map-server doesn't belong to the specified Sub-network.\033[0m\n");
+ return false;
}
}
- PRINTF("---End reading of Lan Support configuration...\n");
-
- return 0;
+ return true;
}
static
-int char_config_read(ZString cfgName)
+bool char_config(XString w1, ZString w2)
{
struct hostent *h = NULL;
- io::ReadFile in(cfgName);
-
- if (!in.is_open())
{
- PRINTF("Configuration file not found: %s.\n", cfgName);
- exit(1);
- }
-
- FString line;
- while (in.getline(line))
- {
- XString w1;
- ZString w2;
- if (!split_key_value(line, &w1, &w2))
- continue;
-
if (w1 == "userid")
userid = stringish<AccountName>(w2);
else if (w1 == "passwd")
@@ -2665,8 +2633,8 @@ int char_config_read(ZString cfgName)
}
else
{
- PRINTF("Bad IP value: %s\n", line);
- abort();
+ PRINTF("Bad IP value: %s\n", w2);
+ return false;
}
}
else if (w1 == "login_port")
@@ -2689,8 +2657,8 @@ int char_config_read(ZString cfgName)
}
else
{
- PRINTF("Bad IP value: %s\n", line);
- abort();
+ PRINTF("Bad IP value: %s\n", w2);
+ return false;
}
}
else if (w1 == "char_port")
@@ -2775,18 +2743,13 @@ int char_config_read(ZString cfgName)
std::chrono::seconds(atoi(w2.c_str())),
std::chrono::seconds(5));
}
- else if (w1 == "import")
- {
- char_config_read(w2);
- }
else
{
- FString w1z = w1;
- PRINTF("WARNING: unknown char config key: %s\n", w1z);
+ return false;
}
}
- return 0;
+ return true;
}
void term_func(void)
@@ -2808,39 +2771,70 @@ void term_func(void)
CHAR_LOG("----End of char-server (normal end with closing of all files).\n");
}
+static
+bool char_confs(XString key, ZString value)
+{
+ unsigned sum = 0;
+ sum += char_config(key, value);
+ sum += char_lan_config(key, value);
+ sum += inter_config(key, value);
+ if (sum >= 2)
+ abort();
+ return sum;
+}
+
int do_init(int argc, ZString *argv)
{
- int i;
+ for (int i = 0; i < MAX_MAP_SERVERS; i++)
+ {
+ server[i] = mmo_map_server{};
+ server_fd[i] = -1;
+ }
+
+ bool loaded_config_yet = false;
+ for (int i = 1; i < argc; ++i)
+ {
+ if (argv[i].startswith('-'))
+ {
+ if (argv[i] == "--help")
+ {
+ PRINTF("Usage: %s [--help] [--version] [files...]\n",
+ argv[0]);
+ exit(0);
+ }
+ else if (argv[i] == "--version")
+ {
+ PRINTF("%s\n", CURRENT_VERSION_STRING);
+ exit(0);
+ }
+ else
+ {
+ FPRINTF(stderr, "Unknown argument: %s\n", argv[i]);
+ runflag = false;
+ }
+ }
+ else
+ {
+ loaded_config_yet = true;
+ runflag &= load_config_file(argv[i], char_confs);
+ }
+ }
+
+ if (!loaded_config_yet)
+ runflag &= load_config_file("conf/tmwa-char.conf", char_confs);
// a newline in the log...
CHAR_LOG("");
CHAR_LOG("The char-server starting...\n");
- if (argc > 1)
- char_config_read(argv[1]);
- else
- char_config_read(CHAR_CONF_NAME);
- if (argc > 1)
- lan_config_read(argv[2]);
- else
- lan_config_read(LOGIN_LAN_CONF_NAME);
-
- for (i = 0; i < MAX_MAP_SERVERS; i++)
- {
- server[i] = mmo_map_server{};
- server_fd[i] = -1;
- }
+ runflag &= lan_check();
+ inter_init2();
mmo_char_init();
update_online = TimeT::now();
create_online_files(); // update online players files at start of the server
- if (argc > 3)
- inter_init(argv[3]);
- else
- inter_init(inter_cfgName);
-
// set_termfunc (do_final);
set_defaultparse(parse_char);
diff --git a/src/char/char.hpp b/src/char/char.hpp
index f24acbc..27bdd36 100644
--- a/src/char/char.hpp
+++ b/src/char/char.hpp
@@ -9,10 +9,6 @@
constexpr int MAX_MAP_SERVERS = 30;
-# define CHAR_CONF_NAME "conf/char_athena.conf"
-
-# define LOGIN_LAN_CONF_NAME "conf/lan_support.conf"
-
struct mmo_map_server
{
IP4Address ip;
diff --git a/src/char/int_party.cpp b/src/char/int_party.cpp
index 2972689..1fc0c05 100644
--- a/src/char/int_party.cpp
+++ b/src/char/int_party.cpp
@@ -102,11 +102,11 @@ bool extract(XString str, party *p)
}
// パーティデータのロード
-int inter_party_init(void)
+void inter_party_init(void)
{
io::ReadFile in(party_txt);
if (!in.is_open())
- return 1;
+ return;
// TODO: convert to use char_id, and change to extract()
FString line;
@@ -136,9 +136,6 @@ int inter_party_init(void)
}
c++;
}
-// PRINTF("int_party: %s read done (%d parties)\n", party_txt, c);
-
- return 0;
}
// パーティーデータのセーブ用
diff --git a/src/char/int_party.hpp b/src/char/int_party.hpp
index e5a3ab9..4e5547c 100644
--- a/src/char/int_party.hpp
+++ b/src/char/int_party.hpp
@@ -3,7 +3,7 @@
# include "../strings/fwd.hpp"
-int inter_party_init(void);
+void inter_party_init(void);
int inter_party_save(void);
int inter_party_parse_frommap(int fd);
diff --git a/src/char/int_storage.cpp b/src/char/int_storage.cpp
index 4e52215..323a451 100644
--- a/src/char/int_storage.cpp
+++ b/src/char/int_storage.cpp
@@ -100,7 +100,7 @@ struct storage *account2storage(int account_id)
//---------------------------------------------------------
// 倉庫データを読み込む
-int inter_storage_init(void)
+void inter_storage_init(void)
{
int c = 0;
@@ -108,7 +108,7 @@ int inter_storage_init(void)
if (!in.is_open())
{
PRINTF("cant't read : %s\n", storage_txt);
- return 1;
+ return;
}
FString line;
@@ -126,8 +126,6 @@ int inter_storage_init(void)
}
c++;
}
-
- return 0;
}
static
diff --git a/src/char/int_storage.hpp b/src/char/int_storage.hpp
index 6c13923..23d7441 100644
--- a/src/char/int_storage.hpp
+++ b/src/char/int_storage.hpp
@@ -3,7 +3,7 @@
# include "../strings/fwd.hpp"
-int inter_storage_init(void);
+void inter_storage_init(void);
int inter_storage_save(void);
void inter_storage_delete(int account_id);
struct storage *account2storage(int account_id);
diff --git a/src/char/inter.cpp b/src/char/inter.cpp
index 38e6194..a0569a7 100644
--- a/src/char/inter.cpp
+++ b/src/char/inter.cpp
@@ -15,6 +15,7 @@
#include "../io/lock.hpp"
#include "../io/read.hpp"
+#include "../common/config_parse.hpp"
#include "../common/db.hpp"
#include "../common/extract.hpp"
#include "../common/socket.hpp"
@@ -106,13 +107,13 @@ bool extract(XString str, struct accreg *reg)
// アカウント変数の読み込み
static
-int inter_accreg_init(void)
+void inter_accreg_init(void)
{
int c = 0;
io::ReadFile in(accreg_txt);
if (!in.is_open())
- return 1;
+ return;
FString line;
while (in.getline(line))
{
@@ -128,8 +129,6 @@ int inter_accreg_init(void)
}
c++;
}
-
- return 0;
}
// アカウント変数のセーブ用
@@ -160,30 +159,9 @@ int inter_accreg_save(void)
return 0;
}
-//--------------------------------------------------------
-
-/*==========================================
- * 設定ファイルを読み込む
- *------------------------------------------
- */
-static
-int inter_config_read(ZString cfgName)
+bool inter_config(XString w1, ZString w2)
{
- io::ReadFile in(cfgName);
- if (!in.is_open())
- {
- PRINTF("file not found: %s\n", cfgName);
- return 1;
- }
-
- FString line;
- while (in.getline(line))
{
- XString w1;
- ZString w2;
- if (!split_key_value(line, &w1, &w2))
- continue;
-
if (w1 == "storage_txt")
{
storage_txt = w2;
@@ -202,18 +180,13 @@ int inter_config_read(ZString cfgName)
if (party_share_level < 0)
party_share_level = 0;
}
- else if (w1 == "import")
- {
- inter_config_read(w2);
- }
else
{
- FString w1z = w1;
- PRINTF("WARNING: unknown inter config key: %s\n", w1z);
+ return false;
}
}
- return 0;
+ return true;
}
// セーブ
@@ -225,10 +198,8 @@ void inter_save(void)
}
// 初期化
-void inter_init(ZString file)
+void inter_init2()
{
- inter_config_read(file);
-
inter_party_init();
inter_storage_init();
inter_accreg_init();
diff --git a/src/char/inter.hpp b/src/char/inter.hpp
index ece340a..ae508f6 100644
--- a/src/char/inter.hpp
+++ b/src/char/inter.hpp
@@ -3,14 +3,13 @@
# include "../strings/fwd.hpp"
-void inter_init(ZString file);
+bool inter_config(XString key, ZString value);
+void inter_init2();
void inter_save(void);
int inter_parse_frommap(int fd);
int inter_check_length(int fd, int length);
-# define inter_cfgName "conf/inter_athena.conf"
-
extern int party_share_level;
#endif // INTER_HPP