Browse Source

Added message parsing. Added Message events. Added basic interface. Separated core services into separate modules.

pull/1/head
Teknikode 7 years ago
parent
commit
ca82f763d0
  1. 26
      Bot.cs
  2. BIN
      Bot.ico
  3. 17
      Combot.sln
  4. 64
      Combot/Bot.cs
  5. 20
      Combot/Combot.csproj
  6. 26
      Combot/Config.cs
  7. 0
      Combot/Methods.cs
  8. 4
      Combot/Modules/Module.cs
  9. 2
      Combot/Properties.cs
  10. 4
      Combot/Properties/AssemblyInfo.cs
  11. 42
      Combot/Types.cs
  12. 93
      IRC/Channel.cs
  13. 24
      IRC/IRCMessages.cs
  14. 1155
      IRC/IRCMethods.cs
  15. 85
      IRC/IRCService.cs
  16. 379
      IRC/IRCTypes.cs
  17. 2
      IRCServices/AccessControl/Access.cs
  18. 138
      IRCServices/Channel.cs
  19. 115
      IRCServices/IRC.cs
  20. 63
      IRCServices/IRCServices.csproj
  21. 18
      IRCServices/Messaging/GetReply.cs
  22. 267
      IRCServices/Messaging/MessageTypes.cs
  23. 398
      IRCServices/Messaging/Messages.cs
  24. 566
      IRCServices/Methods.cs
  25. 2
      IRCServices/Nick.cs
  26. 36
      IRCServices/Properties/AssemblyInfo.cs
  27. 2
      IRCServices/TCP/TCPInterface.cs
  28. 2
      IRCServices/TCP/TCPTypes.cs
  29. 188
      IRCServices/Types.cs
  30. 6
      Interface/App.config
  31. 8
      Interface/App.xaml
  32. 17
      Interface/App.xaml.cs
  33. 120
      Interface/Interface.csproj
  34. 11
      Interface/MainWindow.xaml
  35. 31
      Interface/MainWindow.xaml.cs
  36. 55
      Interface/Properties/AssemblyInfo.cs
  37. 71
      Interface/Properties/Resources.Designer.cs
  38. 117
      Interface/Properties/Resources.resx
  39. 30
      Interface/Properties/Settings.Designer.cs
  40. 7
      Interface/Properties/Settings.settings
  41. 123
      Interface/ViewModels/MainViewModel.cs
  42. 57
      Interface/ViewModels/ViewModelBase.cs

26
Bot.cs

@ -1,26 +0,0 @@ @@ -1,26 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Combot
{
class Bot
{
public event Action<BotError> ErrorEvent;
public Config Config;
public IRCService IRCService;
internal Bot()
{
IRCService = new IRCService(this);
Message msg = new Message();
Nick nick = new Nick();
msg.Sender = nick;
}
}
}

BIN
Bot.ico

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

17
Combot.sln

