never gonna give~

This commit is contained in:
Sardelka 2022-06-24 18:25:24 +08:00
parent 46f75c5a21
commit 9cf23cac7f
12 changed files with 122 additions and 110 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 106 KiB

View File

@ -7,9 +7,10 @@
[![Issues][issues-shield]][issues-url]
# Disclaimer
# ⚠ Notice
The original author of this project is [EntenKoeniq](https://github.com/EntenKoeniq).
The project has been reworked and is currently maintained by [Sardelka9515](https://github.com/Sardelka9515).
To download the legacy versions, go to [this repository](https://github.com/RAGECOOP/RAGECOOP-V.OLD)
# 🧠 That's it
RAGECOOP is a multiplayer mod to play story mode or some mods made for RAGECOOP or just drive around with your buddy.
@ -28,6 +29,7 @@ _Old name: GTACOOP:R_
- - No new features (only improvements)
- [Newtonsoft.Json](https://www.nuget.org/packages/Newtonsoft.Json/13.0.1)
- [ClearScript](https://github.com/microsoft/ClearScript)
- [SharpZipLib](https://github.com/icsharpcode/SharpZipLib)
# Features

View File

@ -17,7 +17,7 @@
<Description>An API reference for developing client-side resource for RAGECOOP</Description>
<PackageProjectUrl>https://ragecoop.online/</PackageProjectUrl>
<RepositoryUrl>https://github.com/RAGECOOP/RAGECOOP-V</RepositoryUrl>
<ApplicationIcon>favicon.ico</ApplicationIcon>
<ApplicationIcon>icon.ico</ApplicationIcon>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
</PropertyGroup>
@ -27,7 +27,7 @@
</PropertyGroup>
<ItemGroup>
<Content Include="favicon.ico" />
<Content Include="icon.ico" />
</ItemGroup>
<ItemGroup>

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -48,7 +48,7 @@ namespace RageCoop.Server
}
};
_ = new Server(mainLogger);
_ = new Server(Util.Read<ServerSettings>("Settings.xml"), mainLogger);
}
catch (Exception e)
{

View File

@ -16,7 +16,8 @@
<DebugType>embedded</DebugType>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Description>An library for hosting a RAGECOOP server or API reference for developing a resource.</Description>
<ApplicationIcon>favicon.ico</ApplicationIcon>
<ApplicationIcon>icon.ico</ApplicationIcon>
<PackageIcon>icon.png</PackageIcon>
</PropertyGroup>
<ItemGroup>
@ -26,7 +27,14 @@
</ItemGroup>
<ItemGroup>
<Content Include="favicon.ico" />
<Content Include="icon.ico" />
</ItemGroup>
<ItemGroup>
<None Include="..\images\icon.png">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
<ItemGroup>

View File

@ -17,99 +17,94 @@ namespace RageCoop.Server.Scripting
Server = server;
}
private List<string> ClientResourceZips=new List<string>();
public bool HasClientResources { get; private set; }
public void LoadAll()
{
#region CLIENT
var path = Path.Combine("Resources", "Client");
var tmp = Path.Combine("Resources", "ClientTemp");
Directory.CreateDirectory(path);
if (Directory.Exists(tmp))
// Client
{
foreach(var dir in Directory.GetDirectories(tmp))
{
Directory.Delete(dir, true);
}
}
else
{
Directory.CreateDirectory(tmp);
}
var resourceFolders = Directory.GetDirectories(path,"*",SearchOption.TopDirectoryOnly);
if (resourceFolders.Length!=0)
{
HasClientResources=true;
foreach (var resourceFolder in resourceFolders)
{
// Pack client side resource as a zip file
Logger?.Info("Packing client-side resource:"+resourceFolder);
var zipPath = Path.Combine(tmp, Path.GetFileName(resourceFolder));
try
{
using (ZipFile zip = ZipFile.Create(zipPath))
{
foreach (var dir in Directory.GetDirectories(resourceFolder, "*", SearchOption.AllDirectories))
{
zip.AddDirectory(dir.Substring(resourceFolder.Length+1));
}
foreach (var file in Directory.GetFiles(resourceFolder, "*", SearchOption.AllDirectories))
{
zip.Add(file,file.Substring(resourceFolder.Length+1));
}
zip.Close();
ClientResourceZips.Add(zipPath);
}
}
catch (Exception ex)
{
Logger?.Error($"Failed to pack client resource:{resourceFolder}");
Logger?.Error(ex);
}
}
}
var packed = Directory.GetFiles(path, "*.zip", SearchOption.TopDirectoryOnly);
if (packed.Length>0)
{
HasClientResources =true;
ClientResourceZips.AddRange(packed);
}
#endregion
#region SERVER
path = Path.Combine("Resources", "Server");
var dataFolder = Path.Combine(path, "data");
Directory.CreateDirectory(path);
foreach (var resource in Directory.GetDirectories(path))
{
if (Path.GetFileName(resource).ToLower()=="data") { continue; }
Logger?.Info($"Loading resource: {Path.GetFileName(resource)}");
LoadResource(resource,dataFolder);
}
foreach(var resource in Directory.GetFiles(path, "*.zip", SearchOption.TopDirectoryOnly))
{
Logger?.Info($"Loading resource: {Path.GetFileName(resource)}");
LoadResource(new ZipFile(resource), dataFolder);
}
// Start scripts
lock (LoadedResources)
{
foreach (var r in LoadedResources)
var path = Path.Combine("Resources", "Client");
var tmpDir = Path.Combine("Resources", "Temp");
Directory.CreateDirectory(path);
if (Directory.Exists(tmpDir))
{
foreach (ServerScript s in r.Scripts)
Directory.Delete(tmpDir, true);
}
Directory.CreateDirectory(tmpDir);
var resourceFolders = Directory.GetDirectories(path, "*", SearchOption.TopDirectoryOnly);
if (resourceFolders.Length!=0)
{
foreach (var resourceFolder in resourceFolders)
{
s.API=Server.API;
try
// Pack client side resource as a zip file
Logger?.Info("Packing client-side resource: "+resourceFolder);
var zipPath = Path.Combine(tmpDir, Path.GetFileName(resourceFolder))+".zip";
try
{
Logger?.Debug("Starting script:"+s.CurrentFile.Name);
s.OnStart();
using (ZipFile zip = ZipFile.Create(zipPath))
{
zip.BeginUpdate();
foreach (var dir in Directory.GetDirectories(resourceFolder, "*", SearchOption.AllDirectories))
{
zip.AddDirectory(dir.Substring(resourceFolder.Length+1));
}
foreach (var file in Directory.GetFiles(resourceFolder, "*", SearchOption.AllDirectories))
{
zip.Add(file, file.Substring(resourceFolder.Length+1));
}
zip.CommitUpdate();
zip.Close();
ClientResourceZips.Add(zipPath);
}
}
catch (Exception ex)
{
Logger?.Error($"Failed to pack client resource:{resourceFolder}");
Logger?.Error(ex);
}
}
}
var packed = Directory.GetFiles(path, "*.zip", SearchOption.TopDirectoryOnly);
if (packed.Length>0)
{
ClientResourceZips.AddRange(packed);
}
}
// Server
{
var path = Path.Combine("Resources", "Server");
var dataFolder = Path.Combine(path, "data");
Directory.CreateDirectory(path);
foreach (var resource in Directory.GetDirectories(path))
{
if (Path.GetFileName(resource).ToLower()=="data") { continue; }
Logger?.Info($"Loading resource: {Path.GetFileName(resource)}");
LoadResource(resource, dataFolder);
}
foreach (var resource in Directory.GetFiles(path, "*.zip", SearchOption.TopDirectoryOnly))
{
Logger?.Info($"Loading resource: {Path.GetFileName(resource)}");
LoadResource(new ZipFile(resource), dataFolder);
}
// Start scripts
lock (LoadedResources)
{
foreach (var r in LoadedResources)
{
foreach (ServerScript s in r.Scripts)
{
s.API=Server.API;
try
{
Logger?.Debug("Starting script:"+s.CurrentFile.Name);
s.OnStart();
}
catch (Exception ex) { Logger?.Error($"Failed to start resource: {r.Name}"); Logger?.Error(ex); }
}
catch(Exception ex) {Logger?.Error($"Failed to start resource: {r.Name}"); Logger?.Error(ex); }
}
}
}
#endregion
}
}
public void StopAll()
{
@ -135,13 +130,13 @@ namespace RageCoop.Server.Scripting
public void SendTo(Client client)
{
string path;
if (HasClientResources && File.Exists(path = Path.Combine("Resources", "Client", "Resources.zip")))
if (ClientResourceZips.Count!=0)
{
Task.Run(() =>
{
Logger?.Info($"Sending resources to client:{client.Username}");
Server.SendFile(path, "Resources.zip", client);
Logger?.Info($"Resources sent to:{client.Username}");
});

View File

@ -28,7 +28,7 @@ namespace RageCoop.Server
{
private readonly string _compatibleVersion = "V0_5";
internal BaseScript BaseScript { get; set; }=new BaseScript();
internal readonly Settings MainSettings = Util.Read<Settings>("Settings.xml");
internal readonly ServerSettings Settings;
internal NetServer MainNetServer;
internal readonly Dictionary<Command, Action<CommandContext>> Commands = new();
@ -40,14 +40,17 @@ namespace RageCoop.Server
public API API { get; private set; }
internal Logger Logger;
private Security Security;
public Server(Logger logger=null)
public Server(ServerSettings settings,Logger logger=null)
{
Settings = settings;
if (settings==null) { throw new ArgumentNullException("Server settings cannot be null!"); }
Logger=logger;
if (Logger!=null) { Logger.LogLevel=Settings.LogLevel;}
API=new API(this);
Resources=new Resources(this);
Security=new Security(Logger);
Logger?.Info("================");
Logger?.Info($"Server bound to: 0.0.0.0:{MainSettings.Port}");
Logger?.Info($"Server bound to: 0.0.0.0:{Settings.Port}");
Logger?.Info($"Server version: {Assembly.GetCallingAssembly().GetName().Version}");
Logger?.Info($"Compatible RAGECOOP versions: {_compatibleVersion.Replace('_', '.')}.x");
Logger?.Info("================");
@ -55,8 +58,8 @@ namespace RageCoop.Server
// 623c92c287cc392406e7aaaac1c0f3b0 = RAGECOOP
NetPeerConfiguration config = new("623c92c287cc392406e7aaaac1c0f3b0")
{
Port = MainSettings.Port,
MaximumConnections = MainSettings.MaxPlayers,
Port = Settings.Port,
MaximumConnections = Settings.MaxPlayers,
EnableUPnP = false,
AutoFlushSendQueue = true
};
@ -71,7 +74,7 @@ namespace RageCoop.Server
SendPlayerTimer.AutoReset=true;
SendPlayerTimer.Enabled=true;
Logger?.Info(string.Format("Server listening on {0}:{1}", config.LocalAddress.ToString(), config.Port));
if (MainSettings.AnnounceSelf)
if (Settings.AnnounceSelf)
{
#region -- MASTERSERVER --
@ -104,17 +107,17 @@ namespace RageCoop.Server
Logger?.Error(ex.InnerException?.Message ?? ex.Message);
return;
}
var realMaster = MainSettings.MasterServer=="[AUTO]" ? Util.DownloadString("https://ragecoop.online/stuff/masterserver") : MainSettings.MasterServer;
var realMaster = Settings.MasterServer=="[AUTO]" ? Util.DownloadString("https://ragecoop.online/stuff/masterserver") : Settings.MasterServer;
while (!Program.ReadyToStop)
{
string msg =
"{ " +
"\"address\": \"" + info.Address + "\", " +
"\"port\": \"" + MainSettings.Port + "\", " +
"\"name\": \"" + MainSettings.Name + "\", " +
"\"port\": \"" + Settings.Port + "\", " +
"\"name\": \"" + Settings.Name + "\", " +
"\"version\": \"" + _compatibleVersion.Replace("_", ".") + "\", " +
"\"players\": \"" + MainNetServer.ConnectionsCount + "\", " +
"\"maxPlayers\": \"" + MainSettings.MaxPlayers + "\"" +
"\"maxPlayers\": \"" + Settings.MaxPlayers + "\"" +
" }";
HttpResponseMessage response = null;
try
@ -583,9 +586,9 @@ namespace RageCoop.Server
Logger?.Info($"Player {newClient.Username} connected!");
if (!string.IsNullOrEmpty(MainSettings.WelcomeMessage))
if (!string.IsNullOrEmpty(Settings.WelcomeMessage))
{
SendChatMessage(new Packets.ChatMessage() { Username = "Server", Message = MainSettings.WelcomeMessage }, null,new List<NetConnection>() { newClient.Connection });
SendChatMessage(new Packets.ChatMessage() { Username = "Server", Message = Settings.WelcomeMessage }, null,new List<NetConnection>() { newClient.Connection });
}
}
@ -659,12 +662,12 @@ namespace RageCoop.Server
// Check streaming distance
if (isPlayer)
{
if ((MainSettings.PlayerStreamingDistance!=-1)&&(packet.Position.DistanceTo(c.Player.Position)>MainSettings.PlayerStreamingDistance))
if ((Settings.PlayerStreamingDistance!=-1)&&(packet.Position.DistanceTo(c.Player.Position)>Settings.PlayerStreamingDistance))
{
continue;
}
}
else if ((MainSettings.NpcStreamingDistance!=-1)&&(packet.Position.DistanceTo(c.Player.Position)>MainSettings.NpcStreamingDistance))
else if ((Settings.NpcStreamingDistance!=-1)&&(packet.Position.DistanceTo(c.Player.Position)>Settings.NpcStreamingDistance))
{
continue;
}
@ -683,13 +686,13 @@ namespace RageCoop.Server
if (isPlayer)
{
// Player's vehicle
if ((MainSettings.PlayerStreamingDistance!=-1)&&(packet.Position.DistanceTo(c.Player.Position)>MainSettings.PlayerStreamingDistance))
if ((Settings.PlayerStreamingDistance!=-1)&&(packet.Position.DistanceTo(c.Player.Position)>Settings.PlayerStreamingDistance))
{
continue;
}
}
else if((MainSettings.NpcStreamingDistance!=-1)&&(packet.Position.DistanceTo(c.Player.Position)>MainSettings.NpcStreamingDistance))
else if((Settings.NpcStreamingDistance!=-1)&&(packet.Position.DistanceTo(c.Player.Position)>Settings.NpcStreamingDistance))
{
continue;
}

View File

@ -1,6 +1,6 @@
namespace RageCoop.Server
{
public class Settings
public class ServerSettings
{
public int Port { get; set; } = 4499;
public int MaxPlayers { get; set; } = 32;
@ -10,7 +10,11 @@
public bool HolePunch { get; set; } = true;
public bool AnnounceSelf { get; set; } = false;
public string MasterServer { get; set; } = "[AUTO]";
public bool DebugMode { get; set; } = false;
/// <summary>
/// See <see cref="Core.Logger.LogLevel"/>.
/// </summary>
public int LogLevel=2;
/// <summary>
/// NPC data won't be sent to a player if their distance is greater than this value. -1 for unlimited.
/// </summary>

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

BIN
images/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
images/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB