#NoTrayIcon #include #include #include ; ---- Variables ---- ; -- IRC Variables ;Global $addr = "82.96.64.4" ;irc.freenode.net Global $addr = "irc.freenode.net" Global $port = "6667" Global $channel = "#thesoftwarejedi" Global $nick = "version2" Global $nick_pw = "" ; -- App Variables Global $appname = "FooIRC Client" Global $appversion = "0.1.2" Global $iconpath = "images/icons/irc_online.ico" Global $connected = 0 Global $settingsfile = "settings.ini" ; -- Environment Variables Global $fontcolor = "000000" Global $backgroundcolor = "ffffff" ; -- Predefined Variables Global $sock = -1 ; Create settings file if it doesn't exist. If Not FileExists ($settingsfile) Then IniWrite($settingsfile, "App", "server", $addr) IniWrite($settingsfile, "App", "port", $port) IniWrite($settingsfile, "App", "channel", $channel) IniWrite($settingsfile, "Environment", "fontcolor", $fontcolor) IniWrite($settingsfile, "Environment", "backgroundcolor", $backgroundcolor) IniWrite($settingsfile, "Profile", "nick", $nick) IniWrite($settingsfile, "Profile", "password", $nick_pw) EndIf $addr = IniRead($settingsfile, "App", "server", $addr) $port = IniRead($settingsfile, "App", "port", $port) $channel = IniRead($settingsfile, "App", "channel", $channel) $fontcolor = IniRead($settingsfile, "Environment", "fontcolor", $fontcolor) $backgroundcolor = IniRead($settingsfile, "Environment", "backgroundcolor", $backgroundcolor) $nick = IniRead($settingsfile, "Profile", "nick", $nick) $nick_pw = IniRead($settingsfile, "Profile", "password", $nick_pw) ; ---- Set Script Options ---- Opt("GUIOnEventMode", 1) Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 1) AutoItSetOption("RunErrorsFatal", 0) Opt("TCPTimeout",100) ;in ms ; --- GUI $gui = GuiCreate($appname & " - " & $appversion, 500, 517) GUISetOnEvent($GUI_EVENT_CLOSE, "Quit") $serveroutput = GUICtrlCreateEdit("", 3, 25, 494, 466, $ES_READONLY+$WS_VSCROLL) GUICtrlSetBkColor($serveroutput, "0x" & $backgroundcolor) ; Set background color of output field GUICtrlSetColor($serveroutput, "0x" & $fontcolor) ; Set font color of output field $serverinput = GuiCtrlCreateInput("", 3, 494, 494, 20) GUICtrlSetState(-1, $GUI_FOCUS) $submit = GUICtrlCreateButton ("Submit", 500, 496, 60, 22, $BS_DEFPUSHBUTTON) GUICtrlSetOnEvent(-1, "Submit") GuiSetIcon(@ScriptDir & "/" & $iconpath, 0) GuiSetState() GUICtrlCreatePic("images/bmp/irc_channel.bmp",6,4, 0,0) GUICtrlSetOnEvent(-1, "QuickConnect") GUICtrlCreatePic("images/bmp/irc_profile.bmp",30,4, 0,0) GUICtrlSetOnEvent(-1, "Profile") GUICtrlCreatePic("images/bmp/color.bmp",54,4, 0,0) GUICtrlSetOnEvent(-1, "Colors") GUICtrlCreatePic("images/bmp/irc_settings.bmp",78,4, 0,0) GUICtrlSetOnEvent(-1, "Settings") GUICtrlCreatePic("images/bmp/exit.bmp",102,3, 0,0) GUICtrlSetOnEvent(-1, "Quit") TraySetState() TraySetToolTip($appname & " - Quate.net") TrayCreateItem("About") TrayItemSetOnEvent(-1, "AboutTray") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "Quit") TraySetIcon(@ScriptDir & "/" & $iconpath, "") TCPStartup() ;QuickConnect() While $connected = 0 Sleep(100) WEnd GuiCtrlSetData($serveroutput, "*** Attempting to connect to " & $addr & "" & @CRLF) $ip = TCPNameToIP($addr) $sock = TCPConnect($ip, $port) If @error Then ReportError("Could not connect to " & $addr & ":" & $port & ".") Exit EndIf $prev = GuiCtrlRead($serveroutput) GuiCtrlSetData($serveroutput, $prev & "*** Connected to " & $addr & "" & @CRLF) $loop = 0 While 1 $irc = TCPRecv($sock, 384) If @error Then ReportError("Could not recieve data from " & $addr & ":" & $port & ".") Exit EndIf If $irc <> "" Then ; Create a log of the raw data. Below uses two different log files. ; One displays the data & time, which can be useful sometimes. ; The other does not display the data & time, so that you can see exactly what was receieved without any problems. ; Eventually I will choose one and stick with it, probably the second one. _FileWriteLog(@ScriptDir & "\log_backup.txt", $irc) ; Analize data if StringinStr($irc,"/quote pong")Then $irc = $irc&"PONG " & StringMid($irc,StringInStr($irc,"/quote pong")+12,StringInStr($irc," or /raw")-StringInStr($irc,"/quote pong")-12)&@crlf&"JOIN "&$channel&@crlf IRC_Send("PONG " & StringMid($irc,StringInStr($irc,"/quote pong")+12,StringInStr($irc," or /raw")-StringInStr($irc,"/quote pong")-12)&@crlf&"JOIN "&$channel&@crlf) endif If StringinStr($irc, ":") Then $message1 = StringSplit ($irc, ":", 1) $irc1 = $message1[1] $irc2 = $message1[2] If StringinStr($irc1, "NOTICE AUTH ") Then $message = StringReplace($irc, "NOTICE AUTH :", "") $irc = $message ElseIf StringinStr($irc1, "PING ") OR StringinStr($irc, "VERSION") Then ; Do nothing. (just as long as it doesn't parse under PRIVMSG) ;MsgBox(0, $irc, $irc) $irc = "" ElseIf StringinStr($irc2, "PRIVMSG") AND StringinStr($irc2, "!") Then $message = StringSplit ($irc, "PRIVMSG " & $channel & " :", 1) $name_temp = StringSplit($irc, "!", 1) $name = StringReplace($name_temp[1], ":", "") $irc = "<" & $name & "> " & $message[2] ElseIf StringinStr($irc2, "QUIT") AND StringinStr($irc2, "!") Then $message = StringSplit ($irc, "QUIT :", 1) $name_temp = StringSplit($irc, "!", 1) $name = StringReplace($name_temp[1], ":", "") $irc = "*** " & $name & " left: " & $message[2] & @CRLF ElseIf StringinStr($irc2, "JOIN") AND StringinStr($irc2, "!") Then $message = StringSplit ($irc, "JOIN :"& $channel, 1) $name_temp = StringSplit($irc, "!", 1) $name = StringReplace($name_temp[1], ":", "") $irc = "*** " & $name & " joined" & @CRLF EndIf EndIf ;PRIVMSG #TheSoftwareJedi :ACTION $prev = GuiCtrlRead($serveroutput) guiCtrlSetData($serveroutput, $prev & $irc) _guiCtrlEdit_LineScroll($serveroutput, 0, 100000) EndIf If $loop = 1 Then IRC_Send("NICK " & $nick & @CRLF) If $nick_pw <> "" Then ;IRC_Send("/msg nickserv IDENTIFY " & $nick_pw & "" & @CRLF) IRC_Send("PRIVMSG NickServ IDENTIFY " & $nick_pw & "" & @CRLF) EndIf IRC_Send("USER " & $nick & " " & $addr & " " & $addr & " " & $appname & "" & @CRLF) IRC_Send("JOIN " & $channel & @CRLF) EndIf $loop += 1 WEnd ; ---- Functions ---- Func IRC_Send($Msg) Global $sock TCPSend($sock, $Msg) EndFunc Func Submit() IRC_Send("PRIVMSG " & $channel & " : " & GUICtrlRead($serverinput) & "" & @CRLF) $prev = GuiCtrlRead($serveroutput) GuiCtrlSetData($serveroutput, $prev & "<" & $nick & "> " & GUICtrlRead($serverinput) & "" & @CRLF) ; Clear input box. GuiCtrlSetData($serverinput, "") _GUICtrlEdit_LineScroll($serveroutput, 0, 100000) EndFunc Func ReportError($Msg) Opt("GUIOnEventMode", 0) GUICreate($appname & " Error", 260, 80) GuiSetIcon(@ScriptDir & "\" & $iconpath, 0) $Label = GuiCtrlCreateLabel($Msg, 10, 10, 240, 42) $OkayButton = GUICtrlCreateButton("OK", 90, 50, 72, 22, $BS_DEFPUSHBUTTON) GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then GUIDelete() ExitLoop Exit ElseIf $msg = $OkayButton Then GUIDelete() ExitLoop Exit EndIf WEnd GUIDelete() Opt("GUIOnEventMode", 1) EndFunc Func PromptGUI($Title, $Msg, $Default = "") Opt("GUIOnEventMode", 0) $parent_win_pos = WinGetPos("") $gui_prompt = GUICreate($Title, 260, 96, $parent_win_pos[0]+120, $parent_win_pos[1]+200) GuiSetIcon(@ScriptDir & "\" & $iconpath, 0) $Label = GuiCtrlCreateLabel($Msg, 10, 10, 240, 39) $OkayButton = GUICtrlCreateButton("OK", 30, 65, 72, 22, $BS_DEFPUSHBUTTON) $CancelButton = GUICtrlCreateButton("Cancel", 150, 65, 72, 22) $Input = GuiCtrlCreateInput($Default, 10, 40, 240, 20) GUICtrlSetState(-1, $GUI_FOCUS) GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then GUIDelete() ;TCPShutdown() ;Exit GUISetState($gui) GUISetState(@SW_SHOW) Opt("GUIOnEventMode", 1) Return "" ElseIf $msg = $CancelButton Then GUIDelete() ;TCPShutdown() ;Exit GUISetState($gui) GUISetState(@SW_SHOW) Opt("GUIOnEventMode", 1) Return "" ElseIf $msg = $OkayButton Then $Value = GUICtrlRead($Input) GUIDelete() GUISetState($gui) GUISetState(@SW_SHOW) Opt("GUIOnEventMode", 1) Return $Value EndIf WEnd GUIDelete() Opt("GUIOnEventMode", 1) EndFunc ; -- GUI/Tray Functions Func QuickConnect() $addr = PromptGUI("Connect to server", "Enter the server you wish to connect to.", $addr) If $addr = "" Then Return $addr EndIf IniWrite($settingsfile, "App", "server", $addr) $channel = PromptGUI("Connect to channel", "Enter the channel name to connect to.", $channel) If $channel = "" Then Return $channel EndIf IniWrite($settingsfile, "App", "channel", $channel) $connected = 1 EndFunc Func Profile() Opt("GUIOnEventMode", 0) $parent_win_pos = WinGetPos("") $gui_profile = GUICreate("User Profile", 200, 96, $parent_win_pos[0]+150, $parent_win_pos[1]+200) GuiSetIcon(@ScriptDir & "\" & $iconpath, 0) $OkayButton = GUICtrlCreateButton("OK", 20, 65, 72, 22, $BS_DEFPUSHBUTTON) ;GUICtrlSetState(-1, $GUI_FOCUS) $CancelButton = GUICtrlCreateButton("Cancel", 110, 65, 72, 22) $Label = GuiCtrlCreateLabel("User:", 10, 10, 90, 20) $Input = GuiCtrlCreateInput($nick, 90, 8, 100, 20) $Label2 = GuiCtrlCreateLabel("Password:", 10, 35, 90, 20) $Input2 = GuiCtrlCreateInput($nick_pw, 90, 32, 100, 20) GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then GUIDelete() GUISetState($gui) Opt("GUIOnEventMode", 1) Return "" ElseIf $msg = $CancelButton Then GUIDelete() GUISetState($gui) Opt("GUIOnEventMode", 1) Return "" ElseIf $msg = $OkayButton Then $nick = GUICtrlRead($Input) $nick_pw = GUICtrlRead($Input2) GUIDelete() GUISetState($gui) Opt("GUIOnEventMode", 1) ; Save settings. IniWrite($settingsfile, "Profile", "nick", $nick) IniWrite($settingsfile, "Profile", "password", $nick_pw) Return $nick EndIf WEnd EndFunc Func Colors() Opt("GUIOnEventMode", 0) $parent_win_pos = WinGetPos("") $gui_colors = GUICreate("Colors", 200, 96, $parent_win_pos[0]+150, $parent_win_pos[1]+200) GuiSetIcon(@ScriptDir & "\" & $iconpath, 0) $OkayButton = GUICtrlCreateButton("OK", 20, 65, 72, 22) GUICtrlSetState(-1, $GUI_FOCUS) $CancelButton = GUICtrlCreateButton("Cancel", 110, 65, 72, 22) $Label = GuiCtrlCreateLabel("Font:", 10, 10, 90, 20) $Input = GuiCtrlCreateInput($fontcolor, 90, 8, 100, 20) $Label2 = GuiCtrlCreateLabel("Background:", 10, 35, 90, 20) $Input2 = GuiCtrlCreateInput($backgroundcolor, 90, 32, 100, 20) GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then GUIDelete() GUISetState($gui) GUISetState(@SW_SHOW) Opt("GUIOnEventMode", 1) Return "" ElseIf $msg = $CancelButton Then GUIDelete() GUISetState($gui) GUISetState(@SW_SHOW) Opt("GUIOnEventMode", 1) Return "" ElseIf $msg = $OkayButton Then $fontcolor = GUICtrlRead($Input) $backgroundcolor = GUICtrlRead($Input2) GUIDelete() GUISetState($gui) GUISetState(@SW_SHOW) Opt("GUIOnEventMode", 1) ; Save settings. IniWrite($settingsfile, "Environment", "fontcolor", $fontcolor) IniWrite($settingsfile, "Environment", "backgroundcolor", $backgroundcolor) GUICtrlSetBkColor($serveroutput, "0x" & $backgroundcolor) ; Set background color of output field GUICtrlSetColor($serveroutput, "0x" & $fontcolor) ; Set font color of output field Return $fontcolor EndIf WEnd EndFunc Func Settings() Opt("GUIOnEventMode", 0) $parent_win_pos = WinGetPos("") $gui_settings = GUICreate("Settings", 300, 200, $parent_win_pos[0]+100, $parent_win_pos[1]+150) GuiSetIcon(@ScriptDir & "\" & $iconpath, 0) GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then GUIDelete() GUISetState($gui) GUISetState(@SW_SHOW) Opt("GUIOnEventMode", 1) Return "" EndIf WEnd EndFunc Func AboutTray() ;MsgBox(0, $appname & " " & $appversion, $appname & " created by Quate.net. Licensed under the GPL.") Opt("GUIOnEventMode", 0) $parent_win_pos = WinGetPos("") $gui_settings = GUICreate("About " & $appname, 300, 130, $parent_win_pos[0]+150, $parent_win_pos[1]+200) $Label = GuiCtrlCreateLabel($appname & " " & $appversion & "" & @CRLF & "" & @CRLF & "Program created by Quate (www.quate.net), licensed under the GPL. Icons by Everaldo Coelho (www.everaldo.com), licensed under the LGPL", 10, 10, 280, 80) GuiSetIcon(@ScriptDir & "\" & $iconpath, 0) $OkayButton = GUICtrlCreateButton("OK", 120, 100, 72, 22) GUICtrlSetState(-1, $GUI_FOCUS) GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then GUIDelete() GUISetState($gui) GUISetState(@SW_SHOW) Opt("GUIOnEventMode", 1) Return "" ElseIf $msg = $OkayButton Then GUIDelete() GUISetState($gui) GUISetState(@SW_SHOW) Opt("GUIOnEventMode", 1) Return "" EndIf WEnd EndFunc Func Quit() TCPShutdown() Exit EndFunc