2023-03-06 10:06:43 +04:00
|
|
|
/*
|
2024-05-19 12:26:42 +03:00
|
|
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
2023-03-06 10:06:43 +04:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2024-05-19 08:54:49 +03:00
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using Newtonsoft.Json;
|
2023-03-06 10:06:43 +04:00
|
|
|
using Ragon.Server;
|
2023-10-08 21:13:31 +03:00
|
|
|
using Ragon.Server.ENetServer;
|
2023-04-09 11:06:52 +04:00
|
|
|
using Ragon.Server.IO;
|
2024-05-19 08:54:49 +03:00
|
|
|
using Ragon.Server.Logging;
|
2023-04-09 11:06:52 +04:00
|
|
|
using Ragon.Server.Plugin;
|
2024-05-19 08:54:49 +03:00
|
|
|
using Ragon.Server.WebSocketServer;
|
2023-03-06 10:06:43 +04:00
|
|
|
|
2024-05-19 08:54:49 +03:00
|
|
|
namespace Ragon.Relay
|
2023-03-06 10:06:43 +04:00
|
|
|
{
|
2024-05-19 08:54:49 +03:00
|
|
|
public class Relay
|
2023-03-06 10:06:43 +04:00
|
|
|
{
|
2024-05-19 08:54:49 +03:00
|
|
|
public void Start()
|
|
|
|
|
{
|
|
|
|
|
LoggerManager.SetLoggerFactory(new RelayLoggerFactory());
|
2023-03-06 10:06:43 +04:00
|
|
|
|
2024-05-19 08:54:49 +03:00
|
|
|
var logger = LoggerManager.GetLogger("Relay");
|
|
|
|
|
logger.Info("Relay Application");
|
2023-03-06 10:06:43 +04:00
|
|
|
|
2024-05-19 08:54:49 +03:00
|
|
|
var data = File.ReadAllText("relay.config.json");
|
|
|
|
|
var configuration = JsonConvert.DeserializeObject<RelayConfiguration>(data);
|
|
|
|
|
var serverType = RagonServerConfiguration.GetServerType(configuration.ServerType);
|
|
|
|
|
|
|
|
|
|
INetworkServer networkServer = new ENetServer();
|
|
|
|
|
IServerPlugin plugin = new RelayServerPlugin();
|
2024-05-19 11:28:36 +03:00
|
|
|
|
2024-05-19 08:54:49 +03:00
|
|
|
switch (serverType)
|
|
|
|
|
{
|
|
|
|
|
case ServerType.ENET:
|
|
|
|
|
networkServer = new ENetServer();
|
|
|
|
|
break;
|
|
|
|
|
case ServerType.WEBSOCKET:
|
|
|
|
|
networkServer = new WebSocketServer();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-03-06 10:06:43 +04:00
|
|
|
|
2024-05-19 08:54:49 +03:00
|
|
|
var serverConfiguration = new RagonServerConfiguration()
|
|
|
|
|
{
|
|
|
|
|
LimitConnections = configuration.LimitConnections,
|
|
|
|
|
LimitRooms = configuration.LimitConnections,
|
|
|
|
|
LimitBufferedEvents = configuration.LimitConnections,
|
|
|
|
|
LimitPlayersPerRoom = configuration.LimitConnections,
|
|
|
|
|
Port = configuration.Port,
|
|
|
|
|
Protocol = configuration.Protocol,
|
|
|
|
|
ServerKey = configuration.ServerKey,
|
|
|
|
|
ServerTickRate = configuration.ServerTickRate,
|
2024-08-15 23:20:23 +03:00
|
|
|
ServerAddress = configuration.ServerAddress,
|
2024-05-19 08:54:49 +03:00
|
|
|
};
|
2024-05-19 11:28:36 +03:00
|
|
|
|
2024-05-19 08:54:49 +03:00
|
|
|
var relay = new RagonServer(networkServer, plugin, serverConfiguration);
|
|
|
|
|
relay.Start();
|
|
|
|
|
while (relay.IsRunning)
|
|
|
|
|
{
|
|
|
|
|
relay.Tick();
|
|
|
|
|
Thread.Sleep(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
relay.Dispose();
|
|
|
|
|
}
|
2023-03-06 10:06:43 +04:00
|
|
|
}
|
|
|
|
|
}
|