Small fix
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>
|
||||
public static void Connect(string serverAddress)
|
||||
{
|
||||
Networking.DisConnectFromServer(serverAddress);
|
||||
Networking.DisconnectFromServer(serverAddress);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -99,7 +99,7 @@ namespace RageCoop.Client
|
||||
/// </summary>
|
||||
public static void Disconnect()
|
||||
{
|
||||
Networking.DisConnectFromServer(null);
|
||||
Networking.DisconnectFromServer(null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -41,7 +41,7 @@ namespace RageCoop.Client.Menus
|
||||
|
||||
_usernameItem.Activated += UsernameActivated;
|
||||
ServerIpItem.Activated += ServerIpActivated;
|
||||
_serverConnectItem.Activated += (sender, item) => { Networking.DisConnectFromServer(Main.Settings.LastServerAddress); };
|
||||
_serverConnectItem.Activated += (sender, item) => { Networking.DisconnectFromServer(Main.Settings.LastServerAddress); };
|
||||
|
||||
|
||||
Menu.Add(_usernameItem);
|
||||
|
133
Client/Menus/Sub/ServersMenu.cs
Normal file
133
Client/Menus/Sub/ServersMenu.cs
Normal file
@ -0,0 +1,133 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Drawing;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using LemonUI.Menus;
|
||||
|
||||
namespace RageCoop.Client.Menus
|
||||
{
|
||||
internal class ServerListClass
|
||||
{
|
||||
[JsonProperty("address")]
|
||||
public string Address { get; set; }
|
||||
[JsonProperty("port")]
|
||||
public string Port { get; set; }
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty("version")]
|
||||
public string Version { get; set; }
|
||||
[JsonProperty("players")]
|
||||
public int Players { get; set; }
|
||||
[JsonProperty("maxPlayers")]
|
||||
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>
|
||||
/// Don't use it!
|
||||
/// </summary>
|
||||
internal class Servers
|
||||
{
|
||||
internal NativeMenu MainMenu = new NativeMenu("RAGECOOP", "Servers", "Go to the server list")
|
||||
{
|
||||
UseMouse = false,
|
||||
Alignment = Main.Settings.FlipMenu ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left
|
||||
};
|
||||
internal NativeItem ResultItem = null;
|
||||
|
||||
/// <summary>
|
||||
/// Don't use it!
|
||||
/// </summary>
|
||||
public Servers()
|
||||
{
|
||||
MainMenu.Banner.Color = Color.FromArgb(225, 0, 0, 0);
|
||||
MainMenu.Title.Color = Color.FromArgb(255, 165, 0);
|
||||
|
||||
MainMenu.Opening += (object sender, System.ComponentModel.CancelEventArgs e) =>
|
||||
{
|
||||
MainMenu.Add(ResultItem = new NativeItem("Loading..."));
|
||||
GetAllServer();
|
||||
};
|
||||
MainMenu.Closing += (object sender, System.ComponentModel.CancelEventArgs e) =>
|
||||
{
|
||||
CleanUpList();
|
||||
};
|
||||
}
|
||||
|
||||
private void CleanUpList()
|
||||
{
|
||||
MainMenu.Clear();
|
||||
ResultItem = null;
|
||||
}
|
||||
|
||||
private void GetAllServer()
|
||||
{
|
||||
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)
|
||||
{
|
||||
ResultItem.Title = "Download failed!";
|
||||
ResultItem.Description = ex.Message;
|
||||
return;
|
||||
}
|
||||
|
||||
if (serverList == null)
|
||||
{
|
||||
ResultItem.Title = "Something went wrong!";
|
||||
return;
|
||||
}
|
||||
if (serverList.Count == 0)
|
||||
{
|
||||
ResultItem.Title = "No server was found!";
|
||||
return;
|
||||
}
|
||||
|
||||
CleanUpList();
|
||||
|
||||
foreach (ServerListClass server in serverList)
|
||||
{
|
||||
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~")}]" };
|
||||
tmpItem.Activated += (object sender, EventArgs e) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
MainMenu.Visible = false;
|
||||
|
||||
Networking.DisconnectFromServer(address);
|
||||
#if !NON_INTERACTIVE
|
||||
CoopMenu.ServerIpItem.AltTitle = address;
|
||||
|
||||
CoopMenu.Menu.Visible = true;
|
||||
#endif
|
||||
Main.Settings.LastServerAddress = address;
|
||||
Util.SaveSettings();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
GTA.UI.Notification.Show($"~r~{ex.Message}");
|
||||
}
|
||||
};
|
||||
MainMenu.Add(tmpItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ namespace RageCoop.Client
|
||||
public static int BytesSend = 0;
|
||||
private static Thread ReceiveThread;
|
||||
|
||||
public static void DisConnectFromServer(string address)
|
||||
public static void DisconnectFromServer(string address)
|
||||
{
|
||||
if (IsOnServer)
|
||||
{
|
||||
|
@ -123,6 +123,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="DevTools\DevTool.cs" />
|
||||
<Compile Include="Menus\Sub\DevToolMenu.cs" />
|
||||
<Compile Include="Menus\Sub\ServersMenu.cs" />
|
||||
<Compile Include="Scripting\ClientScript.cs" />
|
||||
<Compile Include="Scripting\Engine.cs" />
|
||||
<Compile Include="Util\MathExtensions.cs" />
|
||||
|
@ -4,7 +4,6 @@ using System.Text;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using RageCoop.Core.Logging;
|
||||
using System.Linq;
|
||||
|
||||
[assembly: InternalsVisibleTo("RageCoop.Server")]
|
||||
@ -14,8 +13,8 @@ namespace RageCoop.Core.Scripting
|
||||
internal class ScriptingEngine
|
||||
{
|
||||
private Type BaseScriptType;
|
||||
public Logger Logger { get; set; }
|
||||
public ScriptingEngine(Type baseScriptType,Logger logger)
|
||||
public Logging.Logger Logger { get; set; }
|
||||
public ScriptingEngine(Type baseScriptType, Logging.Logger logger)
|
||||
{
|
||||
BaseScriptType = baseScriptType;
|
||||
Logger = logger;
|
||||
|
Reference in New Issue
Block a user