コード例 #1
0
        /// <summary>
        ///     Ends a clients session, and disconnects them.
        /// </summary>
        private void EndSession(object?sender, NetChannelArgs args)
        {
            if (!TryGetSessionByChannel(args.Channel, out var session))
            {
                return;
            }

            // make sure nothing got messed up during the life of the session
            DebugTools.Assert(session.ConnectedClient == args.Channel);

            //Detach the entity and (don't)delete it.
            session.OnDisconnect();
            _sessionsLock.EnterWriteLock();
            try
            {
                _sessions.Remove(session.SessionId);
            }
            finally
            {
                _sessionsLock.ExitWriteLock();
            }

            PlayerCountMetric.Set(PlayerCount);
            Dirty();
        }
コード例 #2
0
        /// <summary>
        ///     Creates a new session for a client.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void NewSession(object?sender, NetChannelArgs args)
        {
            if (!_playerData.TryGetValue(args.Channel.UserId, out var data))
            {
                data = new PlayerData(args.Channel.UserId);
                _playerData.Add(args.Channel.UserId, data);
            }

            _userIdMap[args.Channel.UserName] = args.Channel.UserId;

            var session = new PlayerSession(this, args.Channel, data);

            session.PlayerStatusChanged += (obj, sessionArgs) => OnPlayerStatusChanged(session, sessionArgs.OldStatus, sessionArgs.NewStatus);

            _sessionsLock.EnterWriteLock();
            try
            {
                _sessions.Add(args.Channel.UserId, session);
            }
            finally
            {
                _sessionsLock.ExitWriteLock();
            }

            PlayerCountMetric.Set(PlayerCount);
        }
コード例 #3
0
 private void HandleClientDisconnect(object sender, NetChannelArgs e)
 {
     if (_ackedStates.ContainsKey(e.Channel.ConnectionId))
     {
         _ackedStates.Remove(e.Channel.ConnectionId);
     }
 }
コード例 #4
0
        private void OnConnected(object?sender, NetChannelArgs args)
        {
            // request base info about the server
            var msgInfo = _net.CreateNetMessage <MsgServerInfoReq>();

            _net.ClientSendMessage(msgInfo);
        }
コード例 #5
0
        private void HandleClientDisconnect(object?sender, NetChannelArgs e)
        {
            _entityManager.DropPlayerState(_playerManager.GetSessionById(e.Channel.SessionId));

            if (_ackedStates.ContainsKey(e.Channel.ConnectionId))
            {
                _ackedStates.Remove(e.Channel.ConnectionId);
            }
        }
コード例 #6
0
 private void ServerNetManagerOnConnected(object?sender, NetChannelArgs e)
 {
     foreach (var(path, data) in ContentRoot.GetAllFiles())
     {
         var msg = _serverNetManager.CreateNetMessage <NetworkResourceUploadMessage>();
         msg.RelativePath = path;
         msg.Data         = data;
         e.Channel.SendMessage(msg);
     }
 }
コード例 #7
0
        private void OnNetDisconnect(object sender, NetChannelArgs args)
        {
            Debug.Assert(RunLevel > ClientRunLevel.Initialize);

            PlayerLeaveServer?.Invoke(this, new PlayerEventArgs(_playMan.LocalPlayer.Session));

            _stateManager.RequestStateChange <MainScreen>();

            _playMan.Shutdown();
            Reset();
        }
コード例 #8
0
        /// <summary>
        ///     Ends a clients session, and disconnects them.
        /// </summary>
        private void EndSession(object sender, NetChannelArgs args)
        {
            var session = GetSessionByChannel(args.Channel);

            // make sure nothing got messed up during the life of the session
            DebugTools.Assert(session.ConnectedClient == args.Channel);

            //Detach the entity and (don't)delete it.
            session.OnDisconnect();
            _sessions.Remove(session.SessionId);
        }
コード例 #9
0
        private void HandleClientDisconnect(object?sender, NetChannelArgs e)
        {
            _ackedStates.Remove(e.Channel.ConnectionId);

            if (!_playerManager.TryGetSessionByChannel(e.Channel, out var session))
            {
                return;
            }

            _entityManager.DropPlayerState(session);
        }
コード例 #10
0
 private void HandleClientConnected(object?sender, NetChannelArgs e)
 {
     if (!_ackedStates.ContainsKey(e.Channel.ConnectionId))
     {
         _ackedStates.Add(e.Channel.ConnectionId, GameTick.Zero);
     }
     else
     {
         _ackedStates[e.Channel.ConnectionId] = GameTick.Zero;
     }
 }
