Browse Source

Added check to kick/ban to check kicking/banning nick's privilege against the target - should fix #6

tags/3.0.3^0
Teknikode 4 years ago
parent
commit
e09d520c2f
3 changed files with 98 additions and 4 deletions
  1. 95
    1
      Combot/Bot.cs
  2. 2
    2
      Modules/Moderation/Moderation.cs
  3. 1
    1
      Modules/Moderation/Module.config

+ 95
- 1
Combot/Bot.cs View File

@@ -294,6 +294,101 @@ namespace Combot
return hasAccess;
}

/// <summary>
/// Checks to see if the first nick has access to perform a command on the second nick
/// </summary>
/// <param name="channel">Channel the command is being applied on</param>
/// <param name="firstNick">The nick applying the command</param>
/// <param name="secondNick">The nick the command is being performed on</param>
/// <returns></returns>
public bool CheckNickAccess(string channel, string firstNick, string secondNick)
{
bool access = false;
Channel foundChannel = IRC.Channels.Find(chan => chan.Name == channel);
if (foundChannel != null)
{
Nick foundFirstNick = foundChannel.Nicks.Find(nick => nick.Nickname == firstNick);
Nick foundSecondNick = foundChannel.Nicks.Find(nick => nick.Nickname == secondNick);
if (foundFirstNick != null && foundSecondNick != null)
{
for (int i = 0; i < foundSecondNick.Privileges.Count; i++)
{
access = foundFirstNick.Privileges.Contains(foundSecondNick.Privileges[i]);
if (foundFirstNick.Privileges.Contains(foundSecondNick.Privileges[i]))
{
access = true;
}
else
{
access = false;
}
switch (foundSecondNick.Privileges[i])
{
case PrivilegeMode.v:
if (foundFirstNick.Privileges.Contains(PrivilegeMode.v) || foundFirstNick.Privileges.Contains(PrivilegeMode.h) || foundFirstNick.Privileges.Contains(PrivilegeMode.o) || foundFirstNick.Privileges.Contains(PrivilegeMode.a) || foundFirstNick.Privileges.Contains(PrivilegeMode.q))
{
access = true;
}
else
{
access = false;
}
break;
case PrivilegeMode.h:
if (foundFirstNick.Privileges.Contains(PrivilegeMode.h) || foundFirstNick.Privileges.Contains(PrivilegeMode.o) || foundFirstNick.Privileges.Contains(PrivilegeMode.a) || foundFirstNick.Privileges.Contains(PrivilegeMode.q))
{
access = true;
}
else
{
access = false;
}
break;
case PrivilegeMode.o:
if (foundFirstNick.Privileges.Contains(PrivilegeMode.o) || foundFirstNick.Privileges.Contains(PrivilegeMode.a) || foundFirstNick.Privileges.Contains(PrivilegeMode.q))
{
access = true;
}
else
{
access = false;
}
break;
case PrivilegeMode.a:
if (foundFirstNick.Privileges.Contains(PrivilegeMode.a) || foundFirstNick.Privileges.Contains(PrivilegeMode.q))
{
access = true;
}
else
{
access = false;
}
break;
case PrivilegeMode.q:
if (foundFirstNick.Privileges.Contains(PrivilegeMode.q))
{
access = true;
}
else
{
access = false;
}
break;
}
}
}
if (foundFirstNick != null && ServerConfig.Owners.Contains(firstNick) && foundFirstNick.Modes.Contains(UserMode.r))
{
access = true;
}
}
if (firstNick == IRC.Nickname)
{
access = true;
}
return access;
}

public void ExecuteCommand(string message, string location, MessageType type)
{
ParseCommandMessage(DateTime.Now, message, new Nick { Nickname = IRC.Nickname }, location, type);
@@ -617,7 +712,6 @@ namespace Combot
string missingArgument = string.Format("Missing a required argument for \u0002{0}{1}\u0002{2}. The required arguments are \u0002{3}\u0002.", ServerConfig.CommandPrefix, command, argHelp, string.Join(", ", validArguments.Where(arg => arg.Required).Select(arg => arg.Name)));
module.SendResponse(messageType, location, sender.Nickname, missingArgument);
}

}
}
}

+ 2
- 2
Modules/Moderation/Moderation.cs View File

@@ -247,7 +247,7 @@ namespace Combot.Modules.Plugins
private void BanNick(bool set, Command curCommand, CommandMessage command)
{
string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
if (Bot.CheckChannelAccess(channel, command.Nick.Nickname, curCommand.AllowedAccess))
if (Bot.CheckChannelAccess(channel, command.Nick.Nickname, curCommand.AllowedAccess) && Bot.CheckNickAccess(channel, command.Nick.Nickname, command.Arguments["Nickname"]))
{
string banMask = command.Arguments["Nickname"];
Channel foundChannel = Bot.IRC.Channels.Find(chan => chan.Nicks.Exists(nick => nick.Nickname == banMask));
@@ -327,7 +327,7 @@ namespace Combot.Modules.Plugins
private void KickNick(Command curCommand, CommandMessage command)
{
string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
if (Bot.CheckChannelAccess(channel, command.Nick.Nickname, curCommand.AllowedAccess))
if (Bot.CheckChannelAccess(channel, command.Nick.Nickname, curCommand.AllowedAccess) && Bot.CheckNickAccess(channel, command.Nick.Nickname, command.Arguments["Nickname"]))
{
if (command.Arguments.ContainsKey("Reason"))
{

+ 1
- 1
Modules/Moderation/Module.config View File

@@ -504,7 +504,7 @@
"ChannelBlacklist": [],
"NickBlacklist": [],
"Triggers": [
"dehop"
"devoice"
],
"Arguments": [
{

Loading…
Cancel
Save