private void RunAsync(Session session, L2M_TeamModifyMember message, Action <M2L_TeamModifyMember> reply) { M2L_TeamModifyMember response = new M2L_TeamModifyMember(); try { var roomComponent = Game.Scene.GetComponent <RoomComponent>(); var room = roomComponent.Get(message.RoomId); if (room == null) { response.Error = ErrorCode.ERR_RoomIdNotFound; reply(response); return; } var roomTeamComponent = room.GetComponent <RoomTeamComponent>(); if (roomTeamComponent == null) { response.Error = ErrorCode.ERR_RoomTeamComponentNull; reply(response); return; } TeamMemberData selfMemberData = roomTeamComponent.GetMember(message.Uid); M2C_TeamModifyMember m2c_TeamModifyMember = new M2C_TeamModifyMember(); m2c_TeamModifyMember.Uid = message.Uid; m2c_TeamModifyMember.MemberData = selfMemberData; MapMessageHelper.BroadcastRoom(room.Id, m2c_TeamModifyMember, message.Uid); reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
public static async void KickMember(RoomTeamComponent roomTeamComponent, MapUnit kickMember, TeamLoseType loseType) { if (kickMember == null) { return; } //廣播給指定玩家失去房間 M2C_TeamLose m2c_TeamLose = new M2C_TeamLose(); m2c_TeamLose.LoseType = loseType; List <MapUnit> broadcastMapUnits = new List <MapUnit>(); broadcastMapUnits.Add(kickMember); MapMessageHelper.BroadcastTarget(m2c_TeamLose, broadcastMapUnits); //Player移除mapUnitId var proxy = Game.Scene.GetComponent <CacheProxyComponent>(); var playerSync = proxy.GetMemorySyncSolver <Player>(); var player = playerSync.Get <Player>(kickMember.Uid); player?.LeaveRoom(); await playerSync.Update(player); //中斷指定玩家與Map的連接 var mapUnitGateComponent = kickMember?.GetComponent <MapUnitGateComponent>(); if (mapUnitGateComponent != null) { mapUnitGateComponent.IsDisconnect = true; } Game.Scene.GetComponent <MapUnitComponent>().Remove(kickMember.Id); if (m2c_TeamLose.LoseType != TeamLoseType.LoadingTimeOut) { //廣播給離開玩家外的玩家 成員異動 M2C_TeamModifyMember m2c_TeamModifyMember = new M2C_TeamModifyMember(); m2c_TeamModifyMember.Uid = kickMember.Uid; MapMessageHelper.BroadcastRoom(roomTeamComponent.RoomEntity.Id, m2c_TeamModifyMember, kickMember.Uid); } }
protected override async ETTask Run(MapUnit mapUnit, C2M_TeamLeave message, Action <M2C_TeamLeave> reply) { await ETTask.CompletedTask; M2C_TeamLeave response = new M2C_TeamLeave(); try { //判斷房間是否合法 Room room = mapUnit.Room; if (room == null) { response.Error = ErrorCode.ERR_RoomIdNotFound; reply(response); return; } if (room.Type != RoomType.Team) { response.Error = ErrorCode.ERR_RoonTypeError; reply(response); return; } var roomTeamComponent = room.GetComponent <RoomTeamComponent>(); if (roomTeamComponent == null) { response.Error = ErrorCode.ERR_RoomTeamComponentNull; reply(response); return; } //刪除MapUnit訊息 M2C_MapUnitDestroy m2C_MapUnitDestroy = new M2C_MapUnitDestroy(); m2C_MapUnitDestroy.MapUnitId = mapUnit.Id; //廣播刪除MapUnit訊息(不包含自己) List <MapUnit> broadcastMapUnits = new List <MapUnit>(); broadcastMapUnits.AddRange(room.GetAll()); for (int i = 0; i < broadcastMapUnits.Count; i++) { //過濾自己 if (broadcastMapUnits[i].Uid == mapUnit.Uid) { broadcastMapUnits.RemoveAt(i); break; } } MapMessageHelper.BroadcastTarget(m2C_MapUnitDestroy, broadcastMapUnits); //對全體廣播離開組隊訊息(不包含自己) M2C_TeamModifyMember m2c_TeamModifyMember = new M2C_TeamModifyMember(); m2c_TeamModifyMember.Uid = mapUnit.Uid; MapMessageHelper.BroadcastTarget(m2c_TeamModifyMember, broadcastMapUnits); //廣播給自己失去房間 M2C_TeamLose m2c_TeamLose = new M2C_TeamLose(); m2c_TeamLose.LoseType = TeamLoseType.Other; MapMessageHelper.BroadcastTarget(m2c_TeamLose, mapUnit); bool isLeader = mapUnit.Uid == roomTeamComponent.Data.LeaderUid; //對全體廣播更換隊長(不包含自己) if (isLeader) { M2C_TeamModifyData m2c_TeamModifyData = new M2C_TeamModifyData(); m2c_TeamModifyData.Data = roomTeamComponent.Data; MapMessageHelper.BroadcastTarget(m2c_TeamModifyData, broadcastMapUnits); } //Player移除mapUnitId var proxy = Game.Scene.GetComponent <CacheProxyComponent>(); var playerSync = proxy.GetMemorySyncSolver <Player>(); var player = playerSync.Get <Player>(mapUnit.Uid); player?.LeaveRoom(); await playerSync.Update(player); //先Response才釋放mapUnit reply(response); //中斷指定玩家與Map的連接 mapUnit.GetComponent <MapUnitGateComponent>().IsDisconnect = true; Game.Scene.GetComponent <MapUnitComponent>().Remove(mapUnit.Id); } catch (Exception e) { ReplyError(response, e, reply); } }
protected async ETTask RunAsync(Session session, C2G_TeamInviteAccept message, Action <G2C_TeamInviteAccept> reply) { G2C_TeamInviteAccept response = new G2C_TeamInviteAccept(); try { //取得自身資料 Player player = session.GetComponent <SessionPlayerComponent>().Player; User user = await UserDataHelper.FindOneUser((player?.uid).GetValueOrDefault(0)); if (user == null) { response.Error = ErrorCode.ERR_AccountDoesntExist; reply(response); return; } //判斷邀請是否合法 var inviteComponent = Game.Scene.GetComponent <InviteComponent>(); var invite = inviteComponent.GetByInviteId(message.InviteId); if (invite == null) { response.Error = ErrorCode.ERR_InviteIdNotFind; reply(response); return; } if (invite.data.ReceiverUid != player?.uid) { response.Error = ErrorCode.ERR_InviteNotSelf; reply(response); return; } //刪除該邀請 await inviteComponent.DestroyByInviteId(message.InviteId); //判斷房間是否合法 var room = Game.Scene.GetComponent <RoomComponent>().Get(invite.data.TeamRoomId); if (room == null) { response.Error = ErrorCode.ERR_RoomIdNotFound; reply(response); return; } if (room.Type != RoomType.Team) { response.Error = ErrorCode.ERR_RoonTypeError; reply(response); return; } if (room.State != RoomState.Start) { response.Error = ErrorCode.ERR_RoomTeamStateCanNotEnter; reply(response); return; } var roomTeamComponent = room.GetComponent <RoomTeamComponent>(); if (roomTeamComponent == null) { response.Error = ErrorCode.ERR_RoomTeamComponentNull; reply(response); return; } if (room.info.NowMemberCount >= room.info.MaxMemberCount) { response.Error = ErrorCode.ERR_RoomTeamMemberIsFull; reply(response); return; } // 連接到Map伺服器,並創建Unit實體 IPEndPoint mapAddress = StartConfigComponent.Instance.Get(player.mapAppId).GetComponent <InnerConfig>().IPEndPoint; Session mapSession = Game.Scene.GetComponent <NetInnerComponent>().Get(mapAddress); //建立Map實體並進入房間 G2M_MapUnitCreate g2M_MapUnitCreate = new G2M_MapUnitCreate(); g2M_MapUnitCreate.Uid = player.uid; g2M_MapUnitCreate.GateSessionId = session.InstanceId; g2M_MapUnitCreate.MapUnitInfo = new MapUnitInfo() { Name = user.name, Location = user.location, RoomId = room.Id, DistanceTravelled = 0, CharSetting = user.playerCharSetting, //PathId 一般組隊入場再決定 }; //建立自身MapUnit M2G_MapUnitCreate createUnit = (M2G_MapUnitCreate)await mapSession.Call(g2M_MapUnitCreate); g2M_MapUnitCreate.MapUnitInfo.MapUnitId = createUnit.MapUnitId; player.EnterRoom(createUnit.MapUnitId, room); //對全體廣播自己剛建立的MapUnitInfo(不包含自己) TeamMemberData selfMemberData = roomTeamComponent.GetMember(player.uid); M2C_TeamModifyMember m2c_TeamModifyMember = new M2C_TeamModifyMember(); m2c_TeamModifyMember.Uid = player.uid; m2c_TeamModifyMember.MemberData = selfMemberData; MapMessageHelper.BroadcastRoom(room.Id, m2c_TeamModifyMember, player.uid); //回傳資料 response.Info = room.info; response.Data = roomTeamComponent.Data; for (int i = 0; i < roomTeamComponent.MemberDatas.Length; i++) { if (roomTeamComponent.MemberDatas[i] != null) { response.MemberDatas.Add(roomTeamComponent.MemberDatas[i]); } } reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
protected override void Run(MapUnit mapUnit, G2M_SessionDisconnect message) { //先Player離開地圖再移除mapUnit var proxy = Game.Scene.GetComponent <CacheProxyComponent>(); var playerSync = proxy.GetMemorySyncSolver <Player>(); var player = playerSync.Get <Player>(mapUnit.Uid); player?.LeaveRoom(); Room room = mapUnit.Room; if (room != null) { RoomTeamComponent roomTeamComponent = room.GetComponent <RoomTeamComponent>(); //刪除MapUnit M2C_MapUnitDestroy m2C_MapUnitDestroy = new M2C_MapUnitDestroy(); m2C_MapUnitDestroy.MapUnitId = mapUnit.Id; //製作廣播列表 List <MapUnit> broadcastMapUnits = new List <MapUnit>(); broadcastMapUnits.AddRange(room.GetAll()); for (int i = 0; i < broadcastMapUnits.Count; i++) { //過濾自己 if (broadcastMapUnits[i].Uid == mapUnit.Uid) { broadcastMapUnits.RemoveAt(i); break; } } MapMessageHelper.BroadcastTarget(m2C_MapUnitDestroy, broadcastMapUnits); switch (room.Type) { case RoomType.Roaming: { } break; case RoomType.Team: { //廣播成員異動訊息 M2C_TeamModifyMember m2c_TeamModifyMember = new M2C_TeamModifyMember(); m2c_TeamModifyMember.Uid = mapUnit.Uid; MapMessageHelper.BroadcastTarget(m2c_TeamModifyMember, broadcastMapUnits); //判斷自身是否為隊長 bool isLeader = mapUnit.Uid == roomTeamComponent.Data.LeaderUid; //廣播替換隊長訊息 if (isLeader) { M2C_TeamModifyData m2c_TeamModifyData = new M2C_TeamModifyData(); m2c_TeamModifyData.Data = roomTeamComponent.Data; MapMessageHelper.BroadcastTarget(m2c_TeamModifyData, broadcastMapUnits); } } break; } } //中斷指定玩家與Map的連接 mapUnit.GetComponent <MapUnitGateComponent>().IsDisconnect = true; Game.Scene.GetComponent <MapUnitComponent>().Remove(mapUnit.Id); }
private async ETVoid RunAsync(Session session, C2G_TeamReservationJoin message, Action <G2C_TeamReservationJoin> reply) { G2C_TeamReservationJoin response = new G2C_TeamReservationJoin(); try { //取得自身資料 Player player = session.GetComponent <SessionPlayerComponent>().Player; User user = await UserDataHelper.FindOneUser((player?.uid).GetValueOrDefault()); if (user == null) { response.Error = ErrorCode.ERR_AccountDoesntExist; reply(response); return; } //取得預約資料 var reservationComponent = Game.Scene.GetComponent <ReservationComponent>(); var reservation = reservationComponent.GetByReservationId(message.ReservationId); //判斷是否有該預約 if (reservation == null) { response.Error = ErrorCode.ERR_ReservationIdNotFind; reply(response); return; } //判斷是否為被邀請者 if (!reservation.allData.MemberUid.Contains(player.uid)) { response.Error = ErrorCode.ERR_ReservationNotTheOwner; reply(response); return; } //判斷是否有該房間 if (reservation.room == null) { response.Error = ErrorCode.ERR_ReservationRoomNotFind; reply(response); return; } //判斷該房間是否可以進入 if (reservation.room.State != RoomState.Start) { response.Error = ErrorCode.ERR_RoomTeamStateCanNotEnter; reply(response); return; } //判斷是否人滿 if (reservation.room.info.NowMemberCount >= reservation.room.info.MaxMemberCount) { response.Error = ErrorCode.ERR_RoomTeamMemberIsFull; reply(response); return; } //判斷房間資料是否正確 var roomTeamComponent = reservation.room.GetComponent <RoomTeamComponent>(); if (roomTeamComponent == null) { response.Error = ErrorCode.ERR_RoomTeamComponentNull; reply(response); return; } // 連接到Map伺服器,並創建Unit實體 IPEndPoint mapAddress = StartConfigComponent.Instance.Get(player.mapAppId).GetComponent <InnerConfig>().IPEndPoint; Session mapSession = Game.Scene.GetComponent <NetInnerComponent>().Get(mapAddress); //建立Map實體並進入房間 G2M_MapUnitCreate g2M_MapUnitCreate = new G2M_MapUnitCreate(); g2M_MapUnitCreate.Uid = player.uid; g2M_MapUnitCreate.GateSessionId = session.InstanceId; g2M_MapUnitCreate.MapUnitInfo = new MapUnitInfo() { Name = user.name, Location = user.location, RoomId = reservation.room.Id, DistanceTravelled = 0, CharSetting = user.playerCharSetting, //PathId 一般組隊入場再決定 }; //建立自身MapUnit M2G_MapUnitCreate createUnit = (M2G_MapUnitCreate)await mapSession.Call(g2M_MapUnitCreate); g2M_MapUnitCreate.MapUnitInfo.MapUnitId = createUnit.MapUnitId; player.EnterRoom(createUnit.MapUnitId, reservation.room); //對全體廣播自己剛建立的MapUnitInfo(不包含自己) TeamMemberData selfMemberData = roomTeamComponent.GetMember(player.uid); M2C_TeamModifyMember m2c_TeamModifyMember = new M2C_TeamModifyMember(); m2c_TeamModifyMember.Uid = player.uid; m2c_TeamModifyMember.MemberData = selfMemberData; MapMessageHelper.BroadcastRoom(reservation.room.Id, m2c_TeamModifyMember, player.uid); //回傳資料 response.Error = ErrorCode.ERR_Success; response.Info = reservation.room.info; response.Data = roomTeamComponent.Data; for (int i = 0; i < roomTeamComponent.MemberDatas.Length; i++) { if (roomTeamComponent.MemberDatas[i] != null) { response.MemberDatas.Add(roomTeamComponent.MemberDatas[i]); } } for (int i = 0; i < roomTeamComponent.ReservationMembers.Count; i++) { if (roomTeamComponent.ReservationMembers[i] != null) { response.ReservationMemberDatas.Add(roomTeamComponent.ReservationMembers[i]); } } reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
private void RunAsync(MapUnit mapUnit, L2M_SessionDisconnect message) { try { Room room = mapUnit.Room; if (room != null) { RoomTeamComponent roomTeamComponent = room.GetComponent <RoomTeamComponent>(); // 刪除MapUnit M2C_MapUnitDestroy m2C_MapUnitDestroy = new M2C_MapUnitDestroy(); m2C_MapUnitDestroy.MapUnitId = mapUnit.Id; // 製作廣播列表 List <MapUnit> broadcastMapUnits = new List <MapUnit>(); broadcastMapUnits.AddRange(room.GetAll()); for (int i = 0; i < broadcastMapUnits.Count; i++) { // 過濾自己 if (broadcastMapUnits[i].Uid == mapUnit.Uid) { broadcastMapUnits.RemoveAt(i); break; } } MapMessageHelper.BroadcastTarget(m2C_MapUnitDestroy, broadcastMapUnits); switch (room.Type) { case RoomType.Roaming: { } break; case RoomType.Team: { // 廣播成員異動訊息 M2C_TeamModifyMember m2c_TeamModifyMember = new M2C_TeamModifyMember(); m2c_TeamModifyMember.Uid = mapUnit.Uid; MapMessageHelper.BroadcastTarget(m2c_TeamModifyMember, broadcastMapUnits); // 判斷自身是否為隊長 bool isLeader = mapUnit.Uid == roomTeamComponent.Data.LeaderUid; // 廣播替換隊長訊息 if (isLeader) { M2C_TeamModifyData m2c_TeamModifyData = new M2C_TeamModifyData(); m2c_TeamModifyData.Data = roomTeamComponent.Data; MapMessageHelper.BroadcastTarget(m2c_TeamModifyData, broadcastMapUnits); } } break; } } // 中斷指定玩家與Map的連接 mapUnit.GetComponent <MapUnitGateComponent>().IsDisconnect = true; Game.Scene.GetComponent <MapUnitComponent>().Remove(mapUnit.Id); } catch (Exception e) { Log.Error(e); } }