forked from Uncled1023/Combot
Browse Source
Added reconnection on disconnect. Added disconnection checking. Fixed kicked logging. Fixed version exploit.master
13 changed files with 441 additions and 33 deletions
@ -0,0 +1,25 @@
@@ -0,0 +1,25 @@
|
||||
{ |
||||
"Name": "Spam Control", |
||||
"ClassName": "Spam_Control", |
||||
"Enabled": true, |
||||
"ChannelBlacklist": [], |
||||
"NickBlacklist": [], |
||||
"Commands": [], |
||||
"Options": [ |
||||
{ |
||||
"Name": "Max Messages", |
||||
"Description": "The maximum number of messages allowed per time alotted.", |
||||
"Value": 5 |
||||
}, |
||||
{ |
||||
"Name": "Maximum Highlights", |
||||
"Description": "The maximum number of highlights allowed in a set period of time.", |
||||
"Value": 5 |
||||
}, |
||||
{ |
||||
"Name": "Time Threshold", |
||||
"Description": "The minimum time allowed for a set of messages in milliseconds.", |
||||
"Value": 5000 |
||||
} |
||||
] |
||||
} |
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
using System.Reflection; |
||||
using System.Runtime.CompilerServices; |
||||
using System.Runtime.InteropServices; |
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Spam_Control Module")] |
||||
[assembly: AssemblyDescription("")] |
||||
[assembly: AssemblyConfiguration("")] |
||||
[assembly: AssemblyCompany("Teknik")] |
||||
[assembly: AssemblyProduct("Combot")] |
||||
[assembly: AssemblyCopyright("Copyright © 2015")] |
||||
[assembly: AssemblyTrademark("")] |
||||
[assembly: AssemblyCulture("")] |
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)] |
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("5c350b8e-5820-4034-9d67-49d2ddbfcc6f")] |
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")] |
||||
[assembly: AssemblyFileVersion("1.0.0.0")] |
@ -0,0 +1,76 @@
@@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> |
||||
<PropertyGroup> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
<ProjectGuid>{921B252D-D2D0-412F-BD6D-9559DCD20BB0}</ProjectGuid> |
||||
<OutputType>Library</OutputType> |
||||
<AppDesignerFolder>Properties</AppDesignerFolder> |
||||
<RootNamespace>Spam_Control</RootNamespace> |
||||
<AssemblyName>Spam Control</AssemblyName> |
||||
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion> |
||||
<FileAlignment>512</FileAlignment> |
||||
<TargetFrameworkProfile /> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
||||
<DebugSymbols>true</DebugSymbols> |
||||
<DebugType>full</DebugType> |
||||
<Optimize>false</Optimize> |
||||
<OutputPath>..\..\Bin\Modules\Spam Control\Debug\</OutputPath> |
||||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
||||
<DebugType>pdbonly</DebugType> |
||||
<Optimize>true</Optimize> |
||||
<OutputPath>..\..\Bin\Modules\Spam Control\Release\</OutputPath> |
||||
<DefineConstants>TRACE</DefineConstants> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
</PropertyGroup> |
||||
<ItemGroup> |
||||
<Reference Include="System" /> |
||||
<Reference Include="System.Core" /> |
||||
<Reference Include="System.Xml.Linq" /> |
||||
<Reference Include="System.Data.DataSetExtensions" /> |
||||
<Reference Include="Microsoft.CSharp" /> |
||||
<Reference Include="System.Data" /> |
||||
<Reference Include="System.Xml" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="SpamHighlightInfo.cs" /> |
||||
<Compile Include="SpamMessageInfo.cs" /> |
||||
<Compile Include="Spam_Control.cs" /> |
||||
<Compile Include="Properties\AssemblyInfo.cs" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<ProjectReference Include="..\..\Combot\Combot.csproj"> |
||||
<Project>{23e4c371-16e4-4fac-8b11-44288399bb55}</Project> |
||||
<Name>Combot</Name> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\..\IRCServices\IRCServices.csproj"> |
||||
<Project>{65fcbf1c-8c9e-4688-becc-185d9030899f}</Project> |
||||
<Name>IRCServices</Name> |
||||
</ProjectReference> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<None Include="Module.config"> |
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
||||
</None> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
||||
<PropertyGroup> |
||||
<PostBuildEvent>mkdir "$(SolutionDir)Bin\Interface\$(ConfigurationName)\Modules\$(TargetName)" |
||||
copy /Y "$(TargetPath)" "$(SolutionDir)Bin\Interface\$(ConfigurationName)\Modules\$(TargetName)" |
||||
copy /Y "$(TargetDir)Module.config" "$(SolutionDir)Bin\Interface\$(ConfigurationName)\Modules\$(TargetName)"</PostBuildEvent> |
||||
</PropertyGroup> |
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
||||
Other similar extension points exist, see Microsoft.Common.targets. |
||||
<Target Name="BeforeBuild"> |
||||
</Target> |
||||
<Target Name="AfterBuild"> |
||||
</Target> |
||||
--> |
||||
</Project> |
@ -0,0 +1,25 @@
@@ -0,0 +1,25 @@
|
||||
using System; |
||||
|
||||
namespace Combot.Modules.Plugins |
||||
{ |
||||
public class SpamHighlightInfo |
||||
{ |
||||
public string Channel { get; set; } |
||||
public string Nick { get; set; } |
||||
public int Highlights { get; set; } |
||||
public DateTime FirstHighlightTime { get; set; } |
||||
|
||||
public SpamHighlightInfo() |
||||
{ |
||||
SetDefaults(); |
||||
} |
||||
|
||||
private void SetDefaults() |
||||
{ |
||||
Channel = string.Empty; |
||||
Nick = string.Empty; |
||||
Highlights = 0; |
||||
FirstHighlightTime = DateTime.Now; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,25 @@
@@ -0,0 +1,25 @@
|
||||
using System; |
||||
|
||||
namespace Combot.Modules.Plugins |
||||
{ |
||||
public class SpamMessageInfo |
||||
{ |
||||
public string Channel { get; set; } |
||||
public string Nick { get; set; } |
||||
public int Lines { get; set; } |
||||
public DateTime FirstMessageTime { get; set; } |
||||
|
||||
public SpamMessageInfo() |
||||
{ |
||||
SetDefaults(); |
||||
} |
||||
|
||||
private void SetDefaults() |
||||
{ |
||||
Channel = string.Empty; |
||||
Nick = string.Empty; |
||||
Lines = 0; |
||||
FirstMessageTime = DateTime.Now; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,115 @@
@@ -0,0 +1,115 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading; |
||||
using Combot.IRCServices; |
||||
using Combot.IRCServices.Messaging; |
||||
|
||||
namespace Combot.Modules.Plugins |
||||
{ |
||||
public class Spam_Control : Module |
||||
{ |
||||
private List<SpamMessageInfo> SpamMessageList; |
||||
private List<SpamHighlightInfo> SpamHighlightList; |
||||
private ReaderWriterLockSlim SpamMessageLock; |
||||
private ReaderWriterLockSlim SpamHighlightLock; |
||||
|
||||
public override void Initialize() |
||||
{ |
||||
SpamMessageList = new List<SpamMessageInfo>(); |
||||
SpamHighlightList = new List<SpamHighlightInfo>(); |
||||
SpamMessageLock = new ReaderWriterLockSlim(); |
||||
SpamHighlightLock = new ReaderWriterLockSlim(); |
||||
Bot.IRC.Message.ChannelMessageReceivedEvent += HandleChannelMessage; |
||||
} |
||||
|
||||
private void HandleChannelMessage(object sender, ChannelMessage message) |
||||
{ |
||||
if (!ChannelBlacklist.Contains(message.Channel) && !NickBlacklist.Contains(message.Sender.Nickname)) |
||||
{ |
||||
// Check for line spam
|
||||
if (SpamMessageList.Exists(msg => msg.Channel == message.Channel && msg.Nick == message.Sender.Nickname)) |
||||
{ |
||||
SpamMessageLock.EnterReadLock(); |
||||
SpamMessageInfo info = SpamMessageList.Find(msg => msg.Channel == message.Channel && msg.Nick == message.Sender.Nickname); |
||||
SpamMessageLock.ExitReadLock(); |
||||
TimeSpan difference = message.TimeStamp.Subtract(info.FirstMessageTime); |
||||
if (difference.TotalMilliseconds < (int) GetOptionValue("Time Threshold")) |
||||
{ |
||||
info.Lines++; |
||||
if (info.Lines > (int) GetOptionValue("Max Messages")) |
||||
{ |
||||
Bot.IRC.SendKick(info.Channel, info.Nick, string.Format("Please do not spam. You have messaged {0} times within {1}ms.", info.Lines, GetOptionValue("Time Threshold"))); |
||||
SpamMessageLock.EnterWriteLock(); |
||||
SpamMessageList.Remove(info); |
||||
SpamMessageLock.ExitWriteLock(); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
SpamMessageLock.EnterWriteLock(); |
||||
info.Lines = 1; |
||||
info.FirstMessageTime = message.TimeStamp; |
||||
SpamMessageLock.ExitWriteLock(); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
SpamMessageInfo info = new SpamMessageInfo(); |
||||
info.Channel = message.Channel; |
||||
info.Nick = message.Sender.Nickname; |
||||
info.Lines = 1; |
||||
info.FirstMessageTime = message.TimeStamp; |
||||
SpamMessageLock.EnterWriteLock(); |
||||
SpamMessageList.Add(info); |
||||
SpamMessageLock.ExitWriteLock(); |
||||
} |
||||
|
||||
// Check for highlight spam
|
||||
List<string> splitMessage = message.Message.Split(new [] {' '}, StringSplitOptions.RemoveEmptyEntries).ToList(); |
||||
Channel channel = Bot.IRC.Channels.Find(chan => chan.Name == message.Channel); |
||||
if (channel != null) |
||||
{ |
||||
List<string> foundNicks = splitMessage.FindAll(msg => channel.Nicks.Exists(nick => msg.Contains(nick.Nickname))); |
||||
if (foundNicks.Any()) |
||||
{ |
||||
if (!SpamHighlightList.Exists(msg => msg.Channel == message.Channel && msg.Nick == message.Sender.Nickname)) |
||||
{ |
||||
SpamHighlightInfo newInfo = new SpamHighlightInfo(); |
||||
newInfo.Channel = message.Channel; |
||||
newInfo.Nick = message.Sender.Nickname; |
||||
newInfo.Highlights = 0; |
||||
newInfo.FirstHighlightTime = message.TimeStamp; |
||||
|
||||
SpamHighlightLock.EnterWriteLock(); |
||||
SpamHighlightList.Add(newInfo); |
||||
SpamHighlightLock.ExitWriteLock(); |
||||
} |
||||
SpamHighlightLock.EnterReadLock(); |
||||
SpamHighlightInfo info = SpamHighlightList.Find(highlight => highlight.Channel == message.Channel && highlight.Nick == message.Sender.Nickname); |
||||
SpamHighlightLock.ExitReadLock(); |
||||
TimeSpan difference = message.TimeStamp.Subtract(info.FirstHighlightTime); |
||||
if (difference.TotalMilliseconds < (int) GetOptionValue("Time Threshold")) |
||||
{ |
||||
info.Highlights += foundNicks.Count; |
||||
if (info.Highlights > (int) GetOptionValue("Maximum Highlights")) |
||||
{ |
||||
Bot.IRC.SendKick(info.Channel, info.Nick, string.Format("Please do not highlight spam. You have highlighted {0} nicks within {1}ms.", info.Highlights, GetOptionValue("Time Threshold"))); |
||||
SpamHighlightLock.EnterWriteLock(); |
||||
SpamHighlightList.Remove(info); |
||||
SpamHighlightLock.ExitWriteLock(); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
SpamHighlightLock.EnterWriteLock(); |
||||
info.Highlights = foundNicks.Count; |
||||
info.FirstHighlightTime = message.TimeStamp; |
||||
SpamHighlightLock.ExitWriteLock(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue