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);
            }
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        protected async ETTask RunAsync(Session session, C2G_RoamingEnter message, Action <G2C_RoamingEnter> reply)
        {
            G2C_RoamingEnter response = new G2C_RoamingEnter();

            try
            {
                //判斷房間是否合法
                Room room = Game.Scene.GetComponent <RoomComponent>().Get(message.RoamingRoomId);
                if (room == null)
                {
                    response.Error = ErrorCode.ERR_RoomIdNotFound;
                    reply(response);
                    return;
                }

                //回傳房間設定
                response.RoadSettingId = room.info.RoadSettingId;

                //取得自身資料
                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;
                }

                // 連接到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            = message.RoamingRoomId,
                    DistanceTravelled = 0,
                    SpeedMS           = 0,
                    CharSetting       = user.playerCharSetting,
                    PathId            = room.info.NowMemberCount % 4,
                    StartUTCTick      = DateTime.UtcNow.Ticks
                };

                //建立自身MapUnit
                M2G_MapUnitCreate createUnit = (M2G_MapUnitCreate)await mapSession.Call(g2M_MapUnitCreate);

                g2M_MapUnitCreate.MapUnitInfo.MapUnitId = createUnit.MapUnitId;

                //進入房間
                player.EnterRoom(createUnit.MapUnitId, room);
                player.StartRoom();

                //TODO:紀錄
                //回傳自己MapUnitInfo
                response.SelfInfo = g2M_MapUnitCreate.MapUnitInfo;
                var mapUnits = room.GetAll();
                for (int i = 0; i < mapUnits.Count; i++)
                {
                    response.GlobalInfos.Add(mapUnits[i].GlobalInfo);
                }
                reply(response);

                ////對全體廣播MapUnitInfo(不包含自己)
                //M2C_MapUnitCreate m2C_MapUnitCreate = new M2C_MapUnitCreate();
                //m2C_MapUnitCreate.MapUnitInfo = g2M_MapUnitCreate.MapUnitInfo;
                //MapMessageHelper.BroadcastRoom(g2M_MapUnitCreate.MapUnitInfo.RoomId, m2C_MapUnitCreate, player.Uid);

                // 紀錄所有MapUnit(包含自己)
                //List<MapUnit> mapUnits = room.GetAll();
                //for (int i = 0; i < mapUnits.Count; i++)
                //{
                //    response.MapUnitInfos.Add(mapUnits[i].Info);
                //}
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
        private async ETTask RunAsync(Session session, C2G_TeamCreate message, Action <G2C_TeamCreate> reply)
        {
            G2C_TeamCreate response = new G2C_TeamCreate();

            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;
                }

                RoomInfo roomInfo = new RoomInfo()
                {
                    RoomId         = 0,
                    Title          = user.name,
                    RoadSettingId  = message.RoadSettingId,
                    MaxMemberCount = 8,
                    NowMemberCount = 0,
                };

                TeamRoomData teamRoomData = new TeamRoomData()
                {
                    LeaderUid        = player.uid,
                    LeaderName       = user.name,
                    StartUTCTimeTick = -1,
                };

                var roomComponent = Game.Scene.GetComponent <RoomComponent>();
                var room          = await roomComponent.CreateTeamRoom(roomInfo, teamRoomData);

                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;
                }

                // 連接到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);

                //回傳資料
                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);
            }
        }