IRC AutoIT Console


SUBMITTED BY: Guest

DATE: May 28, 2013, 5:39 p.m.

FORMAT: Text only

SIZE: 5.9 kB

HITS: 1366

  1. #include "TCP.au3"
  2. $hServer = _TCP_Server_Create(6667); A IRC server. Tadaa!
  3. Global $GLOBAL_hSocket, $connected, $motd = False, $username
  4. AdlibRegister("pingpong", 60000)
  5. AdlibRegister("sendmodt", 1000)
  6. _TCP_RegisterEvent($hServer, $TCP_NEWCLIENT, "NewClient")
  7. _TCP_RegisterEvent($hServer, $TCP_DISCONNECT, "Disconnect")
  8. _TCP_RegisterEvent($hServer, $TCP_RECEIVE, "Received")
  9. While 1
  10. WEnd
  11. Func NewClient($hSocket, $iError)
  12. ConsoleWrite("New Client: " & $hSocket & @CRLF)
  13. $connected = True
  14. $motd = True
  15. $GLOBAL_hSocket = $hSocket
  16. EndFunc ;==>NewClient
  17. Func Disconnect($hSocket, $iError)
  18. ConsoleWrite("!Disconnect: " & $hSocket & @CRLF)
  19. $connected = False
  20. $GLOBAL_hSocket = False
  21. EndFunc ;==>Disconnect
  22. Func Received($hSocket, $sReceived, $iError)
  23. Local $msg = StringSplit($sReceived, @LF)
  24. For $i = 0 To UBound($msg) - 1 Step 1
  25. rcv_msg($hSocket, $msg[$i], $iError)
  26. Next
  27. EndFunc ;==>Received
  28. Func rcv_msg($hSocket, $msg, $iError)
  29. ConsoleWrite("+receive:" & $msg & @CRLF)
  30. If StringLeft($msg, 4) = "ping" Then ircsend($hSocket, StringReplace($msg, "ping", "pong") & @CRLF)
  31. If StringLeft($msg, 4) = "NICK" Then $username = StringTrimLeft($msg, 5)
  32. If StringLeft($msg, 17) = "PRIVMSG #autoit :" Then
  33. ircsend($hSocket, ":root!root PRIVMSG #autoit :" & StringTrimLeft($msg, 17) & @CRLF)
  34. commands(StringTrimLeft($msg, 17))
  35. EndIf
  36. EndFunc ;==>rcv_msg
  37. Func pingpong()
  38. If $connected Then ircsend($GLOBAL_hSocket, "PING :" & Random(1000, 9999, 1) & @CRLF)
  39. EndFunc ;==>pingpong
  40. Func sendmodt()
  41. If $motd Then
  42. For $i = 1 To 1
  43. ircsend($GLOBAL_hSocket, ":localhost 001 " & $username & " :Welcome to the AutoIT Internet Relay Chat Network " & $username & "" & @CRLF)
  44. ircsend($GLOBAL_hSocket, ":localhost 002 " & $username & " :Your host is localhost[localhost/6667], running version AutoIT-Console v0.1" & @CRLF)
  45. ircsend($GLOBAL_hSocket, ":localhost 375 " & $username & " :- localhost Message of the Day -" & @CRLF)
  46. ircsend($GLOBAL_hSocket, ":localhost 372 " & $username & " :- Welcome to AutoIT - The Open and Free Management System" & @CRLF)
  47. ircsend($GLOBAL_hSocket, ":localhost 376 " & $username & " :End of /MOTD command." & @CRLF)
  48. ircsend($GLOBAL_hSocket, ":" & $username & "!" & $username & " JOIN :#autoit" & @CRLF)
  49. ircsend($GLOBAL_hSocket, ":localhost 332 " & $username & " #autoit :Welcome to the AutoIT Console v0.1" & @CRLF)
  50. ircsend($GLOBAL_hSocket, ":localhost 353 " & $username & " @ #autoit :root " & $username & "" & @CRLF)
  51. ircsend($GLOBAL_hSocket, "366 " & $username & " #bitlbee :End of /NAMES list." & @CRLF)
  52. ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :Hi" & $username & @CRLF)
  53. Next
  54. EndIf
  55. $motd = False
  56. EndFunc ;==>sendmodt
  57. Func ircsend($GLOBAL_hSocket, $msg)
  58. ConsoleWrite("-output :" & $msg)
  59. TCPSend($GLOBAL_hSocket, $msg)
  60. EndFunc ;==>ircsend
  61. Func commands($command)
  62. Switch $command
  63. Case "status"
  64. ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :+--------------------------------------------------------------+" & @CRLF)
  65. ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :|----------------------------STATUS----------------------------|" & @CRLF)
  66. ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :+--------------------------------------------------------------+" & @CRLF)
  67. ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :" & padmsg("Computername: " & @ComputerName) & @CRLF)
  68. ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :" & padmsg("IPAdress1: " & @IPAddress1) & @CRLF)
  69. ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :" & padmsg("Username: " & @UserName) & @CRLF)
  70. ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :+--------------------------------------------------------------+" & @CRLF)
  71. Case "help"
  72. ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :+--------------------------------------------------------------+" & @CRLF)
  73. ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :|-----------------------------HELP-----------------------------|" & @CRLF)
  74. ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :+--------------------------------------------------------------+" & @CRLF)
  75. ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :" & padmsg("List of commands that can be issued against root") & @CRLF)
  76. ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :+--------------------------------------------------------------+" & @CRLF)
  77. ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :" & padmsg("help you are looking at it") & @CRLF)
  78. ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :" & padmsg("status shows the current status of the server") & @CRLF)
  79. ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :+--------------------------------------------------------------+" & @CRLF)
  80. Case Else
  81. ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :command unknown, try help" & @CRLF)
  82. EndSwitch
  83. EndFunc ;==>commands
  84. Func padmsg($msg)
  85. Local $len = StringLen($msg)
  86. Local $res = "| "
  87. $res &= $msg
  88. For $i = $len To 60
  89. $res &= " "
  90. Next
  91. $res &= "|"
  92. Return $res
  93. EndFunc ;==>padmsg

comments powered by Disqus