コード例 #1
0
        public async ETVoid DispatchAsync(Session session, ushort opcode, object message)
        {
            // 根据消息接口判断是不是Actor消息,不同的接口做不同的处理
            switch (message)
            {
            case IActorLocationRequest actorLocationRequest:                     // gate session收到actor rpc消息,先向actor 发送rpc请求,再将请求结果返回客户端
            {
                long unitId = session.GetComponent <SessionPlayerComponent>().Player.UnitId;
                ActorLocationSender actorLocationSender = Game.Scene.GetComponent <ActorLocationSenderComponent>().Get(unitId);

                int       rpcId      = actorLocationRequest.RpcId;              // 这里要保存客户端的rpcId
                long      instanceId = session.InstanceId;
                IResponse response   = await actorLocationSender.Call(actorLocationRequest);

                response.RpcId = rpcId;

                // session可能已经断开了,所以这里需要判断
                if (session.InstanceId == instanceId)
                {
                    session.Reply(response);
                }

                break;
            }

            case IActorLocationMessage actorLocationMessage:
            {
                long unitId = session.GetComponent <SessionPlayerComponent>().Player.UnitId;
                ActorLocationSender actorLocationSender = Game.Scene.GetComponent <ActorLocationSenderComponent>().Get(unitId);
                _ = actorLocationSender.Send(actorLocationMessage);
                break;
            }

            case IActorRequest actorRequest:                      // 分发IActorRequest消息,目前没有用到,需要的自己添加
            {
                break;
            }

            case IActorMessage actorMessage:                      // 分发IActorMessage消息,目前没有用到,需要的自己添加
            {
                break;
            }

            default:
            {
                // 非Actor消息
                Game.Scene.GetComponent <MessageDispatcherComponent>().Handle(session, new MessageInfo(opcode, message));
                break;
            }
            }
        }
コード例 #2
0
        public async void Dispatch(Session session, Packet packet)
        {
            ushort opcode      = packet.Opcode();
            Type   messageType = Game.Scene.GetComponent <OpcodeTypeComponent>().GetType(opcode);
            object message     = session.Network.MessagePacker.DeserializeFrom(messageType, packet.Bytes, Packet.Index, packet.Length - Packet.Index);

            // 如果是帧指令消息,构造成OneFrameMessage发给对应的unit
            if (message is IFrameMessage)
            {
                long       unitId     = session.GetComponent <SessionPlayerComponent>().Player.UnitId;
                ActorProxy actorProxy = Game.Scene.GetComponent <ActorProxyComponent>().Get(unitId);

                // 这里设置了帧消息的id,防止客户端伪造
                IFrameMessage iFrameMessage = (IFrameMessage)message;
                iFrameMessage.Id = unitId;

                OneFrameMessage oneFrameMessage = new OneFrameMessage();
                oneFrameMessage.Op       = opcode;
                oneFrameMessage.AMessage = session.Network.MessagePacker.SerializeToByteArray(iFrameMessage);
                actorProxy.Send(oneFrameMessage);
                return;
            }

            // gate session收到actor消息直接转发给actor自己去处理
            if (message is IActorMessage)
            {
                long       unitId     = session.GetComponent <SessionPlayerComponent>().Player.UnitId;
                ActorProxy actorProxy = Game.Scene.GetComponent <ActorProxyComponent>().Get(unitId);
                actorProxy.Send((IMessage)message);
                return;
            }

            // gate session收到actor rpc消息,先向actor 发送rpc请求,再将请求结果返回客户端
            if (message is IActorRequest aActorRequest)
            {
                long       unitId     = session.GetComponent <SessionPlayerComponent>().Player.UnitId;
                ActorProxy actorProxy = Game.Scene.GetComponent <ActorProxyComponent>().Get(unitId);
                IResponse  response   = await actorProxy.Call(aActorRequest);

                session.Reply(response);
                return;
            }

            if (message != null)
            {
                Game.Scene.GetComponent <MessageDispatherComponent>().Handle(session, new MessageInfo(opcode, message));
                return;
            }

            throw new Exception($"message type error: {message.GetType().FullName}");
        }
