#RequireAdmin #Include #Include #Include #Include #Include #Include #Include ;~ #NoTrayIcon Opt ('GUIOnEventMode', 1) TcpStartUp () Global $Server = -1, $Logs $Settings = GUICreate ('Connection Settings', 180, 100, -1, -1, -1, 128) GUISetOnEvent ($GUI_EVENT_CLOSE, '_Exit') GUICtrlCreateGroup ('', 5, 0, 170, 94) $IP = GUICtrlCreateInput (IniRead ('Settings.ini','Settings','IP',0), 12, 13, 100, 21, 1) $Port = GUICtrlCreateInput (IniRead ('Settings.ini','Settings','Port',0), 117, 13, 50, 21, 1) $User = GUICtrlCreateInput (IniRead ('Settings.ini','Settings','User',0), 12, 39, 156, 21, 1) $Connect = GUICtrlCreateButton ('Connect', 12, 66, 100, 20, $WS_GROUP) GUICtrlSetOnEvent ($Connect, '_Start') $Exit = GUICtrlCreateButton ('Exit', 117, 66, 50, 20, $WS_GROUP) GUICtrlSetOnEvent ($Exit, '_Exit') GUISetState (@SW_SHOW) WinSetOnTop ($Settings, '', 1) $GUI = GUICreate ('TCP Chat Room', 375, 275, -1, -1, -1, 128) GUISetOnEvent ($GUI_EVENT_CLOSE, '_Toggle') $History = GUICtrlCreateEdit ('', 0, 1, 375, 203, 2103360 + $ES_MULTILINE) GUICtrlSetFont ($History, 10, -1, -1, 'Lucida Sans Unicode') GUICtrlSetBkColor ($History, 0x83B4FC) GUICtrlSetColor ($History, 0xFFFFFF) $Send = GUICtrlCreateEdit ('', 0, 205, 375, 70, 2101248) GUICtrlSetFont ($Send, 10, -1, -1, 'Lucida Sans Unicode') GUICtrlSetColor ($Send, 0x83B4FC) GUISetState (@SW_HIDE) While 1 Sleep (15) If $Server <> -1 Then $Recv = TcpRecv ($Server, 1000000) If @Error Then GUISetState (@SW_HIDE, $GUI) WinSetOnTop ($GUI, '', 0) Sleep (100) MsgBox (48, 'Server Notice','You have been disconnected from the server.') _Disconnect () EndIf If $Recv = 'Error:Username.Exists;' Then GUISetState (@SW_HIDE, $GUI) WinSetOnTop ($GUI, '', 0) Sleep (100) MsgBox (48, 'Server Notice','Your username is already in use, please change it and try again.') _Disconnect () ElseIf $Recv = 'Error:Max.Connections;' Then GUISetState (@SW_HIDE, $GUI) WinSetOnTop ($GUI, '', 0) Sleep (100) MsgBox (48, 'Server Notice','Max amount of connections reached, try again later.') _Disconnect () ElseIf $Recv = 'Error:IP.Banned;' Then GUISetState (@SW_HIDE, $GUI) WinSetOnTop ($GUI, '', 0) Sleep (100) MsgBox (48, 'Server Notice','Your IP address has been banned.') _Disconnect () ElseIf StringLeft ($Recv, 4) = '.log' Then FileWriteLine ('Logged.txt', StringTrimLeft ($Recv, 5)) ElseIf $Recv <> '' Then _Log (StringReplace ($Recv, '%Time', @HOUR & ':' & @MIN)) EndIf If _IsPressed ('0D') And GUICtrlRead ($Send) <> '' And ControlGetFocus ($GUI) = 'Edit2' Then $Read = StringReplace (GUICtrlRead ($Send), @CRLF, '') $Read = StringReplace ($Read, @CR, '') $Read = StringReplace ($Read, @LF, '') If $Read = '.clear' Then GUICtrlSetData ($History, '') ElseIf $Read = '.logs' Then _Logs () ElseIf $Read = '.save' Then FileWrite (@MDAY & '-' & @MON & '-' & @YEAR & '_' & @HOUR & '-' & @MIN & '-' & @SEC & '_Logs.txt', GUICtrlRead ($History)) ElseIf $Read = '.disconnect' Or $Read = '.exit' Then _Disconnect () Else TcpSend ($Server, $Read) EndIf GUICtrlSetData ($Send, '') EndIf EndIf WEnd Func _Logs () $Logs = GUICreate ('Admin Logs', 375, 203, -1, -1, -1, 128) GUISetOnEvent ($GUI_EVENT_CLOSE, '_Delete') $Edit = GUICtrlCreateEdit ('', 0, 1, 375, 203, 2103360 + $ES_MULTILINE) GUICtrlSetFont ($Edit, 10, -1, -1, 'Lucida Sans Unicode') GUICtrlSetBkColor ($Edit, 0x83B4FC) GUICtrlSetColor ($Edit, 0xFFFFFF) GUISetState (@SW_SHOW) GUICtrlSetData ($Edit, FileRead ('Logged.txt')) WinSetOnTop ($Logs, '', 1) EndFunc Func _Delete () GUIDelete ($Logs) EndFunc Func _Disconnect () GUICtrlSetData ($History, '') TcpCloseSocket ($Server) $Server = -1 GUISetState (@SW_HIDE, $GUI) WinSetOnTop ($GUI, '', 0) GUISetState (@SW_SHOW, $Settings) WinSetOnTop ($Settings, '', 1) EndFunc Func _Toggle () GUICtrlSetData ($History, '') TcpCloseSocket ($Server) $Server = -1 GUISetState (@SW_HIDE, $GUI) WinSetOnTop ($GUI, '', 0) GUISetState (@SW_SHOW, $Settings) WinSetOnTop ($Settings, '', 1) EndFunc Func _Log ($Data) GUICtrlSetData ($History, GUICtrlRead ($History) & $Data & @CRLF) _GUICtrlEdit_LineScroll ($History, 0, _GUICtrlEdit_GetLineCount ($History) - 1) EndFunc Func _Start () If GUICtrlRead ($User) == '' Or GUICtrlRead ($IP) == '' Or GUICtrlRead ($Port) == '' Then Return @Error $Server = TcpConnect (GUICtrlRead ($IP), GUICtrlRead ($Port)) If $Server = -1 Or @Error Then WinSetOnTop ($Settings, '', 0) Sleep (100) MsgBox (16, 'Fatal Error','Unable to connect to the server, change your settings and try again.') WinSetOnTop ($Settings, '', 1) Return @Error EndIf Sleep (150) TcpSend ($Server, GUICtrlRead ($User)) GUISetState (@SW_HIDE, $Settings) WinSetOnTop ($Settings, '', 0) GUISetState (@SW_SHOW, $GUI) WinSetOnTop ($GUI, '', 1) EndFunc Func _Exit () IniWrite ('Settings.ini','Settings','IP', GUICtrlRead ($IP)) IniWrite ('Settings.ini','Settings','Port', GUICtrlRead ($Port)) IniWrite ('Settings.ini','Settings','User', GUICtrlRead ($User)) Exit EndFunc