protected async override void Run(Session session, C2G_QuitRoom_Req message, Action <G2C_QuitRoom_Res> reply) { G2C_QuitRoom_Res response = new G2C_QuitRoom_Res(); try { if (!GateHelper.SingSession(session)) { response.Error = ErrorCode.ERR_SessionError; response.Message = " 当前的session已经断开 !!!"; reply(response); return; } var Result = await RoomHelper.QuitRoom(message.GameId, message.AreaId, message.UserId, message.RoomId); if (Result != "0" && Result != "1") { response.Error = ErrorCode.ERR_QuitRoomError; response.Message = Result; reply(response); return; } reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
public async override void Destroy(SessionUserComponent self) { DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>(); try { StartConfigComponent config = Game.Scene.GetComponent <StartConfigComponent>(); IPEndPoint realmIPEndPoint = config.RealmConfig.GetComponent <InnerConfig>().IPEndPoint; Session realmSession = Game.Scene.GetComponent <NetInnerComponent>().Get(realmIPEndPoint); await realmSession.Call(new G2R_PlayerOffline_Req() { UserID = self.userInfo.Id }); var myLastRoomInfo = self.userInfo.GetComponent <MyLastJionRoom>().MyLastJionRoomList; if (myLastRoomInfo.Count > 0) { RoomHelper.QuitRoom(myLastRoomInfo.First().GameId, myLastRoomInfo.First().AreaId, self.userInfo.Id, myLastRoomInfo.First().RoomId); } self.userInfo.IsOnline = false; DateTime endTime = DateTime.Now; await dbProxy.Save(Game.Scene.GetComponent <PlayerManagerComponent>().Get(self.userInfo.Id)); Game.Scene.GetComponent <PlayerManagerComponent>()?.Remove(self.userInfo.Id); self.userInfo.Dispose(); self.userInfo = null; Game.Scene.GetComponent <PingComponent>().RemoveSession(self.sessionId); } catch (System.Exception e) { Log.Trace(e.ToString()); } }