Exemplo n.º 1
0
        public override void Update()
        {
            if (Listener?.Pending() == true)
            {
                PlayersJoining.Add(new SCONClient(Listener.AcceptSocket(), this));
            }

            #region Player Filtration

            for (var i = 0; i < PlayersToAdd.Count; i++)
            {
                var playerToAdd = PlayersToAdd[i];

                Clients.Add(playerToAdd);
                PlayersToAdd.Remove(playerToAdd);
            }

            for (var i = 0; i < PlayersToRemove.Count; i++)
            {
                var playerToRemove = PlayersToRemove[i];

                Clients.Remove(playerToRemove);
                PlayersJoining.Remove(playerToRemove);
                PlayersToRemove.Remove(playerToRemove);

                playerToRemove.Dispose();
            }

            #endregion Player Filtration

            #region Player Updating

            // Update actual players
            for (var i = Clients.Count - 1; i >= 0; i--)
            {
                Clients[i]?.Update();
            }

            // Update joining players
            for (var i = PlayersJoining.Count - 1; i >= 0; i--)
            {
                PlayersJoining[i]?.Update();
            }

            #endregion Player Updating
        }
Exemplo n.º 2
0
        public override void Update()
        {
            if (Listener?.Pending() == true)
            {
                PlayersJoining.Add(new PokeDPlayer(Listener.AcceptSocket(), this));
            }

            #region Player Filtration

            for (var i = 0; i < PlayersToAdd.Count; i++)
            {
                var playerToAdd = PlayersToAdd[i];

                Clients.Add(playerToAdd);
                PlayersToAdd.Remove(playerToAdd);

                if (playerToAdd.ID != 0)
                {
                    /*
                     * var mapData = Maps.GetFileAsync("0.0.tmx").Result.ReadAllTextAsync().Result;
                     * //var mapData = Maps.GetFileAsync(playerToAdd.LevelFile).Result.ReadAllTextAsync().Result;
                     *
                     #region Hash
                     *
                     * Map map;
                     * using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(mapData)))
                     *  map = Map.Load(stream);
                     *
                     * var tileSetHashesh = map.TileSets.Select(tileSet => new FileHash()
                     *          {
                     *              Name = tileSet.Source.Replace(".tsx", ""),
                     *              Hash = TileSets.GetFileAsync(tileSet.Source).Result.MD5Hash()
                     *          });
                     *
                     * var imageHashesh = map.TileSets.Select(tileSet =>
                     *          new FileHash()
                     *          {
                     *              Name = tileSet.Source.Replace(".tsx", ""),
                     *              Hash = TileSets.GetFileAsync(tileSet.Source.Replace(".tsx", ".png")).Result.MD5Hash()
                     *          });
                     #endregion Hash
                     *
                     *
                     * playerToAdd.SendPacket(new MapPacket()
                     * {
                     *  MapData = mapData,
                     *  TileSetHashes = tileSetHashesh.ToArray(),
                     *  ImageHashes = imageHashesh.ToArray()
                     * });
                     */
                }
            }

            for (var i = 0; i < PlayersToRemove.Count; i++)
            {
                var playerToRemove = PlayersToRemove[i];

                Clients.Remove(playerToRemove);
                PlayersJoining.Remove(playerToRemove);
                PlayersToRemove.Remove(playerToRemove);

                playerToRemove.Dispose();
            }

            #endregion Player Filtration


            #region Player Updating

            // Update actual players
            for (var i = Clients.Count - 1; i >= 0; i--)
            {
                Clients[i]?.Update();
            }

            // Update joining players
            for (var i = PlayersJoining.Count - 1; i >= 0; i--)
            {
                PlayersJoining[i]?.Update();
            }

            #endregion Player Updating


            if (UpdateWatch.ElapsedMilliseconds > 5000)
            {
                for (var i = Clients.Count - 1; i >= 0; i--)
                {
                    Clients[i]?.SendPacket(new PingPacket());
                }

                UpdateWatch.Reset();
                UpdateWatch.Start();
            }
        }