masterserver finished

This commit is contained in:
EntenKoeniq
2021-12-08 03:59:14 +01:00
parent 14698f93dd
commit ed46eb5a8b
5 changed files with 22 additions and 8 deletions

View File

@ -21,7 +21,7 @@ namespace CoopClient
private bool GameLoaded = false;
internal static readonly string CurrentVersion = "V0_8_0_1";
internal static readonly string CurrentVersion = "V0_9_0";
internal static bool ShareNpcsWithPlayers = false;
internal static bool DisableTraffic = false;

View File

@ -64,7 +64,7 @@ namespace CoopClient.Menus.Sub
try
{
WebClient client = new WebClient();
string data = client.DownloadString("http://gtacoopr.000webhostapp.com/");
string data = client.DownloadString(Main.MainSettings.MasterServer);
serverList = JsonConvert.DeserializeObject<List<ServerListClass>>(data);
}
catch (Exception ex)

View File

@ -16,6 +16,10 @@
/// <summary>
/// Don't use it!
/// </summary>
public string MasterServer { get; set; } = "http://gtacoopr.000webhostapp.com/servers.php";
/// <summary>
/// Don't use it!
/// </summary>
public bool FlipMenu { get; set; } = false;
/// <summary>
/// Don't use it!

View File

@ -20,7 +20,7 @@ namespace CoopServer
internal class Server
{
private static readonly string CompatibleVersion = "V0_8_0_1";
private static readonly string CompatibleVersion = "V0_9_0";
public static readonly Settings MainSettings = Util.Read<Settings>("CoopSettings.xml");
private readonly Blocklist MainBlocklist = Util.Read<Blocklist>("Blocklist.xml");
@ -71,8 +71,10 @@ namespace CoopServer
}
}
if (1 == 1) // TODO
if (MainSettings.AnnounceSelf)
{
Logging.Info("Announcing to master server...");
#region -- MASTERSERVER --
new Thread(async () =>
{
@ -110,10 +112,16 @@ namespace CoopServer
"\"country\": \"" + info.Country + "\"" +
" }";
HttpResponseMessage response = null;
string responseContent = "";
try
{
HttpResponseMessage response = await httpClient.PostAsync("http://gtacoopr.000webhostapp.com/", new StringContent(msg, Encoding.UTF8, "application/json"));
response = await httpClient.PostAsync(MainSettings.MasterServer, new StringContent(msg, Encoding.UTF8, "application/json"));
if (response == null)
{
Logging.Error("MasterServer: Something went wrong!");
continue;
}
responseContent = await response.Content.ReadAsStringAsync();
}
@ -123,9 +131,9 @@ namespace CoopServer
continue;
}
if (responseContent != "OK")
if (response.StatusCode != System.Net.HttpStatusCode.OK)
{
Logging.Error(responseContent);
Logging.Error($"MasterServer: {response.StatusCode}");
responseError = true;
}
else
@ -137,7 +145,7 @@ namespace CoopServer
}
catch (Exception ex)
{
Logging.Error(ex.Message);
Logging.Error($"MasterServer: {ex.Message}");
}
}).Start();
#endregion

View File

@ -11,6 +11,8 @@
public bool NpcsAllowed { get; set; } = true;
public bool ModsAllowed { get; set; } = false;
public bool UPnP { get; set; } = true;
public bool AnnounceSelf { get; set; } = true;
public string MasterServer { get; set; } = "http://gtacoopr.000webhostapp.com/servers.php";
public bool DebugMode { get; set; } = false;
}
}