示例#1
0
        public static void RunServer(Assembly assembly, EServerType serverType, ConfigInfo allConfig)
        {
            string serverTypeStr = "Lockstep.Server." + serverType.ToString().Replace("Server", "") + "." +
                                   (serverType).ToString();
            var type = assembly.GetType(serverTypeStr);

            if (type == null)
            {
                Console.WriteLine("StartServerFailed!: have no server type:" + serverTypeStr);
                return;
            }

            var        sobj   = Activator.CreateInstance(type);
            BaseServer server = sobj as BaseServer;

            server.serverType = serverType;
            RunServer(assembly, server, allConfig);
        }
示例#2
0
        public static void RunServer(Assembly assembly, BaseServer server, ConfigInfo allConfig)
        {
            if (server == null)
            {
                Console.WriteLine("RunServer failed sobj is not a BaseServer");
                return;
            }

            var  serverConfig = allConfig.GetServerConfig(server.serverType);
            long lastTick     = 1;
            int  tickInterval = 40;

            Console.WriteLine("=============== LockstepPlatform " + serverConfig.type + " Start!! ===============");
            Console.WriteLine("config: " + serverConfig.ToString());
            servers.Add(server);
            if (hasInited)
            {
                return;
            }

            hasInited = true;
            Utils.StartServices();

            var sw = new Stopwatch();

            sw.Start();
            {
                while (true)
                {
                    var count = servers.Count;
                    for (int i = 0; i < count; i++)
                    {
                        var svr = servers[i];
                        if (!svr.HasInit)
                        {
                            var initConfig =
                                allConfig.GetServerConfig((EServerType)(Enum.Parse(typeof(EServerType),
                                                                                   svr.GetType().Name)));
                            svr.DoAwake(initConfig);
                            svr.DoStart();
                        }
                    }

                    foreach (var svr in servers)
                    {
                        svr.PollEvents();
                    }

                    var curTick = sw.ElapsedMilliseconds;
                    var elapse  = curTick - lastTick;
                    if (elapse >= tickInterval)
                    {
                        lastTick = curTick;
                        Utils.UpdateServices();
                        foreach (var svr in servers)
                        {
                            svr.DoUpdate((int)elapse);
                        }
                    }

                    Thread.Sleep(1);
                }
            }
        }
示例#3
0
 private static void RunServer(object sobj, ConfigInfo config)
 {
 }