Esempio n. 1
0
 public Server()
 {
     config = new INIReader(System.IO.File.ReadAllLines("config.ini"));
     chat = new ServerChat();
     instance = this;
     vehicleController = new ServerVehicleController();
     api = new ServerApi(this);
     gamemodeManager = new GamemodeManager(api);
     gamemodeManager.loadFromFile("gamemodes/" + config.getString("gamemode"));
     server = new TcpListener(IPAddress.Any, config.getInt("game_port"));
     server.Start();
     server.BeginAcceptTcpClient(onIncomingConnection, null);
     playerpool = new List<ServerPlayer>();
     Timer timer = new Timer();
     timer.Elapsed += onBroadcastTimer;
     timer.Interval = config.getInt("broadcast_interval");
     timer.Enabled = true;
     timer.Start();
     UDPStartPort = config.getInt("udp_start_port");
     Timer timer_slow = new Timer();
     timer_slow.Elapsed += timer_slow_Elapsed;
     timer_slow.Interval = config.getInt("slow_interval");
     timer_slow.Enabled = true;
     timer_slow.Start();
     http_server = new HTTPServer();
     Console.WriteLine("Started game server on port " + config.getInt("game_port").ToString());
     Console.WriteLine("Started http server on port " + config.getInt("http_port").ToString());
 }
Esempio n. 2
0
 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();
     }
 }
 private void loadConfiguration()
 {
     if (System.IO.File.Exists("miv_client_config.ini"))
     {
         var ini = new INIReader(System.IO.File.ReadAllLines("miv_client_config.ini"));
         textBox1.Text = ini.getString("nickname");
     }
 }