Пример #1
0
        static bool ReadyServer()
        {
            ServerConfiguration.Instance.WriteLog();

            if (Server.StaticInit(Convert.ToUInt16(ServerConfiguration.Instance.config["port"]),
                                  Convert.ToByte(ServerConfiguration.Instance.config["world_count"]),
                                  Convert.ToInt32(ServerConfiguration.Instance.config["map_id"]),
                                  Convert.ToBoolean(ServerConfiguration.Instance.config["battle_auth"])) == false)
            {
                Log.Error("Server.StaticInit error");
                return(false);
            }

            string dns = "";

            if (ServerConfiguration.Instance.config["ip"] != null)
            {
                dns = ServerConfiguration.Instance.config["ip"];
            }
            else if (ServerConfiguration.Instance.config["meta_hostname"] != null)
            {
                try
                {
                    HttpClient client = new HttpClient();

                    HttpRequestMessage msg = new HttpRequestMessage(HttpMethod.Get, ServerConfiguration.Instance.config["meta_hostname"]);


                    HttpResponseMessage response = client.SendAsync(msg).Result;

                    // Get the response
                    var responseString = response.Content.ReadAsStringAsync().Result;
                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        Log.Error($"getInfo error :{responseString}");
                        return(false);
                    }
                    dns = responseString;
                }
                catch (HttpRequestException e)
                {
                    Log.Error($"HttpRequestException :{e.Message}");
                    return(false);
                }
                catch (Exception e)
                {
                    Log.Error($"Exception :{e.Message}");
                    return(false);
                }
            }
            else
            {
                Log.Error("server address error");
                return(false);
            }


            var server_addr = dns + ":" + ServerConfiguration.Instance.config["port"];
            var redis_addr  = ServerConfiguration.Instance.config["redis:ip"] + ":" + ServerConfiguration.Instance.config["redis:port"];

            var DefaultFirstReplicationTimeout = ServerConfiguration.Instance.config.GetSection("DefaultFirstReplicationTimeout");

            if (DefaultFirstReplicationTimeout.Value != null)
            {
                ReplicationManagerServer.DefaultFirstReplicationTimeout = int.Parse(DefaultFirstReplicationTimeout.Value);
            }

            if (Convert.ToBoolean(ServerConfiguration.Instance.config["server_process_update"]))
            {
                ServerProcessManager.sInstance.Init(server_addr, redis_addr);
            }

            if (ServerConfiguration.Instance.channel_update == true)
            {
                Cache.sInstance.Init(Convert.ToByte(ServerConfiguration.Instance.config["world_count"]), server_addr,
                                     redis_addr, ServerConfiguration.Instance.config["name"], Convert.ToInt32(ServerConfiguration.Instance.config["map_id"]));
                Subscribe.Do((Lidgren.Network.NetServer)NetworkManagerServer.sInstance.GetServer());
                CacheThread.Run();
            }

            return(true);
        }