Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/general-devel' into pr3005
Browse files Browse the repository at this point in the history
  • Loading branch information
sgkoishi committed Jan 25, 2025
2 parents b9d9848 + 251353c commit 8de0b50
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 51 deletions.
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
6 changes: 3 additions & 3 deletions TShockAPI/Bouncer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1884,7 +1884,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 @@ -2087,7 +2087,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 @@ -2595,7 +2595,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
8 changes: 4 additions & 4 deletions TShockAPI/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3070,12 +3070,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
6 changes: 3 additions & 3 deletions TShockAPI/Rest/RestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ private object ServerStatusV2(RestRequestArgs args)
{"serverversion", Main.versionNumber},
{"tshockversion", TShock.VersionNum},
{"port", TShock.Config.Settings.ServerPort},
{"playercount", Main.player.Where(p => null != p && p.active).Count()},
{"playercount", TShock.Utils.GetActivePlayerCount()},
{"maxplayers", TShock.Config.Settings.MaxSlots},
{"world", (TShock.Config.Settings.UseServerName ? TShock.Config.Settings.ServerName : Main.worldName)},
{"uptime", (DateTime.Now - System.Diagnostics.Process.GetCurrentProcess().StartTime).ToString(@"d'.'hh':'mm':'ss")},
Expand Down Expand Up @@ -944,8 +944,8 @@ private object PlayerMute(RestRequestArgs args)
[Token]
private object PlayerList(RestRequestArgs args)
{
var activeplayers = Main.player.Where(p => null != p && p.active).ToList();
return new RestObject() { { "players", string.Join(", ", activeplayers.Select(p => p.name)) } };
var activeplayers = TShock.Players.Where(p => null != p && p.Active).Select(p => p.Name);
return new RestObject() { { "players", string.Join(", ", activeplayers) } };
}

[Description("Fetches detailed user information on all connected users, and can be filtered by specifying a key value pair filter users where the key is a field and the value is a users field value.")]
Expand Down
2 changes: 1 addition & 1 deletion TShockAPI/TShockAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<ItemGroup>
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="GetText.NET" Version="1.7.14" />
<PackageReference Include="MySql.Data" Version="8.0.31" />
<PackageReference Include="MySql.Data" Version="8.4.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.11" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions TShockAPI/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void SendLogs(string log, Color color, TSPlayer excludedPlayer = null)
foreach (TSPlayer player in TShock.Players)
{
if (player != null && player != excludedPlayer && player.Active && player.HasPermission(Permissions.logs) &&
player.DisplayLogs && TShock.Config.Settings.DisableSpewLogs == false)
player.DisplayLogs && !TShock.Config.Settings.DisableSpewLogs)
player.SendMessage(log, color);
}
}
Expand All @@ -183,7 +183,7 @@ public void SendLogs(string log, Color color, TSPlayer excludedPlayer = null)
/// <returns>The number of active players on the server.</returns>
public int GetActivePlayerCount()
{
return Main.player.Where(p => null != p && p.active).Count();
return TShock.Players.Count(p => null != p && p.Active);
}

//Random should not be generated in a method
Expand Down
2 changes: 1 addition & 1 deletion TShockLauncher/TShockLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<ItemGroup>
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="MySql.Data" Version="8.0.31" />
<PackageReference Include="MySql.Data" Version="8.4.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.11" />
<PackageReference Include="ModFramework" Version="1.1.7" GeneratePathProperty="true" /> <!-- only used to extract out to ./bin. -->
<PackageReference Include="GetText.NET" Version="1.7.14" /> <!-- only used to extract out to ./bin. -->
Expand Down
5 changes: 4 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Use past tense when adding new entries; sign your name off when you add or chang
## Upcoming changes
* Fixed `/dump-reference-data` mutate the command names. (#2943, @sgkoishi)
* Added `ParryDamageBuff` (Striking Moment with Brand of the Inferno and shield) for player, updated `CursedInferno` buff for NPC (@sgkoishi, #3005)
* Changed the use of `Player.active` to `TSPlayer.Active` for consistency. (@sgkoishi, #2939)
* Fix typo in config for IP bans. (@redchess64)

## TShock 5.2.1
Expand All @@ -96,6 +97,9 @@ Use past tense when adding new entries; sign your name off when you add or chang
* Fixed bug where when the `UseSqlLogs` config property is true, an empty log file would still get created. (@ZakFahey)
* Fixed typo in `/gbuff`. (@sgkoishi, #2955)
* Rewrote the `.dockerignore` file into a denylist. (@timschumi)
* Added CI for Docker images. (@timschumi)
* Fixed Cursed Flares kicking players for invalid buff. (@Arthri)
* Added automatic publishing of Docker images to GHCR. (@timschumi)

## TShock 5.2
* An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK)
Expand Down Expand Up @@ -129,7 +133,6 @@ Use past tense when adding new entries; sign your name off when you add or chang
* Relaxed custom death message restrictions to allow Inferno potions in PvP. (@drunderscore)
* Allowed Flower Boots to place Ash Flowers on Ash Grass blocks. (@punchready)
* Removed unnecessary range check that artifically shortened quick stack reach. (@boddyn, #2885, @bcat)
* Re-wrote tile rect handling from scratch, fixing a certain exploitable flaw in the old code and significantly reducing the potential exploit surface, potentially even down to zero. (@punchready)

## TShock 5.1.3
* Added support for Terraria 1.4.4.9 via OTAPI 3.1.20. (@SignatureBeef)
Expand Down
29 changes: 12 additions & 17 deletions docs/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,27 @@ Open ports can also be passed through using `-p <host_port>:<container_port>`.

For Example:
```bash
# Building the image using buildx and loading it into docker
docker buildx build -t tshock:latest --load .

# Running the image
docker run -p 7777:7777 -p 7878:7878 \
-v /home/cider/tshock/:/tshock \
-v /home/cider/.local/share/Terraria/Worlds:/worlds \
-v /home/cider/tshock/plugins:/plugins \
--rm -it tshock:latest \
--rm -it ghcr.io/pryaxis/tshock:latest \
-world /worlds/backflip.wld -motd "OMFG DOCKER"
```

## Building for Other Platforms
## Building custom images

Using `docker buildx`, you could build [multi-platform images](https://docs.docker.com/build/building/multi-platform/) for TShock.
Occasionally, it may be necessary to adjust TShock with customizations that are not included in the upstream project.
Therefore, these changes are also not available in the officially provided Docker images.

To build and load a Docker image from your local checkout, use the following `buildx` command:

For Example:
```bash
# Building the image using buildx and loading it into docker
docker buildx build -t tshock:linux-arm64 --platform linux/arm64 --load .
docker buildx build -t tshock:latest --load .
```

# Running the image
docker run -p 7777:7777 -p 7878:7878 \
-v /home/cider/tshock/:/tshock \
-v /home/cider/.local/share/Terraria/Worlds:/worlds \
-v /home/cider/tshock/plugins:/plugins \
--rm -it tshock:linux-arm64 \
-world /worlds/backflip.wld -motd "ARM64 ftw"
It is also possible to build [multi-platform images](https://docs.docker.com/build/building/multi-platform/) for TShock (e.g. an image targeting `arm64`, on a host that is not `arm64`):

```bash
docker buildx build -t tshock:linux-arm64 --platform linux/arm64 --load .
```
17 changes: 0 additions & 17 deletions renovate.json

This file was deleted.

0 comments on commit 8de0b50

Please sign in to comment.