Skip to content

Commit

Permalink
Merge pull request #22 from 1249993110/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
1249993110 authored Sep 22, 2024
2 parents 42bba0e + 525538f commit a76f452
Show file tree
Hide file tree
Showing 41 changed files with 1,129 additions and 78 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
## 10.42 (2024-09-22)
### New Features
- Added commands for placing prefabs, undo prefab, and set undo history size, enter `help ty-PlacePrefab` in the console to view details
- Added a simple web ui for placing prefabs
- Add the last time the owner was online under the territory stone information on the GPS map

### Notable Changes
- Update GameIcon font size


## 10.41 (2024-09-13)
### New Features
- Added color chat function, supports customizing player name color and text color, supports using variable {PlayerName} to customize title
- Added color chat function, supports customizing player name color and text color, supports using variable `{PlayerName}` to customize title
- Added automatic zombie cleanup function
- Supports customizing global chat server name and whisper chat server name

Expand Down
20 changes: 20 additions & 0 deletions src/SdtdServerKit/Commands/ConsoleCmdBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,25 @@ protected virtual void Log(string line, params object[] args)
{
SdtdConsole.Instance.Output(CustomLogger.Prefix + string.Format(line, args));
}

/// <summary>
/// Checks if the arguments contain the specified name.
/// </summary>
/// <param name="args"></param>
/// <param name="name"></param>
/// <param name="startIndex"></param>
/// <returns></returns>
protected static bool ContainsCaseInsensitive(List<string> args, string name, int startIndex = 0)
{
for (int i = startIndex; i < args.Count; i++)
{
if (string.Equals(args[i], name, StringComparison.OrdinalIgnoreCase))
{
return true;
}
}

return false;
}
}
}
2 changes: 1 addition & 1 deletion src/SdtdServerKit/Commands/GarbageCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class GarbageCollection : ConsoleCmdBase
/// <inheritdoc/>
public override string getDescription()
{
return "Garbage collection";
return "Use the framework's own methods for garbage collection.";
}

/// <inheritdoc/>
Expand Down
27 changes: 22 additions & 5 deletions src/SdtdServerKit/Commands/GlobalMessage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace SdtdServerKit.Commands
using SdtdServerKit.Managers;
using SdtdServerKit.Models;

namespace SdtdServerKit.Commands
{
/// <summary>
/// Sends a message to all connected clients.
Expand Down Expand Up @@ -33,9 +36,9 @@ public override string[] getCommands()
{
return new string[]
{
"ty-GlobalMessage",
"ty-gm",
"ty-say"
"ty-GlobalMessage",
"ty-gm",
"ty-say"
};
}

Expand All @@ -53,7 +56,21 @@ public override void Execute(List<string> args, CommandSenderInfo _senderInfo)
}

string message = args[0];
string senderName = args.Count > 1 ? args[1] : Localization.Get("xuiChatServer", false);
string senderName;
if (args.Count > 1)
{
senderName = args[1];
}
else
{
senderName = ConfigManager.GlobalSettings.GlobalServerName;
}

if (string.IsNullOrEmpty(senderName))
{
senderName = Localization.Get("xuiChatServer", false);
}

message = global::Utils.CreateGameMessage(senderName, message);

GameManager.Instance.ChatMessageServer(
Expand Down
216 changes: 216 additions & 0 deletions src/SdtdServerKit/Commands/PlacePrefab.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
using SdtdServerKit.Managers;

namespace SdtdServerKit.Commands
{
/// <summary>
/// Places a Prefab on given location.
/// </summary>
public class PlacePrefab : ConsoleCmdBase
{
/// <summary>
/// <inheritdoc/>
/// </summary>
/// <returns></returns>
public override string getDescription()
{
return "Places a Prefab on given location.";
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <returns></returns>
public override string getHelp()
{
return "Usage:\n" +
" 1. ty-PlacePrefab {prefabFileName} {x} {y} {z} [noSleepers] [addToRWG]\n" +
" 2. ty-PlacePrefab {prefabFileName} {x} {y} {z} {rot} [noSleepers] [addToRWG]\n" +
" 3. ty-PlacePrefab {prefabFileName} [noSleepers] [addToRWG]\n" +
" 4. ty-PlacePrefab {prefabFileName} {rot} [noSleepers] [addToRWG]\n" +
" 5. ty-PlacePrefab {prefabFileName} {rot} {depth} [noSleepers] [addToRWG]\n" +
"1. Places a prefab on {x} {y} {z} location\n" +
"2. Places a prefab on {x} {y} {z} location with rot\n" +
"3. Places a prefab on your position\n" +
"4. Places a prefab on your position with rot\n" +
"5. Places a prefab on your position with rot and y deslocated (depth blocks)\n" +
"NOTE: {rot} means rotate the prefab to the left, must be equal to 0=0°, 1=90°, 2=180° or 3=270°\n" +
"NOTE: Sleeper control is ONLY possible on prefabs that are present in prefabs.xml (world folder) that is used to create the map (RWG).\n" +
"NOTE: Use parameter \"addToRWG\" to permanently add this prefab to the current RWG world. Can be reset like any other RWG prefab and will still be in world after a wipe. Will cause re-download of world for clients!\n" +
"NOTE: Runtime search and load from {UserDataFolder}/LocalPrefabs\n" +
"NOTE: If {prefabFileName} is a full file name that actually exists, it will be loaded exactly";
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <returns></returns>
public override string[] getCommands()
{
return new string[]
{
"ty-PlacePrefab",
"ty-pp"
};
}

/// <summary>
/// <inheritdoc/>
/// </summary>
public override void Execute(List<string> args, CommandSenderInfo senderInfo)
{
try
{
//CustomLogger.Warn("Is Main: " + ThreadManager.IsMainThread());
if (args.Count < 1 || args.Count > 7)
{
Log($"ERR: Wrong number of arguments, expected 1 to 7, found {args.Count}.");
Log(this.GetHelp());
return;
}

bool addToRWG = ContainsCaseInsensitive(args, "addtorwg");
bool noSleepers = ContainsCaseInsensitive(args, "nosleepers");
if (addToRWG)
{
args.RemoveAll(i => string.Equals(i, "addtorwg", StringComparison.OrdinalIgnoreCase));
}
if (noSleepers)
{
args.RemoveAll(i => string.Equals(i, "nosleepers", StringComparison.OrdinalIgnoreCase));
}

string prefabName = args[0];
string? runtimeSearchDir = null;
bool isExactlyLoad = File.Exists(prefabName);
if (isExactlyLoad)
{
runtimeSearchDir = Path.GetDirectoryName(prefabName);
prefabName = Path.GetFileNameWithoutExtension(prefabName);
}
else
{
var dir = new DirectoryInfo(Path.Combine(LaunchPrefs.UserDataFolder.Value, "LocalPrefabs"));
runtimeSearchDir = dir.FullName;
}

int x;
int y;
int z;
int rot = 0;

if (args.Count == 4)
{
x = int.Parse(args[1]);
y = int.Parse(args[2]);
z = int.Parse(args[3]);
}
else if(args.Count == 5)
{
x = int.Parse(args[1]);
y = int.Parse(args[2]);
z = int.Parse(args[3]);
rot = int.Parse(args[4]);
}
else
{
int entityId = senderInfo.GetEntityId();
if (entityId == -1)
{
Log("ERR: This command can be only sent by player in game.");
return;
}
if (LivePlayerManager.TryGetByEntityId(entityId, out var managedPlayer) == false)
{
Log("ERR: Unable to get your position");
return;
}

var playerBlockPosition = managedPlayer!.EntityPlayer.GetBlockPosition();
x = playerBlockPosition.x;
y = playerBlockPosition.y;
z = playerBlockPosition.z;

if(args.Count >= 2)
{
rot = int.Parse(args[1]);
if (rot < 0 || rot > 3)
{
Log("ERR: Invalid rotation parameter. It need to be 0,1,2 or 3.");
return;
}

if (args.Count == 3)
{
int depth = int.Parse(args[2]);
y += depth;
}
}
}

var prefab = new Prefab()
{
bCopyAirBlocks = true
};
if (isExactlyLoad || prefab.Load(prefabName, true, true, false, false) == false)
{
Log("Try loading prefab from " + runtimeSearchDir);
var abstractedLocation = new PathAbstractions.AbstractedLocation(PathAbstractions.EAbstractedLocationType.UserDataPath, prefabName, runtimeSearchDir, null, prefabName, ".tts", true, null);
if (prefab.Load(abstractedLocation, true, true, false, false) == false)
{
Log("ERR: Unable to load prefab " + prefabName);
return;
}
}

Log("Rendering..., please wait.");

y += prefab.yOffset;
prefab.RotateY(true, rot);

var prefabSize = prefab.size;
var offsetPosition = new Vector3i(x, y, z);

IEnumerable<Chunk>? chunks;
try
{
chunks = ChunkHelper.GetChunksInArea(offsetPosition, prefabSize);
}
catch (Exception ex)
{
Log("ERR: " + ex.Message);
return;
}

var oldPrefab = new Prefab(prefabSize)
{
bCopyAirBlocks = true
};
oldPrefab.copyFromWorld(GameManager.Instance.World, offsetPosition, new Vector3i(x + prefabSize.x, y + prefabSize.y, z + prefabSize.z));

if (noSleepers)
{
prefab.SleeperVolumes.Clear();
}
prefab.CopyIntoLocal(GameManager.Instance.World.ChunkCache, offsetPosition, true, true, FastTags<TagGroup.Global>.none);

ChunkHelper.ForceReload(chunks);

ChunkHelper.CalculateStability(offsetPosition, prefabSize);

int prefabInstanceId = -1;
if (addToRWG)
{
prefabInstanceId = ChunkHelper.AddPrefabToRWG(prefab, offsetPosition);
}

UndoPrefab.SetUndo(senderInfo.GetEntityId(), oldPrefab, prefabName, offsetPosition, prefabInstanceId);

Log($"Prefab {prefabName} loaded at {offsetPosition}");
}
catch (Exception ex)
{
Log("Error in PlacePrefab.Execute" + Environment.NewLine + ex.ToString());
}
}
}
}
12 changes: 3 additions & 9 deletions src/SdtdServerKit/Commands/RemoveEntity.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SdtdServerKit.Commands
namespace SdtdServerKit.Commands
{
/// <summary>
/// Remove Entity
Expand All @@ -27,8 +21,8 @@ public override string getDescription()
public override string getHelp()
{
return "Removes an entity from the game\n" +
"Usage: ty-re <EntityId>\n" +
"Usage: rem <EntityId>";
"Usage: ty-re {EntityId}\n" +
"Usage: ty-RemoveEntity {EntityId}";
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/SdtdServerKit/Commands/RestartServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public override string getHelp()
/// <inheritdoc />
public override string[] getCommands()
{
return new[] { "ty-rs", "ty-RestartServer" };
return new[] { "ty-RestartServer", "ty-rs" };
}

/// <inheritdoc />
Expand Down
20 changes: 18 additions & 2 deletions src/SdtdServerKit/Commands/SayToPlayer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace SdtdServerKit.Commands
using SdtdServerKit.Managers;

namespace SdtdServerKit.Commands
{
/// <summary>
/// Send a message to a single player.
Expand Down Expand Up @@ -66,7 +68,21 @@ public override void Execute(List<string> args, CommandSenderInfo senderInfo)
}

string message = args[1];
string senderName = args.Count > 2 ? args[2] : Localization.Get("xuiChatServer", false);
string senderName;
if (args.Count > 2)
{
senderName = args[2];
}
else
{
senderName = ConfigManager.GlobalSettings.WhisperServerName;
}

if (string.IsNullOrEmpty(senderName))
{
senderName = Localization.Get("xuiChatServer", false);
}

message = global::Utils.CreateGameMessage(senderName, message);

GameManager.Instance.ChatMessageServer(
Expand Down
Loading

0 comments on commit a76f452

Please sign in to comment.