예제 #1
0
파일: App.cs 프로젝트: dora-BYR/Fenix
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                var cfgList = new List <RuntimeConfig>();

                var obj = new RuntimeConfig();
                obj.ExternalIp          = "auto";
                obj.InternalIp          = "auto";
                obj.Port                = 17777; //auto
                obj.AppName             = "Login.App";
                obj.HeartbeatIntervalMS = 5000;
                obj.ClientNetwork       = NetworkType.TCP;
                obj.DefaultActorNames   = new List <string>()
                {
                    "LoginService"
                };

                cfgList.Add(obj);

                obj                     = new RuntimeConfig();
                obj.ExternalIp          = "auto";
                obj.InternalIp          = "auto";
                obj.Port                = 17778; //auto
                obj.AppName             = "Match.App";
                obj.HeartbeatIntervalMS = 5000;
                obj.ClientNetwork       = NetworkType.TCP;
                obj.DefaultActorNames   = new List <string>()
                {
                    "MatchService"
                };

                cfgList.Add(obj);

                obj                     = new RuntimeConfig();
                obj.ExternalIp          = "auto";
                obj.InternalIp          = "auto";
                obj.Port                = 17779; //auto
                obj.AppName             = "Master.App";
                obj.HeartbeatIntervalMS = 5000;
                obj.ClientNetwork       = NetworkType.TCP;
                obj.DefaultActorNames   = new List <string>()
                {
                    "MasterService"
                };

                cfgList.Add(obj);

                obj                     = new RuntimeConfig();
                obj.ExternalIp          = "auto";
                obj.InternalIp          = "auto";
                obj.Port                = 17780; //auto
                obj.AppName             = "Zone.App";
                obj.HeartbeatIntervalMS = 5000;
                obj.ClientNetwork       = NetworkType.TCP;
                obj.DefaultActorNames   = new List <string>()
                {
                    "ZoneService"
                };

                cfgList.Add(obj);

                using (StreamWriter sw = new StreamWriter("app.json", false, Encoding.UTF8))
                {
                    var content = JsonConvert.SerializeObject(cfgList, Formatting.Indented);
                    sw.Write(content);
                }

                Environment.SetEnvironmentVariable("AppName", "Login.App");

                //Bootstrap.Start(new Assembly[] { typeof(UModule.Avatar).Assembly }, cfgList, OnInit, isMultiProcess:true); //单进程模式

                Bootstrap.Start(new Assembly[] { typeof(UModule.Avatar).Assembly }, cfgList, OnInit, isMultiProcess: false); //单进程模式
            }
            else
            {
                var builder = new ConfigurationBuilder().AddCommandLine(args);
                var cmdLine = builder.Build();

                //将命令行参数,设置到进程的环境变量
                Environment.SetEnvironmentVariable("AppName", cmdLine["AppName"]);

                using (var sr = new StreamReader(cmdLine["Config"]))
                {
                    var cfgList = JsonConvert.DeserializeObject <List <RuntimeConfig> >(sr.ReadToEnd());
                    Bootstrap.Start(new Assembly[] { typeof(UModule.Avatar).Assembly }, cfgList, OnInit, isMultiProcess: true); //分布式
                }
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            StaticCompositeResolver.Instance.Register(
                MessagePack.Resolvers.ClientAppResolver.Instance,
                MessagePack.Resolvers.FenixRuntimeResolver.Instance,
                MessagePack.Resolvers.SharedResolver.Instance,
                MessagePack.Unity.UnityResolver.Instance,
                MessagePack.Unity.Extension.UnityBlitResolver.Instance,
                MessagePack.Unity.Extension.UnityBlitWithPrimitiveArrayResolver.Instance,
                MessagePack.Resolvers.StandardResolver.Instance
                );

            if (args.Length == 0)
            {
                var cfgList = new List <RuntimeConfig>();

                var obj = new RuntimeConfig();
                obj.ExternalIp          = "auto";
                obj.InternalIp          = "auto";
                obj.Port                = 17777; //auto
                obj.AppName             = "Login.App";
                obj.HeartbeatIntervalMS = 5000;
                obj.ClientNetwork       = NetworkType.TCP;
                obj.DefaultActorNames   = new List <string>()
                {
                    "LoginService"
                };

                cfgList.Add(obj);

                obj                     = new RuntimeConfig();
                obj.ExternalIp          = "auto";
                obj.InternalIp          = "auto";
                obj.Port                = 17778; //auto
                obj.AppName             = "Match.App";
                obj.HeartbeatIntervalMS = 5000;
                obj.ClientNetwork       = NetworkType.TCP;
                obj.DefaultActorNames   = new List <string>()
                {
                    "MatchService"
                };

                cfgList.Add(obj);

                obj                     = new RuntimeConfig();
                obj.ExternalIp          = "auto";
                obj.InternalIp          = "auto";
                obj.Port                = 17779; //auto
                obj.AppName             = "Master.App";
                obj.HeartbeatIntervalMS = 5000;
                obj.ClientNetwork       = NetworkType.TCP;
                obj.DefaultActorNames   = new List <string>()
                {
                    "MasterService"
                };

                cfgList.Add(obj);

                obj                     = new RuntimeConfig();
                obj.ExternalIp          = "auto";
                obj.InternalIp          = "auto";
                obj.Port                = 17780; //auto
                obj.AppName             = "Zone.App";
                obj.HeartbeatIntervalMS = 5000;
                obj.ClientNetwork       = NetworkType.TCP;
                obj.DefaultActorNames   = new List <string>()
                {
                    "ZoneService"
                };

                cfgList.Add(obj);

                using (var sw = new StreamWriter("app.json", false, Encoding.UTF8))
                {
                    var content = JsonConvert.SerializeObject(cfgList, Formatting.Indented);
                    sw.Write(content);
                }

                Environment.SetEnvironmentVariable("AppName", "Login.App");

                Bootstrap.Start(new Assembly[] { typeof(UModule.Avatar).Assembly }, cfgList, OnInit, isMultiProcess: true); //单进程模式

                //Bootstrap.Start(new Assembly[] { typeof(UModule.Avatar).Assembly }, cfgList, OnInit, isMultiProcess: false); //单进程模式
            }
            else
            {
                Parser.Default.ParseArguments <Options>(args)
                .WithParsed <Options>(o =>
                {
                    //将命令行参数,设置到进程的环境变量
                    Environment.SetEnvironmentVariable("AppName", o.AppName);

                    using (var sr = new StreamReader(o.Config))
                    {
                        var cfgList = JsonConvert.DeserializeObject <List <RuntimeConfig> >(sr.ReadToEnd());
                        Bootstrap.Start(new Assembly[] { typeof(UModule.Avatar).Assembly }, cfgList, OnInit, isMultiProcess: true);    //分布式
                    }
                });
            }
        }