Other small changes
This commit is contained in:
@ -226,7 +226,6 @@ namespace CoopClient.Entities.Player
|
|||||||
MainVehicle.IsEngineRunning = VehIsEngineRunning;
|
MainVehicle.IsEngineRunning = VehIsEngineRunning;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (MainVehicle.IsPlane)
|
if (MainVehicle.IsPlane)
|
||||||
{
|
{
|
||||||
if (VehLandingGear != (byte)MainVehicle.LandingGearState)
|
if (VehLandingGear != (byte)MainVehicle.LandingGearState)
|
||||||
@ -253,6 +252,15 @@ namespace CoopClient.Entities.Player
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (MainVehicle.HasRoof)
|
||||||
|
{
|
||||||
|
bool roofOpened = MainVehicle.RoofState == VehicleRoofState.Opened || MainVehicle.RoofState == VehicleRoofState.Opening;
|
||||||
|
if (roofOpened != VehRoofOpened)
|
||||||
|
{
|
||||||
|
MainVehicle.RoofState = VehRoofOpened ? VehicleRoofState.Opening : VehicleRoofState.Closing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (VehAreLightsOn != MainVehicle.AreLightsOn)
|
if (VehAreLightsOn != MainVehicle.AreLightsOn)
|
||||||
{
|
{
|
||||||
MainVehicle.AreLightsOn = VehAreLightsOn;
|
MainVehicle.AreLightsOn = VehAreLightsOn;
|
||||||
@ -283,23 +291,14 @@ namespace CoopClient.Entities.Player
|
|||||||
_lastHornActive = false;
|
_lastHornActive = false;
|
||||||
MainVehicle.SoundHorn(1);
|
MainVehicle.SoundHorn(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MainVehicle.HasRoof)
|
|
||||||
{
|
|
||||||
bool roofOpened = MainVehicle.RoofState == VehicleRoofState.Opened || MainVehicle.RoofState == VehicleRoofState.Opening;
|
|
||||||
if (roofOpened != VehRoofOpened)
|
|
||||||
{
|
|
||||||
MainVehicle.RoofState = VehRoofOpened ? VehicleRoofState.Opening : VehicleRoofState.Closing;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MainVehicle.CurrentRPM = VehRPM;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateVehiclePosition()
|
private void UpdateVehiclePosition()
|
||||||
{
|
{
|
||||||
MainVehicle.CurrentRPM = VehRPM;
|
|
||||||
|
|
||||||
float avrLat = Math.Min(1.5f, (Util.GetTickCount64() - LastUpdateReceived) / AverageLatency);
|
float avrLat = Math.Min(1.5f, (Util.GetTickCount64() - LastUpdateReceived) / AverageLatency);
|
||||||
|
|
||||||
if (_lastVehicleSteeringAngle != VehicleSteeringAngle)
|
if (_lastVehicleSteeringAngle != VehicleSteeringAngle)
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<AssemblyVersion>1.47.5.0001</AssemblyVersion>
|
<AssemblyVersion>1.52.1.0001</AssemblyVersion>
|
||||||
<FileVersion>1.0.0.0</FileVersion>
|
<FileVersion>1.0.0.0</FileVersion>
|
||||||
<RepositoryUrl>https://github.com/GTACOOP-R/GTACoop-R</RepositoryUrl>
|
<RepositoryUrl>https://github.com/GTACOOP-R/GTACoop-R</RepositoryUrl>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
148
Server/Server.cs
148
Server/Server.cs
@ -16,7 +16,6 @@ namespace CoopServer
|
|||||||
{
|
{
|
||||||
internal class IpInfo
|
internal class IpInfo
|
||||||
{
|
{
|
||||||
public string ip { get; set; }
|
|
||||||
public string country { get; set; }
|
public string country { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,14 +38,22 @@ 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: {MainSettings.Address}:{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("================");
|
||||||
|
|
||||||
IPAddress parsedAddress = IPAddress.Parse(MainSettings.Address);
|
|
||||||
|
|
||||||
// 623c92c287cc392406e7aaaac1c0f3b0 = RAGECOOP
|
// 623c92c287cc392406e7aaaac1c0f3b0 = RAGECOOP
|
||||||
NetPeerConfiguration config = new("623c92c287cc392406e7aaaac1c0f3b0")
|
NetPeerConfiguration config = new("623c92c287cc392406e7aaaac1c0f3b0")
|
||||||
{
|
{
|
||||||
@ -84,92 +91,95 @@ namespace CoopServer
|
|||||||
{
|
{
|
||||||
Logging.Info("Announcing to master server...");
|
Logging.Info("Announcing to master server...");
|
||||||
|
|
||||||
#region -- MASTERSERVER --
|
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)))
|
||||||
new Thread(async () =>
|
|
||||||
{
|
{
|
||||||
try
|
Logging.Error($"Announcing to the master server failed because this is not a public address!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#region -- MASTERSERVER --
|
||||||
|
new Thread(async () =>
|
||||||
{
|
{
|
||||||
// TLS only
|
|
||||||
ServicePointManager.Expect100Continue = true;
|
|
||||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13 | SecurityProtocolType.Tls12;
|
|
||||||
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
|
|
||||||
|
|
||||||
HttpClient httpClient = new();
|
|
||||||
|
|
||||||
IpInfo info;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string data = await httpClient.GetStringAsync("https://ipinfo.io/json");
|
// TLS only
|
||||||
|
ServicePointManager.Expect100Continue = true;
|
||||||
|
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13 | SecurityProtocolType.Tls12;
|
||||||
|
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
|
||||||
|
|
||||||
info = JsonConvert.DeserializeObject<IpInfo>(data);
|
HttpClient httpClient = new();
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
info = new() { ip = MainNetServer.Configuration.LocalAddress.ToString(), country = "?" };
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!Program.ReadyToStop)
|
IpInfo info;
|
||||||
{
|
|
||||||
string msg =
|
|
||||||
"{ " +
|
|
||||||
"\"address\": \"" + info.ip + "\", " +
|
|
||||||
"\"port\": \"" + MainSettings.Port + "\", " +
|
|
||||||
"\"name\": \"" + MainSettings.Name + "\", " +
|
|
||||||
"\"version\": \"" + _compatibleVersion.Replace("_", ".") + "\", " +
|
|
||||||
"\"players\": \"" + MainNetServer.ConnectionsCount + "\", " +
|
|
||||||
"\"maxPlayers\": \"" + MainSettings.MaxPlayers + "\", " +
|
|
||||||
"\"allowlist\": \"" + _mainAllowlist.Username.Any() + "\", " +
|
|
||||||
"\"mods\": \"" + MainSettings.ModsAllowed + "\", " +
|
|
||||||
"\"npcs\": \"" + MainSettings.NpcsAllowed + "\", " +
|
|
||||||
"\"country\": \"" + info.country + "\"" +
|
|
||||||
" }";
|
|
||||||
|
|
||||||
HttpResponseMessage response = null;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
response = await httpClient.PostAsync(MainSettings.MasterServer, new StringContent(msg, Encoding.UTF8, "application/json"));
|
string data = await httpClient.GetStringAsync("https://ipinfo.io/json");
|
||||||
|
|
||||||
|
info = JsonConvert.DeserializeObject<IpInfo>(data);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
info = new() { country = "?" };
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!Program.ReadyToStop)
|
||||||
|
{
|
||||||
|
string msg =
|
||||||
|
"{ " +
|
||||||
|
"\"address\": \"" + MainSettings.Address + "\", " +
|
||||||
|
"\"port\": \"" + MainSettings.Port + "\", " +
|
||||||
|
"\"name\": \"" + MainSettings.Name + "\", " +
|
||||||
|
"\"version\": \"" + _compatibleVersion.Replace("_", ".") + "\", " +
|
||||||
|
"\"players\": \"" + MainNetServer.ConnectionsCount + "\", " +
|
||||||
|
"\"maxPlayers\": \"" + MainSettings.MaxPlayers + "\", " +
|
||||||
|
"\"allowlist\": \"" + _mainAllowlist.Username.Any() + "\", " +
|
||||||
|
"\"mods\": \"" + MainSettings.ModsAllowed + "\", " +
|
||||||
|
"\"npcs\": \"" + MainSettings.NpcsAllowed + "\", " +
|
||||||
|
"\"country\": \"" + info.country + "\"" +
|
||||||
|
" }";
|
||||||
|
|
||||||
|
HttpResponseMessage response = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
response = await httpClient.PostAsync(MainSettings.MasterServer, new StringContent(msg, Encoding.UTF8, "application/json"));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logging.Error($"MasterServer: {ex.Message}");
|
||||||
|
|
||||||
|
// Sleep for 5s
|
||||||
|
Thread.Sleep(5000);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (response == null)
|
if (response == null)
|
||||||
{
|
{
|
||||||
Logging.Error("MasterServer: Something went wrong!");
|
Logging.Error("MasterServer: Something went wrong!");
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
else if (response.StatusCode != System.Net.HttpStatusCode.OK)
|
||||||
catch (Exception ex)
|
{
|
||||||
{
|
Logging.Error($"MasterServer: [{(int)response.StatusCode}]");
|
||||||
Logging.Error($"MasterServer: {ex.Message}");
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response.StatusCode != System.Net.HttpStatusCode.OK)
|
// Sleep for 10s
|
||||||
{
|
Thread.Sleep(10000);
|
||||||
Logging.Error($"MasterServer: [{(int)response.StatusCode}]");
|
|
||||||
|
|
||||||
// Wait 5 seconds before trying again
|
|
||||||
Thread.Sleep(5000);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sleep for 12.5s
|
|
||||||
Thread.Sleep(12500);
|
|
||||||
}
|
}
|
||||||
}
|
catch (HttpRequestException ex)
|
||||||
catch (HttpRequestException ex)
|
{
|
||||||
{
|
Logging.Error($"MasterServer: {ex.InnerException.Message}");
|
||||||
Logging.Error($"MasterServer: {ex.InnerException.Message}");
|
}
|
||||||
}
|
catch (Exception ex)
|
||||||
catch (Exception ex)
|
{
|
||||||
{
|
Logging.Error($"MasterServer: {ex.Message}");
|
||||||
Logging.Error($"MasterServer: {ex.Message}");
|
}
|
||||||
}
|
}).Start();
|
||||||
}).Start();
|
#endregion
|
||||||
#endregion
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(MainSettings.Resource))
|
if (!string.IsNullOrEmpty(MainSettings.Resource))
|
||||||
{
|
{
|
||||||
Commands = new();
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string resourcepath = AppDomain.CurrentDomain.BaseDirectory + "resources" + Path.DirectorySeparatorChar + MainSettings.Resource + ".dll";
|
string resourcepath = AppDomain.CurrentDomain.BaseDirectory + "resources" + Path.DirectorySeparatorChar + MainSettings.Resource + ".dll";
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
public bool ModsAllowed { get; set; } = false;
|
public bool ModsAllowed { get; set; } = false;
|
||||||
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://ragecoop.online/servers";
|
public string MasterServer { get; set; } = "https://ragecoop.online/gtav/servers";
|
||||||
public bool DebugMode { get; set; } = false;
|
public bool DebugMode { get; set; } = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user