Skip to content

Commit

Permalink
Merge pull request #83 from jonathan-robertson/fix
Browse files Browse the repository at this point in the history
Fix Bug Allowing Bypass of PVP Protection, Add/Update Console Commands
  • Loading branch information
jonathan-robertson authored Jun 5, 2023
2 parents a1bb9d5 + 6885df8 commit 0871ea3
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 15 deletions.
Binary file modified Amnesia.dll
Binary file not shown.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.2.1] - 2023-06-04

- add admin command to give/heal fragile memory
- fix bug allowing bypass of pvp protection
- fix/update admin command players

## [1.2.0] - 2023-05-31

- add clarification for blood moon protection buff
Expand Down
2 changes: 1 addition & 1 deletion ModInfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Name value="Amnesia" />
<Description value="Reset player progress after dying under a configurable set of circumstances" />
<Author value="Jonathan Robertson (Kanaverum)" />
<Version value="1.2.0" />
<Version value="1.2.1" />
<Website value="https://github.com/jonathan-robertson/amnesia" />
</ModInfo>
</xml>
35 changes: 33 additions & 2 deletions src/Commands/ConsoleCmdAmnesia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public ConsoleCmdAmnesia()
{ "debug", "toggle debug logging mode" },
{ "players", "show players and their amnesia-related info" },
{ "grant <user id / player name / entity id> <timeInSeconds>", "grant player some bonus xp time" },
{ "fragile <user id / player name / entity id> <true/false>", "give or remove fragile memory debuff" },
{ "config", "show current amnesia configuration" },
{ "set", "show the single-value fields you can adjust" },
{ "set <field>", "describe how you can update this field" },
Expand Down Expand Up @@ -81,6 +82,13 @@ public override void Execute(List<string> _params, CommandSenderInfo _senderInfo
}
HandleGrant(_params);
return;
case "fragile":
if (_params.Count != 3)
{
break;
}
HandleFragile(_params);
return;
case "config":
SdtdConsole.Instance.Output(Config.AsString());
return;
Expand Down Expand Up @@ -109,9 +117,9 @@ private void HandleShowPlayers()
{
SdtdConsole.Instance.Output("No players are currently online.");
}
foreach (var player in players)
for (var i = 0; i < players.Count; i++)
{
SdtdConsole.Instance.Output($"{player.entityId}. {Values.BuffHardenedMemory}: {player.Buffs.HasBuff(Values.BuffHardenedMemory)}, {Values.CVarPositiveOutlookRemTime}: {player.GetCVar(Values.CVarPositiveOutlookRemTime)} ({player.GetDebugName()})");
SdtdConsole.Instance.Output($"{players[i].entityId,8} | {players[i].GetDebugName()} | level {players[i].Progression.Level} | {Values.BuffFragileMemory}: {players[i].Buffs.HasBuff(Values.BuffFragileMemory)} | {Values.CVarPositiveOutlookRemTime}: {players[i].GetCVar(Values.CVarPositiveOutlookRemTime)}");
}
}

Expand Down Expand Up @@ -150,6 +158,29 @@ private void HandleGrant(List<string> @params)
SdtdConsole.Instance.Output($"Added {valueToAdd} seconds of bonus xp time to {player.GetDebugName()} for a new value of {newValue}.");
}

private void HandleFragile(List<string> @params)
{
if (!bool.TryParse(@params[2], out var shouldAdd))
{
SdtdConsole.Instance.Output("Unable to parse valueToAdd: must be of type bool");
return;
}
var clientInfo = ConsoleHelper.ParseParamIdOrName(@params[1], true, false);
if (clientInfo == null || !GameManager.Instance.World.Players.dict.TryGetValue(clientInfo.entityId, out var player))
{
SdtdConsole.Instance.Output("Unable to find this player; note: player must be online");
return;
}
if (shouldAdd)
{
_ = player.Buffs.AddBuff(Values.BuffFragileMemory);
SdtdConsole.Instance.Output($"Successfully added {Values.BuffFragileMemory} to {player.GetDebugName()}.");
return;
}
player.Buffs.RemoveBuff(Values.BuffFragileMemory);
SdtdConsole.Instance.Output($"Successfully removed {Values.BuffFragileMemory} from {player.GetDebugName()}.");
}

