public Client() { var startup = new Timer(6000); startup.Tick += (o, e) => { startup.Stop(); BindConsoleCommand("reconnect", (a) => { if (System.IO.File.Exists("miv_lastserver.ini")) { darkscreen = new ClientRectangleView(new System.Drawing.RectangleF(0, 0, 2000, 2000), System.Drawing.Color.Black); Game.FadeScreenOut(1); string[] lines = System.IO.File.ReadAllLines("miv_lastserver.ini"); INIReader reader = new INIReader(lines); initAndConnect(reader.getString("ip"), reader.getInt16("port"), reader.getString("nickname")); } }); if (System.IO.File.Exists("_serverinit.ini")) { darkscreen = new ClientRectangleView(new System.Drawing.RectangleF(0, 0, 2000, 2000), System.Drawing.Color.Black); string[] lines = System.IO.File.ReadAllLines("_serverinit.ini"); INIReader reader = new INIReader(lines); Int64 timestamp_saved = reader.getInt64("timestamp"); Int64 timestamp_now = System.Diagnostics.Stopwatch.GetTimestamp(); TimeSpan time_delta = new TimeSpan(timestamp_now - timestamp_saved); if (time_delta.Minutes < 5) { System.IO.File.Delete("_serverinit.ini"); System.IO.File.WriteAllLines("miv_lastserver.ini", lines); initAndConnect(reader.getString("ip"), reader.getInt16("port"), reader.getString("nickname")); } } else { FileSystemOverlay.crashIfSPPreparationFail(); } }; startup.Start(); // nope? nothing to do }
private void refreshList() { if (!File.Exists("servers.list")) { File.WriteAllText("servers.list", ""); } listView1.Items.Clear(); var servers = loadFromFile(); foreach (ServerInfo server in servers) { new Task(new Action(delegate { try { var request = HttpWebRequest.CreateHttp("http://" + server.IP + ":" + server.Port.ToString() + "/get_server_data"); var response = (HttpWebResponse)request.GetResponse(); string ini = new StreamReader(response.GetResponseStream()).ReadToEnd(); INIReader reader = new INIReader(ini.Split('\n')); response.Close(); server.GamePort = reader.getInt16("game_port"); ListViewItem item = createListItem(reader.getString("name"), server.IP, server.Port.ToString() + "." + server.GamePort.ToString(), reader.getString("players") + "/" + reader.getString("max_players")); item.Tag = server; listView1.Items.Add(item); } catch { ListViewItem item = createListItem("Offline", server.IP, server.Port.ToString() + "." + server.GamePort.ToString(), "-"); listView1.Items.Add(item); } })).Start(); } }