#include "TCP.au3"
$hServer = _TCP_Server_Create(6667); A IRC server. Tadaa!
Global $GLOBAL_hSocket, $connected, $motd = False, $username
AdlibRegister("pingpong", 60000)
AdlibRegister("sendmodt", 1000)
_TCP_RegisterEvent($hServer, $TCP_NEWCLIENT, "NewClient")
_TCP_RegisterEvent($hServer, $TCP_DISCONNECT, "Disconnect")
_TCP_RegisterEvent($hServer, $TCP_RECEIVE, "Received")
While 1
WEnd
Func NewClient($hSocket, $iError)
ConsoleWrite("New Client: " & $hSocket & @CRLF)
$connected = True
$motd = True
$GLOBAL_hSocket = $hSocket
EndFunc ;==>NewClient
Func Disconnect($hSocket, $iError)
ConsoleWrite("!Disconnect: " & $hSocket & @CRLF)
$connected = False
$GLOBAL_hSocket = False
EndFunc ;==>Disconnect
Func Received($hSocket, $sReceived, $iError)
Local $msg = StringSplit($sReceived, @LF)
For $i = 0 To UBound($msg) - 1 Step 1
rcv_msg($hSocket, $msg[$i], $iError)
Next
EndFunc ;==>Received
Func rcv_msg($hSocket, $msg, $iError)
ConsoleWrite("+receive:" & $msg & @CRLF)
If StringLeft($msg, 4) = "ping" Then ircsend($hSocket, StringReplace($msg, "ping", "pong") & @CRLF)
If StringLeft($msg, 4) = "NICK" Then $username = StringTrimLeft($msg, 5)
If StringLeft($msg, 17) = "PRIVMSG #autoit :" Then
ircsend($hSocket, ":root!root PRIVMSG #autoit :" & StringTrimLeft($msg, 17) & @CRLF)
commands(StringTrimLeft($msg, 17))
EndIf
EndFunc ;==>rcv_msg
Func pingpong()
If $connected Then ircsend($GLOBAL_hSocket, "PING :" & Random(1000, 9999, 1) & @CRLF)
EndFunc ;==>pingpong
Func sendmodt()
If $motd Then
For $i = 1 To 1
ircsend($GLOBAL_hSocket, ":localhost 001 " & $username & " :Welcome to the AutoIT Internet Relay Chat Network " & $username & "" & @CRLF)
ircsend($GLOBAL_hSocket, ":localhost 002 " & $username & " :Your host is localhost[localhost/6667], running version AutoIT-Console v0.1" & @CRLF)
ircsend($GLOBAL_hSocket, ":localhost 375 " & $username & " :- localhost Message of the Day -" & @CRLF)
ircsend($GLOBAL_hSocket, ":localhost 372 " & $username & " :- Welcome to AutoIT - The Open and Free Management System" & @CRLF)
ircsend($GLOBAL_hSocket, ":localhost 376 " & $username & " :End of /MOTD command." & @CRLF)
ircsend($GLOBAL_hSocket, ":" & $username & "!" & $username & " JOIN :#autoit" & @CRLF)
ircsend($GLOBAL_hSocket, ":localhost 332 " & $username & " #autoit :Welcome to the AutoIT Console v0.1" & @CRLF)
ircsend($GLOBAL_hSocket, ":localhost 353 " & $username & " @ #autoit :root " & $username & "" & @CRLF)
ircsend($GLOBAL_hSocket, "366 " & $username & " #bitlbee :End of /NAMES list." & @CRLF)
ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :Hi" & $username & @CRLF)
Next
EndIf
$motd = False
EndFunc ;==>sendmodt
Func ircsend($GLOBAL_hSocket, $msg)
ConsoleWrite("-output :" & $msg)
TCPSend($GLOBAL_hSocket, $msg)
EndFunc ;==>ircsend
Func commands($command)
Switch $command
Case "status"
ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :+--------------------------------------------------------------+" & @CRLF)
ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :|----------------------------STATUS----------------------------|" & @CRLF)
ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :+--------------------------------------------------------------+" & @CRLF)
ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :" & padmsg("Computername: " & @ComputerName) & @CRLF)
ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :" & padmsg("IPAdress1: " & @IPAddress1) & @CRLF)
ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :" & padmsg("Username: " & @UserName) & @CRLF)
ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :+--------------------------------------------------------------+" & @CRLF)
Case "help"
ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :+--------------------------------------------------------------+" & @CRLF)
ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :|-----------------------------HELP-----------------------------|" & @CRLF)
ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :+--------------------------------------------------------------+" & @CRLF)
ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :" & padmsg("List of commands that can be issued against root") & @CRLF)
ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :+--------------------------------------------------------------+" & @CRLF)
ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :" & padmsg("help you are looking at it") & @CRLF)
ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :" & padmsg("status shows the current status of the server") & @CRLF)
ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :+--------------------------------------------------------------+" & @CRLF)
Case Else
ircsend($GLOBAL_hSocket, ":root!root PRIVMSG #autoit :command unknown, try help" & @CRLF)
EndSwitch
EndFunc ;==>commands
Func padmsg($msg)
Local $len = StringLen($msg)
Local $res = "| "
$res &= $msg
For $i = $len To 60
$res &= " "
Next
$res &= "|"
Return $res
EndFunc ;==>padmsg