コード例 #3
0
        protected async ETVoid RunAsync(Session session, C2G_EnterMap message, Action <G2C_EnterMap> reply)
        {
            G2C_EnterMap response = new G2C_EnterMap();

            try
            {
                ///20190716 加入心跳包
                Game.Scene.GetComponent <BongComponent>().AddSession(session.InstanceId);
                Console.WriteLine(" session.InstanceId/Id: " + session.InstanceId + " / " + session.Id);

                Player player = session.GetComponent <SessionPlayerComponent>().Player;

                // 在map服务器上创建战斗Unit
                M2G_CreateUnit createResponse = (M2G_CreateUnit)await SessionHelper.MapSession().Call(new G2M_CreateUnit()
                {
                    UnitType = (int)UnitType.Player, RolerId = player.Id, GateSessionId = session.InstanceId, UnitId = 0
                });

                player.UnitId = createResponse.UnitId;

                response.UnitId = player.UnitId;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #4
0
        private long DispatchActorId(Session session, ushort opcode)
        {
            AppType appType = MessageHelper.Get(opcode);
            long    actorId = 0L;
            var     sessionPlayerComponent = session.GetComponent <SessionPlayerComponent>();

            if (sessionPlayerComponent == null)
            {
                Log.Warning($"OuterMessageDispatcher.DispatchActorId actorId is zero. appType: {appType}, opcode: {opcode}");
                return(actorId);
            }

            Player player = sessionPlayerComponent.Player;

            switch (appType)
            {
            case AppType.Lobby:
                actorId = player.uid;
                break;

            case AppType.Map:
                actorId = player.mapUnitId;
                break;

            default:
                actorId = 0L;
                break;
            }

            if (actorId == 0L)
            {
                Log.Warning($"OuterMessageDispatcher.DispatchActorId actorId is zero. appType: {appType}, opcode: {opcode}");
            }
            return(actorId);
        }
コード例 #5
0
ファイル: C2G_ExitRoomHandler.cs プロジェクト: spadd/ET_Tank
        protected override void Run(Session session, C2G_ExitRoom message, Action <G2C_ExitRoom> reply)
        {
            G2C_ExitRoom response = new G2C_ExitRoom();

            try
            {
                Player player = session.GetComponent <SessionPlayerComponent>().Player;

                long roomId = message.Id;

                Room room = Game.Scene.GetComponent <RoomComponent>().Get(roomId);

                room.Remove(player.Id);

                if (room.Count == 0)
                {
                    Game.Scene.GetComponent <RoomComponent>().Remove(roomId);
                }
                else
                {
                    room.BroadcastRoomDetailInfo();
                }


                reply(response);

                BroadcastMessage.Send_G2C_Rooms();
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #6
0
        protected override async void Run(Session session, A1001_GetUserInfo_C2G message, Action <A1001_GetUserInfo_G2C> reply)
        {
            A1001_GetUserInfo_G2C response = new A1001_GetUserInfo_G2C();

            try
            {
                //验证Session
                if (!GateHelper.SignSession(session))
                {
                    response.Error = ErrorCode.ERR_UserNotOnline;
                    reply(response);
                    return;
                }

                //获取玩家对象
                User user = session.GetComponent <SessionUserComponent>().User;

                DBProxyComponent dbProxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                UserInfo         userInfo         = await dbProxyComponent.Query <UserInfo>(user.UserID);

                response.UserName  = userInfo.UserName;
                response.UserLevel = userInfo.UserLevel;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #7
0
        protected override async void Run(Session session, C2G_EnterMap message, Action <G2C_EnterMap> reply)
        {
            G2C_EnterMap response = new G2C_EnterMap();

            try
            {
                Player player = session.GetComponent <SessionPlayerComponent>().Player;
                // 在map服务器上创建战斗Unit
                IPEndPoint     mapAddress = StartConfigComponent.Instance.MapConfigs[0].GetComponent <InnerConfig>().IPEndPoint;
                Session        mapSession = Game.Scene.GetComponent <NetInnerComponent>().Get(mapAddress);
                M2G_CreateUnit createUnit = (M2G_CreateUnit)await mapSession.Call(new G2M_CreateUnit()
                {
                    PlayerId = player.Id, GateSessionId = session.InstanceId
                });

                player.UnitId   = createUnit.UnitId;
                response.UnitId = createUnit.UnitId;
                response.Count  = createUnit.Count;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #8
0
        protected override async void Run(Session session, C2G_ReturnLobby_Ntt message)
        {
            //验证Session
            if (!GateHelper.SignSession(session))
            {
                return;
            }

            User user = session.GetComponent <SessionUserComponent>().User;
            //StartConfigComponent config = Game.Scene.GetComponent<StartConfigComponent>();
            ActorMessageSenderComponent actorProxyComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>();

            //正在匹配中发送玩家退出匹配请求
            //if (user.IsMatching)
            //{
            //    IPEndPoint matchIPEndPoint = config.MatchConfig.GetComponent<InnerConfig>().IPEndPoint;
            //    Session matchSession = Game.Scene.GetComponent<NetInnerComponent>().Get(matchIPEndPoint);
            //    await matchSession.Call(new G2M_PlayerExitMatch_Req() { UserID = user.UserID });

            //    user.IsMatching = false;
            //}

            //正在游戏中发送玩家退出房间请求
            if (user.ActorID != 0)
            {
                ActorMessageSender actorProxy = actorProxyComponent.Get(user.ActorID);
                await actorProxy.Call(new Actor_PlayerExitRoom_Req()
                {
                    UserID = user.UserID
                });

                user.ActorID = 0;
            }
        }
コード例 #9
0
        protected async ETVoid RunAsync(Session session, C2G_EnterMap message, Action <G2C_EnterMap> reply)
        {
            G2C_EnterMap response = new G2C_EnterMap();

            try
            {
                Player player = session.GetComponent <SessionPlayerComponent>().Player;
                // 在map服务器上创建战斗Unit
                IPEndPoint mapAddress = StartConfigComponent.Instance.MapConfigs[0].GetComponent <InnerConfig>().IPEndPoint;
                Session    mapSession = Game.Scene.GetComponent <NetInnerComponent>().Get(mapAddress);

                M2G_CreateUnit createUnit = (M2G_CreateUnit)await mapSession.Call(new G2M_CreateUnit()
                {
                    PlayerId   = player.Id, GateSessionId = session.InstanceId,
                    groupIndex = (int)GroupIndex.Player,
                    layerMask  = (int)UnitLayerMask.ALL,
                    unitLayer  = (int)UnitLayer.Character,
                    unitTag    = (int)UnitTag.Player
                });



                player.UnitId   = createUnit.UnitId;
                response.UnitId = createUnit.UnitId;
                response.Frame  = Game.Scene.GetComponent <UnitStateMgrComponent>().currFrame;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #10
0
            protected override void Run(Session session, M2C_MapUnitCreateAndDestroy message)
            {
                TestPlayerDataComponent testPlayerDataComponent = session.GetComponent <TestPlayerDataComponent>();
                BenchmarkComponent      benchmarkComponent      = Game.Scene.GetComponent <BenchmarkComponent>();

                if (benchmarkComponent.clients.TryGetValue(testPlayerDataComponent.testPlayerSetting.DeviceUniqueIdentifier, out var client))
                {
                    MapUnitBotModule roamingBotModule = client.GetComponent <MapUnitBotModule>();
                    if (!roamingBotModule.isEnableToStartGame)
                    {
                        roamingBotModule._m2cCache.Enqueue(message);
                    }
                    else
                    {
                        for (int i = 0; i < message.DestroyMapUnitIds.Count; i++)
                        {
                            roamingBotModule.SyncM2C_MapUnitDestroy(message.DestroyMapUnitIds[i]);
                        }

                        for (int i = 0; i < message.CreateMapUnitInfos.Count; i++)
                        {
                            roamingBotModule.SyncM2C_MapUnitCreate(message.CreateMapUnitInfos[i]);
                        }
                    }
                    //client.UserLog($"M2C_MapUnitCreateAndDestroyHandler");
                }
            }
コード例 #11
0
        protected override async ETTask Run(Session session, A1001_SetUserInfo_REQ request, A1001_SetUserInfo_ACK response, Action reply)
        {
            try
            {
                //验证Session
                if (!GateHelper.SignSession(session))
                {
                    response.Error = ErrorCode.ERR_UserNotOnline;
                    reply();
                    return;
                }

                //获取玩家对象
                User             user             = session.GetComponent <SessionUserComponent>().User;
                DBProxyComponent dbProxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                UserInfo         userInfo         = await dbProxyComponent.Query <UserInfo>(user.UserID);

                response.Userinfo.Username = userInfo.UserName;
                response.Userinfo.Money    = userInfo.Money;
                response.Userinfo.Level    = userInfo.Level;

                reply();
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #12
0
        protected override async void Run(Session session, C2G_Logout message, Action <G2C_Logout> reply)
        {
            G2C_Logout response = new G2C_Logout();

            try
            {
                var player = session.GetComponent <SessionPlayerComponent>()?.Player;
                if (player == null)
                {
                    response.Error = ErrorCode.ERR_LogoutFailed;
                    reply(response);
                    return;
                }
                // 對Lobby提出登出流程
                Session lobbySession = SessionHelper.GetSession(player.lobbyAppId);
                G2L_LobbyUnitDestroy g2L_LobbyUnitDestroy = new G2L_LobbyUnitDestroy();
                g2L_LobbyUnitDestroy.Uid = player.uid;
                L2G_LobbyUnitDestroy l2G_LobbyUnitDestroy = (L2G_LobbyUnitDestroy)await lobbySession.Call(g2L_LobbyUnitDestroy);

                if (l2G_LobbyUnitDestroy.Error != ErrorCode.ERR_Success)
                {
                    response.Error = ErrorCode.ERR_LogoutFailed;
                    reply(response);
                    return;
                }
                //Game.Scene.GetComponent<PingComponent>().RemoveSession(session.Id);
                session.RemoveComponent <SessionPlayerComponent>();
                session.RemoveComponent <MailBoxComponent>();
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #13
0
        protected override async ETTask Run(Session session, EnterMap_C2G request, EnterMap_G2C response, Action reply)
        {
            try
            {
                User user = session.GetComponent <SessionUserComponent>().User;

                // 在map服务器上创建战斗Unit
                IPEndPoint mapAddress = StartConfigComponent.Instance.MapConfigs[0].GetComponent <InnerConfig>().IPEndPoint;
                Session    mapSession = Game.Scene.GetComponent <NetInnerComponent>().Get(mapAddress);

                mapSession.Send(new CreateUnit_G2M()
                {
                    UserId   = user.UserId,
                    CharaId  = request.CharaId,
                    GActorId = user.InstanceId,
                    CActorId = user.GateSessionId
                });

                // 回复客户端
                response.Frame = Game.Scene.GetComponent <UnitStateMgrComponent>().currFrame;
                reply();

                await ETTask.CompletedTask;
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #14
0
ファイル: C2G_EnterMapHandler.cs プロジェクト: spadd/ET_Tank
        protected async ETVoid RunAsync(Session session, C2G_EnterMap message, Action <G2C_EnterMap> reply)
        {
            G2C_EnterMap response = new G2C_EnterMap();

            try
            {
                Player player = session.GetComponent <SessionPlayerComponent>().Player;
                // 在map服务器上创建战斗Unit
                IPEndPoint mapAddress = StartConfigComponent.Instance.MapConfigs[0].GetComponent <InnerConfig>().IPEndPoint;
                Session    mapSession = Game.Scene.GetComponent <NetInnerComponent>().Get(mapAddress);

                // 此session是gate与client通信的session,将session的instanceId给map进程,map就能将消息给指定的gate的session,并实现转发
                M2G_CreateUnit createUnit = (M2G_CreateUnit)await mapSession.Call(new G2M_CreateUnit()
                {
                    PlayerId = player.Id, GateSessionId = session.InstanceId
                });

                player.UnitId   = createUnit.UnitId;
                response.UnitId = createUnit.UnitId;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #15
0
        protected override async ETTask Run(Session session, GetCharacter_C2G request, CharacterMessage_G2C response, Action reply)
        {
            try
            {
                // 验证Session
                if (!GateHelper.SignSession(session))
                {
                    response.Error = MMOErrorCode.ERR_UserNotOnline;
                    reply();
                    return;
                }

                // 获取用户对象
                User user = session.GetComponent <SessionUserComponent>().User;

                DBProxyComponent dbProxy    = Game.Scene.GetComponent <DBProxyComponent>();
                List <Component> characters = await dbProxy.Query2 <Character>($"{{UserId:{request.UserId},CharaId:{request.CharaId}}}");

                Character character = characters[0] as Character;

                response.Character = GateHelper.CharacterInfoByData(character);


                reply();
                await ETTask.CompletedTask;
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
        protected override void Run(Session session, C2G_TeamReservationGetList message, Action <G2C_TeamReservationGetList> reply)
        {
            G2C_TeamReservationGetList response = new G2C_TeamReservationGetList();

            try
            {
                //取得自身資料
                Player player = session.GetComponent <SessionPlayerComponent>().Player;
                if (player == null)
                {
                    response.Error = ErrorCode.ERR_PlayerDoesntExist;
                    reply(response);
                    return;
                }

                //取得預約資料
                var reservationList = Game.Scene.GetComponent <ReservationComponent>().GetByUid(player.uid);
                if (reservationList != null)
                {
                    response.ReservationDatas = reservationList.Datas;
                }
                response.Error = ErrorCode.ERR_Success;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #17
0
        public async void Dispatch(Session session, ushort opcode, object message)
        {
            switch (message)
            {
            case IFrameMessage iFrameMessage:                     // 如果是帧消息,构造成OneFrameMessage发给对应的unit
            {
                long unitId = session.GetComponent <SessionPlayerComponent>().Player.UnitId;
                ActorMessageSender actorMessageSender = Game.Scene.GetComponent <ActorMessageSenderComponent>().Get(unitId);

                // 这里设置了帧消息的id,防止客户端伪造
                iFrameMessage.Id = unitId;

                OneFrameMessage oneFrameMessage = new OneFrameMessage
                {
                    Op       = opcode,
                    AMessage = ByteString.CopyFrom(session.Network.MessagePacker.SerializeTo(iFrameMessage))
                };
                actorMessageSender.Send(oneFrameMessage);
                return;
            }

            case IActorRequest iActorRequest:                     // gate session收到actor rpc消息,先向actor 发送rpc请求,再将请求结果返回客户端
            {
                long unitId = session.GetComponent <SessionPlayerComponent>().Player.UnitId;
                ActorMessageSender actorMessageSender = Game.Scene.GetComponent <ActorMessageSenderComponent>().Get(unitId);

                int       rpcId    = iActorRequest.RpcId;                // 这里要保存客户端的rpcId
                IResponse response = await actorMessageSender.Call(iActorRequest);

                response.RpcId = rpcId;

                session.Reply(response);
                return;
            }

            case IActorMessage iActorMessage:                     // gate session收到actor消息直接转发给actor自己去处理
            {
                long unitId = session.GetComponent <SessionPlayerComponent>().Player.UnitId;
                ActorMessageSender actorMessageSender = Game.Scene.GetComponent <ActorMessageSenderComponent>().Get(unitId);
                actorMessageSender.Send(iActorMessage);
                return;
            }
            }

            Game.Scene.GetComponent <MessageDispatherComponent>().Handle(session, new MessageInfo(opcode, message));
        }
コード例 #18
0
        protected override void Run(Session session, C2G_AddGold message)
        {
            Player player = session.GetComponent <SessionPlayerComponent>().Player;

            player.UserDB.GetComponent <UserBaseComponent>().Gold += message.Add;

            Send_G2C_Gold(player);
        }
コード例 #19
0
        protected async ETTask RunAsync(Session session, C2G_TeamInviteRefuse message, Action <G2C_TeamInviteRefuse> reply)
        {
            G2C_TeamInviteRefuse response = new G2C_TeamInviteRefuse();

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

                //告知對方拒絕邀請
                var    proxy        = Game.Scene.GetComponent <CacheProxyComponent>();
                var    playerSync   = proxy.GetMemorySyncSolver <Player>();
                Player senderTarget = playerSync.Get <Player>(invite.data.SenderUid);
                if (senderTarget != null)
                {
                    G2C_TeamInviteTargerRefuse g2c_TeamInviteTargerRefuse = new G2C_TeamInviteTargerRefuse();
                    g2c_TeamInviteTargerRefuse.RefuseUid = player.uid;
                    GateMessageHelper.BroadcastTarget(g2c_TeamInviteTargerRefuse, invite.data.SenderUid);
                }

                //刪除該邀請
                await inviteComponent.DestroyByInviteId(message.InviteId);

                //回傳資料
                response.Error = ErrorCode.ERR_Success;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #20
0
        public void Dispatch(Session session, Packet packet)
        {
            Log.Debug("分配消息" + packet.Opcode);
            IMessage message;

            try
            {
                message = session.Network.Entity.GetComponent <OpcodeTypeComponent>().GetNewMessage(packet.Opcode);
                message.MergeFrom(packet.Bytes, packet.Offset, packet.Length);
                //message = session.Network.MessagePacker.DeserializeFrom(messageType, packet.Bytes, Packet.Index, packet.Length - Packet.Index);
            }
            catch (Exception e)
            {
                // 出现任何异常都要断开Session,防止客户端伪造消息
                Log.Error(e);
                session.Error = ErrorCode.ERR_PacketParserError;
                session.Network.Remove(session.Id);
                return;
            }

            //Log.Debug($"recv: {JsonHelper.ToJson(message)}");

            switch (message)
            {
            case IFrameMessage iFrameMessage:     // 如果是帧消息,构造成OneFrameMessage发给对应的unit
            {
                long unitId = session.GetComponent <SessionPlayerComponent>().Player.Id;
                ActorMessageSender actorMessageSender = Game.Scene.GetComponent <ActorMessageSenderComponent>().Get(unitId);
                // 这里设置了帧消息的id,防止客户端伪造
                iFrameMessage.Id = unitId;
                return;
            }

            case IActorMessage iActorMessage:     // gate session收到actor消息直接转发给actor自己去处理
            {
                session.GetComponent <SessionPlayerComponent>().Player.GetComponent <MailBoxComponent>().Add(new ActorMessageInfo()
                    {
                        Session = session, Message = iActorMessage
                    });
                return;
            }
            }

            Game.Scene.GetComponent <MessageDispatherComponent>().Handle(session, new MessageInfo(packet.Opcode, message));
        }
コード例 #21
0
        public async ETVoid DispatchAsync(Session session, ushort opcode, object message)
        {
            try
            {
                switch (message)
                {
                case IActorLocationRequest actorLocationRequest:                         // gate session收到actor rpc消息,先向actor 发送rpc请求,再将请求结果返回客户端
                {
                    Player player = session.GetComponent <SessionPlayerComponent>().Player;

                    long id = player.UnitId == 0L? player.TankId : player.UnitId;

                    ActorLocationSender actorLocationSender = Game.Scene.GetComponent <ActorLocationSenderComponent>().Get(id);

                    int rpcId = actorLocationRequest.RpcId;                             // 这里要保存客户端的rpcId

                    IResponse response = await actorLocationSender.Call(actorLocationRequest);

                    response.RpcId = rpcId;

                    session.Reply(response);
                    return;
                }

                case IActorLocationMessage actorLocationMessage:
                {
                    Player player = session.GetComponent <SessionPlayerComponent>().Player;

                    long id = player.UnitId == 0L? player.TankId : player.UnitId;

                    ActorLocationSender actorLocationSender = Game.Scene.GetComponent <ActorLocationSenderComponent>().Get(id);

                    actorLocationSender.Send(actorLocationMessage);

                    return;
                }
                }

                Game.Scene.GetComponent <MessageDispatcherComponent>().Handle(session, new MessageInfo(opcode, message));
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
コード例 #22
0
        protected override async void Run(Session session, C2G_FriendRoomInfo message, Action <G2C_FriendRoomInfo> reply)
        {
            G2C_FriendRoomInfo response = new G2C_FriendRoomInfo();

            try
            {
                //获取房间信息
                DBProxyComponent      proxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                User                  user           = session.GetComponent <SessionUserComponent>().User;
                List <PlayerBaseInfo> playerInfoList = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{_id:{message.UId}}}");

                if (playerInfoList.Count > 0)
                {
                    response.Score = playerInfoList[0].Score;
                    if (!playerInfoList[0].IsGiveFriendKey)
                    {
                        string endTime = CommonUtil.timeAddDays(CommonUtil.getCurDataNormalFormat(), 1);

                        //每天赠送好友房钥匙
                        await DBCommonUtil.AddFriendKey(message.UId, 3, endTime, "每天赠送3把好友房钥匙");

                        playerInfoList[0].IsGiveFriendKey = true;
                        response.IsGiveFriendKey          = true;
                        Log.Debug(response.IsGiveFriendKey + "bool");
                        await proxyComponent.Save(playerInfoList[0]);
                    }
                    else
                    {
                        //今天已经赠送好友房钥匙
                    }
                }

                {
                    //向map服务器发送请求
                    ConfigComponent      configCom     = Game.Scene.GetComponent <ConfigComponent>();
                    StartConfigComponent _config       = Game.Scene.GetComponent <StartConfigComponent>();
                    IPEndPoint           mapIPEndPoint = _config.MapConfigs[0].GetComponent <InnerConfig>().IPEndPoint;
                    Session mapSession = Game.Scene.GetComponent <NetInnerComponent>().Get(mapIPEndPoint);

                    M2G_FriendRoomInfo m2GFriendRoomInfo = (M2G_FriendRoomInfo)await mapSession.Call(new G2M_FriendRoomInfo()
                    {
                    });

                    response.Info = m2GFriendRoomInfo.Info;

                    int keyCount = await DBCommonUtil.GetUserFriendKeyNum(message.UId);

                    response.KeyCount = keyCount;
                }

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
        public async Task Handle(Session session, Entity entity, object actorMessage)
        {
            try
            {
                IActorMessage iActorMessage = actorMessage as IActorMessage;

                //连接客户端的Seeion
                Session clientSession = entity as Session;



                //如果 是刷新物品消息 也要刷新一个网关的user 的物品数量
                switch (iActorMessage)
                {
                case Actor_UserGetGoods userGetGoods:
                    SendClient(clientSession, iActorMessage);
                    clientSession.GetComponent <SessionUserComponent>().user.RefreshGoods(userGetGoods.GetGoodsList);
                    break;

                case Actor_CompelAccount compelAccount:
                    SendClient(clientSession, iActorMessage);
                    clientSession.GetComponent <SessionUserComponent>().user = null;
                    break;

                case Actor_UserStartGame startGame:
                    clientSession.GetComponent <SessionUserComponent>().GamerSessionActorId = startGame.SessionActorId;
                    break;

                case Actor_UserEndGame userEndGame:
                    clientSession.GetComponent <SessionUserComponent>().GamerSessionActorId = 0;
                    break;

                default:
                    SendClient(clientSession, iActorMessage);
                    break;
                }

                await Task.CompletedTask;
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
コード例 #24
0
        /// <summary>
        /// 验证Session是否绑定了玩家
        /// </summary>
        /// <param name="session"></param>
        /// <returns></returns>
        public static bool SignSession(Session session)
        {
            SessionUserComponent sessionUser = session.GetComponent <SessionUserComponent>();

            if (sessionUser == null || Game.Scene.GetComponent <UserComponent>().Get(sessionUser.User.UserID) == null)
            {
                return(false);
            }
            return(true);
        }
コード例 #25
0
        protected override async void Run(Session session, C2G_HeartBeat message, Action <G2C_HeartBeat> reply)
        {
            G2C_HeartBeat response = new G2C_HeartBeat();

            try
            {
                if (session.GetComponent <HeartBeatComponent>() != null)
                {
                    session.GetComponent <HeartBeatComponent>().CurrentTime = TimeHelper.ClientNowSeconds();
                }
//                Log.Info("服务端发送心跳包");
                reply(response);
            }
            catch (Exception e)
            {
                Log.Debug(e.ToString());
                ReplyError(response, e, reply);
            }
        }
コード例 #26
0
        protected override void Run(Session session, C2G_AgainGame message)
        {
            Player player = session.GetComponent <SessionPlayerComponent>().Player;

            Room room = Game.Scene.GetComponent <RoomComponent>().Get(message.RoomId);



            G2C_RoomDetailInfo msg = new G2C_RoomDetailInfo();
        }
コード例 #27
0
            protected override void Run(Session session, M2C_TeamGoBattleProgressReceiver message)
            {
                TestPlayerDataComponent testPlayerDataComponent = session.GetComponent <TestPlayerDataComponent>();
                BenchmarkComponent      benchmarkComponent      = Game.Scene.GetComponent <BenchmarkComponent>();

                if (benchmarkComponent.clients.TryGetValue(testPlayerDataComponent.testPlayerSetting.DeviceUniqueIdentifier, out var client))
                {
                    //client.UserLog($"M2C_TeamGoBattleProgressReceiverHandler");
                }
            }
コード例 #28
0
        protected override async void Run(Session session, C2G_EnterRoom message, Action <G2C_EnterRoom> reply)
        {
            G2C_EnterRoom response = new G2C_EnterRoom();

            try
            {
                User user = session.GetComponent <SessionUserComponent>().User;

                if (user == null)
                {
                    return;
                }

                //向map服务器发送请求
                StartConfigComponent config        = Game.Scene.GetComponent <StartConfigComponent>();
                IPEndPoint           mapIPEndPoint = config.MapConfigs[0].GetComponent <InnerConfig>().IPEndPoint;
                Session mapSession = Game.Scene.GetComponent <NetInnerComponent>().Get(mapIPEndPoint);

                //玩家进入房间
                M2G_PlayerEnterRoom m2GPlayerEnterRoom = (M2G_PlayerEnterRoom)await mapSession.Call(new G2M_PlayerEnterRoom()
                {
                    RoomType  = message.RoomType,
                    UserId    = user.UserID,
                    SessionId = session.InstanceId,
                    PlayerId  = user.Id,
                    RoomId    = message.RoomId
                });

                Log.Info(JsonHelper.ToJson(m2GPlayerEnterRoom));

                response.Error   = m2GPlayerEnterRoom.Error;
                response.Message = m2GPlayerEnterRoom.Message;

                session.GetComponent <SessionUserComponent>().User.ActorID = m2GPlayerEnterRoom.GameId;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #29
0
ファイル: GateHelper.cs プロジェクト: lantuma/DDZ
        /// <summary>
        /// 验证session是否合法
        /// </summary>
        /// <param name="session"></param>
        /// <returns></returns>
        public static bool SingSession(Session session)
        {
            SessionUserComponent sessionUseer = session.GetComponent <SessionUserComponent>();

            if (sessionUseer == null || Game.Scene.GetComponent <PlayerManagerComponent>().Get(sessionUseer.userInfo.Id) == null)
            {
                return(false);
            }

            return(true);
        }
コード例 #30
0
        protected override void Run(Session session, C2G_ChangeCamp message)
        {
            Player player = session.GetComponent<SessionPlayerComponent>().Player;

            Room room = Game.Scene.GetComponent<RoomComponent>().Get(message.RoomId);

            if (room.ChangeCamp(player.Id, message.TargetCamp))
            {
                room.BroadcastRoomDetailInfo();
            }
        }