public GameServer(NetworkSettings settings, string name, string description) { if (settings == null) throw new ArgumentException("settings"); this.Settings = settings; this.Name = name; this.Description = description; }
/// <summary> /// Creates a new instance of the <see cref="GameServer"/> class. /// </summary> /// <param name="settings"></param> /// <param name="name"></param> /// <param name="description"></param> public GameServer(NetworkSettings settings, string name = DefaultName, string description = null) { if (settings == null) { throw new ArgumentException("settings"); } this.Settings = settings; this.Name = name; this.Description = description; }
public PacketCollection QueryServer(NetworkSettings nwSettings) { if (nwSettings == null) { throw new ArgumentNullException("nwSettings"); } PacketCollection packets = new PacketCollection(); using (UdpClient client = new UdpClient(nwSettings.LocalPort)) { byte[] request, response, timestamp = Helpers.GetTimeStamp(); IPEndPoint remoteIpEndpoint = new IPEndPoint(IPAddress.Parse(nwSettings.Host), nwSettings.RemotePort); client.Client.ReceiveTimeout = nwSettings.ReceiveTimeout; client.Connect(remoteIpEndpoint); request = GetChallengeRequest(timestamp); client.Send(request, request.Length); response = client.Receive(ref remoteIpEndpoint); ChallengePacket pChallenge = new ChallengePacket(response); request = GetInfosRequest(timestamp, pChallenge.GetChallenge()); client.Send(request, request.Length); while (true) { try { response = client.Receive(ref remoteIpEndpoint); packets.Add(new InfoPacket(response)); } catch (SocketException ex) { if (ex.ErrorCode == (int)SocketError.TimedOut) { break; } else { throw; } } } } return(packets); }
public PacketCollection QueryServer(NetworkSettings nwSettings) { if (nwSettings == null) throw new ArgumentNullException("nwSettings"); PacketCollection packets = new PacketCollection(); using (UdpClient client = new UdpClient(nwSettings.LocalPort)) { byte[] request, response, timestamp = Helpers.GetTimeStamp(); IPEndPoint remoteIpEndpoint = new IPEndPoint(IPAddress.Parse(nwSettings.Host), nwSettings.RemotePort); client.Client.ReceiveTimeout = nwSettings.ReceiveTimeout; client.Connect(remoteIpEndpoint); request = GetChallengeRequest(timestamp); client.Send(request, request.Length); response = client.Receive(ref remoteIpEndpoint); ChallengePacket pChallenge = new ChallengePacket(response); request = GetInfosRequest(timestamp, pChallenge.GetChallenge()); client.Send(request, request.Length); while (true) { try { response = client.Receive(ref remoteIpEndpoint); packets.Add(new InfoPacket(response)); } catch (SocketException ex) { if (ex.ErrorCode == (int)SocketError.TimedOut) break; else throw; } } } return packets; }
/// <summary> /// Creates a new instance of the <see cref="GameServer"/> class. /// </summary> /// <param name="host">The IP address of the server</param> /// <param name="port">The port number of the server</param> /// <param name="name">The custom name you want to give to this server</param> /// <param name="description">The custom description you want to give to this server</param> public GameServer(string host, int port, string name = DefaultName, string description = null) : this(NetworkSettings.GetDefault(host, port), name, description) { }
public GameServer(NetworkSettings settings, string name) : this(settings, name, null) { }
/// <summary> /// Creates a new instance of the <see cref="GameServer"/> class. /// </summary> /// <param name="settings"></param> /// <param name="name"></param> /// <param name="description"></param> public GameServer(NetworkSettings settings) : this(settings, DefaultName, null) { }