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

72 lines
2.2 KiB
C#
Raw 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]
public struct Configuration
{
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;
public int LimitConnections;
public int LimitPlayersPerRoom;
public int LimitRooms;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
2023-03-06 10:06:43 +04:00
private static readonly string ServerVersion = "1.1.0-rc";
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
private static void CopyrightInfo()
{
Logger.Info($"Server Version: {ServerVersion}");
Logger.Info($"Machine Name: {Environment.MachineName}");
Logger.Info($"OS: {Environment.OSVersion}");
Logger.Info($"Processors: {Environment.ProcessorCount}");
Logger.Info($"Runtime Version: {Environment.Version}");
Logger.Info("==================================");
Logger.Info("| |");
Logger.Info("| Ragon |");
Logger.Info("| |");
Logger.Info("==================================");
}
public static Configuration Load(string filePath)
{
CopyrightInfo();
var data = File.ReadAllText(filePath);
var configuration = JsonConvert.DeserializeObject<Configuration>(data);
return configuration;
}
2023-03-06 10:06:43 +04:00
public static ServerType GetServerType(string type) => _serverTypes[type];
2022-12-16 00:05:46 +04:00
}