@ -3,7 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00 @@ -3,7 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Combot", "Combot.csproj", "{23E4C371-16E4-4FAC-8B11-44288399BB55}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Interface", "Interface\Interface.csproj", "{AE4AFD7A-CAA4-46A0-9E00-2B3D53F8D0AB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Combot", "Combot\Combot.csproj", "{23E4C371-16E4-4FAC-8B11-44288399BB55}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IRCServices", "IRCServices\IRCServices.csproj", "{65FCBF1C-8C9E-4688-BECC-185D9030899F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -11,12 +15,23 @@ Global @@ -11,12 +15,23 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AE4AFD7A-CAA4-46A0-9E00-2B3D53F8D0AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AE4AFD7A-CAA4-46A0-9E00-2B3D53F8D0AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE4AFD7A-CAA4-46A0-9E00-2B3D53F8D0AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE4AFD7A-CAA4-46A0-9E00-2B3D53F8D0AB}.Release|Any CPU.Build.0 = Release|Any CPU
{23E4C371-16E4-4FAC-8B11-44288399BB55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{23E4C371-16E4-4FAC-8B11-44288399BB55}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23E4C371-16E4-4FAC-8B11-44288399BB55}.Release|Any CPU.ActiveCfg = Release|Any CPU
{23E4C371-16E4-4FAC-8B11-44288399BB55}.Release|Any CPU.Build.0 = Release|Any CPU
{65FCBF1C-8C9E-4688-BECC-185D9030899F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{65FCBF1C-8C9E-4688-BECC-185D9030899F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{65FCBF1C-8C9E-4688-BECC-185D9030899F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{65FCBF1C-8C9E-4688-BECC-185D9030899F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
EndGlobal

64
Combot/Bot.cs

@ -0,0 +1,64 @@ @@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Threading.Tasks;
using Combot.IRCServices;
namespace Combot
{
public class Bot
{
public event Action<BotError> ErrorEvent;
public Config Config;
public IRC IRC;
public bool Connected = false;
public Bot()
{
Config = new Config();
IRC = new IRC();
IRC.DisconnectEvent += HandleDisconnectEvent;
}
public bool Connect()
{
int i = 0;
do
{
if (Config.Server.Hosts.Count > i)
{
Connected = IRC.Connect(Config.Server.Hosts[i].Address, Config.Server.Hosts[i].Port, 5000);
i++;
}
else
{
break;
}
}
while (!Connected);
return Connected;
}
public bool Disconnect()
{
IRC.Disconnect();
Connected = false;
return Connected;
}
public void Login()
{
IRC.Login(Config.Server.Name, new Nick() { Nickname = Config.Nick, Host = Dns.GetHostName(), Realname = Config.Realname });
}
private void HandleDisconnectEvent()
{
Connected = false;
}
}
}

20
Combot.csproj → Combot/Combot.csproj

@ -39,24 +39,22 @@ @@ -39,24 +39,22 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Access.cs" />
<Compile Include="Bot.cs" />
<Compile Include="Config.cs" />
<Compile Include="IRC\Channel.cs" />
<Compile Include="IRC\IRCMethods.cs" />
<Compile Include="IRC\Nick.cs" />
<Compile Include="IRC\IRCService.cs" />
<Compile Include="IRC\IRCTypes.cs" />
<Compile Include="IRC\IRCMessages.cs" />
<Compile Include="Types.cs" />
<Compile Include="Methods.cs" />
<Compile Include="Module.cs" />
<Compile Include="Modules\Module.cs" />
<Compile Include="Properties.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TCP\TCPInterface.cs" />
<Compile Include="TCP\TCPTypes.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Modules\" />
<ProjectReference Include="..\IRCServices\IRCServices.csproj">
<Project>{65fcbf1c-8c9e-4688-becc-185d9030899f}</Project>
<Name>IRCServices</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Service References\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

26
Config.cs → Combot/Config.cs

@ -7,44 +7,44 @@ using System.Net; @@ -7,44 +7,44 @@ using System.Net;
namespace Combot
{
class Config
public class Config
{
private string _name;
public string Name
private Server _server;
public Server Server
{
get
{
return _name;
return _server;
}
set
{
if (value != _name)
if (value != _server)
{
_name = value;
_server = value;
}
}
}
private IPEndPoint _host;
public IPEndPoint Host
private string _realname;
public string Realname
{
get
{
return _host;
return _realname;
}
set
{
if (value != _host)
if (value != _realname)
{
_host = value;
_realname = value;
}
}
}
private Nick _nick;
public Nick Nick
private string _nick;
public string Nick
{
get
{

0
Methods.cs → Combot/Methods.cs

4
Module.cs → Combot/Modules/Module.cs

@ -4,9 +4,9 @@ using System.Linq; @@ -4,9 +4,9 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Combot
namespace Combot.Modules
{
class Module
public class Module
{
internal virtual void Initialize() { }
}

2
Properties.cs → Combot/Properties.cs

@ -6,7 +6,7 @@ using System.Threading.Tasks; @@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Combot
{
class Properties
public class Properties
{
}
}

4
Properties/AssemblyInfo.cs → Combot/Properties/AssemblyInfo.cs

@ -6,9 +6,9 @@ using System.Runtime.InteropServices; @@ -6,9 +6,9 @@ using System.Runtime.InteropServices;
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Combot")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("The friendly IRC Bot")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("Teknik")]
[assembly: AssemblyProduct("Combot")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]

42
Combot/Types.cs

@ -0,0 +1,42 @@ @@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Net;
namespace Combot
{
public enum ErrorType
{
Bot = 0,
TCP = 1,
IRC = 2,
Framework = 3
}
public enum MessageType
{
Service = 0,
Channel = 1,
Query = 2,
Notice = 3,
CTCP = 4
}
public class BotError
{
public ErrorType Type { get; set; }
public string Message { get; set; }
}
public class Server
{
public string Name { get; set; }
public List<IPEndPoint> Hosts { get; set; }
public List<string> Channels { get; set; }
public bool AutoConnect { get; set; }
}
}

93
IRC/Channel.cs

@ -1,93 +0,0 @@ @@ -1,93 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Combot
{
public class Channel
{
public string Name { get; set; }
public string Topic { get; set; }
public string Key { get; set; }
public bool AutoJoin { get; set; }
public DateTime Registration { get; set; }
public List<ChannelMode> Modes { get; set; }
public List<Nick> Nicks { get; set; }
public Channel()
{
Name = string.Empty;
Topic = string.Empty;
Key = string.Empty;
AutoJoin = false;
Registration = DateTime.Now;
Modes = new List<ChannelMode>();
Nicks = new List<Nick>();
}
public Channel(string name, string topic, string key, bool autojoin, DateTime registration, List<ChannelMode> modes, List<Nick> nicks)
{
Name = name;
Topic = topic;
Key = key;
AutoJoin = autojoin;
Registration = registration;
Modes = modes;
Nicks = nicks;
}
public void AddNick(Nick nick)
{
Nicks.Add(nick);
}
public void AddNicks(List<Nick> nicks)
{
Nicks.AddRange(nicks);
}
public void RemoveNick(Nick nick)
{
if (Nicks.Contains(nick))
{
Nicks.Remove(nick);
}
}
public void RemoveNicks(List<Nick> nicks)
{
foreach (Nick nick in nicks)
{
RemoveNick(nick);
}
}
public void AddMode(ChannelMode mode)
{
Modes.Add(mode);
}
public void AddModes(List<ChannelMode> modes)
{
Modes.AddRange(modes);
}
public void RemoveMode(ChannelMode mode)
{
if (Modes.Contains(mode))
{
Modes.Remove(mode);
}
}
public void RemoveModes(List<ChannelMode> modes)
{
foreach (ChannelMode mode in modes)
{
RemoveMode(mode);
}
}
}
}

24
IRC/IRCMessages.cs

@ -1,24 +0,0 @@ @@ -1,24 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Combot
{
internal partial class IRCService
{
public event Action<Message> MessageReceivedEvent;
internal void ParseTCPMessage(string message)
{
Message parsedMessage = new Message();
Action<Message> localEvent = MessageReceivedEvent;
if (localEvent != null)
{
localEvent(parsedMessage);
}
}
}
}

1155
IRC/IRCMethods.cs

File diff suppressed because it is too large Load Diff

85
IRC/IRCService.cs

@ -1,85 +0,0 @@ @@ -1,85 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Net;
namespace Combot
{
internal partial class IRCService
{
protected Bot _Bot;
protected TCPInterface _TCP;
protected Thread TCPReader;
protected event Action<string> TCPMessageEvent;
internal IRCService(Bot bot)
{
_Bot = bot;
_TCP = new TCPInterface();
TCPMessageEvent += ParseTCPMessage;
}
internal bool Connect(IPAddress IP, int port, int readTimeout, int allowedFailedCount = 0)
{
bool result = false;
if (!_TCP.Connected)
{
result = _TCP.Connect(IP, port, readTimeout, allowedFailedCount);
if (result)
{
TCPReader = new Thread(ReadTCPMessages);
TCPReader.IsBackground = true;
TCPReader.Start();
}
}
return result;
}
internal bool Disconnect()
{
bool result = false;
if (_TCP.Connected)
{
_TCP.Disconnect();
}
return result;
}
protected void ReadTCPMessages()
{
while (_TCP.Connected)
{
string response = ReadTCPMessage();
if (TCPMessageEvent != null && response != null && response != string.Empty)
{
TCPMessageEvent(response);
}
Thread.Sleep(10);
}
}
protected string ReadTCPMessage()
{
if (_TCP.Connected)
{
return _TCP.Read();
}
return null;
}
protected void SendTCPMessage(string message)
{
if (_TCP.Connected)
{
_TCP.Write(message);
}
}
}
}

379
IRC/IRCTypes.cs

@ -1,379 +0,0 @@ @@ -1,379 +0,0 @@
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Net;
namespace Combot
{
public enum ErrorType
{
Bot = 0,
TCP = 1,
IRC = 2,
Framework = 3
}
public enum MessageType
{
Service = 0,
Channel = 1,
Query = 2,
Notice = 3,
CTCP = 4
}
public class ChannelModeInfo
{
public ChannelMode Mode { get; set; }
public bool Set { get; set; }
public string Parameter { get; set; }
}
public class UserModeInfo
{
public UserMode Mode { get; set; }
public bool Set { get; set; }
public string Parameter { get; set; }
}
public enum ChannelMode
{
[Description("Admin")]
a,
[Description("Admin Only")]
A,
[Description("Ban")]
b,
[Description("Colourless")]
c,
[Description("No CTCP")]
C,
[Description("Ban Exempt")]
e,
[Description("Flood Protection")]
f,
[Description("HalfOp")]
h,
[Description("Invite Only")]
i,
[Description("Invite Exempt")]
I,
[Description("Join Throttling")]
j,
[Description("Key")]
k,
[Description("No KNOCK")]
K,
[Description("Limit")]
l,
[Description("Link")]
L,
[Description("Moderated")]
m,
[Description("Registered Nicks May Talk")]
M,
[Description("No External Messages")]
n,
[Description("No Nickname Changes")]
N,
[Description("Operator")]
o,
[Description("Oper Only")]
O,
[Description("Private")]
p,
[Description("Owner")]
q,
[Description("No Kicks Allowed")]
Q,
[Description("Registered")]
r,
[Description("Registered Only")]
R,
[Description("Secret")]
s,
[Description("Strip Mirc Colors")]
S,
[Description("+hoaq Only Topic Change")]
t,
[Description("No Notices")]
T,
[Description("Auditorium")]
u,
[Description("Voice")]
v,
[Description("No Invite")]
V,
[Description("Secure Only")]
z
}
public enum UserMode
{
[Description("Service Administrator")]
a,
[Description("Service Administrator")]
A,
[Description("Bot")]
B,
[Description("Connection Notice")]
c,
[Description("C-oAdministrator")]
C,
[Description("Deaf")]
d,
[Description("View 'Eyes' Server Messages")]
e,
[Description("Flood Alerts")]
f,
[Description("Remote Server Connection Notice")]
F,
[Description("GlobOp and LocOp Messages")]
g,
[Description("Censored")]
G,
[Description("Helpful")]
h,
[Description("Hide IRCop Status")]
H,
[Description("Invisible")]
i,
[Description("Junk Messages")]
j,
[Description("Kill Messages")]
k,
[Description("Nick Change Notice")]
n,
[Description("Network Administrator")]
N,
[Description("Global Operator")]
o,
[Description("Local Operator")]
O,
[Description("Hide All Channels")]
p,
[Description("U:Lines Only")]
q,
[Description("Registered")]
r,
[Description("Registered Messages Only")]
R,
[Description("Server Notices")]
s,
[Description("Services Only")]
S,
[Description("VHost")]
t,
[Description("No CTCP")]
T,
[Description("Receive Bad DCC")]
v,
[Description("WebTV User")]
V,
[Description("Wallops")]
w,
[Description("Whois Notice")]
W,
[Description("Hidden Hostname")]
x,
[Description("Secure Connection")]
z
}
public enum ServerStat
{
[Description("List of Servers that allow Server Connection")]
c,
[Description("List of Server Hubs")]
h,
[Description("List of Hosts that allow Client Connection")]
i,
[Description("List of banned user/hostname of Server")]
k,
[Description("Lists Server Connections")]
l,
[Description("Commands Supported")]
m,
[Description("Lists Hosts that allow Normal Operators")]
o,
[Description("List Class lines from Server Config")]
y,
[Description("Server Uptime")]
u
}
public class BotError
{
public ErrorType Type { get; set; }
public string Message { get; set; }
}
public class Server
{
public string Name { get; set; }
public List<IPEndPoint> Hosts { get; set; }
public List<Channel> Channels { get; set; }
public bool AutoConnect { get; set; }
public Nick Nick { get; set; }
}
public class Message
{
public Server Server { get; set; }
public Channel Channel { get; set; }
public Nick Sender { get; set; }
public Nick Recipient { get; set; }
public string Parameters { get; set; }
}
// IRC Reply Codes //
public enum IRCReplyCode
{
RPL_WELCOME = 1,
RPL_YOURHOST = 2,
RPL_CREATED = 3,
RPL_MYINFO = 4,
RPL_BOUNCE = 5,
RPL_TRACELINK = 200,
RPL_TRACECONNECTING = 201,
RPL_TRACEHANDSHAKE = 202,
RPL_TRACEUNKNOWN = 203,
RPL_TRACEOPERATOR = 204,
RPL_TRACEUSER = 205,
RPL_TRACESERVER = 206,
RPL_TRACESERVICE = 207,
RPL_TRACENEWTYPE = 208,
RPL_TRACECLASS = 209,
RPL_TRACERECONNECT = 210,
RPL_STATSLINKINFO = 211,
RPL_STATSCOMMANDS = 212,
RPL_ENDOFSTATS = 219,
RPL_UMODEIS = 221,
RPL_SERVLIST = 234,
RPL_SERVLISTEND = 235,
RPL_STATSUPTIME = 242,
RPL_STATSOLINE = 243,
RPL_LUSERCLIENT = 251,
RPL_LUSEROP = 252,
RPL_LUSERUNKNOWN = 253,
RPL_LUSERCHANNELS = 254,
RPL_LUSERME = 255,
RPL_ADMINME = 256,
RPL_ADMINLOC1 = 257,
RPL_ADMINLOC2 = 258,
RPL_ADMINEMAIL = 259,
RPL_TRACELOG = 261,
RPL_TRACEEND = 262,
RPL_TRYAGAIN = 263,
RPL_AWAY = 301,
RPL_USERHOST = 302,
RPL_ISON = 303,
RPL_UNAWAY = 305,
RPL_NOWAWAY = 306,
RPL_WHOISUSER = 311,
RPL_WHOISSERVER = 312,
RPL_WHOISOPERATOR = 313,
RPL_WHOWASUSER = 314,
RPL_ENDOFWHO = 315,
RPL_WHOISIDLE = 317,
RPL_ENDOFWHOIS = 318,
RPL_WHOISCHANNELS = 319,
RPL_LISTSTART = 321,
RPL_LIST = 322,
RPL_LISTEND = 323,
RPL_CHANNELMODEIS = 324,
RPL_UNIQOPIS = 325,
RPL_NOTOPIC = 331,
RPL_TOPIC = 332,
RPL_INVITING = 341,
RPL_SUMMONING = 342,
RPL_INVITELIST = 346,
RPL_ENDOFINVITELIST = 347,
RPL_EXCEPTLIST = 348,
RPL_ENDOFEXCEPTLIST = 349,
RPL_VERSION = 351,
RPL_WHOREPLY = 352,
RPL_NAMREPLY = 353,
RPL_LINKS = 364,
RPL_ENDOFLINKS = 365,
RPL_ENDOFNAMES = 366,
RPL_BANLIST = 367,
RPL_ENDOFBANLIST = 368,
RPL_ENDOFWHOWAS = 369,
RPL_INFO = 371,
RPL_MOTD = 372,
RPL_ENDOFINFO = 374,
RPL_MOTDSTART = 375,
RPL_ENDOFMOTD = 376,
RPL_YOUREOPER = 381,
RPL_REHASHING = 382,
RPL_YOURESERVICE = 383,
RPL_TIME = 391,
RPL_USERSSTART = 392,
RPL_USERS = 393,
RPL_ENDOFUSERS = 394,
RPL_NOUSERS = 395
}
// IRC Error Codes //
public enum IRCErrorCode
{
ERR_NOSUCHNICK = 401,
ERR_NOSUCHSERVER = 402,
ERR_NOSUCHCHANNEL = 403,
ERR_CANNOTSENDTOCHAN = 404,
ERR_TOOMANYCHANNELS = 405,
ERR_WASNOSUCHNICK = 406,
ERR_TOOMANYTARGETS = 407,
ERR_NOSUCHSERVICE = 408,
ERR_NOORIGIN = 409,
ERR_NORECIPIENT = 411,
ERR_NOTEXTTOSEND = 412,
ERR_NOTOPLEVEL = 413,
ERR_WILDTOPLEVEL = 414,
ERR_BADMASK = 415,
ERR_UNKNOWNCOMMAND = 421,
ERR_NOMOTD = 422,
ERR_NOADMININFO = 423,
ERR_FILEERROR = 424,
ERR_NONICKNAMEGIVEN = 431,
ERR_ERRONEUSNICKNAME = 432,
ERR_NICKNAMEINUSE = 433,
ERR_NICKCOLLISION = 436,
ERR_UNAVAILRESOURCE = 437,
ERR_USERNOTINCHANNEL = 441,
ERR_NOTONCHANNEL = 442,
ERR_USERONCHANNEL = 443,
ERR_NOLOGIN = 444,
ERR_SUMMONDISABLED = 445,
ERR_USERSDISABLED = 446,
ERR_NOTREGISTERED = 451,
ERR_NEEDMOREPARAMS = 461,
ERR_ALREADYREGISTRED = 462,
ERR_NOPERMFORHOST = 463,
ERR_PASSWDMISMATCH = 464,
ERR_YOUREBANNEDCREEP = 465,
ERR_YOUWILLBEBANNED = 466,
ERR_KEYSET = 467,
ERR_CHANNELISFULL = 471,
ERR_UNKNOWNMODE = 472,
ERR_INVITEONLYCHAN = 473,
ERR_BANNEDFROMCHAN = 474,
ERR_BADCHANNELKEY = 475,
ERR_BADCHANMASK = 476,
ERR_NOCHANMODES = 477,
ERR_BANLISTFULL = 478,
ERR_NOPRIVILEGES = 481,
ERR_CHANOPRIVSNEEDED = 482,
ERR_CANTKILLSERVER = 483,
ERR_RESTRICTED = 484,
ERR_UNIQOPPRIVSNEEDED = 485,
ERR_NOOPERHOST = 491,
ERR_UMODEUNKNOWNFLAG = 501,
ERR_USERSDONTMATCH = 502
}
}

2
Access.cs → IRCServices/AccessControl/Access.cs

@ -4,7 +4,7 @@ using System.Linq; @@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Combot
namespace Combot.IRCServices.AccessControl
{
class Access
{

138
IRCServices/Channel.cs

@ -0,0 +1,138 @@ @@ -0,0 +1,138 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Combot.IRCServices
{
public class Channel
{
public string Name { get; set; }
public string Topic { get; set; }
public string Key { get; set; }
public bool AutoJoin { get; set; }
public bool Joined { get; set; }
public DateTime Registration { get; set; }
public List<ChannelMode> Modes { get; set; }
public List<Nick> Nicks { get; set; }
private IRC _IRC;
public Channel(IRC irc)
{
Name = string.Empty;
Topic = string.Empty;
Key = string.Empty;
AutoJoin = false;
Joined = false;
Registration = DateTime.Now;
Modes = new List<ChannelMode>();
Nicks = new List<Nick>();
_IRC = irc;
}
public void AddNick(Nick nick)
{
Nicks.Add(nick);
}
public void AddNicks(List<Nick> nicks)
{
Nicks.AddRange(nicks);
}
public void RemoveNick(Nick nick)
{
if (Nicks.Contains(nick))
{
Nicks.Remove(nick);
}
}
public void RemoveNicks(List<Nick> nicks)
{
foreach (Nick nick in nicks)
{
RemoveNick(nick);
}
}
public void AddMode(ChannelMode mode)
{
if (!Modes.Contains(mode))
{
ChannelModeInfo modeInfo = new ChannelModeInfo();
modeInfo.Mode = mode;
modeInfo.Set = true;
_IRC.IRCSendMode(Name, modeInfo);
Modes.Add(mode);
}
}
public void AddModes(List<ChannelMode> modes)
{
if (!modes.TrueForAll(mode => Modes.Contains(mode)))
{
List<ChannelModeInfo> modeInfos = new List<ChannelModeInfo>();
modes.ForEach(mode => modeInfos.Add(new ChannelModeInfo() { Mode = mode, Set = true }));
_IRC.IRCSendMode(Name, modeInfos);
Modes.AddRange(modes);
}
}
public void RemoveMode(ChannelMode mode)
{
if (Modes.Contains(mode))
{
ChannelModeInfo modeInfo = new ChannelModeInfo();
modeInfo.Mode = mode;
modeInfo.Set = false;
_IRC.IRCSendMode(Name, modeInfo);
Modes.Remove(mode);
}
}
public void RemoveModes(List<ChannelMode> modes)
{
List<ChannelMode> validModes = Modes.FindAll(mode => mode == modes.Find(m => m == mode));
List<ChannelModeInfo> modeInfos = new List<ChannelModeInfo>();
validModes.ForEach(mode => modeInfos.Add(new ChannelModeInfo() { Mode = mode, Set = true }));
validModes.ForEach(mode => Modes.Remove(mode));
_IRC.IRCSendMode(Name, modeInfos);
}
public void Join()
{
if (!Joined)
{
_IRC.IRCSendJoin(Name, Key);
Joined = true;
}
}
public void Part()
{
if (Joined)
{
_IRC.IRCSendPart(Name);
Joined = false;
}
}
public void SetTopic(string topic)
{
if (Joined)
{
_IRC.IRCSendTopic(Name, topic);
}
}
public string GetTopic()
{
return string.Empty;
}
}
}

115
IRCServices/IRC.cs

@ -0,0 +1,115 @@ @@ -0,0 +1,115 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Net;
using Combot.IRCServices.Messaging;
using Combot.IRCServices.TCP;
namespace Combot.IRCServices
{
public partial class IRC
{
public bool Connected;
public List<Channel> Channels = new List<Channel>();
public Messages Message;
public event Action DisconnectEvent;
private TCPInterface _TCP;
private Thread TCPReader;
private event Action<string> TCPMessageEvent;
public IRC()
{
Connected = false;
_TCP = new TCPInterface();
Message = new Messages(this);
TCPMessageEvent += Message.ParseTCPMessage;
Message.ErrorMessageEvent += HandleErrorMessage;
Message.PingEvent += HandlePing;
}
public bool Connect(IPAddress IP, int port, int readTimeout = 5000, int allowedFailedCount = 0)
{
bool result = false;
if (!_TCP.Connected)
{
result = _TCP.Connect(IP, port, readTimeout, allowedFailedCount);
if (result)
{
TCPReader = new Thread(ReadTCPMessages);
TCPReader.IsBackground = true;
TCPReader.Start();
}
}
return result;
}
public bool Disconnect()
{
bool result = false;
if (_TCP.Connected)
{
_TCP.Disconnect();
}
if (DisconnectEvent != null)
{
DisconnectEvent();
}
return result;
}
public void Login(string serverName, Nick nick)
{
IRCSendNick(nick.Nickname);
IRCSendUser(nick.Nickname, nick.Host, serverName, nick.Realname);
}
private void ReadTCPMessages()
{
while (_TCP.Connected)
{
string response = ReadTCPMessage();
if (TCPMessageEvent != null && response != null && response != string.Empty)
{
TCPMessageEvent(response);
}
Thread.Sleep(10);
}
}
private string ReadTCPMessage()
{
if (_TCP.Connected)
{
return _TCP.Read();
}
return null;
}
private void SendTCPMessage(string message)
{
if (_TCP.Connected)
{
_TCP.Write(message);
}
}
private void HandleErrorMessage(object sender, IRCServices.Messaging.ErrorMessage e)
{
Disconnect();
}
private void HandlePing(object sender, IRCServices.Messaging.PingInfo e)
{
IRCSendPong(e.Message);
}
}
}

63
IRCServices/IRCServices.csproj

@ -0,0 +1,63 @@ @@ -0,0 +1,63 @@
<?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>{65FCBF1C-8C9E-4688-BECC-185D9030899F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>IRCServices</RootNamespace>
<AssemblyName>IRCServices</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\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\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="AccessControl\Access.cs" />
<Compile Include="Channel.cs" />
<Compile Include="IRC.cs" />
<Compile Include="Messaging\GetReply.cs" />
<Compile Include="Messaging\Messages.cs" />
<Compile Include="Messaging\MessageTypes.cs" />
<Compile Include="Methods.cs" />
<Compile Include="Nick.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TCP\TCPInterface.cs" />
<Compile Include="TCP\TCPTypes.cs" />
<Compile Include="Types.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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>

18
IRCServices/Messaging/GetReply.cs

@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Combot.IRCServices.Messaging
{
public class GetReply
{
public bool Reattach = true;
public bool Result = false;
public ManualResetEventSlim Ready = new ManualResetEventSlim(false);
public List<IRCReplyCode> Replies = new List<IRCReplyCode>();
public List<IRCErrorCode> Errors = new List<IRCErrorCode>();
}
}

267
IRCServices/Messaging/MessageTypes.cs

@ -0,0 +1,267 @@ @@ -0,0 +1,267 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Combot.IRCServices.Messaging
{
abstract public class IMessage : EventArgs
{
public DateTime TimeStamp { get; set; }
}
abstract public class IReply : IMessage
{
public string Message { get; set; }
}
public class ServerReplyMessage : IReply
{
public IRCReplyCode ReplyCode { get; set; }
}
public class ServerErrorMessage : IReply
{
public IRCErrorCode ErrorCode { get; set; }
}
public class ErrorMessage : IMessage
{
public string Message { get; set; }
}
public class ChannelMessage : IMessage
{
public Channel Channel { get; set; }
public Nick Sender { get; set; }
public string Message { get; set; }
}
public class PrivateMessage : IMessage
{
public Nick Sender { get; set; }
public string Message { get; set; }
}
public class ServerNotice : IMessage
{
public string Message { get; set; }
}
public class ChannelNotice : IMessage
{
public Channel Channel { get; set; }
public Nick Sender { get; set; }
public string Message { get; set; }
}
public class PrivateNotice : IMessage
{
public Nick Sender { get; set; }
public string Message { get; set; }
}
public class TopicChangeInfo : IMessage
{
public Channel Channel { get; set; }
public Nick Nick { get; set; }
public string Topic { get; set; }
}
public class ChannelModeChangeInfo : IMessage
{
public Channel Channel { get; set; }
public Nick Nick { get; set; }
public List<ChannelModeInfo> Modes { get; set; }
}
public class UserModeChangeInfo : IMessage
{
public Nick Nick { get; set; }
public List<UserModeInfo> Modes { get; set; }
}
public class JoinChannelInfo : IMessage
{
public Channel Channel { get; set; }
public Nick Nick { get; set; }
}
public class PartChannelInfo : IMessage
{
public Channel Channel { get; set; }
public Nick Nick { get; set; }
}
public class KickInfo : IMessage
{
public Channel Channel { get; set; }
public Nick Nick { get; set; }
public Nick KickedNick { get; set; }
public string Reason { get; set; }
}
public class QuitInfo : IMessage
{
public Nick Nick { get; set; }
public string Message { get; set; }
}
public class PingInfo : IMessage
{
public string Message { get; set; }
}
public class PongInfo : IMessage
{
public string Message { get; set; }
}
// IRC Reply Codes //
public enum IRCReplyCode
{
RPL_WELCOME = 1,
RPL_YOURHOST = 2,
RPL_CREATED = 3,
RPL_MYINFO = 4,
RPL_BOUNCE = 5,
RPL_TRACELINK = 200,
RPL_TRACECONNECTING = 201,
RPL_TRACEHANDSHAKE = 202,
RPL_TRACEUNKNOWN = 203,
RPL_TRACEOPERATOR = 204,
RPL_TRACEUSER = 205,
RPL_TRACESERVER = 206,
RPL_TRACESERVICE = 207,
RPL_TRACENEWTYPE = 208,
RPL_TRACECLASS = 209,
RPL_TRACERECONNECT = 210,
RPL_STATSLINKINFO = 211,
RPL_STATSCOMMANDS = 212,
RPL_ENDOFSTATS = 219,
RPL_UMODEIS = 221,
RPL_SERVLIST = 234,
RPL_SERVLISTEND = 235,
RPL_STATSUPTIME = 242,
RPL_STATSOLINE = 243,
RPL_LUSERCLIENT = 251,
RPL_LUSEROP = 252,
RPL_LUSERUNKNOWN = 253,
RPL_LUSERCHANNELS = 254,
RPL_LUSERME = 255,
RPL_ADMINME = 256,
RPL_ADMINLOC1 = 257,
RPL_ADMINLOC2 = 258,
RPL_ADMINEMAIL = 259,
RPL_TRACELOG = 261,
RPL_TRACEEND = 262,
RPL_TRYAGAIN = 263,
RPL_AWAY = 301,
RPL_USERHOST = 302,
RPL_ISON = 303,
RPL_UNAWAY = 305,
RPL_NOWAWAY = 306,
RPL_WHOISUSER = 311,
RPL_WHOISSERVER = 312,
RPL_WHOISOPERATOR = 313,
RPL_WHOWASUSER = 314,
RPL_ENDOFWHO = 315,
RPL_WHOISIDLE = 317,
RPL_ENDOFWHOIS = 318,
RPL_WHOISCHANNELS = 319,
RPL_LISTSTART = 321,
RPL_LIST = 322,
RPL_LISTEND = 323,
RPL_CHANNELMODEIS = 324,
RPL_UNIQOPIS = 325,
RPL_NOTOPIC = 331,
RPL_TOPIC = 332,
RPL_INVITING = 341,
RPL_SUMMONING = 342,
RPL_INVITELIST = 346,
RPL_ENDOFINVITELIST = 347,
RPL_EXCEPTLIST = 348,
RPL_ENDOFEXCEPTLIST = 349,
RPL_VERSION = 351,
RPL_WHOREPLY = 352,
RPL_NAMREPLY = 353,
RPL_LINKS = 364,
RPL_ENDOFLINKS = 365,
RPL_ENDOFNAMES = 366,
RPL_BANLIST = 367,
RPL_ENDOFBANLIST = 368,
RPL_ENDOFWHOWAS = 369,
RPL_INFO = 371,
RPL_MOTD = 372,
RPL_ENDOFINFO = 374,
RPL_MOTDSTART = 375,
RPL_ENDOFMOTD = 376,
RPL_YOUREOPER = 381,
RPL_REHASHING = 382,
RPL_YOURESERVICE = 383,
RPL_TIME = 391,
RPL_USERSSTART = 392,
RPL_USERS = 393,
RPL_ENDOFUSERS = 394,
RPL_NOUSERS = 395
}
// IRC Error Codes //
public enum IRCErrorCode
{
ERR_NOSUCHNICK = 401,
ERR_NOSUCHSERVER = 402,
ERR_NOSUCHCHANNEL = 403,
ERR_CANNOTSENDTOCHAN = 404,
ERR_TOOMANYCHANNELS = 405,
ERR_WASNOSUCHNICK = 406,
ERR_TOOMANYTARGETS = 407,
ERR_NOSUCHSERVICE = 408,
ERR_NOORIGIN = 409,
ERR_NORECIPIENT = 411,
ERR_NOTEXTTOSEND = 412,
ERR_NOTOPLEVEL = 413,
ERR_WILDTOPLEVEL = 414,
ERR_BADMASK = 415,
ERR_UNKNOWNCOMMAND = 421,
ERR_NOMOTD = 422,
ERR_NOADMININFO = 423,
ERR_FILEERROR = 424,
ERR_NONICKNAMEGIVEN = 431,
ERR_ERRONEUSNICKNAME = 432,
ERR_NICKNAMEINUSE = 433,
ERR_NICKCOLLISION = 436,
ERR_UNAVAILRESOURCE = 437,
ERR_USERNOTINCHANNEL = 441,
ERR_NOTONCHANNEL = 442,
ERR_USERONCHANNEL = 443,
ERR_NOLOGIN = 444,
ERR_SUMMONDISABLED = 445,
ERR_USERSDISABLED = 446,
ERR_NOTREGISTERED = 451,
ERR_NEEDMOREPARAMS = 461,
ERR_ALREADYREGISTRED = 462,
ERR_NOPERMFORHOST = 463,
ERR_PASSWDMISMATCH = 464,
ERR_YOUREBANNEDCREEP = 465,
ERR_YOUWILLBEBANNED = 466,
ERR_KEYSET = 467,
ERR_CHANNELISFULL = 471,
ERR_UNKNOWNMODE = 472,
ERR_INVITEONLYCHAN = 473,
ERR_BANNEDFROMCHAN = 474,
ERR_BADCHANNELKEY = 475,
ERR_BADCHANMASK = 476,
ERR_NOCHANMODES = 477,
ERR_BANLISTFULL = 478,
ERR_NOPRIVILEGES = 481,
ERR_CHANOPRIVSNEEDED = 482,
ERR_CANTKILLSERVER = 483,
ERR_RESTRICTED = 484,
ERR_UNIQOPPRIVSNEEDED = 485,
ERR_NOOPERHOST = 491,
ERR_UMODEUNKNOWNFLAG = 501,
ERR_USERSDONTMATCH = 502
}
}

398
IRCServices/Messaging/Messages.cs

@ -0,0 +1,398 @@ @@ -0,0 +1,398 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Combot.IRCServices.Messaging
{
public class Messages
{
public event EventHandler<IReply> ServerReplyEvent;
public event EventHandler<ErrorMessage> ErrorMessageEvent;
public event EventHandler<ChannelMessage> ChannelMessageReceivedEvent;
public