Skip to content

Commit

Permalink
Merge branch 'general-devel' into add-moondial-permission
Browse files Browse the repository at this point in the history
  • Loading branch information
hakusaro authored Mar 9, 2025
2 parents 060a3e5 + 1c72490 commit c89c34b
Show file tree
Hide file tree
Showing 36 changed files with 714 additions and 237 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# These are supported funding model platforms
github: [SignatureBeef, hakusaro, Stealownz, QuiCM]
github: [SignatureBeef, QuiCM]
39 changes: 37 additions & 2 deletions .github/workflows/ci-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
permissions:
attestations: write
id-token: write
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -14,12 +18,43 @@ jobs:
uses: docker/setup-qemu-action@v3
- name: Set up buildx
uses: docker/setup-buildx-action@v3
- name: Login to ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate version information
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag,enable=${{ !startsWith(github.ref, 'refs/tags/v') }}
type=ref,event=pr
type=semver,pattern={{version}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=semver,pattern={{major}}.{{minor}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=semver,pattern={{major}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
flavor: |
latest=${{ startsWith(github.ref, 'refs/tags/v') }}
- name: Build image
uses: docker/build-push-action@v5
id: build
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7,windows/amd64
push: false
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
pull: true
cache-from: type=gha, scope=${{ github.workflow }}
cache-to: type=gha, scope=${{ github.workflow }}
- name: Generate build provenance attestation
if: ${{ github.event_name != 'pull_request' }}
uses: actions/attest-build-provenance@v2
with:
subject-name: ghcr.io/${{ github.repository }}
subject-digest: ${{ steps.build.outputs.digest }}
push-to-registry: true
4 changes: 2 additions & 2 deletions .github/workflows/ci-otapi3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ jobs:
tar -cvf ../../../../../../TShock-Beta-${{ matrix.arch }}-Release.tar *
- name: Upload artifact (non-Windows)
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: ${{ matrix.arch != 'win-x64' }}
with:
name: TShock-Beta-${{ matrix.arch }}-Release
path: TShock-Beta-${{ matrix.arch }}-Release.tar

- name: Upload artifact (Windows)
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: ${{ matrix.arch == 'win-x64' }}
with:
name: TShock-Beta-${{ matrix.arch }}-Release
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p align="center">
<img src="https://tshock.co/newlogo.png" alt="TShock for Terraria"><br />
<img src="https://tshock.s3.us-west-001.backblazeb2.com/newlogo.png" alt="TShock for Terraria"><br />
<a href="https://ci.appveyor.com/project/hakusaro/tshock">
<img src="https://ci.appveyor.com/api/projects/status/chhe61q227lqdlg1?svg=true" alt="AppVeyor Build Status">
</a>
Expand Down
2 changes: 1 addition & 1 deletion README_cn.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p align="center">
<img src="https://tshock.co/newlogo.png" alt="TShock for Terraria"><br />
<img src="https://tshock.s3.us-west-001.backblazeb2.com/newlogo.png" alt="TShock for Terraria"><br />
<a href="https://ci.appveyor.com/project/hakusaro/tshock">
<img src="https://ci.appveyor.com/api/projects/status/chhe61q227lqdlg1?svg=true" alt="AppVeyor Build Status">
</a>
Expand Down
56 changes: 51 additions & 5 deletions TShockAPI/Bouncer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ internal Bouncer()
};
PlayerAddBuffWhitelist[BuffID.BrainOfConfusionBuff] = new BuffLimit
{
MaxTicks = 240,
MaxTicks = 60 * 4,
CanBeAddedWithoutHostile = true,
CanOnlyBeAppliedToSender = true
};
Expand All @@ -434,6 +434,12 @@ internal Bouncer()
CanBeAddedWithoutHostile = true,
CanOnlyBeAppliedToSender = true
};
PlayerAddBuffWhitelist[BuffID.ParryDamageBuff] = new BuffLimit
{
MaxTicks = 60 * 5,
CanBeAddedWithoutHostile = true,
CanOnlyBeAppliedToSender = true
};

#endregion Whitelist
}
Expand Down Expand Up @@ -498,6 +504,14 @@ internal void OnPlayerUpdate(object sender, GetDataHandlers.PlayerUpdateEventArg
return;
}

