JavaScript_Freek Posted May 31, 2007 Share Posted May 31, 2007 I broke it down from the example menu and added it to client.au3. No luck. client.au3CODE; Urbanyx (Chat Application); Coded by: Black Aye; HaloGrid.com/MystikFilms.com; Written in AutoIt v3#include <GUIConstants.au3>Opt("GUIOnEventMode", 1)Global Const $PORT = 31758Global $list, $sockGlobal $userlist[17][2] ; [ index ][ username, ctrl id ]TCPStartUp()$gui = GUICreate("Login", 260, 100)GUICtrlCreateLabel("Server IP", 10, 10, 60, 20)GUICtrlCreateLabel("Username", 10, 40, 60, 20)$ipctrl = GUICtrlCreateEdit(@IPADDRESS1, 80, 10, 170, 20, $ES_READONLY)$userctrl = GUICtrlCreateInput("", 80, 40, 170, 20)$login = GUICtrlCreateButton("Login", 170, 70, 80, 20, $BS_DEFPUSHBUTTON)GUICtrlSetOnEvent($login, "_Login")GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")$filemenu = GuiCtrlCreateMenu ("File")$fileitem = GuiCtrlCreateMenuitem ("Open...",$filemenu)$recentfilesmenu = GuiCtrlCreateMenu ("Recent Files",$filemenu)$separator1 = GuiCtrlCreateMenuitem ("",$filemenu)$exititem = GuiCtrlCreateMenuitem ("Exit",$filemenu)$helpmenu = GuiCtrlCreateMenu ("?")$aboutitem = GuiCtrlCreateMenuitem ("About",$helpmenu)$okbutton = GuiCtrlCreateButton ("OK",50,130,70,20)$cancelbutton = GuiCtrlCreateButton ("Cancel",180,130,70,20)GUISetState()$loop = TrueWhile 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton ExitLoop Case $msg = $fileitem $file = FileOpenDialog("Choose file...",@TempDir,"All (*.*)") If @error <> 1 Then GuiCtrlCreateMenuItem ($file,$recentfilesmenu) Case $msg = $exititem ExitLoop Case $msg = $okbutton MsgBox(0, "Click","You clicked OK!") Case $msg = $aboutitem Msgbox(0,"About","GUI Menu Test") EndSelectWEndTrayTip("Login Successfull!", "Welcome to Urbanyx, "& $user &"!", 15, 1)$gui = GUICreate("Urbanyx - User ("& $user & ")", 460, 230)$list = GUICtrlCreateListView(" Users ", 350, 10, 100, 210)$edit = GUICtrlCreateEdit("Welcome to Urbanyx. "& $user & " Follow the rules!" & @CRLF & @CRLF , 10, 70, 330, 150, $ES_READONLY + $WS_VSCROLL + $ES_AUTOVSCROLL)$input = GUICtrlCreateInput("", 10, 10, 330, 20)$send = GUICtrlCreateButton("Send", 10, 40, 80, 20, $BS_DEFPUSHBUTTON)$pm = GUICtrlCreateButton("PM", 100, 40, 80, 20)GUICtrlSetOnEvent($send, "_Send")GUICtrlSetOnEvent($pm, "_PM")GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")GUICtrlSetState($input, $GUI_FOCUS)GUISetState()_ReduceMemory()While 1 Sleep(0) $recv = TCPRecv($sock, 2048) If @error Then mError("Connection lost.", 1) If not $recv Then ContinueLoop ; parse the command(s) $recv = StringSplit($recv, Chr(1)) For $i = 1 to $recv[0] $temp = StringSplit($recv[$i], Chr(2)) Switch $temp[1] Case "rejected" mError("Connection rejected.", 1) Case "kick" mError("Connection kicked.", 1) Case "accepted" If $USER = "admin" Then $kick = GUICtrlCreateButton("Kick", 190, 40, 80, 20) GUICtrlSetOnEvent($kick, "_Kick") EndIf Case "adduser" _AddUser($temp[2]) Case "deluser" _DelUser($temp[2]) Case "exit" mError("Server has closed.", 1) Case Else If $recv[$i] Then GUICtrlSetData($edit, $recv[$i] & @CRLF, 1) EndSwitch Next _ReduceMemory()WEndFunc _Login() $loop = False Global Const $IP = GUICtrlRead($ipctrl) Global Const $USER = GUICtrlRead($userctrl) GUIDelete($gui) If $USER = "admin" Then Local $pass = InputBox("Enter Password:", "Please enter the server password below.", "", "") If @error Then Exit $sock = TCPConnect($IP, $PORT) If $sock = -1 Then mError("Internet needs to be turned on.", 1) Else $sock = TCPConnect($IP, $PORT) If $sock = -1 Then mError("Internet needs to be turned on.", 1) TCPSend($sock, $USER) EndIfEndFuncFunc _Send() If not GUICtrlRead($input) Then Return 0 TCPSend($sock, StringReplace(StringReplace(GUICtrlRead($input), Chr(1), ""), Chr(2), "")) GUICtrlSetData($input, "") Return 1EndFuncFunc _PM() If not GUICtrlRead($input) Then Return 0 Local $user = GUICtrlRead($list), $data = StringReplace(StringReplace(GUICtrlRead($input), Chr(1), ""), Chr(2), "") If not $user Then Return 0 $user = GUICtrlRead($user) TCPSend($sock, Chr(1) & "PM" & Chr(2) & $user & Chr(2) & $data) GUICtrlSetData($input, "") GUICtrlSetData($edit, "PM sent to: " & $user & "" & @CRLF & "" & $data & "" & @CRLF, 1) Return 1EndFuncFunc _Kick() Local $user = GUICtrlRead($list) If not $user Then Return 0 $user = GUICtrlRead($user) TCPSend($sock, Chr(1) & "kick" & Chr(2) & $user) GUICtrlSetData($edit, "<** Kick: " & $user & " **>" & @CRLF, 1) Return 1EndFuncFunc _AddUser( $user ) If $user = "admin" and not $userlist[16][0] Then $userlist[16][0] = $user $userlist[16][1] = GUICtrlCreateListViewItem($user, $list) Return 1 EndIf For $i = 0 to 15 If not $userlist[$i][0] Then $userlist[$i][0] = $user $userlist[$i][1] = GUICtrlCreateListViewItem($user, $list) Return 1 EndIf Next Return 0EndFuncFunc _DelUser( $user ) For $i = 0 to 16 If $userlist[$i][0] = $user Then $userlist[$i][0] = "" GUICtrlDelete($userlist[$i][1]) $userlist[$i][1] = 0 Return 1 EndIf Next Return 0EndFuncFunc _ReduceMemory() DllCall("psapi.dll", "int", "EmptyWorkingSet", "long", -1)EndFuncFunc mError( $sText, $iFatal = 0, $sTitle = "Error", $iOpt = 0 ) Local $ret = MsgBox(48 + 4096 + 262144 + $iOpt, $sTitle, $sText) If $iFatal Then Exit Return $retEndFuncFunc _RC4( $sData, $sKey ) ; based on code by Valik Local $l[256], $i, $t, $x, $y, $s = "" Local $iLen = StringLen($sKey) For $c = 0 to 255 $l[$c] = $c Next For $c = 0 to 255 $i = Mod(Asc(StringMid($sKey, Mod($c, $iLen) + 1, 1)) + $l[$c] + $i, 256) $t = $l[$c] $l[$c] = $l[$i] $l[$i] = $t Next For $c = 1 to StringLen($sData) $x = Mod($x + 1, 256) $y = Mod($l[$x] + $y, 256) $t = $l[$x] $l[$x] = $l[$y] $l[$y] = $t $s &= Chr(BitXOR(Asc(StringMid($sData, $c, 1)), $l[Mod($l[$x] + $l[$y], 256)])) Next Return $sEndFuncFunc _Time() ; based on code by jjohn and his time sync script ; 129.6.15.28 = time-a.nist.gov Local $conn = TCPConnect("129.6.15.28", 37), $recv = "" If $conn = -1 or @error Then Return SetError(1, 0, "...") While $recv = "" $recv = TCPRecv($conn, 512) If @error Then Return SetError(2, 0, "...") WEnd TCPCloseSocket($conn) Return StringTrimRight(Asc(StringMid($recv,1,1))*256^3+Asc(StringMid($recv,2,1))*256^2+Asc(StringMid($recv,3,1))*256+Asc(StringMid($recv,4,1)),1)EndFuncFunc _Exit() ExitEndFuncFunc OnAutoItExit() TCPSend($sock, Chr(1) & "bye") TCPShutdown() ExitEndFuncserver.au3CODEHotKeySet("{ESC}", "OnAutoItExit")Global Const $PASS = "dd"Global Const $IP = @IPADDRESS1Global Const $PORT = 31758Global $listenGlobal $list[17][2] ; [ index ][ socket, username ]TCPStartup()$listen = TCPListen($IP, $PORT, 17)If $listen = -1 Then mError("Unable to connect.", 1)TrayTip("Urbanyx", "Server is connected on:" & @CRLF & $IP & ":" & $PORT, 15, 1)_ReduceMemory()While 1 _CheckConn() Sleep(0) $sock = TCPAccept($listen) If $sock = -1 Then ContinueLoop _AddConn($sock) _ReduceMemory()WEndFunc _AddConn( $iSocket ) ; recieve the username from the client Local $recv = _SockRecv($iSocket), $temp If @error Then _DelConn($iSocket) Else ; if they are trying to login as admin then check the password If StringLeft($recv, 7) = Chr(1) & "admin" & Chr(2) Then $temp = StringSplit($recv, Chr(2)) If _RC4(BinaryString("0x" & $temp[2]), _Time()) == $PASS and not $list[16][0] Then $list[16][0] = $iSocket $list[16][1] = "admin" TCPSend($iSocket, Chr(1) & "accepted") _SendUsers($iSocket) _SendAll(Chr(1) & "adduser" & Chr(2) & "admin", "", $iSocket) Return 1 Else TCPSend($iSocket, Chr(1) & "rejected") EndIf Else ; find an empty space in the userlist For $i = 0 to 15 If not $list[$i][0] Then $list[$i][0] = $iSocket $list[$i][1] = $recv TCPSend($iSocket, Chr(1) & "accepted") _SendUsers($iSocket) _SendAll(Chr(1) & "adduser" & Chr(2) & $recv, "", $iSocket) Return 1 EndIf Next ; too many users, reject the connection TCPSend($iSocket, Chr(1) & "rejected") TCPCloseSocket($iSocket) EndIf EndIf Return 0EndFuncFunc _DelConn( $iSocket ) For $i = 0 to 16 If $list[$i][0] = $iSocket Then TCPCloseSocket($iSocket) $list[$i][0] = 0 $list[$i][1] = "" Return 1 EndIf Next Return 0EndFuncFunc _CheckConn() Local $recv = "" For $i = 0 to 16 If $list[$i][0] Then $recv = TCPRecv($list[$i][0], 2048) If @error Then ; disconnect client TCPCloseSocket($list[$i][0]) _SendAll(Chr(1) & "deluser" & Chr(2) & $list[$i][1]) $list[$i][0] = 0 $list[$i][1] = "" Else If $recv Then ; parse the command(s) $recv = StringSplit($recv, Chr(1)) For $j = 1 to $recv[0] $temp = StringSplit($recv[$j], Chr(2)) Switch $temp[1] Case "bye" TCPCloseSocket($list[$i][0]) _SendAll(Chr(1) & "deluser" & Chr(2) & $list[$i][1]) $list[$i][0] = 0 $list[$i][1] = "" Case "kick" _Kick($temp[2]) Case "PM" _PM($temp[2], $temp[3], $list[$i][1]) Case Else If $recv[$j] Then _SendAll($recv[$j], $list[$i][1]) EndSwitch Next EndIf EndIf EndIf NextEndFuncFunc _SendAll( $str, $from = "", $except = 0 ) ; send a message to all users For $i = 0 to 16 If $list[$i][0] and $list[$i][0] <> $except Then If $from and StringLeft($str, 1) <> Chr(1) Then TCPSend($list[$i][0], $from & ": " & $str) Else TCPSend($list[$i][0], $str) EndIf EndIf NextEndFuncFunc _Kick( $user ) ; kick a user and close their connection For $i = 0 to 15 If $list[$i][1] = $user Then TCPSend($list[$i][0], Chr(1) & "kick") TCPCloseSocket($list[$i][0]) $list[$i][0] = 0 _SendAll(Chr(1) & "deluser" & Chr(2) & $list[$i][1]) $list[$i][1] = "" Return 1 EndIf Next Return 0EndFuncFunc _PM( $user, $str, $from ) ; private message another user For $i = 0 to 16 If $list[$i][1] = $user Then TCPSend($list[$i][0], "~ " & $from & " > " & $str) Return 1 EndIf Next Return 0EndFuncFunc _SendUsers( $iSocket ) ; give the userlist to a connecting client For $i = 0 to 16 If $list[$i][0] Then TCPSend($iSocket, Chr(1) & "adduser" & Chr(2) & $list[$i][1]) NextEndFuncFunc _SockRecv( $iSocket, $iBytes = 2048 ) Local $sData = "" While $sData = "" $sData = TCPRecv($iSocket, $iBytes) If @error Then Return SetError(1, 0, 0) Wend Return $sDataEndFuncFunc _ReduceMemory() DllCall("psapi.dll", "int", "EmptyWorkingSet", "long", -1)EndFuncFunc mError( $sText, $iFatal = 0, $sTitle = "Error", $iOpt = 0 ) Local $ret = MsgBox(48 + 4096 + 262144 + $iOpt, $sTitle, $sText) If $iFatal Then Exit Return $retEndFuncFunc _RC4( $sData, $sKey ) ; based on code by Valik Local $l[256], $i, $t, $x, $y, $s = "" Local $iLen = StringLen($sKey) For $c = 0 to 255 $l[$c] = $c Next For $c = 0 to 255 $i = Mod(Asc(StringMid($sKey, Mod($c, $iLen) + 1, 1)) + $l[$c] + $i, 256) $t = $l[$c] $l[$c] = $l[$i] $l[$i] = $t Next For $c = 1 to StringLen($sData) $x = Mod($x + 1, 256) $y = Mod($l[$x] + $y, 256) $t = $l[$x] $l[$x] = $l[$y] $l[$y] = $t $s &= Chr(BitXOR(Asc(StringMid($sData, $c, 1)), $l[Mod($l[$x] + $l[$y], 256)])) Next Return $sEndFuncFunc _Time() ; based on code by jjohn and his time sync script ; 129.6.15.28 = time-a.nist.gov Local $conn = TCPConnect("129.6.15.28", 37), $recv = "" If $conn = -1 or @error Then Return SetError(1, 0, "...") While $recv = "" $recv = TCPRecv($conn, 512) If @error Then Return SetError(2, 0, "...") WEnd TCPCloseSocket($conn) Return StringTrimRight(Asc(StringMid($recv,1,1))*256^3+Asc(StringMid($recv,2,1))*256^2+Asc(StringMid($recv,3,1))*256+Asc(StringMid($recv,4,1)),1)EndFuncFunc OnAutoItExit() _SendAll(Chr(1) & "exit") TCPShutdown() ExitEndFuncYou gotta double click server.au3 then double-click client.au3 to run the chatroom. [center]Cookyx.com :: Simple LAN Chat[/center] Link to comment Share on other sites More sharing options...
evilertoaster Posted May 31, 2007 Share Posted May 31, 2007 for me nothing happens when i try to logon... although when i look at your code i dont see what is suposed to happen...It seems you have several logic errors in your code flow but it's hard to tell becuase to me it is very...'disorganized' and i can't really read it well.... here are some thing you can maybe clear up- 1. You're mixing the two guievent modes (polling and onevent), that's technically fine but it's kinda senseless... 2. Func _Login() $loop = False Global Const $IP = GUICtrlRead($ipctrl) Global Const $USER = GUICtrlRead($userctrl) GUIDelete($gui) If $USER = "admin" Then Local $pass = InputBox("Enter Password:", "Please enter the server password below.", "", "") If @error Then Exit $sock = TCPConnect($IP, $PORT) If $sock = -1 Then mError("Internet needs to be turned on.", 1) Else $sock = TCPConnect($IP, $PORT) If $sock = -1 Then mError("Internet needs to be turned on.", 1) TCPSend($sock, $USER) EndIf EndFunc When does it ever leave this loop? once the Login function is called it still stays there... there's other wierd things on the server side part also but start here... Link to comment Share on other sites More sharing options...
JavaScript_Freek Posted May 31, 2007 Author Share Posted May 31, 2007 what are you suggesting? [center]Cookyx.com :: Simple LAN Chat[/center] Link to comment Share on other sites More sharing options...
evilertoaster Posted May 31, 2007 Share Posted May 31, 2007 I've made no sugestions yet per-se, I'm just confused about certian parts of your code. Answering the the questions above would help me understand what you want to be going on and how to make it do so. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now