Пример #1
0
        public override async ETTask Actor_TransferRequestHandler(Unit unit, Actor_TransferRequest request, Actor_TransferResponse response, Action reply)
        {
            long unitId = unit.Id;

            // 先在location锁住unit的地址
            await Game.Scene.GetComponent <LocationProxyComponent>().Lock(unitId, unit.InstanceId);

            // 删除unit,让其它进程发送过来的消息找不到actor,重发
            Game.EventSystem.Remove(unitId);

            long instanceId = unit.InstanceId;

            int mapIndex = request.MapIndex;

            StartConfigComponent startConfigComponent = StartConfigComponent.Instance;

            // 传送到map
            StartConfig mapConfig = startConfigComponent.Get(mapIndex);
            var         address   = mapConfig.GetComponent <InnerConfig>().Address;
            Session     session   = Game.Scene.GetComponent <NetInnerComponent>().Get(address);

            // 只删除不disponse否则M2M_TrasferUnitRequest无法序列化Unit
            Game.Scene.GetComponent <UnitComponent>().RemoveNoDispose(unitId);
            M2M_TrasferUnitResponse m2m_TrasferUnitResponse = (M2M_TrasferUnitResponse)await session.Call(new M2M_TrasferUnitRequest()
            {
                Unit = unit
            });

            unit.Dispose();

            // 解锁unit的地址,并且更新unit的instanceId
            await Game.Scene.GetComponent <LocationProxyComponent>().UnLock(unitId, instanceId, m2m_TrasferUnitResponse.InstanceId);

            reply();
        }
