Removed custom ipv4. Small changes
This commit is contained in:
@ -8,18 +8,10 @@ using System.Reflection;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
using Lidgren.Network;
|
using Lidgren.Network;
|
||||||
|
|
||||||
namespace CoopServer
|
namespace CoopServer
|
||||||
{
|
{
|
||||||
internal class IpInfo
|
|
||||||
{
|
|
||||||
[JsonProperty("country")]
|
|
||||||
public string Country { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class Server
|
internal class Server
|
||||||
{
|
{
|
||||||
private static readonly string _compatibleVersion = "V1_4";
|
private static readonly string _compatibleVersion = "V1_4";
|
||||||
@ -39,18 +31,8 @@ namespace CoopServer
|
|||||||
|
|
||||||
public Server()
|
public Server()
|
||||||
{
|
{
|
||||||
if (IPAddress.TryParse(MainSettings.Address, out IPAddress parsedAddress) == false)
|
|
||||||
{
|
|
||||||
throw new Exception($"Something went wrong while parsing IP {MainSettings.Address}!");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parsedAddress.AddressFamily != System.Net.Sockets.AddressFamily.InterNetwork)
|
|
||||||
{
|
|
||||||
throw new Exception("Please use a valid IPv4 address!");
|
|
||||||
}
|
|
||||||
|
|
||||||
Logging.Info("================");
|
Logging.Info("================");
|
||||||
Logging.Info($"Server bound to: {MainSettings.Address}:{MainSettings.Port}");
|
Logging.Info($"Server bound to: 0.0.0.0:{MainSettings.Port}");
|
||||||
Logging.Info($"Server version: {Assembly.GetCallingAssembly().GetName().Version}");
|
Logging.Info($"Server version: {Assembly.GetCallingAssembly().GetName().Version}");
|
||||||
Logging.Info($"Compatible RAGECOOP versions: {_compatibleVersion.Replace('_', '.')}.x");
|
Logging.Info($"Compatible RAGECOOP versions: {_compatibleVersion.Replace('_', '.')}.x");
|
||||||
Logging.Info("================");
|
Logging.Info("================");
|
||||||
@ -58,8 +40,6 @@ namespace CoopServer
|
|||||||
// 623c92c287cc392406e7aaaac1c0f3b0 = RAGECOOP
|
// 623c92c287cc392406e7aaaac1c0f3b0 = RAGECOOP
|
||||||
NetPeerConfiguration config = new("623c92c287cc392406e7aaaac1c0f3b0")
|
NetPeerConfiguration config = new("623c92c287cc392406e7aaaac1c0f3b0")
|
||||||
{
|
{
|
||||||
LocalAddress = parsedAddress,
|
|
||||||
BroadcastAddress = parsedAddress,
|
|
||||||
Port = MainSettings.Port,
|
Port = MainSettings.Port,
|
||||||
MaximumConnections = MainSettings.MaxPlayers,
|
MaximumConnections = MainSettings.MaxPlayers,
|
||||||
EnableUPnP = MainSettings.UPnP
|
EnableUPnP = MainSettings.UPnP
|
||||||
@ -92,12 +72,6 @@ namespace CoopServer
|
|||||||
{
|
{
|
||||||
Logging.Info("Announcing to master server...");
|
Logging.Info("Announcing to master server...");
|
||||||
|
|
||||||
if (new string[5] { "127.0.0.1", "192.168.", "0.0.0.0", "1.1.1.1", "1.2.3.4" }.Any(el => MainSettings.Address.Contains(el, StringComparison.CurrentCultureIgnoreCase)))
|
|
||||||
{
|
|
||||||
Logging.Error($"Announcing to the master server failed because this is not a public address!");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#region -- MASTERSERVER --
|
#region -- MASTERSERVER --
|
||||||
new Thread(async () =>
|
new Thread(async () =>
|
||||||
{
|
{
|
||||||
@ -110,24 +84,10 @@ namespace CoopServer
|
|||||||
|
|
||||||
HttpClient httpClient = new();
|
HttpClient httpClient = new();
|
||||||
|
|
||||||
IpInfo info;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
string data = await httpClient.GetStringAsync("https://ipinfo.io/json");
|
|
||||||
|
|
||||||
info = JsonConvert.DeserializeObject<IpInfo>(data);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
info = new() { Country = "?" };
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!Program.ReadyToStop)
|
while (!Program.ReadyToStop)
|
||||||
{
|
{
|
||||||
string msg =
|
string msg =
|
||||||
"{ " +
|
"{ " +
|
||||||
"\"address\": \"" + MainSettings.Address + "\", " +
|
|
||||||
"\"port\": \"" + MainSettings.Port + "\", " +
|
"\"port\": \"" + MainSettings.Port + "\", " +
|
||||||
"\"name\": \"" + MainSettings.Name + "\", " +
|
"\"name\": \"" + MainSettings.Name + "\", " +
|
||||||
"\"version\": \"" + _compatibleVersion.Replace("_", ".") + "\", " +
|
"\"version\": \"" + _compatibleVersion.Replace("_", ".") + "\", " +
|
||||||
@ -135,8 +95,7 @@ namespace CoopServer
|
|||||||
"\"maxPlayers\": \"" + MainSettings.MaxPlayers + "\", " +
|
"\"maxPlayers\": \"" + MainSettings.MaxPlayers + "\", " +
|
||||||
"\"allowlist\": \"" + _mainAllowlist.Username.Any() + "\", " +
|
"\"allowlist\": \"" + _mainAllowlist.Username.Any() + "\", " +
|
||||||
"\"mods\": \"" + MainSettings.ModsAllowed + "\", " +
|
"\"mods\": \"" + MainSettings.ModsAllowed + "\", " +
|
||||||
"\"npcs\": \"" + MainSettings.NpcsAllowed + "\", " +
|
"\"npcs\": \"" + MainSettings.NpcsAllowed + "\"" +
|
||||||
"\"country\": \"" + info.Country + "\"" +
|
|
||||||
" }";
|
" }";
|
||||||
|
|
||||||
HttpResponseMessage response = null;
|
HttpResponseMessage response = null;
|
||||||
@ -157,10 +116,18 @@ namespace CoopServer
|
|||||||
{
|
{
|
||||||
Logging.Error("MasterServer: Something went wrong!");
|
Logging.Error("MasterServer: Something went wrong!");
|
||||||
}
|
}
|
||||||
else if (response.StatusCode != System.Net.HttpStatusCode.OK)
|
else if (response.StatusCode != HttpStatusCode.OK)
|
||||||
|
{
|
||||||
|
if (response.StatusCode == HttpStatusCode.BadRequest)
|
||||||
|
{
|
||||||
|
string requestContent = await response.Content.ReadAsStringAsync();
|
||||||
|
Logging.Error($"MasterServer: [{(int)response.StatusCode}], {requestContent}");
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
Logging.Error($"MasterServer: [{(int)response.StatusCode}]");
|
Logging.Error($"MasterServer: [{(int)response.StatusCode}]");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Sleep for 10s
|
// Sleep for 10s
|
||||||
Thread.Sleep(10000);
|
Thread.Sleep(10000);
|
||||||
@ -177,7 +144,6 @@ namespace CoopServer
|
|||||||
}).Start();
|
}).Start();
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(MainSettings.Resource))
|
if (!string.IsNullOrEmpty(MainSettings.Resource))
|
||||||
{
|
{
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
{
|
{
|
||||||
public class Settings
|
public class Settings
|
||||||
{
|
{
|
||||||
public string Address { get; set; } = "127.0.0.1";
|
|
||||||
public int Port { get; set; } = 4499;
|
public int Port { get; set; } = 4499;
|
||||||
public int MaxPlayers { get; set; } = 16;
|
public int MaxPlayers { get; set; } = 16;
|
||||||
public int MaxLatency { get; set; } = 300;
|
public int MaxLatency { get; set; } = 300;
|
||||||
|
Reference in New Issue
Block a user