コード例 #11
0
        /// <summary>
        /// Ends a clients session, and disconnects them.
        /// </summary>
        /// <param name="client">Client network channel to close.</param>
        public void EndSession(object sender, NetChannelArgs args)
        {
            var session = GetSessionById(args.Channel.NetworkId);

            if (session == null)
            {
                return; //There is no session!
            }
            //Detach the entity and (don't)delete it.
            session.OnDisconnect();

            _sessions.Remove(args.Channel.NetworkId);
        }
コード例 #12
0
        /// <summary>
        ///     Creates a new session for a client.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void NewSession(object sender, NetChannelArgs args)
        {
            if (!_playerData.TryGetValue(args.Channel.SessionId, out var data))
            {
                data = new PlayerData(args.Channel.SessionId);
                _playerData.Add(args.Channel.SessionId, data);
            }
            var session = new PlayerSession(this, args.Channel, data);

            session.PlayerStatusChanged += (obj, sessionArgs) => OnPlayerStatusChanged(session, sessionArgs.OldStatus, sessionArgs.NewStatus);

            _sessions[args.Channel.SessionId] = session;
        }
コード例 #13
0
        /// <summary>
        ///     Ends a clients session, and disconnects them.
        /// </summary>
        private void EndSession(object sender, NetChannelArgs args)
        {
            var session = GetSessionByChannel(args.Channel);

            // make sure nothing got messed up during the life of the session
            Debug.Assert(_sessionCount > 0);
            Debug.Assert(0 <= session.Index && session.Index <= MaxPlayers);
            Debug.Assert(_sessions[session.Index] != null);
            Debug.Assert(_sessions[session.Index].ConnectedClient.ConnectionId == args.Channel.ConnectionId);

            //Detach the entity and (don't)delete it.
            session.OnDisconnect();
            _sessionCount--;
            _sessions[session.Index] = null;
        }
コード例 #14
0
    private async void OnConnected(object?sender, NetChannelArgs e)
    {
        if (IPAddress.IsLoopback(e.Channel.RemoteEndPoint.Address) && _cfg.GetCVar(CCVars.RulesExemptLocal))
        {
            return;
        }

        var lastRead = await _dbManager.GetLastReadRules(e.Channel.UserId);

        if (lastRead > LastValidReadTime)
        {
            return;
        }

        var message = new ShouldShowRulesPopupMessage();

        _netManager.ServerSendMessage(message, e.Channel);
    }
コード例 #15
0
        /// <summary>
        ///     Creates a new session for a client.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void NewSession(object sender, NetChannelArgs args)
        {
            var pos = GetFirstOpenIndex();

            if (pos == -1)
            {
                throw new InvalidOperationException("NewSession was called, but there are no available slots!");
            }

            var index   = new PlayerIndex(pos);
            var session = new PlayerSession(this, args.Channel, index);

            session.PlayerStatusChanged += (obj, sessionArgs) => OnPlayerStatusChanged(session, sessionArgs.OldStatus, sessionArgs.NewStatus);

            Debug.Assert(_sessions[pos] == null);
            _sessionCount++;
            _sessions[pos] = session;
        }
コード例 #16
0
        /// <summary>
        ///     Creates a new session for a client.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void NewSession(object sender, NetChannelArgs args)
        {
            if (!_playerData.TryGetValue(args.Channel.SessionId, out var data))
            {
                data = new PlayerData(args.Channel.SessionId);
                _playerData.Add(args.Channel.SessionId, data);
            }
            var session = new PlayerSession(this, args.Channel, data);

            session.PlayerStatusChanged += (obj, sessionArgs) => OnPlayerStatusChanged(session, sessionArgs.OldStatus, sessionArgs.NewStatus);

            _sessionsLock.EnterWriteLock();
            try
            {
                _sessions.Add(args.Channel.SessionId, session);
            }
            finally
            {
                _sessionsLock.ExitWriteLock();
            }
        }
コード例 #17
0
 private void OnConnected(object?sender, NetChannelArgs args)
 {
     _configManager.SyncWithServer();
     _configManager.ReceivedInitialNwVars += OnReceivedClientData;
 }
コード例 #18
0
 private void OnNetworkConnected(object?sender, NetChannelArgs netChannelArgs)
 {
     SendServerCommandRequest();
 }
コード例 #19
0
        private void RequestMaxLength(object sender, NetChannelArgs args)
        {
            ChatMaxMsgLengthMessage msg = _netManager.CreateNetMessage <ChatMaxMsgLengthMessage>();

            _netManager.ClientSendMessage(msg);
        }
コード例 #20
0
        /// <summary>
        /// Creates a new session for a client.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void NewSession(object sender, NetChannelArgs args)
        {
            var session = new PlayerSession(args.Channel, this);

            _sessions.Add(args.Channel.NetworkId, session);
        }