Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ You can still use old plugins without any changes/recompilation/updates.
- [x] Commands:
- [x] /position /pos (current position of the player).
- [x] /tpwp (improved version of /tp wp).
- [x] /savelogs (a fast way for sending logs to plugin developer or whatever).
- [ ] Remove Features:
- [x] Command /compass
- [x] Gather a Team with a direct access to the repo edit without admins help. (We still gather a team)
Expand Down
113 changes: 113 additions & 0 deletions Rocket.Unturned/Commands/CommandSaveLogs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Reflection;
using System.Text;
using Rocket.API;
using Rocket.Core.Logging;
using Rocket.Unturned.Chat;
using SDG.Unturned;
using UnityEngine;
using RocketLogger = Rocket.Core.Logging.Logger;

namespace Rocket.Unturned.Commands;

public class CommandSaveLogs : IRocketCommand
{
public AllowedCaller AllowedCaller
{
get
{
return AllowedCaller.Both;
}
}

public string Name
{
get { return "savelogs"; }
}

public string Help
{
get { return "Saves Rocket and other logs for faster and easier problem solving"; }
}

public string Syntax
{
get { return ""; }
}

public List<string> Aliases
{
get { return new List<string>(); }
}

public List<string> Permissions
{
get { return new List<string>() { "rocket.savelogs" }; }
}

public void Execute(IRocketPlayer caller, string[] command)
{
var workingDirectory = ReadWrite.PATH;
var serverId = Dedicator.serverID;
var serverDirectory = Path.Combine(workingDirectory, "Servers", serverId);

var saveLogsDirectory = Path.Combine(serverDirectory, "SaveLogs");

var logId = $"savelogs-{((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds).ToString()}";
var saveLogDirectory = Path.Combine(saveLogsDirectory, logId);

var logFiles = GetLogFiles();
if (logFiles.Count == 0)
{
UnturnedChat.Say(caller, "No one log were found.", Color.red);
return;
}

Directory.CreateDirectory(saveLogDirectory);
if (Directory.Exists(saveLogsDirectory) == false)
{
Directory.CreateDirectory(saveLogsDirectory);
}

foreach (var logFilePath in logFiles)
{
if (File.Exists(logFilePath) == false)
{
RocketLogger.LogError("Log file not found: " + logFilePath);
continue;
}

try
{
File.Copy(logFilePath, Path.Combine(saveLogDirectory, Path.GetFileName(logFilePath)));
UnturnedChat.Say($"Saved {logFilePath} to {saveLogDirectory}", Color.yellow);
}
catch (Exception ex)
{
RocketLogger.LogException(ex, $"An error occured while saving {logFilePath} to {saveLogDirectory}");
}
}

var logArchivePath = Path.Combine(saveLogsDirectory, $"{logId}.zip");
ZipFile.CreateFromDirectory(saveLogDirectory, logArchivePath);

UnturnedChat.Say(caller, $"Done! Your logs have been saved to: {logArchivePath}", Color.green);
}

private static IReadOnlyCollection<string> GetLogFiles()
{
var files = new List<string>();

var logFilePath = Logs.getLogFilePath();
files.Add(logFilePath);

var prevLogFilePath = Path.Combine(Path.GetDirectoryName(logFilePath)!, Path.GetFileNameWithoutExtension(logFilePath) + "_Prev.log");
files.Add(prevLogFilePath);

return files;
}
}
11 changes: 11 additions & 0 deletions Rocket.Unturned/Module/RuntimeLibs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Runtime Libraries

Here we just store the runtime libraries that are used by the Rocket or other plugins. These libraries are not included in the plugin itself, but are required to be present in the Module directory in order for Rocket itself and the other plugins to work correctly.

## Add/Update Runtime Library

To add/update a Runtime Library, keep these steps:
1. Have installed Mono/Unity Editor with the same version as in Unturned.
2. To find the needed library: `Program Files\Mono\lib\mono\gac` or also you can try this place: `Program Files\Mono\lib\mono\4.5\Facades`.

You can also check this [post](https://sunnamed434.github.io/posts/assemblyresolve-and-mono/) to understand things better about libraries, specifically in Unity.
Binary file not shown.
Binary file not shown.
4 changes: 3 additions & 1 deletion Rocket.Unturned/Rocket.Unturned.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<RocketModFiles Include="$(OutDir)*Rocket*.dll"/>
<RocketModModuleFiles Include="Module/Rocket.Unturned/*"/>
<RocketModInstallationGuides Include="Module/InstallationGuides/*.txt"/>
<RocketModRuntimeLibs Include="Module/RuntimeLibs/*.dll"/>
</ItemGroup>

<PropertyGroup>
Expand All @@ -35,9 +36,10 @@

<MakeDir Directories="$(RocketUnturnedOutputDirectory)"/>

<Copy SourceFiles="@(RocketModInstallationGuides)" DestinationFolder="$(RocketUnturnedOutputDirectory)\.."/>
<Copy SourceFiles="@(RocketModFiles)" DestinationFolder="$(RocketUnturnedOutputDirectory)"/>
<Copy SourceFiles="@(RocketModModuleFiles)" DestinationFolder="$(RocketUnturnedOutputDirectory)"/>
<Copy SourceFiles="@(RocketModInstallationGuides)" DestinationFolder="$(RocketUnturnedOutputDirectory)\.."/>
<Copy SourceFiles="@(RocketModRuntimeLibs)" DestinationFolder="$(RocketUnturnedOutputDirectory)"/>

</Target>

Expand Down