public static void Awake(this NetInnerComponent self, string address)
 {
     self.Awake(NetworkProtocol.TCP, address);
     self.MessagePacker     = new MongoPacker();
     self.MessageDispatcher = new InnerMessageDispatcher();
     self.AppType           = StartConfigComponent.Instance.StartConfig.AppType;
 }
 public static void Awake(this NetInnerComponent self)
 {
     self.Awake(NetworkProtocol.TCP);
     self.MessagePacker     = new MongoPacker();
     self.MessageDispatcher = new InnerMessageDispatcher();
     self.AppType           = self.GetComponent <StartConfigComponent>().StartConfig.AppType;
 }
예제 #3
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);
            }
        }
예제 #4
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);
            }
        }
 public static void Awake(this NetInnerComponent self, IPEndPoint ipEndPoint)
 {
     self.Awake(NetworkProtocol.TCP, ipEndPoint);
     self.MessagePacker     = new ProtobufPacker();
     self.MessageDispatcher = new InnerMessageDispatcher();
     self.AppType           = self.Entity.GetComponent <StartConfigComponent>().StartConfig.AppType;
 }
예제 #6
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);
            }
        }
 public static void Awake(this NetInnerComponent self)
 {
     self.Awake(NetworkProtocol.TCP, Packet.PacketSizeLength4);
     self.MessagePacker     = new MongoPacker();
     self.MessageDispatcher = new InnerMessageDispatcher();
     self.AppType           = StartConfigComponent.Instance.StartConfig.AppType;
 }
예제 #8
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);
        }
예제 #9
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);
            }
        }
 public static void Awake(this NetInnerComponent self, string address)
 {
     //初始化 也是Tcp协议 包体长度 用4个字节表示
     self.Awake(NetworkProtocol.TCP, address, Packet.PacketSizeLength4);
     //内网通信 使用的是Bson进行序列化和反序列化的
     self.MessagePacker     = new MongoPacker();
     self.MessageDispatcher = new InnerMessageDispatcher();
     self.AppType           = StartConfigComponent.Instance.StartConfig.AppType;
 }
        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);
            }
        }
예제 #12
0
        protected override async ETTask Run(Session session, C2M_Reload request, M2C_Reload response, Action reply)
        {
            if (request.Account != "panda" && request.Password != "panda")
            {
                Log.Error($"error reload account and password: {MongoHelper.ToJson(request)}");
                return;
            }
            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();
        }
예제 #13
0
 public static void Update(this NetInnerComponent self)
 {
     self.Update();
 }
예제 #14
0
 public static void Awake(this NetInnerComponent self, IPEndPoint ipEndPoint)
 {
     self.Awake(NetworkProtocol.TCP, ipEndPoint);
     self.MessagePacker     = new MongoPacker();
     self.MessageDispatcher = new InnerMessageDispatcher();
 }
 public static void Awake(this NetInnerComponent self, string host, int port)
 {
     self.Awake(NetworkProtocol.TCP, host, port);
     self.MessagePacker     = new MongoPacker();
     self.MessageDispatcher = new InnerMessageDispatcher();
 }