internal async Task Init()
    {
        PlatformRacing3Server.StartTime = Stopwatch.StartNew();

        PlatformRacing3Server.ServerConfig = await JsonSerializer.DeserializeAsync <ServerConfig>(File.OpenRead("settings.json"));

        RedisConnection.Init(PlatformRacing3Server.ServerConfig);
        DatabaseConnection.Init(PlatformRacing3Server.ServerConfig);

        await this.serverManager.LoadServersAsync();

        await this.campaignManager.LoadCampaignTimesAsync();

        await this.campaignManager.LoadPrizesAsync();

        if (PlatformRacing3Server.ServerConfig.DiscordChatWebhookId != 0)
        {
            PlatformRacing3Server.DiscordChatWebhook = new DiscordWebhookClient(PlatformRacing3Server.ServerConfig.DiscordChatWebhookId, PlatformRacing3Server.ServerConfig.DiscordChatWebhookToken);
        }

        if (PlatformRacing3Server.ServerConfig.DiscordNotificationsWebhookId != 0)
        {
            PlatformRacing3Server.DiscordNotificationsWebhook = new DiscordWebhookClient(PlatformRacing3Server.ServerConfig.DiscordNotificationsWebhookId, PlatformRacing3Server.ServerConfig.DiscordNotificationsWebhookToken);
        }

        BytePacketManager bytePacketManager = new(this.serviceProvider);

        this.listener = IListener.CreateTcpListener(new IPEndPoint(IPAddress.Parse(PlatformRacing3Server.ServerConfig.BindIp), PlatformRacing3Server.ServerConfig.BindPort), socket =>
        {
            socket.Pipeline.AddHandlerFirst(new SplitPacketHandler(bytePacketManager, new ClientSession(socket)));
            socket.Pipeline.AddHandlerFirst(new FlashSocketPolicyRequestHandler());
        }, this.serviceProvider);

        _ = UpdateStatus();
    }
Exemplo n.º 2
0
        internal void Init()
        {
            PlatformRacing3Server.Logger.Info("Starting up server...");

            try
            {
                PlatformRacing3Server.StartTime = Stopwatch.StartNew();

                PlatformRacing3Server.ServerConfig = JsonConvert.DeserializeObject <ServerConfig>(File.ReadAllText("settings.json"));

                RedisConnection.Init(PlatformRacing3Server.ServerConfig);
                DatabaseConnection.Init(PlatformRacing3Server.ServerConfig);

                PlatformRacing3Server.ServerManager = new ServerManager();
                PlatformRacing3Server.ServerManager.LoadServersAsync().Wait();
                PlatformRacing3Server.CommandManager      = new CommandManager();
                PlatformRacing3Server.ChatRoomManager     = new ChatRoomManager();
                PlatformRacing3Server.MatchListingManager = new MatchListingManager();
                PlatformRacing3Server.MatchManager        = new MatchManager();

                PlatformRacing3Server.CampaignManager = new CampaignManager();
                PlatformRacing3Server.CampaignManager.LoadCampaignTimesAsync().Wait();
                PlatformRacing3Server.CampaignManager.LoadPrizesAsync().Wait();

                PlatformRacing3Server.BytePacketManager = new BytePacketManager(new StandardKernel());
                PlatformRacing3Server.PacketManager     = new PacketManager();
                PlatformRacing3Server.ClientManager     = new ClientManager();
                PlatformRacing3Server.Listener          = IListener.CreateTcpListener(new IPEndPoint(IPAddress.Parse(PlatformRacing3Server.ServerConfig.BindIp), PlatformRacing3Server.ServerConfig.BindPort), socket =>
                {
                    socket.Pipeline.AddHandlerFirst(new SplitPacketHandler(new ClientSession(socket)));
                    socket.Pipeline.AddHandlerFirst(new FlashSocketPolicyRequestHandler());
                });

                if (PlatformRacing3Server.ServerConfig.DiscordChatWebhookId != 0)
                {
                    PlatformRacing3Server.DiscordChatWebhook = new DiscordWebhookClient(PlatformRacing3Server.ServerConfig.DiscordChatWebhookId, PlatformRacing3Server.ServerConfig.DiscordChatWebhookToken);
                }

                if (PlatformRacing3Server.ServerConfig.DiscordNotificationsWebhookId != 0)
                {
                    PlatformRacing3Server.DiscordNotificationsWebhook = new DiscordWebhookClient(PlatformRacing3Server.ServerConfig.DiscordNotificationsWebhookId, PlatformRacing3Server.ServerConfig.DiscordNotificationsWebhookToken);
                }

                PlatformRacing3Server.StatusTimer = new Timer(this.UpdateStatus, null, 1000, 1000);
            }
            catch (Exception ex)
            {
                PlatformRacing3Server.Logger.Fatal("Failed to boot", ex);

                this.FailedToBoot();
            }
        }