2019-06-18 22:55:32 -04:00
|
|
|
|
/*
|
|
|
|
|
===========================================================================
|
|
|
|
|
Copyright (C) 2015-2019 Project Meteor Dev Team
|
|
|
|
|
|
|
|
|
|
This file is part of Project Meteor Server.
|
|
|
|
|
|
|
|
|
|
Project Meteor Server is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
Project Meteor Server 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 Affero General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
along with Project Meteor Server. If not, see <https:www.gnu.org/licenses/>.
|
|
|
|
|
===========================================================================
|
|
|
|
|
*/
|
|
|
|
|
|
2019-06-19 00:05:18 -04:00
|
|
|
|
using Meteor.Common;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2016-12-04 21:41:34 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
2019-06-19 01:10:15 -04:00
|
|
|
|
namespace Meteor.Map
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
|
|
|
|
class ConfigConstants
|
|
|
|
|
{
|
|
|
|
|
public static String OPTIONS_BINDIP;
|
2016-06-08 22:29:04 +01:00
|
|
|
|
public static String OPTIONS_PORT;
|
2016-12-04 21:41:34 +00:00
|
|
|
|
public static bool OPTIONS_TIMESTAMP = false;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
2016-12-04 21:41:34 +00:00
|
|
|
|
public static uint DATABASE_WORLDID;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
public static String DATABASE_HOST;
|
|
|
|
|
public static String DATABASE_PORT;
|
|
|
|
|
public static String DATABASE_NAME;
|
|
|
|
|
public static String DATABASE_USERNAME;
|
|
|
|
|
public static String DATABASE_PASSWORD;
|
|
|
|
|
|
2016-06-14 21:29:10 +01:00
|
|
|
|
public static bool Load()
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
2016-06-15 19:14:21 +01:00
|
|
|
|
Program.Log.Info("Loading map_config.ini file... ");
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
2016-06-08 22:29:04 +01:00
|
|
|
|
if (!File.Exists("./map_config.ini"))
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
2016-06-15 20:09:53 -04:00
|
|
|
|
Program.Log.Error("FILE NOT FOUND");
|
2016-12-04 21:41:34 +00:00
|
|
|
|
Program.Log.Error("Loading defaults... ");
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-08 22:29:04 +01:00
|
|
|
|
INIFile configIni = new INIFile("./map_config.ini");
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
2016-12-05 14:34:40 +00:00
|
|
|
|
ConfigConstants.OPTIONS_BINDIP = configIni.GetValue("General", "server_ip", "127.0.0.1");
|
|
|
|
|
ConfigConstants.OPTIONS_PORT = configIni.GetValue("General", "server_port", "1989");
|
|
|
|
|
ConfigConstants.OPTIONS_TIMESTAMP = configIni.GetValue("General", "showtimestamp", "true").ToLower().Equals("true");
|
|
|
|
|
|
|
|
|
|
ConfigConstants.DATABASE_WORLDID = UInt32.Parse(configIni.GetValue("Database", "worldid", "0"));
|
|
|
|
|
ConfigConstants.DATABASE_HOST = configIni.GetValue("Database", "host", "");
|
|
|
|
|
ConfigConstants.DATABASE_PORT = configIni.GetValue("Database", "port", "");
|
|
|
|
|
ConfigConstants.DATABASE_NAME = configIni.GetValue("Database", "database", "");
|
|
|
|
|
ConfigConstants.DATABASE_USERNAME = configIni.GetValue("Database", "username", "");
|
|
|
|
|
ConfigConstants.DATABASE_PASSWORD = configIni.GetValue("Database", "password", "");
|
2016-12-04 21:41:34 +00:00
|
|
|
|
|
2015-09-25 18:52:25 -04:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-12-04 21:41:34 +00:00
|
|
|
|
|
|
|
|
|
public static void ApplyLaunchArgs(string[] launchArgs)
|
|
|
|
|
{
|
|
|
|
|
var args = (from arg in launchArgs select arg.ToLower().Trim().TrimStart('-')).ToList();
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i + 1 < args.Count; i += 2)
|
|
|
|
|
{
|
|
|
|
|
var arg = args[i];
|
|
|
|
|
var val = args[i + 1];
|
|
|
|
|
var legit = false;
|
|
|
|
|
|
|
|
|
|
if (arg == "ip")
|
|
|
|
|
{
|
|
|
|
|
IPAddress ip;
|
|
|
|
|
if (IPAddress.TryParse(val, out ip) && (legit = true))
|
|
|
|
|
OPTIONS_BINDIP = val;
|
|
|
|
|
}
|
|
|
|
|
else if (arg == "port")
|
|
|
|
|
{
|
|
|
|
|
UInt16 port;
|
|
|
|
|
if (UInt16.TryParse(val, out port) && (legit = true))
|
|
|
|
|
OPTIONS_PORT = val;
|
|
|
|
|
}
|
2017-03-25 04:36:19 +00:00
|
|
|
|
else if (arg == "user" && (legit = true))
|
|
|
|
|
{
|
|
|
|
|
DATABASE_USERNAME = val;
|
|
|
|
|
}
|
|
|
|
|
else if (arg == "p" && (legit = true))
|
|
|
|
|
{
|
|
|
|
|
DATABASE_PASSWORD = val;
|
|
|
|
|
}
|
|
|
|
|
else if (arg == "db" && (legit = true))
|
|
|
|
|
{
|
|
|
|
|
DATABASE_NAME = val;
|
|
|
|
|
}
|
|
|
|
|
else if (arg == "host" && (legit = true))
|
|
|
|
|
{
|
|
|
|
|
DATABASE_HOST = val;
|
|
|
|
|
}
|
2016-12-04 21:41:34 +00:00
|
|
|
|
if (!legit)
|
|
|
|
|
{
|
|
|
|
|
Program.Log.Error("Invalid parameter <{0}> for argument: <--{1}> or argument doesnt exist!", val, arg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
}
|