rcmaehl

IRC2EMU

Feb 19th, 2014
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 7.95 KB | None | 0 0
  1. ;===============================================================================
  2. ;I've stopped developing for the night. Please check back in ~8-12 hours - Currently: 1AM GMT-5
  3. ;===============================================================================
  4.  
  5. ;IRC BOT Coding
  6. ;No Rights Reserved
  7. ;No Copyright
  8. ;Requires Windows XP SP3+, AutoIt (If compiling from source).
  9. ;Estimated Compile Size: 3MB
  10. ;Please give mention to me (rcmaehl) though :D
  11.  
  12. ; Changes since last version:
  13. ; Fixed missing '
  14.  
  15. ; Todo
  16. ;Detect if PRIVMSG is coming from player or channel
  17. ;Add in support for disabling buttons
  18. ;Setup config file making/parsing for (Keys, Window Name to Send Keys to, IRC Server, IRC Channel, IRC Nick, IRC Port, Start Command Throttle)
  19. ;Add in parsing for other IRC error messages
  20. ;Add in democracy mode
  21.  
  22. ; Compatibility:
  23. ; GB - Yes
  24. ; GBC - Yes
  25. ; GBA - Yes
  26. ; DS - Missing X/Y button Support
  27.  
  28. TCPStartup()
  29.  
  30. ;IRC Config
  31. Global $server = "irc.systemnet.info"
  32. Global $Port = 6667
  33. Global $channel = "#bulbagarden"
  34. Global $Nick = "IRC2EMU"
  35. Global $Sock ;This will hold the socket
  36.  
  37. ;EMU config
  38. Global $Throttle = 2 ; 1 in $Throttle Chance of Start Button actually going through
  39. Global $Window = "Untitled" ; Temporarily Send Commands to Notepad
  40. Global $A = 'a'
  41. Global $B = 'b'
  42. Global $L = 'l'
  43. Global $R = 'r'
  44. Global $UP = '8'
  45. Global $DOWN = '2'
  46. Global $LEFT = '4'
  47. Global $RIGHT = '6'
  48. Global $START = '5'
  49. Global $SELECT = '0'
  50.  
  51. $Sock = _IRCConnect($server, $Port, $Nick)
  52.  
  53. While 1
  54.     $Recv = TCPRecv($Sock, 8192)
  55.     If Not $Recv Then ContinueLoop ;Nothing useful, check buffer again
  56.     $sData = StringSplit($Recv, @CRLF, 1) ;If the buffer has more than one packet in it, split the packets into an array so they can all be processed in the order they were recieved
  57.     For $i = 1 To $sData[0] ;Check through all packets if any were buffered
  58.         $sTemp = StringSplit($sData[$i], " ")
  59.         If $sTemp[1] = "PING" Then TCPSend($Sock, "PONG " & $sTemp[2] & @CRLF) ;Respond to PING requests from the server
  60.         If $sTemp[0] < 3 Then ContinueLoop ;Error handling
  61.         Switch $sTemp[2]
  62.             Case "PRIVMSG" ;Main message opcode
  63.                 $User = StringMid($sTemp[1], 2, StringInStr($sTemp[1], "!") - 2) ;Parse the sender's username
  64.                 $Message = StringMid($sData[$i], StringInStr($sData[$i], ":", 0, 2) + 1) ;Parse the sender's full message
  65.                 ConsoleWrite($User & " - " & $Message & @CRLF)
  66.                 Switch StringLower($Message) ;Message parsing test
  67.                     Case "a"
  68.                         WinActivate($Window)
  69.                         Send($A)
  70.                     Case "b"
  71.                         WinActivate($Window)
  72.                         Send($B)
  73.                     Case "l"
  74.                         WinActivate($Window)
  75.                         Send($L)
  76.                     Case "r"
  77.                         WinActivate($Window)
  78.                         Send($R)
  79.                     Case "up"
  80.                         WinActivate($Window)
  81.                         Send($UP)
  82.                     Case "down"
  83.                         WinActivate($Window)
  84.                         Send($DOWN)
  85.                     Case "left"
  86.                         WinActivate($Window)
  87.                         Send($LEFT)
  88.                     Case "right"
  89.                         WinActivate($Window)
  90.                         Send($RIGHT)
  91.                     Case "start"
  92.                             If Random(1, $Throttle, 1) = 1 Then
  93.                             WinActivate($Window)
  94.                             Send($START)
  95.                         EndIf
  96.                     Case "select"
  97.                             If Random(1, $Throttle, 1) = 1 Then
  98.                             WinActivate($Window)
  99.                             Send($SELECT)
  100.                         EndIf
  101.                 EndSwitch
  102.             Case "004"
  103.                 _IRCJoinChannel($Sock, $channel)
  104.                 _IRCChangeMode($Sock, "+i", $Nick)
  105.             Case "443"
  106.                 MsgBox(1, "irc.au3", "IRC username in use")
  107.             Case Else
  108.                 ConsoleWrite($sTemp[2] & " - " & $sData[$i] & @CRLF) ;Write all unhandled packets to STDOUT
  109.         EndSwitch
  110.     Next
  111. WEnd
  112.  
  113. ;===============================================================================
  114. ;
  115. ; Description:      Connects you to a IRC Server, and gives your chosen Nick
  116. ; Parameter(s):     $server - IRC Server you wish to connect to
  117. ;                   $port - Port to connect to (Usually 6667)
  118. ;                   $nick - Nick you choose to use (You can change later)
  119. ; Requirement(s):   TCPStartup () to be run
  120. ; Return Value(s):  On Success - Socket identifer
  121. ;                   On Failure - It will exit on error
  122. ; Author(s):        Chip
  123. ; Note(s):          English only
  124. ;
  125. ;===============================================================================
  126. Func _IRCConnect($server, $port, $nick)
  127.     Local $i = TCPConnect(TCPNameToIP($server), $port)
  128.     If $i = -1 Then Exit MsgBox(1, "irc.au3 Error", "Server " & $server & " is not responding.")
  129.     TCPSend($i, "NICK " & $nick & @CRLF)
  130.     TCPSend($i, "USER " & $nick & " 0 0 " & $nick & @CRLF)
  131.     Return $i
  132. EndFunc   ;==>_IRCConnect
  133.  
  134. ;===============================================================================
  135. ;
  136. ; Description:      Joins an IRC Channel
  137. ; Parameter(s):     $irc - Socket Identifer from _IRCConnect ()
  138. ;                   $chan - Channel you wish to join
  139. ; Requirement(s):   _IRCConnect () to be run
  140. ; Return Value(s):  On Success - 1
  141. ;                   On Failure - -1 = Server disconnected.
  142. ; Author(s):        Chip
  143. ; Note(s):          English only
  144. ;
  145. ;===============================================================================
  146. Func _IRCJoinChannel($irc, $chan)
  147.     If $irc = -1 Then Return 0
  148.     TCPSend($irc, "JOIN " & $chan & @CRLF)
  149.     If @error Then
  150.         MsgBox(1, "irc.au3", "Server has disconnected.")
  151.         Return -1
  152.     EndIf
  153.     Return 1
  154. EndFunc   ;==>_IRCJoinChannel
  155.  
  156. ;===============================================================================
  157. ;
  158. ; Description:      Sends a message using IRC
  159. ; Parameter(s):     $irc - Socket Identifer from _IRCConnect ()
  160. ;                   $msg - Message you want to send
  161. ;                   $chan - Channel/Nick you wish to send to
  162. ; Requirement(s):   _IRCConnect () to be run
  163. ; Return Value(s):  On Success - 1
  164. ;                   On Failure - -1 = Server disconnected.
  165. ; Author(s):        Chip
  166. ; Note(s):          English only
  167. ;
  168. ;===============================================================================
  169. Func _IRCSendMessage($irc, $msg, $chan = "")
  170.     If $irc = -1 Then Return 0
  171.     If $chan = "" Then
  172.         TCPSend($irc, $msg & @CRLF)
  173.         If @error Then
  174.             MsgBox(1, "irc.au3", "Server has disconnected.")
  175.             Return -1
  176.         EndIf
  177.         Return 1
  178.     EndIf
  179.     TCPSend($irc, "PRIVMSG " & $chan & " :" & $msg & @CRLF)
  180.     If @error Then
  181.         MsgBox(1, "irc.au3", "Server has disconnected.")
  182.         Return -1
  183.     EndIf
  184.     Return 1
  185. EndFunc   ;==>_IRCSendMessage
  186.  
  187. ;===============================================================================
  188. ;
  189. ; Description:      Changes a MODE on IRC
  190. ; Parameter(s):     $irc - Socket Identifer from _IRCConnect ()
  191. ;                   $mode - Mode you wish to change
  192. ;                   $chan - Channel/Nick you wish to send to
  193. ; Requirement(s):   _IRCConnect () to be run
  194. ; Return Value(s):  On Success - 1
  195. ;                   On Failure - -1 = Server disconnected.
  196. ; Author(s):        Chip
  197. ; Note(s):          English only
  198. ;
  199. ;===============================================================================
  200. Func _IRCChangeMode($irc, $mode, $chan = "")
  201.     If $irc = -1 Then Return 0
  202.     If $chan = "" Then
  203.         TCPSend($irc, "MODE " & $mode & @CRLF)
  204.         If @error Then
  205.             MsgBox(1, "irc.au3", "Server has disconnected.")
  206.             Return -1
  207.         EndIf
  208.         Return 1
  209.     EndIf
  210.     TCPSend($irc, "MODE " & $chan & " " & $mode & @CRLF)
  211.     If @error Then
  212.         MsgBox(1, "irc.au3", "Server has disconnected.")
  213.         Return -1
  214.     EndIf
  215.     Return 1
  216. EndFunc   ;==>_IRCChangeMode
  217.  
  218. ;===============================================================================
  219. ;
  220. ; Description:      Returns a PING to Server
  221. ; Parameter(s):     $irc - Socket Identifer from _IRCConnect ()
  222. ;                   $ret - The end of the PING to return
  223. ; Requirement(s):   _IRCConnect () to be run
  224. ; Return Value(s):  On Success - 1
  225. ;                   On Failure - -1 = Server disconnected.
  226. ; Author(s):        Chip
  227. ; Note(s):          English only
  228. ;
  229. ;===============================================================================
  230. Func _IRCPing($irc, $ret)
  231.     If $irc = -1 Then Return 0
  232.     If $ret = "" Then Return -1
  233.     TCPSend($irc, "PONG " & $ret & @CRLF)
  234.     If @error Then
  235.         MsgBox(1, "irc.au3", "Server has disconnected.")
  236.         Return -1
  237.     EndIf
  238.     Return 1
  239. EndFunc   ;==>_IRCPing
Advertisement
Add Comment
Please, Sign In to add comment