protected void Page_Load(object sender, EventArgs e) { ServerFinder finder = new ServerFinder(new ServerFinder.AnswerDelegate(Answer), false, true); GridView1.AutoGenerateColumns = true; for (int i = 0; i < 5; ++i) { finder.Tick(0.5f); Thread.Sleep(500); } GridView1.DataSource = infos; GridView1.DataBind(); }
public static void ConsoleMain(string[] args) { Root r = new Root(args, false); SpaceWar2006.GameSystem.Mod.Instance.Init(); ServerFinder scanner = new ServerFinder(Answer,true,true); for (int i = 0; i < 50; ++i) { scanner.Tick(0.1f); Thread.Sleep(100); } System.Console.WriteLine("---------SERVERS----------"); List<IPEndPoint> list = new List<IPEndPoint>(); int j = 0; foreach (KeyValuePair<IPEndPoint, GameSystem.GameServerInfo> kv in servers) { list.Add(kv.Key); j++; System.Console.Write("["+ j.ToString()+"] "+kv.Key.ToString()+": "); System.Console.WriteLine(kv.Value.ToString()); } System.Console.WriteLine("--------------------------"); System.Console.Write("select server: "); int select = int.Parse(System.Console.ReadLine()) - 1; IPEndPoint connect = list[select]; System.Console.WriteLine("Connecting to "+connect.ToString()+"..."); args = new string[] { "client", "-connect", connect.ToString() }; Root.Instance.Args = args; r.ClientClient(args); Flow f = new SpaceWar2006.Flows.ClientStart(); r.CurrentFlow = f; f.Start(); r.ClientLoop(); r.Dispose(); }
public static void Main(string[] args) { NpgsqlConnectionStringBuilder builder = new NpgsqlConnectionStringBuilder (); builder.Host = "localhost"; builder.Password = ""; builder.Pooling = false; builder.UserName = "******"; builder.Database = "game"; int i = Array.IndexOf<string> (args, "--password"); if (i != -1) { builder.Password = args[i + 1]; } i = Array.IndexOf<string> (args, "--host"); if (i != -1) { builder.Host = args[i + 1]; } i = Array.IndexOf<string> (args, "--database"); if (i != -1) { builder.Database = args[i + 1]; } i = Array.IndexOf<string> (args, "--username"); if (i != -1) { builder.UserName = args[i + 1]; } string cstring = builder.ToString (); System.Console.WriteLine (cstring); while (true) { try { infos.Clear(); using (NpgsqlConnection c = new NpgsqlConnection(cstring)) { c.Open(); NpgsqlCommand cmd = c.CreateCommand(); cmd.CommandText = "SELECT * FROM gameserver"; NpgsqlDataReader r = cmd.ExecuteReader(); List<ServerFinder.Server> list = new List<ServerFinder.Server>(); while (r.Read()) { string host = (string)r["host"]; int port = (int)r["port"]; ServerFinder.Server s = new ServerFinder.Server(host, port); list.Add(s); } ServerFinder finder = new ServerFinder(new ServerFinder.AnswerDelegate(Answer), false, list); while (true) { for (i = 0; i < 10; ++i) { finder.Tick(0.1f); Thread.Sleep(100); } foreach (KeyValuePair<string, SpaceWar2006.GameSystem.GameServerInfo> info in infos) { string host = info.Key.Split(':')[0]; int port = int.Parse(info.Key.Split(':')[1]); string map = info.Value.Map; int numplayers = info.Value.NumPlayers; int maxplayers = info.Value.MaxPlayers; string sql = string.Format(@"INSERT INTO gameinfo(time,map,numplayers,maxplayers,gameserver_id) VALUES (NOW(),'{2}',{3},{4},(SELECT id FROM gameserver WHERE host='{0}' AND port={1}));", host, port, map, numplayers, maxplayers); System.Console.WriteLine(sql); cmd = c.CreateCommand(); cmd.CommandText = sql; cmd.ExecuteNonQuery(); } infos.Clear(); } } } catch (NpgsqlException e) { System.Console.WriteLine(e.GetType().ToString()); System.Console.WriteLine(e.StackTrace); System.Console.WriteLine(e.Message); } Thread.Sleep(1000); } }