if (!float.IsFinite(pos.X) || !float.IsFinite(pos.Y))
{
TShock.Log.ConsoleInfo(GetString("Bouncer / OnPlayerUpdate force kicked (attempted to set position to infinity or NaN) from {0}", args.Player.Name));
args.Player.Kick(GetString("Detected DOOM set to ON position."), true, true);
args.Handled = true;
return;
}

if (pos.X < 0 || pos.Y < 0 || pos.X >= Main.maxTilesX * 16 - 16 || pos.Y >= Main.maxTilesY * 16 - 16)
{
TShock.Log.ConsoleDebug(GetString("Bouncer / OnPlayerUpdate rejected from (position check) {0}", args.Player.Name));
Expand Down Expand Up @@ -1066,6 +1080,22 @@ internal void OnItemDrop(object sender, GetDataHandlers.ItemDropEventArgs args)
bool noDelay = args.NoDelay;
short type = args.Type;

if (!float.IsFinite(pos.X) || !float.IsFinite(pos.Y))
{
TShock.Log.ConsoleInfo(GetString("Bouncer / OnItemDrop force kicked (attempted to set position to infinity or NaN) from {0}", args.Player.Name));
args.Player.Kick(GetString("Detected DOOM set to ON position."), true, true);
args.Handled = true;
return;
}

if (!float.IsFinite(vel.X) || !float.IsFinite(vel.Y))
{
TShock.Log.ConsoleInfo(GetString("Bouncer / OnItemDrop force kicked (attempted to set velocity to infinity or NaN) from {0}", args.Player.Name));
args.Player.Kick(GetString("Detected DOOM set to ON position."), true, true);
args.Handled = true;
return;
}

// player is attempting to crash clients
if (type < -48 || type >= Terraria.ID.ItemID.Count)
{
Expand Down Expand Up @@ -1169,6 +1199,22 @@ internal void OnNewProjectile(object sender, GetDataHandlers.NewProjectileEventA
int index = args.Index;
float[] ai = args.Ai;

if (!float.IsFinite(pos.X) || !float.IsFinite(pos.Y))
{
TShock.Log.ConsoleInfo(GetString("Bouncer / OnNewProjectile force kicked (attempted to set position to infinity or NaN) from {0}", args.Player.Name));
args.Player.Kick(GetString("Detected DOOM set to ON position."), true, true);
args.Handled = true;
return;
}

if (!float.IsFinite(vel.X) || !float.IsFinite(vel.Y))
{
TShock.Log.ConsoleInfo(GetString("Bouncer / OnNewProjectile force kicked (attempted to set velocity to infinity or NaN) from {0}", args.Player.Name));
args.Player.Kick(GetString("Detected DOOM set to ON position."), true, true);
args.Handled = true;
return;
}

if (index > Main.maxProjectiles)
{
TShock.Log.ConsoleDebug(GetString("Bouncer / OnNewProjectile rejected from above projectile limit from {0}", args.Player.Name));
Expand Down Expand Up @@ -1878,7 +1924,7 @@ void Reject(bool shouldResync = true)
return;
}

if (TShock.Players[id] == null)
if (TShock.Players[id] == null || !TShock.Players[id].Active)
{
TShock.Log.ConsoleDebug(GetString(
"Bouncer / OnPlayerBuff rejected {0} ({1}) applying buff {2} to {3} for {4} ticks: target is null", args.Player.Name,
Expand Down Expand Up @@ -2081,7 +2127,7 @@ internal void OnHealOtherPlayer(object sender, GetDataHandlers.HealOtherPlayerEv
short amount = args.Amount;
byte plr = args.TargetPlayerIndex;

if (amount <= 0 || Main.player[plr] == null || !Main.player[plr].active)
if (amount <= 0 || TShock.Players[plr] == null || !TShock.Players[plr].Active)
{
TShock.Log.ConsoleDebug(GetString("Bouncer / OnHealOtherPlayer rejected null checks"));
args.Handled = true;
Expand Down Expand Up @@ -2589,7 +2635,7 @@ internal void OnPlayerDamage(object sender, GetDataHandlers.PlayerDamageEventArg
byte direction = args.Direction;
PlayerDeathReason reason = args.PlayerDeathReason;

if (id >= Main.maxPlayers || TShock.Players[id] == null)
if (id >= Main.maxPlayers || TShock.Players[id] == null || !TShock.Players[id].Active)
{
TShock.Log.ConsoleDebug(GetString("Bouncer / OnPlayerDamage rejected null check"));
args.Handled = true;
Expand Down Expand Up @@ -2854,7 +2900,7 @@ internal static int GetMaxPlaceStyle(int tileID)
{ BuffID.Poisoned, 3600 }, // BuffID: 20
{ BuffID.OnFire, 1200 }, // BuffID: 24
{ BuffID.Confused, short.MaxValue }, // BuffID: 31 Brain of Confusion Internal Item ID: 3223
{ BuffID.CursedInferno, 420 }, // BuffID: 39
{ BuffID.CursedInferno, 600 }, // BuffID: 39
{ BuffID.Frostburn, 900 }, // BuffID: 44
{ BuffID.Ichor, 1200 }, // BuffID: 69
{ BuffID.Venom, 1800 }, // BuffID: 70
Expand Down
48 changes: 32 additions & 16 deletions TShockAPI/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,24 +148,29 @@ public Command(CommandDelegate cmd, params string[] names)
Permissions = new List<string>();
}

public bool Run(string msg, bool silent, TSPlayer ply, List<string> parms)
public bool Run(CommandArgs args)
{
if (!CanRun(ply))
if (!CanRun(args.Player))
return false;

try
{
CommandDelegate(new CommandArgs(msg, silent, ply, parms));
CommandDelegate(args);
}
catch (Exception e)
{
ply.SendErrorMessage(GetString("Command failed, check logs for more details."));
args.Player.SendErrorMessage(GetString("Command failed, check logs for more details."));
TShock.Log.Error(e.ToString());
}

return true;
}

public bool Run(string msg, bool silent, TSPlayer ply, List<string> parms)
{
return Run(new CommandArgs(msg, silent, ply, parms));
}

public bool Run(string msg, TSPlayer ply, List<string> parms)
{
return Run(msg, false, ply, parms);
Expand Down Expand Up @@ -704,7 +709,12 @@ public static bool HandleCommand(TSPlayer player, string text)
TShock.Utils.SendLogs(GetString("{0} executed: {1}{2}.", player.Name, silent ? SilentSpecifier : Specifier, cmdText), Color.PaleVioletRed, player);
else
TShock.Utils.SendLogs(GetString("{0} executed (args omitted): {1}{2}.", player.Name, silent ? SilentSpecifier : Specifier, cmdName), Color.PaleVioletRed, player);
cmd.Run(cmdText, silent, player, args);

CommandArgs arguments = new CommandArgs(cmdText, silent, player, args);
bool handled = PlayerHooks.OnPrePlayerCommand(cmd, ref arguments);
if (!handled)
cmd.Run(arguments);
PlayerHooks.OnPostPlayerCommand(cmd, arguments, handled);
}
}
return true;
Expand Down Expand Up @@ -1176,7 +1186,7 @@ private static void ManageUsers(CommandArgs args)

try
{
TShock.UserAccounts.SetUserGroup(account, args.Parameters[2]);
TShock.UserAccounts.SetUserGroup(args.Player, account, args.Parameters[2]);
TShock.Log.ConsoleInfo(GetString("{0} changed account {1} to group {2}.", args.Player.Name, account.Name, args.Parameters[2]));
args.Player.SendSuccessMessage(GetString("Account {0} has been changed to group {1}.", account.Name, args.Parameters[2]));

Expand All @@ -1193,6 +1203,10 @@ private static void ManageUsers(CommandArgs args)
{
args.Player.SendErrorMessage(GetString($"User {account.Name} does not exist."));
}
catch (UserGroupUpdateLockedException)
{
args.Player.SendErrorMessage(GetString("Hook blocked the attempt to change the user group."));
}
catch (UserAccountManagerException e)
{
args.Player.SendErrorMessage(GetString($"User {account.Name} could not be added. Check console for details."));
Expand Down Expand Up @@ -2044,6 +2058,7 @@ private static void Off(CommandArgs args)
private static void OffNoSave(CommandArgs args)
{
string reason = ((args.Parameters.Count > 0) ? GetString("Server shutting down: ") + String.Join(" ", args.Parameters) : GetString("Server shutting down."));
Netplay.SaveOnServerExit = false;
TShock.Utils.StopServer(false, reason);
}

Expand Down Expand Up @@ -3070,12 +3085,12 @@ private static void TPHere(CommandArgs args)
args.Player.SendErrorMessage(GetString("You do not have permission to teleport all other players."));
return;
}
for (int i = 0; i < Main.maxPlayers; i++)
foreach (var player in TShock.Players)
{
if (Main.player[i].active && (Main.player[i] != args.TPlayer))
if (player != null && player.Active && player.Index != args.Player.Index)
{
if (TShock.Players[i].Teleport(args.TPlayer.position.X, args.TPlayer.position.Y))
TShock.Players[i].SendSuccessMessage(GetString("You were teleported to {0}.", args.Player.Name));
if (player.Teleport(args.TPlayer.position.X, args.TPlayer.position.Y))
player.SendSuccessMessage(GetString("You were teleported to {0}.", args.Player.Name));
}
}
args.Player.SendSuccessMessage(GetString("Teleported everyone to yourself."));
Expand Down Expand Up @@ -4622,21 +4637,22 @@ private static void Wind(CommandArgs args)
{
if (args.Parameters.Count != 1)
{
args.Player.SendErrorMessage(GetString("Invalid syntax. Proper syntax: {0}wind <speed>.", Specifier));
args.Player.SendErrorMessage(GetString("Invalid syntax. Proper syntax: {0}wind <speed in mph>.", Specifier));
return;
}

int speed;
if (!int.TryParse(args.Parameters[0], out speed) || speed * 100 < 0)
float mph;
if (!float.TryParse(args.Parameters[0], out mph) || mph is < -40f or > 40f)
{
args.Player.SendErrorMessage(GetString("Invalid wind speed."));
args.Player.SendErrorMessage(GetString("Invalid wind speed (must be between -40 and 40)."));
return;
}

float speed = mph / 50f; // -40 to 40 mph -> -0.8 to 0.8
Main.windSpeedCurrent = speed;
Main.windSpeedTarget = speed;
TSPlayer.All.SendData(PacketTypes.WorldInfo);
TSPlayer.All.SendInfoMessage(GetString("{0} changed the wind speed to {1}.", args.Player.Name, speed));
TSPlayer.All.SendInfoMessage(GetString("{0} changed the wind speed to {1}mph.", args.Player.Name, mph));
}

#endregion Time/PvpFun Commands
Expand Down Expand Up @@ -5347,7 +5363,7 @@ private static void ListConnectedPlayers(CommandArgs args)

foreach (TSPlayer ply in TShock.Players)
{
if (ply != null && ply.Active)
if (ply != null && ply.Active && ply.FinishedHandshake)
{
if (displayIdsRequested)
if (ply.Account != null)
Expand Down
4 changes: 2 additions & 2 deletions TShockAPI/Configuration/TShockConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ public class TShockSettings
[Description("The reason given if banning a mediumcore player on death.")]
public string MediumcoreBanReason = GetString("Death results in a ban");

/// <summary>Disbales IP bans by default, if no arguments are passed to the ban command.</summary>
[Description("Disbales IP bans by default, if no arguments are passed to the ban command.")]
/// <summary>Disables IP bans by default, if no arguments are passed to the ban command.</summary>
[Description("Disables IP bans by default, if no arguments are passed to the ban command.")]
public bool DisableDefaultIPBan;

/// <summary>Enable or disable the whitelist based on IP addresses in the whitelist.txt file.</summary>
Expand Down
2 changes: 1 addition & 1 deletion TShockAPI/DB/CharacterManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public CharacterManager(IDbConnection db)

public PlayerData GetPlayerData(TSPlayer player, int acctid)
{
PlayerData playerData = new PlayerData(player);
PlayerData playerData = new PlayerData(false);

try
{
Expand Down
Loading

0 comments on commit c89c34b

Please sign in to comment.