Exemple #1
0
        void ParseBlockInteractionAction(ClientState client)
        {
            var pc     = ServerPlayerEntityManager.Instance;
            var player = pc.GetPlayerByOwner(client);

            if (player == null)
            {
                return;
            }
            if (pc.GetBlockInSight(player, out var pos, out var block))
            {
                DebugOutput.Log($"Player {client.UserName} tried to interact with block of type {block.Type} at {pos} .");
                ServerChunkManager.Instance.InteractWithBlockAt(pos);
            }
Exemple #2
0
        public void Run(ServerGameManager server, int tickTime, int rareTickTime, CancellationTokenSource cancellationTokenSource)
        {
            _cancellationTokenSource = cancellationTokenSource;
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            server.Create(tickTime / (float)1000);
            server.Init();
            server.PostInit();
            server.Load();
            Thread.Sleep(tickTime);
            server.PostLoad();

            var rareTickCount = rareTickTime / tickTime;

            sw.Stop();
            DebugOutput.Log($"Server initialization time: {sw.ElapsedMilliseconds} ms");
            Thread.Sleep(tickTime);
            int counter = 0;

            while (!_cancellationTokenSource.Token.IsCancellationRequested)
            {
                sw.Restart();
                server.UpdateControllers();
                server.LateUpdateControllers();
                counter++;
                if (counter >= rareTickCount)
                {
                    counter = 0;
                    server.RareUpdateControllers();
                }
                sw.Stop();
                var waitTime = tickTime - sw.ElapsedMilliseconds;
                if (waitTime < 0)
                {
                    waitTime = 0;
                }
                Thread.Sleep((int)waitTime);
            }

            server.Save();
            server.Reset();
        }