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);
        }
Exemple #2
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;

            if (server == null)
            {
                Console.WriteLine("RunServer failed sobj is not a BaseServer");
                return;
            }

            var  serverConfig = allConfig.GetServerConfig(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;
            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;
                        UpdateServices();
                        foreach (var svr in servers)
                        {
                            svr.DoUpdate((int)elapse);
                        }
                    }

                    Thread.Sleep(1);
                }
            }
        }