document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. Imports Globals
  2. Imports Globals.GlobalResources
  3. Imports System.Security.Cryptography
  4. Imports System.IO
  5. Imports System.Text
  6. Imports System.Net.NetworkInformation
  7. Public Class Main
  8.     Private WithEvents ConsoleUpdateTimer As New Timer
  9.     Private Sub Main_ClientSizeChanged(sender As Object, e As EventArgs) Handles Me.ClientSizeChanged
  10.         For Each ctrl As Control In Output.Controls
  11.             ctrl.MaximumSize = New Size(Output.Width - 24, 9999)
  12.         Next
  13.         If Output.Controls.Count > 0 Then _
  14.             Output.ScrollControlIntoView(Output.Controls(Output.Controls.Count - 1))
  15.     End Sub
  16.     Private Sub Main_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
  17.         CloseAllResources()
  18.     End Sub
  19.     Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  20.         SharedResources.Add(New Resource("Main"))
  21.         SharedResources(0).Resources.Add(New ResourceElement("Received Messages", "RecvMsgs", New List(Of String))) \'0,0
  22.         SharedResources(0).Resources.Add(New ResourceElement("To Send Messages", "SndMsgs", New List(Of String))) \'0,1
  23.         SharedResources(0).Resources.Add(New ResourceElement("Plugins", "Plugins", New List(Of Plgn))) \'0,2
  24.         SharedResources(0).Resources.Add(New ResourceElement("Plugin Manager", "PlgnMngr", New PluginManager)) \'0,3
  25.         SharedResources(0).Resources.Add(New ResourceElement("IRC Client", "IRCclient", New Client)) \'0,4
  26.         SharedResources(0).Resources.Add(New ResourceElement("Configuration", "ConfigLocation", New String(My.Application.Info.DirectoryPath & "\\config.ini"))) \'0,5
  27.         SharedResources(0).Resources.Add(New ResourceElement("Console Messages", "Output", New List(Of String))) \'0,6
  28.         SharedResources(0).Resources.Add(New ResourceElement("GlobalChan", "Chan", "")) \'0,7
  29.         If System.IO.File.Exists(SharedResources(0).Resources(5).Value.ToString) Then
  30.             Dim ConfigReader As New StreamReader(SharedResources(0).Resources(5).Value.ToString)
  31.             While ConfigReader.Peek <> -1
  32.                 Dim line As String = ConfigReader.ReadLine.Trim
  33.                 If line.StartsWith("Owner:") Then
  34.                     OwnerTxt.Text = line.Remove(0, 6).Trim
  35.                 ElseIf line.StartsWith("OAuth:") Then
  36.                     PassTxt.Text = Encryption.decryptString(line.Remove(0, 6).Trim)
  37.                 ElseIf line.StartsWith("Nick:") Then
  38.                     NickTxt.Text = line.Remove(0, 5).Trim
  39.                 ElseIf line.StartsWith("Channel:") Then
  40.                     ChannelTxt.Text = line.Remove(0, 8).Trim
  41.                 ElseIf line.StartsWith("Server:") Then
  42.                     ServerTxt.Text = line.Remove(0, 7).Trim
  43.                 ElseIf line.StartsWith("Port:") Then
  44.                     PortTxt.Text = line.Remove(0, 5).Trim
  45.                 ElseIf line.StartsWith("JMsg:") Then
  46.                     JoinMsgTxt.Text = line.Remove(0, 5).Trim
  47.                 End If
  48.             End While
  49.             ConfigReader.Close()
  50.             ConfigReader.Dispose()
  51.         End If
  52.         ConsoleUpdateTimer.Interval = 1
  53.         UpdatePluginsList()
  54.     End Sub
  55.     Public Sub UpdatePluginsList()
  56.         SyncLock SharedResources(0).Resources(2).Value
  57.             For Each plgn As Plgn In SharedResources(0).Resources(2).Value
  58.                 Me.PlgnList.Items.Add(plgn.Name)
  59.             Next
  60.         End SyncLock
  61.     End Sub
  62.     Private Sub ConnectBtn_Click(sender As Object, e As EventArgs) Handles ConnectBtn.Click
  63.         If sender.Text = "Connect" Then
  64.             sender.Enabled = False
  65.             Dim ready As Boolean = True
  66.             If IsNumeric(PortTxt.Text) = False OrElse _
  67.                 CInt(PortTxt.Text) < 0 OrElse _
  68.                 CInt(PortTxt.Text) > 65535 Then
  69.                 PortTxt.BackColor = Color.Red
  70.                 ready = False
  71.                 sender.Enabled = True
  72.                 Output.Focus()
  73.             End If
  74.             For Each ctrl As Control In SetupArea.Controls
  75.                 If ctrl.GetType() Is GetType(TextBox) Then
  76.                     If ctrl.Text = String.Empty And Not ctrl.Name = "JoinMsgTxt" Then
  77.                         ctrl.BackColor = Color.Red
  78.                         ready = False
  79.                         sender.Enabled = True
  80.                         Output.Focus()
  81.                     End If
  82.                 End If
  83.             Next
  84.             If ready Then
  85.                 For Each ctrl As Control In SetupArea.Controls
  86.                     If ctrl.GetType() Is GetType(TextBox) Then ctrl.Enabled = False
  87.                 Next
  88.                 If Not ChannelTxt.Text.StartsWith("#") Then ChannelTxt.Text = "#" & ChannelTxt.Text
  89.                 If StartConnectionClient(ServerTxt.Text, PortTxt.Text, NickTxt.Text, ChannelTxt.Text, PassTxt.Text, JoinMsgTxt.Text) Then
  90.                     SetCurrentChan(ChannelTxt.Text)
  91.                     SaveInfo()
  92.                     SendTxt.Text = String.Empty
  93.                     SendTxt.Enabled = True
  94.                     ConsoleUpdateTimer.Start()
  95.                     StartPluginManager(OwnerTxt.Text, ServerTxt.Text, NickTxt.Text)
  96.                     sender.Text = "Disconnect"
  97.                     sender.Enabled = True
  98.                     Output.Focus()
  99.                 Else
  100.                     MessageBox.Show("Connection could not be established with current settings", "Check your settings", MessageBoxButtons.OK, MessageBoxIcon.Information)
  101.                     CloseAllResources()
  102.                 End If
  103.             End If
  104.         Else
  105.             CloseAllResources()
  106.         End If
  107.     End Sub
  108.     Private Sub SaveInfo()
  109.         Dim Saver As New StreamWriter(SharedResources(0).Resources(5).Value.ToString, False)
  110.         Saver.WriteLine("Owner:" & OwnerTxt.Text.Trim.ToLower)
  111.         Saver.WriteLine("OAuth:" & Encryption.encryptString(PassTxt.Text.Trim))
  112.         Saver.WriteLine("Nick:" & NickTxt.Text.Trim.ToLower)
  113.         Saver.WriteLine("Channel:" & ChannelTxt.Text.Trim.ToLower)
  114.         Saver.WriteLine("Server:" & ServerTxt.Text.Trim)
  115.         Saver.WriteLine("Port:" & PortTxt.Text.Trim)
  116.         Saver.WriteLine("JMsg:" & JoinMsgTxt.Text.Trim)
  117.         Saver.Close()
  118.         Saver.Dispose()
  119.     End Sub
  120.     Private Sub CloseAllResources()
  121.         On Error Resume Next
  122.         StopPluginManager()
  123.         StopConnectionClient()
  124.         ConsoleUpdateTimer.Stop()
  125.         For Each ctrl As Control In SetupArea.Controls
  126.             If ctrl.GetType() Is GetType(TextBox) Then ctrl.Enabled = Enabled
  127.         Next
  128.         SendTxt.Text = " Send: <Connect first>"
  129.         SendTxt.Enabled = False
  130.         ConnectBtn.Text = "Connect"
  131.         ConnectBtn.Enabled = True
  132.         System.GC.Collect()
  133.     End Sub
  134.     Private Sub ConsoleUpdateTimer_Tick(sender As Object, e As EventArgs) Handles ConsoleUpdateTimer.Tick
  135.         Dim CrntConsole As String = GetConsoleMsg()
  136.         If Not CrntConsole = String.Empty Then
  137.             Output.Controls.Add(New AutoLabel(CrntConsole))
  138.             Output.Controls.Add(New AutoLabel(" "))
  139.         End If
  140.     End Sub
  141.     Private Sub SendTxt_KeyDown(sender As Object, e As KeyEventArgs) Handles SendTxt.KeyDown
  142.         If e.KeyCode = Keys.Return Then
  143.             If Not sender.text.trim = "" Then
  144.                 AddToSend("PRIVMSG " & ChannelTxt.Text & " :" & SendTxt.Text.Trim)
  145.             End If
  146.             e.SuppressKeyPress = True
  147.             SendTxt.Text = String.Empty
  148.         End If
  149.     End Sub
  150.     Private Sub JoinMsgTxt_TextChanged(sender As TextBox, e As EventArgs) Handles JoinMsgTxt.TextChanged
  151.         If JoinMsgTxt.Text.Contains(vbCrLf) Then
  152.             sender.Text = sender.Text.Replace(vbCrLf, " ")
  153.             sender.Select(sender.Text.Length, 0)
  154.         End If
  155.     End Sub
  156.     Private Sub OwnerTxt_TextChanged(sender As TextBox, e As EventArgs) Handles _
  157.     OwnerTxt.TextChanged, _
  158.     PassTxt.TextChanged, _
  159.     NickTxt.TextChanged, _
  160.     ChannelTxt.TextChanged, _
  161.     ServerTxt.TextChanged, _
  162.     PortTxt.TextChanged
  163.         If sender.BackColor = Color.Red Then sender.BackColor = Color.White
  164.     End Sub
  165.     Private Sub Output_ControlAdded(sender As Object, e As ControlEventArgs) Handles Output.ControlAdded
  166.         Output.ScrollControlIntoView(e.Control)
  167.         While Output.Controls.Count > 100
  168.             Output.Controls.RemoveAt(0)
  169.         End While
  170.     End Sub
  171.     Private Sub Output_ControlRemoved(sender As Object, e As ControlEventArgs) Handles Output.ControlRemoved
  172.         Output.ScrollControlIntoView(Output.Controls(Output.Controls.Count - 1))
  173.     End Sub
  174.     Private Sub PlgnList_DrawItem(sender As Object, e As DrawItemEventArgs) Handles PlgnList.DrawItem
  175.         e.DrawBackground()
  176.         If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
  177.             e.Graphics.FillRectangle(Brushes.White, e.Bounds)
  178.         End If
  179.         Using b As New SolidBrush(Color.Black)
  180.             e.Graphics.DrawString(PlgnList.GetItemText(PlgnList.Items(e.Index)), e.Font, b, e.Bounds)
  181.         End Using
  182.         e.DrawFocusRectangle()
  183.     End Sub
  184.     Private Sub PlgnList_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles PlgnList.MouseDoubleClick
  185.         On Error Resume Next
  186.         SyncLock SharedResources(0).Resources(2).Value
  187.             SharedResources(0).Resources(2).Value(PlgnList.SelectedIndex).config()
  188.         End SyncLock
  189.     End Sub
  190.     Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
  191.         Process.Start("http://www.twitchapps.com/tmi/")
  192.     End Sub
  193.     Private Sub Output_MouseClick(sender As Object, e As MouseEventArgs) Handles Output.MouseClick
  194.         sender.focus()
  195.     End Sub
  196. End Class
  197.  
  198. Module Encryption
  199.     Private key As String = NetworkInterface.GetAllNetworkInterfaces(0).GetPhysicalAddress.ToString
  200.     Public Function encryptString(ByVal strtext As String) As String
  201.         Return Encrypt(strtext, key)
  202.     End Function
  203.     Public Function decryptString(ByVal strtext As String) As String
  204.         Return Decrypt(strtext, key)
  205.     End Function
  206.     Private Function Encrypt(ByVal strText As String, ByVal strEncrKey As String) As String
  207.         Dim byKey() As Byte = {}
  208.         Dim IV() As Byte = {&H12, &H34, &H56, &H78, &H90, &HAB, &HCD, &HEF}
  209.         Try
  210.             byKey = System.Text.Encoding.UTF8.GetBytes(Left(strEncrKey, 8))
  211.             Dim des As New DESCryptoServiceProvider()
  212.             Dim inputByteArray() As Byte = Encoding.UTF8.GetBytes(strText)
  213.             Dim ms As New MemoryStream()
  214.             Dim cs As New CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write)
  215.             cs.Write(inputByteArray, 0, inputByteArray.Length)
  216.             cs.FlushFinalBlock()
  217.             Return Convert.ToBase64String(ms.ToArray())
  218.         Catch ex As Exception
  219.             Return ex.Message
  220.         End Try
  221.     End Function
  222.     Private Function Decrypt(ByVal strText As String, ByVal sDecrKey As String) As String
  223.         Dim byKey() As Byte = {}
  224.         Dim IV() As Byte = {&H12, &H34, &H56, &H78, &H90, &HAB, &HCD, &HEF}
  225.         Dim inputByteArray(strText.Length) As Byte
  226.         Try
  227.             byKey = System.Text.Encoding.UTF8.GetBytes(Left(sDecrKey, 8))
  228.             Dim des As New DESCryptoServiceProvider()
  229.             inputByteArray = Convert.FromBase64String(strText)
  230.             Dim ms As New MemoryStream()
  231.             Dim cs As New CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write)
  232.             cs.Write(inputByteArray, 0, inputByteArray.Length)
  233.             cs.FlushFinalBlock()
  234.             Dim encoding As System.Text.Encoding = System.Text.Encoding.UTF8
  235.             Return encoding.GetString(ms.ToArray())
  236.         Catch ex As Exception
  237.             Return ex.Message
  238.         End Try
  239.     End Function
  240. End Module
  241.  
  242. Imports System.Net.Sockets
  243. Imports System.Text
  244. Imports System.Net
  245. Imports Globals.GlobalResources
  246. Public Class Client
  247.     Private _Server, _Port, _Nick, _Channel, _Pass, _Jmsg As String
  248.     Private ClientThread As Threading.Thread
  249.     Private EP As IPEndPoint
  250.     Private Connection As Socket
  251.     Private WithEvents SendingTimer As Timer
  252.     Public Function StartConnection(ByVal Server As String, ByVal Port As String, ByVal Nick As String, ByVal Channel As String, ByVal Pass As String, ByVal JoinMsg As String) As Boolean
  253.         _Server = Server
  254.         _Port = Port
  255.         _Nick = Nick.Trim.ToLower
  256.         _Channel = Channel
  257.         _Pass = Pass
  258.         _Jmsg = JoinMsg
  259.         Try
  260.             EP = New IPEndPoint(Dns.GetHostEntry(_Server).AddressList(0), _Port)
  261.             Connection = New Socket(EP.Address.AddressFamily, Net.Sockets.SocketType.Stream, Net.Sockets.ProtocolType.Tcp)
  262.             Connection.Connect(_Server, _Port)
  263.             Send("PASS " & _Pass, False) : Send("NICK " & _Nick) : Send("JOIN " & _Channel)
  264.             Send("PRIVMSG " & _Channel & " :" & _Jmsg)
  265.         Catch ex As Exception
  266.             Return False
  267.         End Try
  268.         ClientThread = New Threading.Thread(AddressOf Connect)
  269.         ClientThread.Start()
  270.         SendingTimer = New Timer
  271.         SendingTimer.Interval = 1500
  272.         SendingTimer.Start()
  273.         Return True
  274.     End Function
  275.     Public Function ConnectionStatus() As Boolean
  276.         Try
  277.             SyncLock Connection
  278.                 Return Connection.Connected
  279.             End SyncLock
  280.         Catch ex As Exception
  281.             Return False
  282.         End Try
  283.     End Function
  284.     Public Sub Close()
  285.         On Error Resume Next
  286.         SyncLock Connection
  287.             Connection.Disconnect(False)
  288.             Connection.Close()
  289.         End SyncLock
  290.     End Sub
  291.     Private Sub Connect()
  292.         Dim link As Boolean = True
  293.         Do While link
  294.             recv()
  295.             SyncLock Connection
  296.                 link = Connection.Connected
  297.             End SyncLock
  298.         Loop
  299.         MsgBox("Disconnected") \'add actual disconnect handling
  300.     End Sub
  301.     Public Sub Send(ByVal msg As String, Optional ByVal show As Boolean = True)
  302.         msg = msg.Trim
  303.         Dim data() As Byte = ASCIIEncoding.ASCII.GetBytes(msg & vbCrLf)
  304.         SyncLock Connection
  305.             Connection.Send(data, data.Length, SocketFlags.None)
  306.         End SyncLock
  307.         If show Then AddToConsole(msg)
  308.     End Sub
  309.     Private Sub recv()
  310.         On Error Resume Next
  311.         Dim data(511) As Byte
  312.         Connection.Receive(data, 512, SocketFlags.None)
  313.         Dim mail As String = System.Text.ASCIIEncoding.ASCII.GetString(data)
  314.         mail = mail.TrimEnd(Chr(0)).Remove(mail.LastIndexOf(vbLf), 1).Remove(mail.LastIndexOf(vbCr), 1)
  315.         AddToConsole(mail.Trim)
  316.         If mail.StartsWith("PING") Then
  317.             Dim pserv As String = mail.Substring(mail.IndexOf(" "), mail.Length - mail.IndexOf(" ")).TrimEnd(Chr(0))
  318.             Send("PONG" & pserv)
  319.         End If
  320.         AddToRecv(mail.Trim)
  321.     End Sub
  322.     Private Sub SendingTimer_Tick(sender As Object, e As EventArgs) Handles SendingTimer.Tick
  323.         Dim meh As String = GetToSend()
  324.         If Not meh = String.Empty Then Send(meh)
  325.     End Sub
  326. End Class
  327.  
  328. Imports Globals
  329. Imports Globals.GlobalResources
  330. Imports System.Reflection
  331. Public Class PluginManager
  332.     Private Running As Boolean = False
  333.     Private workingthread As Threading.Thread
  334.     Private _Owner, _Server, _BotNick, _Chan, Crnt As String
  335.     Public Sub New()
  336.         SyncLock SharedResources(0).Resources(2).Value
  337.             PluginLoader.LoadPlugins(Of Plgn)(SharedResources(0).Resources(2).Value, My.Application.Info.DirectoryPath & "\\Plugins\\", "Globals.Plgn")
  338.         End SyncLock
  339.     End Sub
  340.     Public Sub Start(ByVal Owner As String, ByVal Server As String, ByVal BotNick As String)
  341.         _Owner = Owner : _Server = Server : _BotNick = BotNick
  342.         Running = True
  343.         workingthread = New Threading.Thread(AddressOf work)
  344.         workingthread.Start()
  345.     End Sub
  346.     Public Sub Close()
  347.         Running = False
  348.     End Sub
  349.     Public Sub work()
  350.         While Running
  351.             Crnt = GetRecvMsg()
  352.             If Crnt IsNot String.Empty Then
  353.                 Dim ProcdMsg As Message
  354.                 ProcdMsg = New Message(Crnt, _Owner, _Server, _BotNick)
  355.                 HandleMessage(ProcdMsg)
  356.             End If
  357.             Threading.Thread.Sleep(1)
  358.         End While
  359.     End Sub
  360.     Public Sub HandleMessage(ByRef inputMsg As Message)
  361.         SyncLock SharedResources(0).Resources(2).Value
  362.             For Each plugin As Globals.Plgn In SharedResources(0).Resources(2).Value
  363.                 If plugin.ProcessMessage(inputMsg) Then Exit For
  364.             Next
  365.         End SyncLock
  366.     End Sub
  367. End Class
  368.  
  369. Module PluginLoader
  370.     Public Sub LoadPlugins(Of PlugType)(ByRef PluginList As ICollection(Of PlugType), ByRef LocationOfPlugins As String, ByVal InterfaceName As String)
  371.         PluginList.Clear()
  372.         Dim Plugin_DLLs As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = FileIO.FileSystem.GetFiles(LocationOfPlugins, FileIO.SearchOption.SearchTopLevelOnly, "*.dll")
  373.         Dim assemblyObj As Reflection.Assembly
  374.         Dim aDescAttr As AssemblyDescriptionAttribute
  375.         Dim aTitleAttr As AssemblyTitleAttribute
  376.         For Each PluginDLL As String In Plugin_DLLs
  377.             assemblyObj = Reflection.Assembly.LoadFrom(PluginDLL)
  378.             For Each t As Type In assemblyObj.GetTypes
  379.                 If t.IsPublic Then
  380.                     For Each ThisParticularType As Type In t.GetInterfaces
  381.                         Try
  382.                             If ThisParticularType.FullName = InterfaceName Then
  383.                                 PluginList.Add(CType(assemblyObj.CreateInstance(t.FullName, True), PlugType))
  384.                                 aDescAttr = CType(AssemblyDescriptionAttribute.GetCustomAttribute(assemblyObj, GetType(AssemblyDescriptionAttribute)), AssemblyDescriptionAttribute)
  385.                                 aTitleAttr = CType(AssemblyTitleAttribute.GetCustomAttribute(assemblyObj, GetType(AssemblyTitleAttribute)), AssemblyTitleAttribute)
  386.                             End If
  387.                         Catch e As Exception
  388.                         End Try
  389.                     Next
  390.                 End If
  391.             Next
  392.         Next
  393.     End Sub
  394. End Module
');