diff --git a/Images/LOGO.png b/Images/LOGO.png deleted file mode 100644 index 4296928..0000000 Binary files a/Images/LOGO.png and /dev/null differ diff --git a/README.md b/README.md index 16fd197..3fa80da 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/RageCoop.Client/RageCoop.Client.csproj b/RageCoop.Client/RageCoop.Client.csproj index 2133684..9297ee3 100644 --- a/RageCoop.Client/RageCoop.Client.csproj +++ b/RageCoop.Client/RageCoop.Client.csproj @@ -17,7 +17,7 @@ An API reference for developing client-side resource for RAGECOOP https://ragecoop.online/ https://github.com/RAGECOOP/RAGECOOP-V - favicon.ico + icon.ico MIT True @@ -27,7 +27,7 @@ - + diff --git a/RageCoop.Client/favicon.ico b/RageCoop.Client/icon.ico similarity index 100% rename from RageCoop.Client/favicon.ico rename to RageCoop.Client/icon.ico diff --git a/RageCoop.Server/Program.cs b/RageCoop.Server/Program.cs index 08346ab..2cb3bbc 100644 --- a/RageCoop.Server/Program.cs +++ b/RageCoop.Server/Program.cs @@ -48,7 +48,7 @@ namespace RageCoop.Server } }; - _ = new Server(mainLogger); + _ = new Server(Util.Read("Settings.xml"), mainLogger); } catch (Exception e) { diff --git a/RageCoop.Server/RageCoop.Server.csproj b/RageCoop.Server/RageCoop.Server.csproj index 8ce0b0f..418f93e 100644 --- a/RageCoop.Server/RageCoop.Server.csproj +++ b/RageCoop.Server/RageCoop.Server.csproj @@ -16,7 +16,8 @@ embedded True An library for hosting a RAGECOOP server or API reference for developing a resource. - favicon.ico + icon.ico + icon.png @@ -26,7 +27,14 @@ - + + + + + + True + \ + diff --git a/RageCoop.Server/Scripting/Resources.cs b/RageCoop.Server/Scripting/Resources.cs index 0991a9f..8834a67 100644 --- a/RageCoop.Server/Scripting/Resources.cs +++ b/RageCoop.Server/Scripting/Resources.cs @@ -17,99 +17,94 @@ namespace RageCoop.Server.Scripting Server = server; } private List ClientResourceZips=new List(); - 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}"); }); diff --git a/RageCoop.Server/Server.cs b/RageCoop.Server/Server.cs index be2a347..4ec176f 100644 --- a/RageCoop.Server/Server.cs +++ b/RageCoop.Server/Server.cs @@ -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.xml"); + internal readonly ServerSettings Settings; internal NetServer MainNetServer; internal readonly Dictionary> 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() { newClient.Connection }); + SendChatMessage(new Packets.ChatMessage() { Username = "Server", Message = Settings.WelcomeMessage }, null,new List() { 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; } diff --git a/RageCoop.Server/Settings.cs b/RageCoop.Server/ServerSettings.cs similarity index 85% rename from RageCoop.Server/Settings.cs rename to RageCoop.Server/ServerSettings.cs index b81b1fb..483084e 100644 --- a/RageCoop.Server/Settings.cs +++ b/RageCoop.Server/ServerSettings.cs @@ -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; + + /// + /// See . + /// + public int LogLevel=2; /// /// NPC data won't be sent to a player if their distance is greater than this value. -1 for unlimited. /// diff --git a/RageCoop.Server/favicon.ico b/RageCoop.Server/icon.ico similarity index 100% rename from RageCoop.Server/favicon.ico rename to RageCoop.Server/icon.ico diff --git a/images/icon.ico b/images/icon.ico new file mode 100644 index 0000000..46292ea Binary files /dev/null and b/images/icon.ico differ diff --git a/images/icon.png b/images/icon.png new file mode 100644 index 0000000..018a7a8 Binary files /dev/null and b/images/icon.png differ