Auto fetch master server address
This commit is contained in:
parent
11d178498f
commit
5a455d0487
@ -77,26 +77,9 @@ namespace RageCoop.Client.Menus
|
||||
private static void GetAllServers()
|
||||
{
|
||||
List<ServerListClass> serverList = null;
|
||||
try
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
var realUrl = Main.Settings.MasterServer=="[AUTO]" ? DownloadString("https://ragecoop.online/stuff/masterserver") : Main.Settings.MasterServer;
|
||||
serverList = JsonConvert.DeserializeObject<List<ServerListClass>>(DownloadString(realUrl));
|
||||
|
||||
// Need to be processed in main thread
|
||||
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 "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@ namespace RageCoop.Client
|
||||
/// <summary>
|
||||
/// Don't use it!
|
||||
/// </summary>
|
||||
public string MasterServer { get; set; } = "https://masterserver.ragecoop.online/";
|
||||
public string MasterServer { get; set; } = "[AUTO]";
|
||||
/// <summary>
|
||||
/// Don't use it!
|
||||
/// </summary>
|
||||
|
@ -129,15 +129,15 @@ namespace RageCoop.Client
|
||||
if (MainVehicle.Position.DistanceTo(Position)<5)
|
||||
{
|
||||
MainVehicle.Velocity = Velocity+5*(Position+Velocity*SyncParameters.PositioinPredictionDefault - MainVehicle.Position);
|
||||
_lastPositionCalibrated=Main.Counter.ElapsedMilliseconds;
|
||||
MainVehicle.Quaternion=Quaternion.Slerp(MainVehicle.Quaternion, Quaternion, 0.35f);
|
||||
}
|
||||
else
|
||||
{
|
||||
MainVehicle.Position=Position;
|
||||
MainVehicle.Velocity=Velocity;
|
||||
MainVehicle.Quaternion=Quaternion;
|
||||
}
|
||||
// Vector3 r = GetCalibrationRotation();
|
||||
MainVehicle.Quaternion=Quaternion.Slerp(MainVehicle.Quaternion, Quaternion, 0.35f);
|
||||
MainVehicle.RotationVelocity = RotationVelocity;
|
||||
if (DeluxoWingRatio!=-1)
|
||||
{
|
||||
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using GTA.Math;
|
||||
using System.Net;
|
||||
namespace RageCoop.Core
|
||||
{
|
||||
public class CoreUtils
|
||||
@ -35,6 +36,7 @@ namespace RageCoop.Core
|
||||
return (0x0, null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public static class Extensions
|
||||
{
|
||||
|
@ -110,7 +110,7 @@ namespace RageCoop.Server
|
||||
Program.Logger.Error(ex.InnerException?.Message ?? ex.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
var realMaster = MainSettings.MasterServer=="[AUTO]" ? Util.DownloadString("https://ragecoop.online/stuff/masterserver") : MainSettings.MasterServer;
|
||||
while (!Program.ReadyToStop)
|
||||
{
|
||||
string msg =
|
||||
@ -125,7 +125,7 @@ namespace RageCoop.Server
|
||||
HttpResponseMessage response = null;
|
||||
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)
|
||||
{
|
||||
|
@ -10,7 +10,7 @@
|
||||
public string Resource { get; set; } = "";
|
||||
public bool UPnP { get; set; } = true;
|
||||
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;
|
||||
/// <summary>
|
||||
/// NPC data won't be sent to a player if their distance is greater than this value. -1 for unlimited.
|
||||
|
@ -6,11 +6,30 @@ using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using RageCoop.Core;
|
||||
using Lidgren.Network;
|
||||
using System.Net;
|
||||
|
||||
namespace RageCoop.Server
|
||||
{
|
||||
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)
|
||||
{
|
||||
return obj switch
|
||||
|
Loading…
x
Reference in New Issue
Block a user