Files
Ragon/Ragon.Server/Sources/RagonServerConfiguration.cs
T

77 lines
2.4 KiB
C#
Raw Permalink Normal View History

2023-03-06 10:06:43 +04:00
/*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2022-12-16 00:05:46 +04:00
using Newtonsoft.Json;
using NLog;
2023-03-06 10:06:43 +04:00
namespace Ragon.Server;
public enum ServerType
{
ENET,
WEBSOCKET,
}
2022-12-16 00:05:46 +04:00
[Serializable]
2023-07-01 07:47:57 +03:00
public struct RagonServerConfiguration
2022-12-16 00:05:46 +04:00
{
2022-12-20 12:20:52 -08:00
public string ServerKey;
public string ServerType;
public ushort ServerTickRate;
public string GameProtocol;
2022-12-16 00:05:46 +04:00
public ushort Port;
2023-04-13 20:42:05 +04:00
public ushort HttpPort;
public string HttpKey;
2022-12-16 00:05:46 +04:00
public int LimitConnections;
public int LimitPlayersPerRoom;
public int LimitRooms;
2023-07-01 07:47:57 +03:00
public int LimitBufferedEvents;
2023-04-09 10:52:18 +04:00
public Dictionary<string, string> WebHooks;
2022-12-16 00:05:46 +04:00
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
2023-10-22 21:10:31 +03:00
private static readonly string ServerVersion = "1.3.2";
2023-03-06 10:06:43 +04:00
private static Dictionary<string, ServerType> _serverTypes = new Dictionary<string, ServerType>()
{
{"enet", Server.ServerType.ENET},
{"websocket", Server.ServerType.WEBSOCKET}
};
2022-12-16 00:05:46 +04:00
2023-07-01 07:47:57 +03:00
public static RagonServerConfiguration Load(string filePath)
2023-04-09 10:52:18 +04:00
{
CopyrightInfo();
var data = File.ReadAllText(filePath);
2023-07-01 07:47:57 +03:00
var configuration = JsonConvert.DeserializeObject<RagonServerConfiguration>(data);
2023-04-09 10:52:18 +04:00
return configuration;
}
2022-12-16 00:05:46 +04:00
private static void CopyrightInfo()
{
2023-10-14 21:48:33 +03:00
Logger.Info($"Server Version: {ServerVersion}");
2022-12-16 00:05:46 +04:00
Logger.Info($"Machine Name: {Environment.MachineName}");
Logger.Info($"OS: {Environment.OSVersion}");
Logger.Info($"Processors: {Environment.ProcessorCount}");
Logger.Info($"Runtime Version: {Environment.Version}");
Logger.Info("==================================");
2023-04-09 10:52:18 +04:00
Logger.Info(@" ___ _ ___ ___ _ _ ");
Logger.Info(@" | _ \ /_\ / __|/ _ \| \| |");
Logger.Info(@" | / / _ \ (_ | (_) | .` |");
Logger.Info(@" |_|_\/_/ \_\___|\___/|_|\_|");
2022-12-16 00:05:46 +04:00
Logger.Info("==================================");
}
2023-03-06 10:06:43 +04:00
public static ServerType GetServerType(string type) => _serverTypes[type];
2022-12-16 00:05:46 +04:00
}