/// <summary> /// Adds a server to the database /// </summary> /// <param name="data"></param> public static void CreateServer(A2S_InfoResponse data) { if (!Directory.Exists(AppContext.BaseDirectory + "\\Servers\\")) { Directory.CreateDirectory(AppContext.BaseDirectory + "\\Servers\\"); } Directory.CreateDirectory(AppContext.BaseDirectory + "\\Servers\\" + data.Name); File.WriteAllText(AppContext.BaseDirectory + "\\Servers\\" + data.Name + "\\Ip.txt", data.IP); File.WriteAllText(AppContext.BaseDirectory + "\\Servers\\" + data.Name + "\\SteamID.txt", data.SteamID.ToString()); File.WriteAllText(AppContext.BaseDirectory + "\\Servers\\" + data.Name + "\\MaxPlayers.txt", data.MaxPlayers.ToString()); }
/// <summary> /// Adds a server to the database /// </summary> /// <param name="data"></param> public static void CreateServer(A2S_InfoResponse data) { }
public static A2S_InfoResponse GetInfoWithoutSteamID(string IP) { A2S_InfoResponse rg = new A2S_InfoResponse(); rg.IP = IP; try { if (IP.Split(':').Length != 2) { throw new Exception("IP invalid, probably missing port"); } UdpClient client = new UdpClient(); client.Client.SendTimeout = Constants.A2SQuerryTimeout; client.Client.ReceiveTimeout = Constants.A2SQuerryTimeout; IPEndPoint point = new IPEndPoint(IPAddress.Parse(IP.Split(':')[0]), int.Parse(IP.Split(':')[1])); client.Connect(point); byte[] req = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0x54, 0x53, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x20, 0x45, 0x6E, 0x67, 0x69, 0x6E, 0x65, 0x20, 0x51, 0x75, 0x65, 0x72, 0x79, 0x00 }; client.Send(req, req.Length); byte[] response = receive(client, point); if (response.Length < 6) { throw new ArgumentException("Server didn't return data"); } if (!response[4].Equals(0x49)) { throw new ArgumentException("Server returned invalid data"); } //Protocol = response[5] ByteIterator biterator = new ByteIterator(response, 6); //Name normally also contains version, we remove this here and just let name stand rg.Name = biterator.readstring().Split(' ')[0]; rg.Map = biterator.readstring(); //Folder biterator.readstring(); rg.Game = biterator.readstring(); rg.ID = biterator.readshort(); rg.Players = biterator.next(); rg.MaxPlayers = biterator.next(); rg.bots = biterator.next(); //Servertype + enviroment + visibility biterator.next(); biterator.next(); biterator.next(); rg.VAC = biterator.next().Equals(0x01); //Not the ship -> ignoring the possible data rg.Version = biterator.readstring(); return(rg); } catch (TimeoutException ex) { throw new Exception("Could not get info data. Maybe server is offline/temporary outtage"); } catch (IndexOutOfRangeException ex) { throw new Exception("Keywords string not readable -> can not extract steamid"); } catch (Exception ex) { throw new Exception(ex.Message); } return(rg); }