Пример #2
0
        protected override async void Run(Session session, C2M_Reload message, Action <M2C_Reload> reply)
        {
            M2C_Reload response = new M2C_Reload();

            try
            {
                StartConfigComponent startConfigComponent = Game.Scene.GetComponent <StartConfigComponent>();
                NetInnerComponent    netInnerComponent    = Game.Scene.GetComponent <NetInnerComponent>();
                foreach (StartConfig startConfig in startConfigComponent.GetAll())
                {
                    if (!message.AppType.Is(startConfig.AppType))
                    {
                        continue;
                    }
                    InnerConfig innerConfig   = startConfig.GetComponent <InnerConfig>();
                    Session     serverSession = netInnerComponent.Get(innerConfig.Address);
                    await serverSession.Call <M2A_Reload, A2M_Reload>(new M2A_Reload());
                }
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #3
0
        protected override async void Run(Session session, M2A_RegisterService message)
        {
            try
            {
                StartConfig          startConfig          = (StartConfig)message.Component;
                NetInnerComponent    netInnerComponent    = Game.Scene.GetComponent <NetInnerComponent>();
                StartConfigComponent startConfigComponent = Game.Scene.GetComponent <StartConfigComponent>();
                startConfigComponent.AddConfig(startConfig);

                if (startConfig.AppId == (int)IdGenerater.AppId)
                {
                    return;
                }
                InnerConfig        innerConfig        = startConfig.GetComponent <InnerConfig>();
                Session            serverSession      = netInnerComponent.Get(innerConfig.IPEndPoint);
                A2S_ConnectService a2S_ConnectService = (A2S_ConnectService)await serverSession.Call(new S2A_ConnectService());

                if (a2S_ConnectService.Error != ErrorCode.ERR_Success)
                {
                    Log.Error($"to connect service[{startConfig.AppType}:{startConfig.AppId}] is failed.");
                }
                else
                {
                    Log.Info($"to connect service[{startConfig.AppType}:{startConfig.AppId}] is successful.");
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Пример #4
0
        protected override async void Run(Session session, C2M_Reload message, Action <M2C_Reload> reply)
        {
            M2C_Reload m2CReload = new M2C_Reload();

            try
            {
                StartConfigComponent startConfigComponent = Game.Scene.GetComponent <StartConfigComponent>();
                NetInnerComponent    netInnerComponent    = Game.Scene.GetComponent <NetInnerComponent>();
                foreach (StartConfig startConfig in startConfigComponent.GetAll())
                {
                    if (!message.AppType.Is(startConfig.AppType))
                    {
                        continue;
                    }
                    InnerConfig innerConfig   = startConfig.GetComponent <InnerConfig>();
                    Session     serverSession = netInnerComponent.Get(innerConfig.Address);
                    await serverSession.Call <M2A_Reload, A2M_Reload>(new M2A_Reload());
                }
            }
            catch (Exception e)
            {
                m2CReload.Error   = ErrorCode.ERR_ReloadFail;
                m2CReload.Message = e.ToString();
            }
            reply(m2CReload);
        }
Пример #5
0
        protected override async void Run(Session session, C2G_LoginGate message, Action <G2C_LoginGate> reply)
        {
            G2C_LoginGate           response                = new G2C_LoginGate();
            StartConfigComponent    startComponent          = Game.Scene.GetComponent <StartConfigComponent>();
            GateSessionKeyComponent gateSessionKeyComponent = Game.Scene.GetComponent <GateSessionKeyComponent>();

            try
            {
                long uid = gateSessionKeyComponent.Get(message.Key);
                if (uid <= 0)
                {
                    response.Error   = ErrorCode.ERR_ConnectGateKeyError;
                    response.Message = "Gate key驗證失敗!";
                    reply(response);
                    return;
                }
                // 登入成功,刪除Gate的Key
                gateSessionKeyComponent.Remove(message.Key);
                int lobbyAppId = 0;
                var player     = CacheHelper.GetFromCache <Player>(uid);
                if (player != null && player.lobbyAppId != 0)
                {
                    lobbyAppId = player.lobbyAppId;
                }
                else
                {
                    lobbyAppId = SessionHelper.GetLobbyIdRandomly();
                }
                // 隨機連接到Lobby伺服器,並創建PlayerUnit實體
                G2L_LobbyUnitCreate g2L_LobbyUnitCreate = new G2L_LobbyUnitCreate();
                g2L_LobbyUnitCreate.Uid           = uid;
                g2L_LobbyUnitCreate.GateSessionId = session.InstanceId;
                g2L_LobbyUnitCreate.GateAppId     = (int)IdGenerater.AppId;
                g2L_LobbyUnitCreate.LobbyAppId    = lobbyAppId;

                // 等候LobbyUnit單元創建完成,並且也同步Player到了Gate
                Session             lobbySession        = SessionHelper.GetLobbySession(g2L_LobbyUnitCreate.LobbyAppId);
                L2G_LobbyUnitCreate l2G_LobbyUnitCreate = (L2G_LobbyUnitCreate)await lobbySession.Call(g2L_LobbyUnitCreate);

                if (l2G_LobbyUnitCreate.Error != ErrorCode.ERR_Success)
                {
                    response.Error = l2G_LobbyUnitCreate.Error;
                    reply(response);
                    return;
                }

                player = BsonSerializer.Deserialize <Player>(l2G_LobbyUnitCreate.Json);
                CacheExHelper.WriteInCache(player, out player);

                session.AddComponent <SessionPlayerComponent, long>(player.gateSessionActorId).Player = player;
                session.AddComponent <MailBoxComponent, string>(MailboxType.GateSession);

                response.PlayerId = player.Id;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #6
0
        protected async override void Run(Session session, G2G_QuitSave_Req message, Action <G2G_QuitSave_Res> reply)
        {
            G2G_QuitSave_Res response = new G2G_QuitSave_Res();

            try
            {
                DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>();

                var sessionUser = Game.Scene.GetComponent <PlayerManagerComponent>().GetSessionUser(message.UserId);

                await dbProxy.Save(sessionUser.userInfo);

                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 = message.UserId
                });
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
        public override void Destroy(SessionUserComponent self)
        {
            try
            {
                //释放User对象时将User对象从管理组件中移除
                Log.Info($"销毁User和Session{self.User.UserID}");
                Game.Scene.GetComponent <UserComponent>().Remove(self.User.UserID);

                StartConfigComponent config = Game.Scene.GetComponent <StartConfigComponent>();

                //向登录服务器发送玩家下线消息
                IPEndPoint realmIPEndPoint = config.RealmConfig.GetComponent <InnerConfig>().IPEndPoint;
                Session    realmSession    = Game.Scene.GetComponent <NetInnerComponent>().Get(realmIPEndPoint);
                realmSession.Send(new A0005_PlayerOffline_G2R()
                {
                    UserID = self.User.UserID
                });

                //服务端主动断开客户端连接
                Game.Scene.GetComponent <NetOuterComponent>().Remove(self.User.GateSessionID);
                //Log.Info($"将玩家{message.UserID}连接断开");

                self.User.Dispose();
                self.User = null;
            }
            catch (System.Exception e)
            {
                Log.Trace(e.ToString());
            }
        }
        protected override async void Run(Session session, C2G_CreateLandlordRoom message)
        {
            G2C_EnterMap response = new G2C_EnterMap();

            try
            {
                Log.Debug(MongoHelper.ToJson(message));
                Player player = session.GetComponent <SessionPlayerComponent>().Player;
                StartConfigComponent       startConfigComponet = Game.Scene.GetComponent <StartConfigComponent>();
                IPEndPoint                 matchAddress        = startConfigComponet.MatchConfig.GetComponent <InnerConfig>().IPEndPoint;
                Match2G_CreateRoomResponse matchRoomRes        = await Game.Scene.GetComponent <NetInnerComponent>().Get(matchAddress).Call <Match2G_CreateRoomResponse>(new G2Match_CreateRoomRequest());

                long roomId = matchRoomRes.roomId;

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

                //player.UnitId = createUnit.UnitId;
                //response.UnitId = createUnit.UnitId;
                //response.Count = createUnit.Count;
                // reply(response);
            }
            catch (Exception e)
            {
                // ReplyError(response, e, reply);
            }
        }
Пример #9
0
        protected override async void Run(Session session, C2M_Reload message, Action <M2C_Reload> reply)
        {
            M2C_Reload response = new M2C_Reload();

            if (message.Account != "panda" && message.Password != "panda")
            {
                Log.Error($"error reload account and password: {MongoHelper.ToJson(message)}");
                return;
            }
            try
            {
                //获得启动配置
                StartConfigComponent startConfigComponent = Game.Scene.GetComponent <StartConfigComponent>();
                //拿到内网通讯组件
                NetInnerComponent netInnerComponent = Game.Scene.GetComponent <NetInnerComponent>();
                //遍历所有的服务器配置
                foreach (StartConfig startConfig in startConfigComponent.GetAll())
                {
                    InnerConfig innerConfig   = startConfig.GetComponent <InnerConfig>();      //拿到当前服务器的ip端口
                    Session     serverSession = netInnerComponent.Get(innerConfig.IPEndPoint); //得到内部会话serverSession
                    await serverSession.Call(new M2A_Reload());                                //发送RPC消息等待完成
                }
                reply(response);                                                               //回复RPC消息
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #10
0
        private async ETVoid RunAsync(Session session, C2M_Reload message, Action <M2C_Reload> reply)
        {
            M2C_Reload response = new M2C_Reload();

            if (message.Account != "panda" && message.Password != "panda")
            {
                Log.Error($"error reload account and password: {MongoHelper.ToJson(message)}");
                return;
            }
            try
            {
                StartConfigComponent startConfigComponent = Game.Scene.GetComponent <StartConfigComponent>();
                NetInnerComponent    netInnerComponent    = Game.Scene.GetComponent <NetInnerComponent>();
                foreach (StartConfig startConfig in startConfigComponent.GetAll())
                {
                    InnerConfig innerConfig   = startConfig.GetComponent <InnerConfig>();
                    Session     serverSession = netInnerComponent.Get(innerConfig.IPEndPoint);
                    await serverSession.Call(new M2A_Reload());
                }
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #11
0
        protected override async ETTask Run(Session session, LoginGate_C2G request, LoginGate_G2C response, Action reply)
        {
            try
            {
                SessionKeyComponent SessionKeyComponent = Game.Scene.GetComponent <SessionKeyComponent>();
                // 获取玩家的UserID
                long gateUserID = SessionKeyComponent.Get(request.GateLoginKey);

                // 验证登录Key是否正确
                if (gateUserID == 0)
                {
                    response.Error = ErrorCode.ERR_ConnectGateKeyError;
                    //客户端提示:连接网关服务器超时
                    reply();
                    return;
                }

                //Key过期
                SessionKeyComponent.Remove(request.GateLoginKey);

                // gateUserID传参创建User
                User user = ComponentFactory.Create <User, long>(gateUserID);

                // 将新上线的User添加到UserComponent容器中
                Game.Scene.GetComponent <UserComponent>().Add(user);
                user.AddComponent <MailBoxComponent>();

                // session挂SessionUser组件,user绑定到session上
                session.AddComponent <SessionUserComponent>().User = user;
                // session挂MailBox组件可以通过MailBox进行actor通信
                session.AddComponent <MailBoxComponent, string>(MailboxType.GateSession);

                // 构建realmSession通知Realm服务器 玩家已上线
                StartConfigComponent config          = Game.Scene.GetComponent <StartConfigComponent>();
                IPEndPoint           realmIPEndPoint = config.RealmConfig.GetComponent <InnerConfig>().IPEndPoint;
                Session realmSession = Game.Scene.GetComponent <NetInnerComponent>().Get(realmIPEndPoint);
                // 2个参数 1:UserID 2:GateAppID
                realmSession.Send(new PlayerOnline_G2R()
                {
                    UserId = user.UserId, GateAppId = config.StartConfig.AppId
                });

                // 设置User的参数
                user.GateAppId     = config.StartConfig.AppId;
                user.GateSessionId = session.InstanceId;
                user.ActorId       = 0;

                // session.Send(new G2C_TestHotfixMessage() { Info = "recv hotfix message success" });

                // 回复客户端
                response.UserId = user.UserId;
                reply();

                await ETTask.CompletedTask;
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #12
0
        public override async void Destroy(SessionUserComponent self)
        {
            try
            {
                //释放User对象时将User对象从管理组件中移除
                Game.Scene.GetComponent <UserComponent>()?.Remove(self.User.UserID);

                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()
                {
                    UserID = self.User.UserID
                });

                self.User.Dispose();
                self.User = null;
            }
            catch (System.Exception e)
            {
                Log.Trace(e.ToString());
            }
        }
Пример #13
0
        public static void Awake(this LocationProxyComponent self)
        {
            StartConfigComponent startConfigComponent = StartConfigComponent.Instance;

            StartConfig startConfig = startConfigComponent.LocationConfig;              //位置服务器的配置 管理各个单位所在的进程

            self.LocationAddress = startConfig.GetComponent <InnerConfig>().IPEndPoint; //获取内网配置地址 IP:端口
        }
Пример #14
0
        public static void Awake(this LocationProxyComponent self)
        {
            StartConfigComponent startConfigComponent = StartConfigComponent.Instance;

            StartConfig startConfig = startConfigComponent.LocationConfig;

            self.LocationAddress = startConfig.GetComponent <InnerConfig>().IPEndPoint;
        }
Пример #15
0
        public static void Awake(this LocationProxyComponent self)
        {
            StartConfigComponent startConfigComponent = Game.Scene.GetComponent <StartConfigComponent>();

            StartConfig startConfig = startConfigComponent.StartConfig;

            self.LocationAddress = startConfig.GetComponent <LocationConfig>().IPEndPoint;
        }
Пример #16
0
        public static Session GetGateSession()
        {
            StartConfigComponent config         = Game.Scene.GetComponent <StartConfigComponent>();
            IPEndPoint           gateIPEndPoint = config.GateConfigs[0].GetComponent <InnerConfig>().IPEndPoint;
            //Log.Debug(gateIPEndPoint.ToString());
            Session gateSession = Game.Scene.GetComponent <NetInnerComponent>().Get(gateIPEndPoint);

            return(gateSession);
        }
        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);
            }
        }
Пример #18
0
        protected override async void Run(Session session, C2G_LoginGate message, Action <G2C_LoginGate> reply)
        {
            G2C_LoginGate response = new G2C_LoginGate();

            try
            {
                PokerGateSessionKeyCpt pokerGateSessionKey = Game.Scene.GetComponent <PokerGateSessionKeyCpt>();

                long key = pokerGateSessionKey.Get(message.Key);

                if (key == 0)
                {
                    response.Error   = ErrorCode.ERR_ConnectGateKeyError;
                    response.Message = "登录网关服务器失败。";
                    reply(response);
                    return;
                }
                pokerGateSessionKey.Remove(message.Key);

                DBProxyComponent dbProxyComponent = Game.Scene.GetComponent <DBProxyComponent>();

                ETModel.UserInfo userInfo = await dbProxyComponent.Query <ETModel.UserInfo>(message.UserId);

                userInfo.GetComponent <UnitGateComponent>().GateSessionActorId = session.Id;

                if (session.GetComponent <SessionUserComponent>() == null)
                {
                    session.AddComponent <SessionUserComponent>().userInfo = userInfo;
                }

                session.GetComponent <SessionUserComponent>().sessionId = session.Id;

                await session.AddComponent <MailBoxComponent, string>(ActorInterceptType.GateSession).AddLocation();

                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_PlayerOnline_Req()
                {
                    UserID = message.UserId, GateAppID = config.StartConfig.AppId
                });

                Game.Scene.GetComponent <PlayerManagerComponent>().Add(message.UserId, session.GetComponent <SessionUserComponent>(), session.Id);

                userInfo.IsOnline = true;

                await dbProxyComponent.Save(userInfo);

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #19
0
        /// <summary>
        /// 获取斗地主游戏专用Map服务器的Session
        /// </summary>
        /// <returns></returns>
        public static Session GetMapSession()
        {
            StartConfigComponent config        = Game.Scene.GetComponent <StartConfigComponent>();
            IPEndPoint           mapIPEndPoint = config.MapConfigs[0].GetComponent <InnerConfig>().IPEndPoint;

            Log.Debug(mapIPEndPoint.ToString());
            Session mapSession = Game.Scene.GetComponent <NetInnerComponent>().Get(mapIPEndPoint);

            return(mapSession);
        }
Пример #20
0
        /// <summary>
        /// 在初始化LocationProxyComponent组件时  会把位置服务器的IP地址读取出来 保存在LocationAddress中
        /// </summary>
        /// <param name="self"></param>
        public static void Awake(this LocationProxyComponent self)
        {
            //获得启动配置
            StartConfigComponent startConfigComponent = StartConfigComponent.Instance;
            //拿到里面的位置服务器地址
            StartConfig startConfig = startConfigComponent.LocationConfig;

            //保存位置服务器的IP端口
            self.LocationAddress = startConfig.GetComponent <InnerConfig>().IPEndPoint;
        }
Пример #21
0
        protected override void Run(Session session, A0003_LoginGate_C2G message, Action <A0003_LoginGate_G2C> reply)
        {
            A0003_LoginGate_G2C response = new A0003_LoginGate_G2C();

            try
            {
                SessionKeyComponent GateSessionKeyComponent = Game.Scene.GetComponent <SessionKeyComponent>();
                //获取玩家的永久Id
                long userId = GateSessionKeyComponent.Get(message.GateLoginKey);

                //验证登录Key是否正确
                if (userId == 0)
                {
                    response.Error = ErrorCode.ERR_ConnectGateKeyError;
                    //客户端提示:连接网关服务器超时
                    reply(response);
                    return;
                }

                //Key过期
                GateSessionKeyComponent.Remove(message.GateLoginKey);

                //参数userId是数据库中的永久Id
                User user = ComponentFactory.Create <User, long>(userId);
                //将新上线的User添加到容器中
                Game.Scene.GetComponent <UserComponent>().Add(user);
                user.AddComponent <MailBoxComponent>();

                session.AddComponent <SessionUserComponent>().User = user;
                session.AddComponent <MailBoxComponent, string>(MailboxType.GateSession);

                //回复Realm服务器 玩家已上线 GateAppID帮助Realm服务器定位玩家的位置
                StartConfigComponent config          = Game.Scene.GetComponent <StartConfigComponent>();
                IPEndPoint           realmIPEndPoint = config.RealmConfig.GetComponent <InnerConfig>().IPEndPoint;
                Session realmSession = Game.Scene.GetComponent <NetInnerComponent>().Get(realmIPEndPoint);
                //2个参数 1:永久UserID 2:GateAppID
                realmSession.Send(new A0004_PlayerOnline_G2R()
                {
                    UserID = user.UserID, GateAppID = config.StartConfig.AppId
                });

                //设置User的参数
                user.SelfGateAppID     = config.StartConfig.AppId;
                user.SelfGateSessionID = session.InstanceId;
                user.ActorIDforClient  = 0;

                //回复客户端
                response.UserID = user.UserID;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #22
0
        /// <summary>
        /// 发货接口
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="userId"></param>
        /// <param name="goodsId"></param>
        /// <param name="goodsNum"></param>
        /// <param name="price"></param>
        public static async Task UserRecharge(int orderId, long userId, int goodsId, int goodsNum, float price)
        {
            try
            {
                string           reward         = "";
                DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                ShopConfig       config         = ConfigHelp.Get <ShopConfig>(goodsId);

                List <Log_Recharge> log_Recharge = await proxyComponent.QueryJson <Log_Recharge>($"{{Uid:{userId}}}");

                if (log_Recharge.Count == 0)
                {
                    reward = "1:120000;105:20;104:1;107:1";
                    await DBCommonUtil.changeWealthWithStr(userId, reward, "首充奖励");
                }

                reward = config.Items;

                await DBCommonUtil.changeWealthWithStr(userId, reward, "购买元宝");

                //向gate服务器发送请求
                StartConfigComponent startConfig    = Game.Scene.GetComponent <StartConfigComponent>();
                IPEndPoint           gateIPEndPoint = startConfig.GateConfigs[0].GetComponent <InnerConfig>().IPEndPoint;
                Session gateSession = Game.Scene.GetComponent <NetInnerComponent>().Get(gateIPEndPoint);

                G2H_GamerCharge g2HGamerCharge = (G2H_GamerCharge)await gateSession.Call(new H2G_GamerCharge()
                {
                    goodsId = goodsId,
                    UId     = userId
                });

//                UserComponent userComponent = Game.Scene.GetComponent<UserComponent>();
//                User user = userComponent.Get(userId);
//                //给玩家发送消息
//                user?.session?.Send(new Actor_GamerBuyYuanBao()
//                {
//                    goodsId = goodsId
//                });

                // 记录日志
                {
                    Log_Recharge log_recharge = ComponentFactory.CreateWithId <Log_Recharge>(IdGenerater.GenerateId());
                    log_recharge.Uid     = userId;
                    log_recharge.GoodsId = config.Id;
                    log_recharge.Price   = config.Price;
                    log_recharge.OrderId = orderId;
                    await proxyComponent.Save(log_recharge);
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Пример #23
0
        protected override async ETTask Run(Session session, C2G_LoginGate request, G2C_LoginGate response, Action reply)
        {
            GateSessionKeyComponent gateSessionKeyComponent = Game.Scene.GetComponent <GateSessionKeyComponent>();
            //从已经分发的KEY里面寻找,如果没找到,说明非法用户,不给他连接gate服务器
            long playerID = gateSessionKeyComponent.Get(request.Key);

            if (playerID == 0)
            {
                response.Error   = ErrorCode.ERR_ConnectGateKeyError;
                response.Message = "Gate key验证失败!";
                reply();
                return;
            }

            //Key失效
            gateSessionKeyComponent.Remove(request.Key);

            //专门给这个玩家创建一个Player对象
            Player player = ComponentFactory.Create <Player, long>(playerID);

            player.AddComponent <UnitGateComponent, long>(session.InstanceId);

            //注册到PlayerComponent,方便管理
            Game.Scene.GetComponent <PlayerComponent>().Add(player);

            //给这个session安排上Player
            session.AddComponent <SessionPlayerComponent>().Player = player;

            // 增加掉线组件
            session.AddComponent <SessionOfflineComponent>();

            // 增加心跳包
            session.AddComponent <HeartBeatComponent>().CurrentTime = TimeHelper.ClientNowSeconds();

            //添加邮箱组件表示该session是一个Actor,接收的消息将会队列处理
            await session.AddComponent <MailBoxComponent, string>(MailboxType.GateSession).AddLocation();

            Log.Info($"gate的actorid为{session.Id}");
            //向登录服务器发送玩家上线消息
            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_PlayerOnline()
            {
                PlayerIDInPlayerComponent = player.Id, PlayerId = player.PlayerID, GateAppID = config.StartConfig.AppId
            });

            //Log.Info("发送离线消息完毕");

            //回复客户端的连接gate服务器请求
            reply();
            await ETTask.CompletedTask;
        }
Пример #24
0
        protected override async ETTask Run(Session session, A0003_LoginGate_C2G request, A0003_LoginGate_G2C response, Action reply)
        {
            try
            {
                SessionKeyComponent SessionKeyComponent = Game.Scene.GetComponent <SessionKeyComponent>();
                //获取玩家的永久Id
                long gateUserID = SessionKeyComponent.Get(request.GateLoginKey);

                //验证登录Key是否正确
                if (gateUserID == 0)
                {
                    response.Error = ErrorCode.ERR_ConnectGateKeyError;
                    //客户端提示:连接网关服务器超时
                    reply();
                    return;
                }

                //Key过期
                SessionKeyComponent.Remove(request.GateLoginKey);

                //gateUserID传参创建User
                User user = ComponentFactory.Create <User, long>(gateUserID);

                //将新上线的User添加到UserComponent容器中
                Game.Scene.GetComponent <UserComponent>().Add(user);
                user.AddComponent <MailBoxComponent>();

                //session挂SessionUser组件,user绑定到session上
                //session挂MailBox组件可以通过MailBox进行actor通信
                session.AddComponent <SessionUserComponent>().User = user;
                session.AddComponent <MailBoxComponent, string>(MailboxType.GateSession);

                StartConfigComponent config = Game.Scene.GetComponent <StartConfigComponent>();
                //构建realmSession通知Realm服务器 玩家已上线
                //...

                //设置User的参数
                user.GateAppID     = config.StartConfig.AppId;
                user.GateSessionID = session.InstanceId;
                user.ActorID       = 0;

                //回复客户端
                response.UserID = user.UserID;
                reply();

                await ETTask.CompletedTask;
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #25
0
        protected override async void Run(Session session, C2G_LoginGate message, Action <G2C_LoginGate> reply)
        {
            G2C_LoginGate response = new G2C_LoginGate();

            try
            {
                GateSessionKeyComponent gateSessionKeyComponent = Game.Scene.GetComponent <GateSessionKeyComponent>();
                long userId = gateSessionKeyComponent.Get(message.Key);
                if (userId == 0)
                {
                    response.Error   = ErrorCode.ERR_ConnectGateKeyError;
                    response.Message = "Gate key验证失败!";
                    reply(response);
                    return;
                }

                //Key过期
                gateSessionKeyComponent.Remove(message.Key);

                //创建User对象
                User user = UserFactory.Create(userId, session.Id);
                await user.AddComponent <ActorComponent>().AddLocation();

                //添加User对象关联到Session上
                session.AddComponent <SessionUserComponent>().User = user;
                //添加消息转发组件
                await session.AddComponent <ActorComponent, string>(ActorType.GateSession).AddLocation();

                //向登录服务器发送玩家上线消息
                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_PlayerOnline()
                {
                    UserId = userId, GateAppId = config.StartConfig.AppId
                });

                response.PlayerId = user.Id;
                response.UserId   = user.UserID;
                reply(response);

                session.Send(new G2C_TestHotfixMessage()
                {
                    Info = "recv hotfix message success"
                });
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #26
0
        protected override async ETTask Run(Unit unit, Actor_TransferRequest message, Action <Actor_TransferResponse> reply)
        {
            Actor_TransferResponse response = new Actor_TransferResponse();

            try
            {
                long unitId = unit.Id;

                // 先在location锁住unit的地址
                await Game.Scene.GetComponent <LocationProxyComponent>().Lock(unitId, unit.InstanceId);

                // 删除unit,让其它进程发送过来的消息找不到actor,重发
                Game.EventSystem.Remove(unitId);

                long instanceId = unit.InstanceId;

                int mapIndex = message.MapIndex;

                StartConfigComponent startConfigComponent = StartConfigComponent.Instance;

                // 考虑AllServer情况
                if (startConfigComponent.Count == 1)
                {
                    mapIndex = 0;
                }

                // 传送到map
                StartConfig mapConfig = startConfigComponent.MapConfigs[mapIndex];
                IPEndPoint  address   = mapConfig.GetComponent <InnerConfig>().IPEndPoint;
                Session     session   = Game.Scene.GetComponent <NetInnerComponent>().Get(address);

                // 只删除不disponse否则M2M_TrasferUnitRequest无法序列化Unit
                Game.Scene.GetComponent <UnitComponent>().RemoveNoDispose(unitId);
                M2M_TrasferUnitResponse m2m_TrasferUnitResponse = (M2M_TrasferUnitResponse)await session.Call(new M2M_TrasferUnitRequest()
                {
                    Unit = unit
                });

                unit.Dispose();

                // 解锁unit的地址,并且更新unit的instanceId
                await Game.Scene.GetComponent <LocationProxyComponent>().UnLock(unitId, instanceId, m2m_TrasferUnitResponse.InstanceId);

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
        protected override async Task Run(Unit unit, Actor_TransferRequest message, Action <Actor_TransferResponse> reply)
        {
            Actor_TransferResponse response = new Actor_TransferResponse();

            try
            {
                long unitId = unit.Id;


                // 先在location锁住unit的地址
                await Game.Scene.GetComponent <LocationProxyComponent>().Lock(unitId);

                // 删除unit actorcomponent,让其它进程发送过来的消息找不到actor,重发
                unit.RemoveComponent <ActorComponent>();

                int mapIndex = message.MapIndex;

                StartConfigComponent startConfigComponent = Game.Scene.GetComponent <StartConfigComponent>();

                // 考虑AllServer情况
                if (startConfigComponent.Count == 1)
                {
                    mapIndex = 0;
                }

                // 传送到map
                StartConfig mapConfig = startConfigComponent.MapConfigs[mapIndex];
                string      address   = mapConfig.GetComponent <InnerConfig>().Address;
                Session     session   = Game.Scene.GetComponent <NetInnerComponent>().Get(address);

                // 只删除不disponse否则M2M_TrasferUnitRequest无法序列化Unit
                Game.Scene.GetComponent <UnitComponent>().RemoveNoDispose(unitId);
                await session.Call <M2M_TrasferUnitResponse>(new M2M_TrasferUnitRequest()
                {
                    Unit = unit
                });

                unit.Dispose();

                // 解锁unit的地址,并且更新unit的地址
                await Game.Scene.GetComponent <LocationProxyComponent>().UnLock(unitId, mapConfig.AppId);

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #28
0
        protected override async void Run(Session session, C2G_LoginGate message, Action <G2C_LoginGate> reply)
        {
            G2C_LoginGate response = new G2C_LoginGate();

            try
            {
                GameGateSessionKeyComponent landlordsGateSessionKeyComponent = Game.Scene.GetComponent <GameGateSessionKeyComponent>();
                long userId = landlordsGateSessionKeyComponent.Get(message.Key);

                //验证登录Key是否正确
                if (userId == 0)
                {
                    response.Error = ErrorCode.ERR_ConnectGateKeyError;
                    reply(response);
                    return;
                }

                //Key过期
                landlordsGateSessionKeyComponent.Remove(message.Key);


                //创建User对象
                User user = UserFactory.Create(userId, session.Id);
                await user.AddComponent <MailBoxComponent>().AddLocation();

                //添加User对象关联到Session上
                session.AddComponent <SessionUserComponent>().User = user;
                //session.AddComponent<HeartBeatComponent>().CurrentTime = TimeHelper.ClientNowSeconds();
                //添加消息转发组件
                await session.AddComponent <MailBoxComponent, string>(ActorType.GateSession).AddLocation();

                //向登录服务器发送玩家上线消息
                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_PlayerOnline_Req()
                {
                    UserID = userId, GateAppID = config.StartConfig.AppId
                });

                response.PlayerID = user.Id;
                response.UserID   = user.UserID;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #29
0
        protected override async void Run(Session session, StartMatchRt message, Action <StartMatchRe> reply)
        {
            StartMatchRe response = new StartMatchRe();

            try
            {
                //验证玩家ID是否正常
                Player player = Game.Scene.GetComponent <PlayerComponent>().Get(message.PlayerId);
                if (player == null)
                {
                    response.Error = ErrorCode.ERR_AccountOrPasswordError;
                    reply(response);
                    return;
                }

                //验证玩家是否符合进入房间要求
                RoomConfig roomConfig = RoomHelper.GetConfig(message.Level);
                UserInfo   userInfo   = await Game.Scene.GetComponent <DBProxyComponent>().Query <UserInfo>(player.UserId);

                if (userInfo.Money < roomConfig.MinThreshold)
                {
                    response.Error = ErrorCode.ErrUserMoneyLessError;
                    reply(response);
                    return;
                }

                //向匹配服务器发送匹配请求
                StartConfigComponent config       = Game.Scene.GetComponent <StartConfigComponent>();
                IPEndPoint           matchAddress = config.MatchConfig.GetComponent <InnerConfig>().IPEndPoint;
                Session     matchSession          = Game.Scene.GetComponent <NetInnerComponent>().Get(matchAddress);
                JoinMatchRe joinMatchRe           = await matchSession.Call <JoinMatchRe>(new JoinMatchRt()
                {
                    PlayerId      = player.Id,
                    UserId        = player.UserId,
                    GateSessionId = session.Id,
                    GateAppId     = config.StartConfig.AppId
                });

                //设置玩家的Actor消息直接发送给匹配对象
                player.ActorId = joinMatchRe.ActorId;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
        protected override void Run(Session session, S2M_RegisterService message, Action <M2S_RegisterService> reply)
        {
            M2S_RegisterService response = new M2S_RegisterService();

            try
            {
                NetInnerComponent    netInnerComponent    = Game.Scene.GetComponent <NetInnerComponent>();
                StartConfigComponent startConfigComponent = Game.Scene.GetComponent <StartConfigComponent>();
                MasterComponent      masterComponent      = Game.Scene.GetComponent <MasterComponent>();

                StartConfig startConfig = (StartConfig)message.Component;
                if (!masterComponent.AddConfig(startConfig))
                {
                    response.Error = ErrorCode.ERR_RegisterServerRepeatly;
                    reply(response);
                    return;
                }
                else
                {
                    Log.Info($"Server[{startConfig.AppType}:{startConfig.AppId}] is online.");
                }

                startConfigComponent.AddConfig(startConfig);

                var startConfigs = masterComponent.GetAll();
                response.Components = startConfigs.Select(e => (ComponentWithId)e).ToList();
                reply(response);

                foreach (StartConfig v in startConfigs)
                {
                    // 不傳給自己
                    if (v.AppId == startConfig.AppId)
                    {
                        continue;
                    }
                    InnerConfig innerConfig   = v.GetComponent <InnerConfig>();
                    Session     serverSession = netInnerComponent.Get(innerConfig.IPEndPoint);
                    serverSession.Send(new M2A_RegisterService
                    {
                        Component = startConfig
                    });
                }
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }