Master server is back!
This commit is contained in:
@ -91,7 +91,7 @@ namespace RageCoop.Client
|
|||||||
/// <param name="serverAddress">The server address to connect. Example: 127.0.0.1:4499</param>
|
/// <param name="serverAddress">The server address to connect. Example: 127.0.0.1:4499</param>
|
||||||
public static void Connect(string serverAddress)
|
public static void Connect(string serverAddress)
|
||||||
{
|
{
|
||||||
Networking.DisconnectFromServer(serverAddress);
|
Networking.ToggleConnection(serverAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -99,7 +99,7 @@ namespace RageCoop.Client
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static void Disconnect()
|
public static void Disconnect()
|
||||||
{
|
{
|
||||||
Networking.DisconnectFromServer(null);
|
Networking.ToggleConnection(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -41,9 +41,11 @@ namespace RageCoop.Client.Menus
|
|||||||
|
|
||||||
_usernameItem.Activated += UsernameActivated;
|
_usernameItem.Activated += UsernameActivated;
|
||||||
ServerIpItem.Activated += ServerIpActivated;
|
ServerIpItem.Activated += ServerIpActivated;
|
||||||
_serverConnectItem.Activated += (sender, item) => { Networking.DisconnectFromServer(Main.Settings.LastServerAddress); };
|
_serverConnectItem.Activated += (sender, item) => { Networking.ToggleConnection(Main.Settings.LastServerAddress); };
|
||||||
|
|
||||||
|
|
||||||
|
Menu.AddSubMenu(ServersMenu.Menu);
|
||||||
|
|
||||||
Menu.Add(_usernameItem);
|
Menu.Add(_usernameItem);
|
||||||
Menu.Add(ServerIpItem);
|
Menu.Add(ServerIpItem);
|
||||||
Menu.Add(_serverConnectItem);
|
Menu.Add(_serverConnectItem);
|
||||||
@ -58,6 +60,7 @@ namespace RageCoop.Client.Menus
|
|||||||
MenuPool.Add(DevToolMenu.Menu);
|
MenuPool.Add(DevToolMenu.Menu);
|
||||||
MenuPool.Add(DebugMenu.Menu);
|
MenuPool.Add(DebugMenu.Menu);
|
||||||
MenuPool.Add(DebugMenu.DiagnosticMenu);
|
MenuPool.Add(DebugMenu.DiagnosticMenu);
|
||||||
|
MenuPool.Add(ServersMenu.Menu);
|
||||||
|
|
||||||
Menu.Add(_aboutItem);
|
Menu.Add(_aboutItem);
|
||||||
}
|
}
|
||||||
|
@ -4,71 +4,72 @@ using System.Drawing;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using LemonUI.Menus;
|
using LemonUI.Menus;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace RageCoop.Client.Menus
|
namespace RageCoop.Client.Menus
|
||||||
{
|
{
|
||||||
internal class ServerListClass
|
internal class ServerListClass
|
||||||
{
|
{
|
||||||
[JsonProperty("address")]
|
[JsonProperty("ip")]
|
||||||
public string Address { get; set; }
|
public string IP { get; set; }
|
||||||
[JsonProperty("port")]
|
|
||||||
public string Port { get; set; }
|
|
||||||
[JsonProperty("name")]
|
[JsonProperty("name")]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
[JsonProperty("version")]
|
[JsonProperty("version")]
|
||||||
public string Version { get; set; }
|
public string Version { get; set; }
|
||||||
|
|
||||||
[JsonProperty("players")]
|
[JsonProperty("players")]
|
||||||
public int Players { get; set; }
|
public int Players { get; set; }
|
||||||
|
|
||||||
[JsonProperty("maxPlayers")]
|
[JsonProperty("maxPlayers")]
|
||||||
public int MaxPlayers { get; set; }
|
public int MaxPlayers { get; set; }
|
||||||
[JsonProperty("allowlist")]
|
|
||||||
public bool AllowList { get; set; }
|
|
||||||
[JsonProperty("mods")]
|
|
||||||
public bool Mods { get; set; }
|
|
||||||
[JsonProperty("npcs")]
|
|
||||||
public bool NPCs { get; set; }
|
|
||||||
[JsonProperty("country")]
|
|
||||||
public string Country { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Don't use it!
|
/// Don't use it!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class Servers
|
internal static class ServersMenu
|
||||||
{
|
{
|
||||||
internal NativeMenu MainMenu = new NativeMenu("RAGECOOP", "Servers", "Go to the server list")
|
private static Thread GetServersThread;
|
||||||
|
internal static NativeMenu Menu = new NativeMenu("RAGECOOP", "Servers", "Go to the server list")
|
||||||
{
|
{
|
||||||
UseMouse = false,
|
UseMouse = false,
|
||||||
Alignment = Main.Settings.FlipMenu ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left
|
Alignment = Main.Settings.FlipMenu ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left
|
||||||
};
|
};
|
||||||
internal NativeItem ResultItem = null;
|
internal static NativeItem ResultItem = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Don't use it!
|
/// Don't use it!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Servers()
|
static ServersMenu()
|
||||||
{
|
{
|
||||||
MainMenu.Banner.Color = Color.FromArgb(225, 0, 0, 0);
|
Menu.Banner.Color = Color.FromArgb(225, 0, 0, 0);
|
||||||
MainMenu.Title.Color = Color.FromArgb(255, 165, 0);
|
Menu.Title.Color = Color.FromArgb(255, 165, 0);
|
||||||
|
|
||||||
MainMenu.Opening += (object sender, System.ComponentModel.CancelEventArgs e) =>
|
Menu.Opening += (object sender, System.ComponentModel.CancelEventArgs e) =>
|
||||||
{
|
{
|
||||||
MainMenu.Add(ResultItem = new NativeItem("Loading..."));
|
CleanUpList();
|
||||||
GetAllServer();
|
Menu.Add(ResultItem = new NativeItem("Loading..."));
|
||||||
|
|
||||||
|
// Prevent freezing
|
||||||
|
if (GetServersThread!=null && GetServersThread.IsAlive) { GetServersThread?.Abort(); }
|
||||||
|
GetServersThread=new Thread(()=> GetAllServers());
|
||||||
|
GetServersThread.Start();
|
||||||
};
|
};
|
||||||
MainMenu.Closing += (object sender, System.ComponentModel.CancelEventArgs e) =>
|
Menu.Closing += (object sender, System.ComponentModel.CancelEventArgs e) =>
|
||||||
{
|
{
|
||||||
CleanUpList();
|
CleanUpList();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CleanUpList()
|
private static void CleanUpList()
|
||||||
{
|
{
|
||||||
MainMenu.Clear();
|
Menu.Clear();
|
||||||
ResultItem = null;
|
ResultItem = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GetAllServer()
|
private static void GetAllServers()
|
||||||
{
|
{
|
||||||
List<ServerListClass> serverList = null;
|
List<ServerListClass> serverList = null;
|
||||||
try
|
try
|
||||||
@ -100,34 +101,39 @@ namespace RageCoop.Client.Menus
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CleanUpList();
|
|
||||||
|
|
||||||
foreach (ServerListClass server in serverList)
|
// Need to be processed in main thread
|
||||||
|
Main.QueueAction(() =>
|
||||||
{
|
{
|
||||||
string address = $"{server.Address}:{server.Port}";
|
|
||||||
NativeItem tmpItem = new NativeItem($"[{server.Country}] {server.Name}", $"~b~{address}~s~~n~~g~Version {server.Version}.x~s~~n~Mods = {server.Mods}~n~NPCs = {server.NPCs}") { AltTitle = $"[{server.Players}/{server.MaxPlayers}][{(server.AllowList ? "~r~X~s~" : "~g~O~s~")}]" };
|
CleanUpList();
|
||||||
tmpItem.Activated += (object sender, EventArgs e) =>
|
foreach (ServerListClass server in serverList)
|
||||||
{
|
{
|
||||||
try
|
string address = server.IP;
|
||||||
|
NativeItem tmpItem = new NativeItem($"{server.Name}", $"~b~{address}~s~~n~~g~Version {server.Version}.x~s~") { AltTitle = $"[{server.Players}/{server.MaxPlayers}]" };
|
||||||
|
tmpItem.Activated += (object sender, EventArgs e) =>
|
||||||
{
|
{
|
||||||
MainMenu.Visible = false;
|
try
|
||||||
|
{
|
||||||
|
Menu.Visible = false;
|
||||||
|
|
||||||
Networking.DisconnectFromServer(address);
|
Networking.ToggleConnection(address);
|
||||||
#if !NON_INTERACTIVE
|
#if !NON_INTERACTIVE
|
||||||
CoopMenu.ServerIpItem.AltTitle = address;
|
CoopMenu.ServerIpItem.AltTitle = address;
|
||||||
|
|
||||||
CoopMenu.Menu.Visible = true;
|
CoopMenu.Menu.Visible = true;
|
||||||
#endif
|
#endif
|
||||||
Main.Settings.LastServerAddress = address;
|
Main.Settings.LastServerAddress = address;
|
||||||
Util.SaveSettings();
|
Util.SaveSettings();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
GTA.UI.Notification.Show($"~r~{ex.Message}");
|
GTA.UI.Notification.Show($"~r~{ex.Message}");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
MainMenu.Add(tmpItem);
|
Menu.Add(tmpItem);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -20,7 +20,7 @@ namespace RageCoop.Client
|
|||||||
public static int BytesSend = 0;
|
public static int BytesSend = 0;
|
||||||
private static Thread ReceiveThread;
|
private static Thread ReceiveThread;
|
||||||
|
|
||||||
public static void DisconnectFromServer(string address)
|
public static void ToggleConnection(string address)
|
||||||
{
|
{
|
||||||
if (IsOnServer)
|
if (IsOnServer)
|
||||||
{
|
{
|
||||||
|
@ -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://ragecoop.online/gtav/servers";
|
public string MasterServer { get; set; } = "https://ragecoop.000webhostapp.com/master.php";
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Don't use it!
|
/// Don't use it!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1,9 +1 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace RageCoop.Server
|
|
||||||
{
|
|
||||||
public class Allowlist
|
|
||||||
{
|
|
||||||
public List<string> Username { get; set; } = new();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -27,8 +27,6 @@ namespace RageCoop.Server
|
|||||||
|
|
||||||
public static readonly Settings MainSettings = Util.Read<Settings>("Settings.xml");
|
public static readonly Settings MainSettings = Util.Read<Settings>("Settings.xml");
|
||||||
private readonly Blocklist _mainBlocklist = Util.Read<Blocklist>("Blocklist.xml");
|
private readonly Blocklist _mainBlocklist = Util.Read<Blocklist>("Blocklist.xml");
|
||||||
private readonly Allowlist _mainAllowlist = Util.Read<Allowlist>("Allowlist.xml");
|
|
||||||
|
|
||||||
public static NetServer MainNetServer;
|
public static NetServer MainNetServer;
|
||||||
|
|
||||||
public static Resource RunningResource = null;
|
public static Resource RunningResource = null;
|
||||||
@ -104,6 +102,7 @@ namespace RageCoop.Server
|
|||||||
|
|
||||||
string content = await response.Content.ReadAsStringAsync();
|
string content = await response.Content.ReadAsStringAsync();
|
||||||
info = JsonConvert.DeserializeObject<IpInfo>(content);
|
info = JsonConvert.DeserializeObject<IpInfo>(content);
|
||||||
|
Program.Logger.Info($"Your public IP is {info.Address}");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -120,10 +119,8 @@ namespace RageCoop.Server
|
|||||||
"\"name\": \"" + MainSettings.Name + "\", " +
|
"\"name\": \"" + MainSettings.Name + "\", " +
|
||||||
"\"version\": \"" + _compatibleVersion.Replace("_", ".") + "\", " +
|
"\"version\": \"" + _compatibleVersion.Replace("_", ".") + "\", " +
|
||||||
"\"players\": \"" + MainNetServer.ConnectionsCount + "\", " +
|
"\"players\": \"" + MainNetServer.ConnectionsCount + "\", " +
|
||||||
"\"maxPlayers\": \"" + MainSettings.MaxPlayers + "\", " +
|
"\"maxPlayers\": \"" + MainSettings.MaxPlayers + "\"" +
|
||||||
"\"allowlist\": \"" + _mainAllowlist.Username.Any() + "\", " +
|
|
||||||
" }";
|
" }";
|
||||||
|
|
||||||
HttpResponseMessage response = null;
|
HttpResponseMessage response = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -152,6 +149,7 @@ namespace RageCoop.Server
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
Program.Logger.Error($"MasterServer: [{(int)response.StatusCode}]");
|
Program.Logger.Error($"MasterServer: [{(int)response.StatusCode}]");
|
||||||
|
Program.Logger.Error($"MasterServer: [{await response.Content.ReadAsStringAsync()}]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -644,11 +642,6 @@ namespace RageCoop.Server
|
|||||||
local.Deny("Username contains special chars!");
|
local.Deny("Username contains special chars!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_mainAllowlist.Username.Any() && !_mainAllowlist.Username.Contains(packet.Username.ToLower()))
|
|
||||||
{
|
|
||||||
local.Deny("This Username is not on the allow list!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (_mainBlocklist.Username.Contains(packet.Username.ToLower()))
|
if (_mainBlocklist.Username.Contains(packet.Username.ToLower()))
|
||||||
{
|
{
|
||||||
local.Deny("This Username has been blocked by this server!");
|
local.Deny("This Username has been blocked by this server!");
|
||||||
|
@ -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://ragecoop.online/gtav/servers";
|
public string MasterServer { get; set; } = "https://ragecoop.000webhostapp.com/master.php";
|
||||||
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.
|
||||||
|
Reference in New Issue
Block a user