Ejemplo n.º 1
0
        private void DelayedCompleteThread()
        {
            try
            {
                // wait for the last servers to respond
                Thread.Sleep(2500);

                // go find the servers with lowest ping
                var responded = from server in servers.Values
                                where server.Info != null
                                select server;

                // get the percentile
                var pings = from server in responded
                            select server.Ping;

                var percentileTreshold = Percentile(pings, PingPercentile / 100.0);

                Log.Info("Ping treshold: {0}", percentileTreshold);

                var lowPingServers = from server in responded
                                     where server.Ping < percentileTreshold
                                     select server;

                Log.Info("found {0} low-ping servers", lowPingServers.Count());

                // filter them out based on our lovely criteria
                var filteredServers = from server in lowPingServers
                                      where (!server.Info.ContainsKey("fs_game") || server.Info["fs_game"] == "") // mhm
                                      select server;

                // and score them
                var scoredServers = from server in filteredServers
                                    orderby server.GetScore() descending
                                    select server;

                var scoredFinal = scoredServers.ToArray();

                // keep the list up-to-date
                while (true)
                {
                    // refresh player counts every 10 seconds
                    Thread.Sleep(10000);

                    foreach (var server in scoredFinal)
                    {
                        server.Queried = false;
                    }

                    Thread.Sleep(2500);

                    var j  = new JObject();
                    var ss = new JArray();

                    foreach (var server in scoredFinal)
                    {
                        var s = new JObject();

                        foreach (var info in server.Info)
                        {
                            s[info.Key] = info.Value;
                        }

                        s["score"]         = server.GetScore();
                        s["volatileScore"] = server.GetVolatileScore();
                        s["ping"]          = server.Ping;

                        ss.Add(s);
                    }

                    j["servers"] = ss;

                    //Log.Debug("jason is " + j.ToString());

                    GameInterface.ExecuteJS(string.Format("CodeCallback_PageBroadcast(\"{0}\", {1});", "homeServersUpdated", j.ToString()));
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
Ejemplo n.º 2
0
 public void LogMessage(string source, string message, LogLevel level)
 {
     GameInterface.Print("[" + source + "] " + message + "\n");
 }