void GameThread()
        {
            if (needLoadData)
            {
                FLLog.Info("Server", "Loading Game Data...");
                GameData.LoadData();
                FLLog.Info("Server", "Finished Loading Game Data");
            }
            if (!string.IsNullOrWhiteSpace(DbConnectionString))
            {
                Database = new ServerDatabase(DbConnectionString);
            }
            Listener?.Start();
            Stopwatch sw       = Stopwatch.StartNew();
            double    lastTime = 0;

            while (running)
            {
                while (!localPackets.IsEmpty && localPackets.TryDequeue(out var local))
                {
                    LocalPlayer.ProcessPacket(local);
                }
                Action a;
                if (worldRequests.Count > 0 && worldRequests.TryDequeue(out a))
                {
                    a();
                }
                //Start Loop
                var time    = sw.Elapsed.TotalMilliseconds;
                var elapsed = (time - lastTime);
                if (elapsed < 2)
                {
                    continue;
                }
                elapsed /= 1000f;
                lastTime = time;
                //Update
                LocalPlayer?.UpdateMissionRuntime(TimeSpan.FromSeconds(elapsed));
                foreach (var world in worlds.Values)
                {
                    world.Update(TimeSpan.FromSeconds(elapsed));
                }
                //Sleep
                Thread.Sleep(0);
            }
            Listener?.Stop();
        }
예제 #2
0
        void GameThread()
        {
            if (needLoadData)
            {
                FLLog.Info("Server", "Loading Game Data...");
                GameData.LoadData(null);
                FLLog.Info("Server", "Finished Loading Game Data");
            }
            InitBaselinePrices();
            Database = new ServerDatabase(this);
            Listener?.Start();
            double lastTime = 0;

            processingLoop = new ServerLoop(Process);
            processingLoop.Start();
            Listener?.Stop();
        }
예제 #3
0
        void GameThread()
        {
            if (needLoadData)
            {
                FLLog.Info("Server", "Loading Game Data...");
                GameData.LoadData();
                FLLog.Info("Server", "Finished Loading Game Data");
            }
            Database = new ServerDatabase(this);
            Listener?.Start();
            Stopwatch sw       = Stopwatch.StartNew();
            double    lastTime = 0;

            while (running)
            {
                while (!localPackets.IsEmpty && localPackets.TryDequeue(out var local))
                {
                    LocalPlayer.ProcessPacket(local);
                }
                Action a;
                if (worldRequests.Count > 0 && worldRequests.TryDequeue(out a))
                {
                    a();
                }
                //Start Loop
                var time    = sw.Elapsed.TotalMilliseconds;
                var elapsed = (time - lastTime);
                if (elapsed < 2)
                {
                    continue;
                }
                elapsed /= 1000f;
                lastTime = time;
                //Update
                LocalPlayer?.UpdateMissionRuntime(TimeSpan.FromSeconds(elapsed));
                ConcurrentBag <StarSystem> toSpinDown = new ConcurrentBag <StarSystem>();
                Parallel.ForEach(worlds, (world) =>
                {
                    if (!world.Value.Update(TimeSpan.FromSeconds(elapsed)))
                    {
                        toSpinDown.Add(world.Key);
                    }
                });
                //Remove
                if (toSpinDown.Count > 0)
                {
                    lock (availableWorlds)
                    {
                        foreach (var w in toSpinDown)
                        {
                            if (worlds[w].PlayerCount <= 0)
                            {
                                worlds[w].Finish();
                                availableWorlds.Remove(w);
                                worlds.Remove(w);
                                FLLog.Info("Server", $"Shut down world {w.Nickname} ({w.Name})");
                            }
                        }
                    }
                }
                //Sleep
                Thread.Sleep(0);
            }
            Listener?.Stop();
        }