private void RouteListRequest(List<string> @params)
{
if (@params.Count() == 1)
Expand Down
2 changes: 1 addition & 1 deletion src/Data/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static void SetLongTermMemoryLevel(int value)
{
_ = player.Buffs.AddBuff(Values.BuffNewbieCoat);
}
if (player.Buffs.HasBuff(Values.BuffHardenedMemory))
if (player.Buffs.HasBuff(Values.BuffHardenedMemory)) // TODO: deprecated; remove in 2.0.0
{
player.Buffs.RemoveBuff(Values.BuffHardenedMemory);
PlayerHelper.GiveItem(player, Values.NameMemoryBoosters);
Expand Down
2 changes: 1 addition & 1 deletion src/Data/Values.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class Values
public const string BuffPositiveOutlook = "buffAmnesiaPositiveOutlook";
public const string BuffBloodmoonLifeProtection = "buffAmnesiaBloodmoonLifeProtection";
public const string BuffPostBloodmoonLifeProtection = "buffAmnesiaPostBloodmoonLifeProtection";
public const string BuffHardenedMemory = "buffAmnesiaHardenedMemory";
public const string BuffHardenedMemory = "buffAmnesiaHardenedMemory"; // TODO: deprecated; remove in 2.0.0
public const string BuffFragileMemory = "buffAmnesiaFragileMemory";
public const string BuffMemoryLoss = "buffAmnesiaMemoryLoss";
public const string BuffNewbieCoat = "buffNewbieCoat";
Expand Down
13 changes: 6 additions & 7 deletions src/Handlers/GameMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,16 @@ public static bool Handle(ClientInfo clientInfo, EnumGameMessages messageType, s
log.Trace($"{clientIdentifier} died and did not have bloodmoon memory protection.");
}

if (Config.ProtectMemoryDuringPvp && !mainName.Equals(secondaryName))
if (Config.ProtectMemoryDuringPvp && mainName != secondaryName)
{
// TODO: this is nice, but damage/kill handling needs to also be redone to include the killing player in game message even if that player is offline
// and probably also to give that player offline credit for the kill(s).
foreach (var kvp in GameManager.Instance.persistentPlayers.Players)

var killerClient = ConnectionManager.Instance.Clients.GetForNameOrId(secondaryName);
if (killerClient != null)
{
if (secondaryName.Equals(kvp.Value.PlayerName))
{
log.Trace($"{clientIdentifier} was killed by {secondaryName} but this server has pvp deaths set to not harm memory.");
return true; // being killed in pvp doesn't count against player
}
log.Trace($"{clientIdentifier} was killed by {killerClient.InternalId.CombinedString} ({secondaryName}) but this server has pvp deaths set to not harm memory.");
return true; // being killed in pvp doesn't count against player
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Handlers/PlayerSpawnedInWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public static void Handle(ClientInfo clientInfo, RespawnType respawnType, Vector
{
case RespawnType.EnterMultiplayer: // first-time login for new player
_ = PlayerHelper.AddPositiveOutlookTime(player, Config.PositiveOutlookTimeOnFirstJoin);
RefundHardenedMemory(clientInfo, player);
RefundHardenedMemory(clientInfo, player); // TODO: deprecated; remove in 2.0.0
HandleStandardRespawnSteps(player);
break;
case RespawnType.JoinMultiplayer: // existing player rejoining
// grace period should continue only so long as you don't disconnect
player.Buffs.RemoveBuff(Values.BuffPostBloodmoonLifeProtection);
RefundHardenedMemory(clientInfo, player);
RefundHardenedMemory(clientInfo, player); // TODO: deprecated; remove in 2.0.0
HandleStandardRespawnSteps(player);
break;
case RespawnType.Died: // existing player returned from death
Expand Down Expand Up @@ -94,7 +94,7 @@ private static void HandleStandardRespawnSteps(EntityPlayer player)
/// Temporary method to automatically refund any players with the Hardened Memory buff from version 1.0.0.
/// </summary>
/// <param name="player">EntityPlayer to check buffs for and refund if hardened.</param>
private static void RefundHardenedMemory(ClientInfo clientInfo, EntityPlayer player)
private static void RefundHardenedMemory(ClientInfo clientInfo, EntityPlayer player) // TODO: deprecated; remove in 2.0.0
{
if (player.Buffs.HasBuff(Values.BuffHardenedMemory))
{
Expand Down

0 comments on commit 0871ea3

Please sign in to comment.