Auto fetch master server address

This commit is contained in:
Sardelka
2022-06-03 16:28:02 +08:00
parent 11d178498f
commit 5a455d0487
7 changed files with 52 additions and 26 deletions

View File

@ -77,26 +77,9 @@ namespace RageCoop.Client.Menus
private static void GetAllServers() private static void GetAllServers()
{ {
List<ServerListClass> serverList = null; List<ServerListClass> serverList = null;
try var realUrl = Main.Settings.MasterServer=="[AUTO]" ? DownloadString("https://ragecoop.online/stuff/masterserver") : Main.Settings.MasterServer;
{ serverList = JsonConvert.DeserializeObject<List<ServerListClass>>(DownloadString(realUrl));
// TLS only
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
WebClient client = new WebClient();
string data = client.DownloadString(Main.Settings.MasterServer);
serverList = JsonConvert.DeserializeObject<List<ServerListClass>>(data);
}
catch (Exception ex)
{
Main.QueueAction(() =>
{
ResultItem.Title = "Download failed!";
ResultItem.Description = ex.Message;
});
return;
}
// Need to be processed in main thread // Need to be processed in main thread
Main.QueueAction(() => Main.QueueAction(() =>
{ {
@ -139,5 +122,27 @@ namespace RageCoop.Client.Menus
} }
}); });
} }
private static string DownloadString(string url)
{
try
{
// TLS only
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
WebClient client = new WebClient();
return client.DownloadString(url);
}
catch (Exception ex)
{
Main.QueueAction(() =>
{
ResultItem.Title = "Download failed!";
ResultItem.Description = ex.Message;
});
return "";
}
}
} }
} }

View File

@ -18,7 +18,7 @@ namespace RageCoop.Client
/// <summary> /// <summary>
/// Don't use it! /// Don't use it!
/// </summary> /// </summary>
public string MasterServer { get; set; } = "https://masterserver.ragecoop.online/"; public string MasterServer { get; set; } = "[AUTO]";
/// <summary> /// <summary>
/// Don't use it! /// Don't use it!
/// </summary> /// </summary>

View File

@ -129,15 +129,15 @@ namespace RageCoop.Client
if (MainVehicle.Position.DistanceTo(Position)<5) if (MainVehicle.Position.DistanceTo(Position)<5)
{ {
MainVehicle.Velocity = Velocity+5*(Position+Velocity*SyncParameters.PositioinPredictionDefault - MainVehicle.Position); MainVehicle.Velocity = Velocity+5*(Position+Velocity*SyncParameters.PositioinPredictionDefault - MainVehicle.Position);
_lastPositionCalibrated=Main.Counter.ElapsedMilliseconds; MainVehicle.Quaternion=Quaternion.Slerp(MainVehicle.Quaternion, Quaternion, 0.35f);
} }
else else
{ {
MainVehicle.Position=Position; MainVehicle.Position=Position;
MainVehicle.Velocity=Velocity; MainVehicle.Velocity=Velocity;
MainVehicle.Quaternion=Quaternion;
} }
// Vector3 r = GetCalibrationRotation(); // Vector3 r = GetCalibrationRotation();
MainVehicle.Quaternion=Quaternion.Slerp(MainVehicle.Quaternion, Quaternion, 0.35f);
MainVehicle.RotationVelocity = RotationVelocity; MainVehicle.RotationVelocity = RotationVelocity;
if (DeluxoWingRatio!=-1) if (DeluxoWingRatio!=-1)
{ {

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using GTA.Math; using GTA.Math;
using System.Net;
namespace RageCoop.Core namespace RageCoop.Core
{ {
public class CoreUtils public class CoreUtils
@ -35,6 +36,7 @@ namespace RageCoop.Core
return (0x0, null); return (0x0, null);
} }
} }
} }
public static class Extensions public static class Extensions
{ {

View File

@ -110,7 +110,7 @@ namespace RageCoop.Server
Program.Logger.Error(ex.InnerException?.Message ?? ex.Message); Program.Logger.Error(ex.InnerException?.Message ?? ex.Message);
return; return;
} }
var realMaster = MainSettings.MasterServer=="[AUTO]" ? Util.DownloadString("https://ragecoop.online/stuff/masterserver") : MainSettings.MasterServer;
while (!Program.ReadyToStop) while (!Program.ReadyToStop)
{ {
string msg = string msg =
@ -125,7 +125,7 @@ namespace RageCoop.Server
HttpResponseMessage response = null; HttpResponseMessage response = null;
try try
{ {
response = await httpClient.PostAsync(MainSettings.MasterServer, new StringContent(msg, Encoding.UTF8, "application/json")); response = await httpClient.PostAsync(realMaster, new StringContent(msg, Encoding.UTF8, "application/json"));
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -10,7 +10,7 @@
public string Resource { get; set; } = ""; public string Resource { get; set; } = "";
public bool UPnP { get; set; } = true; public bool UPnP { get; set; } = true;
public bool AnnounceSelf { get; set; } = false; public bool AnnounceSelf { get; set; } = false;
public string MasterServer { get; set; } = "https://masterserver.ragecoop.online/"; public string MasterServer { get; set; } = "[AUTO]";
public bool DebugMode { get; set; } = false; public bool DebugMode { get; set; } = false;
/// <summary> /// <summary>
/// NPC data won't be sent to a player if their distance is greater than this value. -1 for unlimited. /// NPC data won't be sent to a player if their distance is greater than this value. -1 for unlimited.

View File

@ -6,11 +6,30 @@ using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using RageCoop.Core; using RageCoop.Core;
using Lidgren.Network; using Lidgren.Network;
using System.Net;
namespace RageCoop.Server namespace RageCoop.Server
{ {
static partial class Util static partial class Util
{ {
public static string DownloadString(string url)
{
try
{
// TLS only
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
WebClient client = new();
return client.DownloadString(url);
}
catch
{
return "";
}
}
public static (byte, byte[]) GetBytesFromObject(object obj) public static (byte, byte[]) GetBytesFromObject(object obj)
{ {
return obj switch return obj switch