/// <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(); }
/// <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); }
private void HandleClientDisconnect(object sender, NetChannelArgs e) { if (_ackedStates.ContainsKey(e.Channel.ConnectionId)) { _ackedStates.Remove(e.Channel.ConnectionId); } }
private void OnConnected(object?sender, NetChannelArgs args) { // request base info about the server var msgInfo = _net.CreateNetMessage <MsgServerInfoReq>(); _net.ClientSendMessage(msgInfo); }
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); } }
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); } }
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(); }
/// <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); }
private void HandleClientDisconnect(object?sender, NetChannelArgs e) { _ackedStates.Remove(e.Channel.ConnectionId); if (!_playerManager.TryGetSessionByChannel(e.Channel, out var session)) { return; } _entityManager.DropPlayerState(session); }
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; } }
/// <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); }
/// <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; }
/// <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; }
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); }
/// <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; }
/// <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(); } }
private void OnConnected(object?sender, NetChannelArgs args) { _configManager.SyncWithServer(); _configManager.ReceivedInitialNwVars += OnReceivedClientData; }
private void OnNetworkConnected(object?sender, NetChannelArgs netChannelArgs) { SendServerCommandRequest(); }
private void RequestMaxLength(object sender, NetChannelArgs args) { ChatMaxMsgLengthMessage msg = _netManager.CreateNetMessage <ChatMaxMsgLengthMessage>(); _netManager.ClientSendMessage(msg); }
/// <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); }