internal void OnPlayerLeave(ClientCloseReason reason) { if (IsAuthorized) { PlayerLeave?.Invoke(this, reason); } }
private void CloseClientSocket(SocketAsyncEventArgs e, ClientCloseReason reason) { GameSession token = e.UserToken as GameSession; // close the socket associated with the client if (token == null) { return; } try { this.OnSessionClosed(token); if (token.Socket.Connected) { token.Socket.Shutdown(SocketShutdown.Both); } } catch (Exception) { // ignored } try { token.Socket.Close(); } catch (Exception) { // ignored } if (_sessions.TryRemove(token.Id, out _)) { if (_users.TryRemove(token.UserId, out _)) { var task = new GamePlayerLeaveTask(token, reason, _controllers.Values); if (reason == ClientCloseReason.Displacement) { try { task.DoAction(); } catch (Exception ex) { _logger.LogError(ex, ex.Message); } } else { //任务队列加入玩家离线 _workingQueue.Enqueue(task); } } token?.Dispose(); // Free the SocketAsyncEventArg so they can be reused by another client _socketRecvArgsPool.Push(e); _logger.LogDebug($"{token.Id}: LEAVE, reason: {reason}"); } }
private void OnSessionClosed(GameSession session, ClientCloseReason reason) { SessionClosed?.Invoke(this, new SessionCloseEventArgs() { GameSession = session, Reason = reason }); }
public override void OnLeave(ClientCloseReason reason) { base.OnLeave(reason); var player = CurrentSession.GetBindPlayer(); //player.OnlineTime += (DateTime.Now - player.LastLoginTime); _db.SaveChanges(); }
//public virtual void OnConnected() //{ //} /// <summary> /// 离开游戏的时候 /// </summary> public virtual void OnLeave(ClientCloseReason reason) { }
public GamePlayerLeaveTask(GameSession session, ClientCloseReason reason, IEnumerable <GameModule> controllers) : base(session) { Reason = reason; _controllers = controllers; }
public override void OnLeave(ClientCloseReason reason) { _logger.LogDebug($"{CurrentSession.Id}: LEAVE, reason: {reason}"); }