public Task <bool> OnHandle(MessageContext context, CLeavePlayerRequestReqMessage message) { var session = context.GetSession <Session>(); var plr = session.Player; var room = plr.Room; var targetPlr = room.Players.GetValueOrDefault(message.AccountId); if (targetPlr == null) { return(Task.FromResult(true)); } // Cant kick people in gm mode also disables AFK kick if (targetPlr.IsInGMMode) { return(Task.FromResult(true)); } switch (message.Reason) { case RoomLeaveReason.Kicked: // Only the master can kick people and kick is only allowed in the lobby if (room.Master != plr && room.GameRule.StateMachine.GameState != GameState.Waiting) { return(Task.FromResult(true)); } break; case RoomLeaveReason.AFK: // The client kicks itself when afk is detected if (message.AccountId != plr.Account.Id) { return(Task.FromResult(true)); } break; default: // Dont allow any other reasons for now return(Task.FromResult(true)); } room.Leave(targetPlr, message.Reason); return(Task.FromResult(true)); }
public void CLeavePlayerRequestReq(GameSession session, CLeavePlayerRequestReqMessage message) { var plr = session.Player; var room = plr.Room; switch (message.Reason) { case RoomLeaveReason.Kicked: // Only the master can kick people and kick is only allowed in the lobby if (room.Master != plr && !room.GameRuleManager.GameRule.StateMachine.IsInState(GameRuleState.Waiting)) { return; } break; case RoomLeaveReason.AFK: // The client kicks itself when afk is detected if (message.AccountId != plr.Account.Id) { return; } break; default: // Dont allow any other reasons for now return; } var targetPlr = room.Players.GetValueOrDefault(message.AccountId); if (targetPlr == null) { return; } room.Leave(targetPlr, message.Reason); }