Exemple #1
0
        /// <summary>
        /// Called every server frame in the PlayerUpdateThread
        /// Calls the Tick() methot for every online PlayerEntity
        /// Also checks for Disconnected clients
        ///
        /// Sends the Movement info to clients of players who changed position in the frame
        /// </summary>
        /// <returns></returns>
        public long PlayerUpdate()
        {
            long startMils = statisticsStopwatch.ElapsedMilliseconds;

            //READ JOB FROM QUE AND HANDLE THAT
            //Update players
            foreach (var player in Data.PlayersByUid.Values)
            {
                player.Tick();

                if (player.Connection != null)
                {
                    if (player.Connection.Status == NetConnectionStatus.Disconnected)
                    {
                        if (Data.RemovePlayer(player))
                        {
                            Console.WriteLine($"Player disconnected:\n{player}");
                            OutgoingMessageHandler.SendDisconnect(player);
                        }
                    }
                }
            }

            OutgoingMessageHandler.SendPlayerMovementInfoByGridCell();

            //MessageSender.Instance.SendPlayerMovementInfoByPlayers();

            _updateTick++;
            return(statisticsStopwatch.ElapsedMilliseconds - startMils);
        }