Skip to content

Commit

Permalink
Merge pull request #16 from Hedius/test
Browse files Browse the repository at this point in the history
Release v8.1.5.0
  • Loading branch information
Hedius authored Oct 7, 2022
2 parents 0815694 + a3a3c4d commit efc0a55
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 23 deletions.
90 changes: 69 additions & 21 deletions AdKats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
* Work on fork by Hedius (Version >= 8.0.0.0)
*
* AdKats.cs
* Version 8.1.4.0
* 15-AUG-2022
* Version 8.1.5.0
* 07-OCT-2022
*
* Automatic Update Information
* <version_code>8.1.4.0</version_code>
* <version_code>8.1.5.0</version_code>
*/

using System;
Expand Down Expand Up @@ -68,7 +68,7 @@ public class AdKats : PRoConPluginAPI, IPRoConPluginInterface
{

//Current Plugin Version
private const String PluginVersion = "8.1.4.0";
private const String PluginVersion = "8.1.5.0";

public enum GameVersionEnum
{
Expand Down Expand Up @@ -533,6 +533,7 @@ public enum VoipJoinDisplayType
private Boolean _MutedPlayerIgnoreCommands = true;
private Boolean _UseFirstSpawnMutedMessage = true;
private String _FirstSpawnMutedMessage = "You are perma or temp muted! Talking will cause punishment!";
private Int32 _ForceMuteBanDuration = 60;

//Surrender
private Boolean _surrenderVoteEnable;
Expand Down Expand Up @@ -1876,6 +1877,7 @@ public void BuildMuteSettings(List<CPluginVariable> lstReturn)
{
buildList.Add(new CPluginVariable(GetSettingSection("A11") + t + "First spawn persistent muted warning text", typeof(String), _FirstSpawnMutedMessage));
}
buildList.Add(new CPluginVariable(GetSettingSection("A11") + t + "Persistent force mute temp-ban duration minutes", typeof(int), _ForceMuteBanDuration));
}
lstReturn.AddRange(buildList);
}
Expand Down Expand Up @@ -8228,6 +8230,17 @@ public void SetPluginVariable(String strVariable, String strValue)
QueueSettingForUpload(new CPluginVariable(@"First spawn persistent muted warning text", typeof(String), _FirstSpawnMutedMessage));
}
}
else if (Regex.Match(strVariable, @"Persistent force mute temp-ban duration minutes").Success)
{
Int32 tmp = 45;
int.TryParse(strValue, out tmp);
if (_ForceMuteBanDuration != tmp)
{
_ForceMuteBanDuration = tmp;
//Once setting has been changed, upload the change to database
QueueSettingForUpload(new CPluginVariable(@"Persistent force mute temp-ban duration minutes", typeof(Int32), _ForceMuteBanDuration));
}
}
else if (Regex.Match(strVariable, @"Ticket Window High").Success)
{
Int32 tmp = 2;
Expand Down Expand Up @@ -17351,7 +17364,7 @@ public override void OnPlayerSpawned(String soldierName, Inventory spawnedInvent
Threading.Wait(2000);

// Send warning to player if the player is muted.
if (_UseFirstSpawnMutedMessage && GetMatchingVerboseASPlayersOfGroup("persistent_mute", aPlayer).Any())
if (_UseFirstSpawnMutedMessage && (GetMatchingVerboseASPlayersOfGroup("persistent_mute", aPlayer).Any() || GetMatchingVerboseASPlayersOfGroup("persistent_mute_force", aPlayer).Any()))
{
PlayerTellMessage(aPlayer.player_name, _FirstSpawnMutedMessage);
Threading.Wait(TimeSpan.FromSeconds(_YellDuration));
Expand Down Expand Up @@ -20046,13 +20059,32 @@ private void MessagingThreadLoop()
Log.Debug(() => "Checking for mute case.", 7);
// Persistent mute?
var persistentMute = GetMatchingVerboseASPlayersOfGroup("persistent_mute", aPlayer).Any();
var persistentForceMute = GetMatchingVerboseASPlayersOfGroup("persistent_mute_force", aPlayer).Any();
// Add persistent mute to RoundMutedPlayers if the player is missing in the list.
if (persistentMute && !_RoundMutedPlayers.ContainsKey(messageObject.Speaker)) {
Log.Debug(() => "Adding missing persistent mute to RoundMutedPlayers.", 4);
_RoundMutedPlayers.Add(messageObject.Speaker, 0);
}
if (_RoundMutedPlayers.ContainsKey(messageObject.Speaker))
if (persistentForceMute)
{
// Force Mute -> Temp Ban Player
ARecord record = new ARecord();
record.record_time = UtcNow();
record.record_source = ARecord.Sources.Automated;
record.server_id = _serverInfo.ServerID;
record.source_name = "PlayerMuteSystem";
_PlayerDictionary.TryGetValue(messageObject.Speaker, out record.target_player);
record.target_name = messageObject.Speaker;
record.record_message = _PersistentMutedPlayerKickMessage;
record.command_type = GetCommandByKey("player_ban_temp");
record.command_action = GetCommandByKey("player_ban_temp");
record.command_numeric = _ForceMuteBanDuration;
QueueRecordForProcessing(record);
continue;
}
else if (_RoundMutedPlayers.ContainsKey(messageObject.Speaker))
{
// Round, Temp Perma Mute Kill -> Kick
if (_MutedPlayerIgnoreCommands && isCommand)
{
Log.Debug(() => "Player muted, but ignoring since message is command.", 3);
Expand Down Expand Up @@ -21160,8 +21192,8 @@ private void QueueRecordForProcessing(ARecord record)
}
Log.Debug(() => record.command_type.command_key + " record allowed to continue processing.", 5);
break;
case "player_peristentmute_remove":
if (!GetMatchingASPlayersOfGroup("persistent_mute", record.target_player).Any())
case "player_persistentmute_remove":
if (!GetMatchingASPlayersOfGroup("persistent_mute", record.target_player).Any() && !GetMatchingASPlayersOfGroup("persistent_mute_force", record.target_player).Any())
{
SendMessageToSource(record, "Matching player not perma/temp muted.");
FinalizeRecord(record);
Expand Down Expand Up @@ -26996,6 +27028,7 @@ public void CompleteRecordInformation(ARecord record, AChatMessage message)
}
break;
case "player_persistentmute":
case "player_persistentmute_force":
{
// Rant: GOD THIS IS SO REDUNDANT - .... same code in each case here...
// MY EYES ARE BLEEDING :) Hedius.
Expand Down Expand Up @@ -30425,8 +30458,11 @@ private void RunAction(ARecord record)
case "player_mute":
MuteTarget(record);
break;
case "player_persistentmute":
PersistentMuteTarget(record);
case "player_persistentmute":
PersistentMuteTarget(record, false);
break;
case "player_persistentmute_force":
PersistentMuteTarget(record, true);
break;
case "player_unmute":
case "player_persistentmute_remove":
Expand Down Expand Up @@ -34385,10 +34421,11 @@ public void MuteTarget(ARecord record)
Log.Debug(() => "Exiting muteTarget", 6);
}

public void PersistentMuteTarget(ARecord record)
public void PersistentMuteTarget(ARecord record, bool force)
{
Log.Debug(() => "Entering PersistentMuteTarget", 6);
if (HasAccess(record.target_player, GetCommandByKey("player_persistentmute")))
if (HasAccess(record.target_player, GetCommandByKey("player_persistentmute"))
|| HasAccess(record.target_player, GetCommandByKey("player_persistentmute_force")))
{
SendMessageToSource(record, "You can't mute an admin.");
FinalizeRecord(record);
Expand All @@ -34405,7 +34442,7 @@ public void PersistentMuteTarget(ARecord record)
command.CommandText = @"
DELETE FROM
`adkats_specialplayers`
WHERE `player_group` = @player_group
WHERE `player_group` IN ('persistent_mute', 'persistent_mute_force')
AND (`player_id` = @player_id OR `player_identifier` = @player_name);
INSERT INTO
`adkats_specialplayers`
Expand Down Expand Up @@ -34435,15 +34472,15 @@ INSERT INTO
{
record.command_numeric = 10518984;
}
command.Parameters.AddWithValue("@player_group", "persistent_mute");
command.Parameters.AddWithValue("@player_group", force ? "persistent_mute_force": "persistent_mute");
command.Parameters.AddWithValue("@player_id", record.target_player.player_id);
command.Parameters.AddWithValue("@player_name", record.target_player.player_name);
command.Parameters.AddWithValue("@duration_minutes", record.command_numeric);

Int32 rowsAffected = SafeExecuteNonQuery(command);
if (rowsAffected > 0)
{
String message = "Player " + record.GetTargetNames() + " given " + ((record.command_numeric == 10518984) ? ("permanent") : (FormatTimeString(TimeSpan.FromMinutes(record.command_numeric), 2))) + " persistent mute on all servers.";
String message = "Player " + record.GetTargetNames() + " given " + ((record.command_numeric == 10518984) ? ("permanent") : (FormatTimeString(TimeSpan.FromMinutes(record.command_numeric), 2))) + " persistent " + (force ? "force ": "") +"mute on all servers.";
AdminSayMessage(message);
if (record.record_source != ARecord.Sources.InGame &&
record.record_source != ARecord.Sources.Automated &&
Expand All @@ -34456,7 +34493,7 @@ INSERT INTO
}
else
{
Log.Error("Unable to add player to persistent mute list. Error uploading.");
Log.Error("Unable to add player to persistent mute list. Error uploading. Force: " + force);
}
}
}
Expand Down Expand Up @@ -34484,10 +34521,12 @@ public void UnMuteTarget(ARecord record)
return;
}
var persistentMute = GetMatchingVerboseASPlayersOfGroup("persistent_mute", record.target_player).Any();
if (persistentMute)
var persistentForceMute = GetMatchingVerboseASPlayersOfGroup("persistent_mute_force", record.target_player).Any();
if (persistentMute || persistentForceMute)
{
List<ASpecialPlayer> matchingPlayers = GetMatchingASPlayersOfGroup("persistent_mute", record.target_player);
if (!matchingPlayers.Any())
List<ASpecialPlayer> matchingPlayersForce = GetMatchingASPlayersOfGroup("persistent_mute_force", record.target_player);
if (!matchingPlayers.Any() && !matchingPlayersForce.Any())
{
SendMessageToSource(record, "Matching player not in the persistent mute list.");
FinalizeRecord(record);
Expand All @@ -34496,7 +34535,7 @@ public void UnMuteTarget(ARecord record)
using (MySqlConnection connection = GetDatabaseConnection())
{
Boolean updated = false;
foreach (ASpecialPlayer asPlayer in matchingPlayers)
foreach (ASpecialPlayer asPlayer in matchingPlayers.Concat(matchingPlayersForce).ToList())
{
using (MySqlCommand command = connection.CreateCommand())
{
Expand Down Expand Up @@ -34532,7 +34571,7 @@ public void UnMuteTarget(ARecord record)
}
else
{
if (!persistentMute)
if (!persistentMute && !persistentForceMute)
SendMessageToSource(record, record.GetTargetNames() + " is not muted.");
FinalizeRecord(record);
return;
Expand Down Expand Up @@ -40787,6 +40826,7 @@ private void UploadAllSettings()
QueueSettingForUpload(new CPluginVariable(@"Ignore commands for mute enforcement", typeof(Boolean), _MutedPlayerIgnoreCommands));
QueueSettingForUpload(new CPluginVariable(@"Send first spawn warning for persistent muted players", typeof(Boolean), _UseFirstSpawnMutedMessage));
QueueSettingForUpload(new CPluginVariable(@"First spawn persistent muted warning text", typeof(String), _FirstSpawnMutedMessage));
QueueSettingForUpload(new CPluginVariable(@"Persistent force mute temp-ban duration minutes", typeof(Int32), _ForceMuteBanDuration));
QueueSettingForUpload(new CPluginVariable(@"Ticket Window High", typeof(Int32), _TeamSwapTicketWindowHigh));
QueueSettingForUpload(new CPluginVariable(@"Ticket Window Low", typeof(Int32), _TeamSwapTicketWindowLow));
QueueSettingForUpload(new CPluginVariable(@"Enable Admin Assistants", typeof(Boolean), _EnableAdminAssistants));
Expand Down Expand Up @@ -47116,6 +47156,11 @@ private void FetchCommands()
SendNonQuery("Adding command player_watchlist_remove", "INSERT INTO `adkats_commands` VALUES(152, 'Active', 'player_watchlist_remove', 'Log', 'Remove Player from Watchlist', 'rwatch', TRUE, 'AnyHidden')", true);
newCommands = true;
}
if (!_CommandIDDictionary.ContainsKey(153))
{
SendNonQuery("Adding command player_persistentmute_force", "INSERT INTO `adkats_commands` VALUES(153, 'Active', 'player_persistentmute_force', 'Log', 'Persistent Force Mute Player', 'fmute', TRUE, 'AnyHidden')", true);
newCommands = true;
}
if (newCommands)
{
FetchCommands();
Expand Down Expand Up @@ -47157,6 +47202,7 @@ private void FillCommandDescDictionary()
_CommandDescriptionDictionary["player_forgive"] = "Decreases infraction points and informs the player. Requires a reason.";
_CommandDescriptionDictionary["player_mute"] = "Mutes a player for the current round. Talking will cause punishment. Requires a reason.";
_CommandDescriptionDictionary["player_persistentmute"] = "Mutes a player for a given time span or permanent. Talking will cause punishment. Requires a reason.";
_CommandDescriptionDictionary["player_persistentmute_force"] = "Mutes a player for a given time span or permanent. Talking will cause a temp ban. Requires a reason.";
_CommandDescriptionDictionary["player_unmute"] = "Unmutes a muted player.";
_CommandDescriptionDictionary["player_persistentmute_remove"] = "Unmutes a perma/temp muted player.";
_CommandDescriptionDictionary["player_join"] = "Switches you to a players squad if there is room.";
Expand Down Expand Up @@ -49551,7 +49597,9 @@ private void ParseExternalCommand(Object commandParams)
//Import the command numeric
//Only required for temp ban & persistent mutes
//ToDo: what about whitelists?
if (record.command_type.command_key == "player_ban_temp" || record.command_type.command_key == "player_persistentmute")
if (record.command_type.command_key == "player_ban_temp"
|| record.command_type.command_key == "player_persistentmute"
|| record.command_type.command_key == "player_persistentmute_force")
{
if (!parsedClientInformation.ContainsKey("command_numeric"))
{
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1527,3 +1527,23 @@ Added small improvements to fuzzy player match response text.</li>
<li><b>No upgrade SQL required.</b></li>
</ul>

<h4>8.1.5.0 (07-OCT-2022)</h4>
<b>Enhancements</b><br/>
<ul>
<li>New Command !fmute for force muting players. Similar to tmute, but player gets instantly temp banned for sending a message.</li>
<li>New setting "Persistent force mute temp-ban duration minutes" for defining how long a force muted player should be banned.</li>
</ul>
<b>Changes</b><br/>
<ul>
<li>None</li>
</ul>
<b>Bugs Fixed</b><br/>
<ul>
<li>None</li>
</ul>
<b>Upgrade SQL from 4.0.0.0 - Current</b><br/>
<ul>
<li><b>No upgrade SQL required.</b></li>
</ul>


Loading

0 comments on commit efc0a55

Please sign in to comment.