Esempio n. 1
0
        private void OnPlayerDisconnect(ushort id)
        {
            // Always propagate this packet to the NetServer
            _netServer.OnClientDisconnect(id);

            if (!_playerData.TryGetValue(id, out _))
            {
                Logger.Warn(this, $"Player disconnect, but player with ID {id} is not in mapping");
                return;
            }

            // Send a player disconnect packet
            var playerDisconnectPacket = new ClientPlayerDisconnectPacket {
                Id       = id,
                Username = _playerData[id].Username
            };

            foreach (var idScenePair in _playerData.GetCopy())
            {
                if (idScenePair.Key == id)
                {
                    continue;
                }

                _netServer.SendTcp(idScenePair.Key, playerDisconnectPacket.CreatePacket());
            }

            // Now remove the client from the player data mapping
            _playerData.Remove(id);
        }