Jump to content

Recommended Posts

Posted (edited)

hi i'm working on a tcp login and then you have a mailbox and you can send messages to eatchother

but on the inbox func i'm stuck and on the message func i'm stuck i dont know how to improve it more that it works bether

pleas take a look at my code and help me

client

#NoTrayIcon
#include <GUIConstants.au3>
HotKeySet("{enter}", "button")
HotKeySet("{esc}", "quit")
TCPStartup()
$gui=GUICreate("Login.", 200, 100)
GUICtrlCreateLabel ("Username: ",  5, 10, 70) 
GUICtrlCreateLabel ("Password: ",  5, 40, 70)
$username = GUICtrlCreateInput ("", 70,  5, 100, 20)
$password = GUICtrlCreateInput ("", 70,  35, 100, 20, $ES_PASSWORD)

$btn = GUICtrlCreateButton ("Login.", 100,  75, 60, 20)

GUISetState () 
$msg = 0
While $msg <> $GUI_EVENT_CLOSE
       $msg = GUIGetMsg()
       Select
           Case $msg = $btn
              $USER = GuiCtrlRead($username)
              $PASS = GuiCtrlRead($password)
                if $USER="" then MsgBox(262144, "Error", "Pleas Fill in a Username.")
                if $Pass="" then MsgBox(262144, "Error", "Pleas Fill in a Password.")
                    if $user>"" and $pass>"" then 
                        $socket=TCPConnect("127.0.0.1",2111)
                            If @error Then
                            MsgBox(16,"Error","Couldn't connect to server")
                            Exit
                            EndIf
                        TCPSend($socket,$USER&"|"&$pass)

                            
                            Do
                                sleep(10)
                                $temp=TCPRecv($socket,256)
                                Until $temp<>""
                                    $array = StringSplit($temp, "%")
                                    
                                    
                                    If $array[1]="Connected" Then 
                                    auth()
                                 Else
                                MsgBox(262144,"Error.","Wrong username / password.")
                                
                            EndIf
                            EndIf
                    
                    
       EndSelect
Wend



func auth()
$mask = StringSplit($array[2], "^")
$mask2 = StringSplit($mask[2], "|")
if $mask2[1] = 0 then 
    login()
EndIf
if $mask2[1] = 1 then inbox()
if $mask2[1] = 2 then inbox()

EndFunc

func login()
$message=0
GUIDelete()
$gui=GUICreate("Login.", 200, 100)
GUICtrlCreateLabel ("Username: ",  5, 10, 70) 
GUICtrlCreateLabel ("Password: ",  5, 40, 70)
$username = GUICtrlCreateInput ("", 70,  5, 100, 20)
$password = GUICtrlCreateInput ("", 70,  35, 100, 20, $ES_PASSWORD)

$btn = GUICtrlCreateButton ("Login.", 100,  75, 60, 20)



GUISetState () 
$msg = 0
While $msg <> $GUI_EVENT_CLOSE
       $msg = GUIGetMsg()
       Select
           Case $msg = $btn
              $USER = GuiCtrlRead($username)
              $PASS = GuiCtrlRead($password)
                if $USER="" then MsgBox(262144, "Error", "Pleas Fill in a Username.")
                if $Pass="" then MsgBox(262144, "Error", "Pleas Fill in a Password.")
                    if $user>"" and $pass>"" then 
                        $socket=TCPConnect("127.0.0.1",2111)
                            If @error Then
                            MsgBox(16,"Error",@error)
                            Exit
                            EndIf
                        TCPSend($socket,$USER&"|"&$pass)

                            Do
                                sleep(10)
                                $temp=TCPRecv($socket,256)
                                Until $temp<>""
                                    $array = StringSplit($temp, "%")
                                    If $array[1]="Connected" Then 
                                    auth()
                                Else
                                MsgBox(262144,"Error.","Wrong username / password.")
                                
                            EndIf
                            EndIf
                    
                    
       EndSelect
Wend
    
EndFunc



func inbox()
$mask = StringSplit($array[2], "^")
$message =0 
        $count_down_time = 350;sec
$corected_time = $count_down_time * 1000
$timer = TimerInit()
Global $display_old
$message="sample"
    $mask2 = StringSplit($mask[2], "|")
    
    if $mask2[1] = 0 then login()
    if $mask2[1] = 1 then $pri="User"
    if $mask2[1] = 2 then $pri="Admin"

GUIDelete()
GUICreate ( "My GUI delete control", 600,200,250,200)
GUICtrlCreateLabel ("Your Logged in as: " & $USER ,  5, 5, 200) 
GUICtrlCreateLabel ("Privileges: " & $pri ,  5, 20, 200) 
$from = GUICtrlCreateLabel ("from:  " & $mask2[4] , 130, 40, 200) 
$list = GuiCtrlCreateList("", 15, 60, 100, 90)
$subject =GUICtrlSetData(-1, $mask2[2])
$list2 = GUICtrlRead($list) 
GuiCtrlCreateEdit($mask2[3] ,130, 60, 300, 83)
$Button_1 = GUICtrlCreateButton ("Quit", 520, 5, 75)
$Button_2 = GUICtrlCreateButton ("Disconnect.", 520, 35, 75)
$Button_3 = GUICtrlCreateButton ("New message.", 520, 65, 75)
GUISetState (); Run the GUI until the dialog is closed
sleep(5000)
MsgBox(4096, "Test", $list2 )
$msg=0
While $msg <> $GUI_EVENT_CLOSE
   
;~  == display countdown part: ===
    $display = Floor(($corected_time-TimerDiff($timer))/1000)
    if $display <> $display_old Then
       GUICtrlCreateLabel ("Auto timeout after: " & $display ,  5, 35, 110) 
        $display_old = $display
    EndIf
;~  == end of display countdown part ===
    if TimerDiff($timer)>= $corected_time Then
        exit
    EndIf

$msg = GUIGetMsg()
   

Select
    Case    $msg = $Button_1
quit()
    Case    $msg = $Button_2
disconnect()
    Case    $msg = $Button_3
message()

EndSelect
WEnd
EndFunc




func message()
$mask = StringSplit($array[2], "^")
$mask2 = StringSplit($mask[2], "|")

    if $mask2[1] = 0 then login()
    if $mask2[1] = 1 then $pri="User"
    if $mask2[1] = 2 then $pri="Admin"
$message=1
$count_down_time = 350;sec
$corected_time = $count_down_time * 1000
$timer = TimerInit()
Global $display_old

GUIDelete()
GUICreate ( "My GUI delete control", 600,200,250,200)
GUICtrlCreateLabel ("You are Logged in as: " & $USER ,  5, 5, 200) 
GUICtrlCreateLabel ("Privileges: " & $pri ,  5, 20, 200) 
$pmuser = GuiCtrlCreatecombo("", 10, 56, 100, 100)
GUICtrlSetData(-1,$mask[1],"")
$subject2 = GUICtrlCreateLabel ("Subject:" ,  295, 22, 40) 
$subject  = GUICtrlCreateInput("", 340,  20, 100, 20)
$message  = GuiCtrlCreateEdit("", 140, 56, 300, 83)

$Button_1 = GUICtrlCreateButton ("Quit", 520, 5, 75)
$Button_2 = GUICtrlCreateButton ("Disconnect.", 520, 35, 75)
$Button_3 = GUICtrlCreateButton ("Inbox.", 520, 65, 75)
$Button_4 = GUICtrlCreateButton ("Send.", 355, 140, 75)

$call = GUICtrlCreateCheckbox ("Call back nota", 250, 145, 100, 20)
$cal1 = GUICtrlRead($call)
GUISetState (); Run the GUI until the dialog is closed



$msg=0
While $msg <> $GUI_EVENT_CLOSE
$cal1  = GUICtrlRead($call)
$input2= GUICtrlRead($subject)
$input =GUICtrlGetState($subject)
$subject3=GUICtrlGetState($subject2)
if $cal1=1 and $subject3 = 80 then GUICtrlSetState($subject2, $GUI_hide)
if $cal1=4 and $subject3 = 96 then GUICtrlSetState($subject2, $GUI_show)
if $cal1=1 and $input = 80 then GUICtrlSetState($subject, $GUI_hide)
if $cal1=4 and $input = 96 then GUICtrlSetState($subject, $GUI_show)
    
    
    if $cal1=1 and $input2 <> "Call Back Nota" then GUICtrlSetData($subject,"Call Back Nota") 
    if $cal1=4 and $input2 = "Call Back Nota" then GUICtrlSetData($subject,"") 



;~  == display countdown part: ===
    $display = Floor(($corected_time-TimerDiff($timer))/1000)
    if $display <> $display_old Then
       GUICtrlCreateLabel ("Auto timeout after: " & $display ,  5, 35, 110) 
        $display_old = $display
    EndIf
;~  == end of display countdown part ===
    if TimerDiff($timer)>= $corected_time Then
        exit
    EndIf

$msg = GUIGetMsg()
   

Select
    Case    $msg = $Button_1
quit()
    Case    $msg = $Button_2
disconnect()
    Case    $msg = $Button_3
inbox()
    Case    $msg = $Button_4
    $send ="sendpm"
    TCPSend($socket,$send&"|"&$subject&"|"&$message&"|"&$pmuser)
    MsgBox(4096, "Send.", "Message was send.")


EndSelect






WEnd
EndFunc




Func Disconnect()
$answer = MsgBox(4, "Exit.", "Are you sure you wanne disconnect?")
If $answer = 6 Then login()

EndFunc


Func button()
ControlClick("", "", "Button1")
EndFunc

func quit()         
$exit = MsgBox(4, "Exit.", "Are you sure you wanne exit ?")
If $exit = 6 Then exit 
EndFunc

server

; Server (Start first)
TCPStartup()



$listen = TCPListen("127.0.0.1", 2111)

Global $loggedin = False

while 1
$result = ""
$var = IniReadSection("C:\Temp\users.ini", "user")
If @error Then
MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
For $i = 1 To $var[0][0]
$result &= $var[$i][0]&"|"
Next
EndIf
$data = StringTrimRight($result, 1)





Do
    Sleep(10)
    $socket = TCPAccept($listen)
    If $socket <> -1 Then
        Do
            Sleep(100)
            $temp = TCPRecv($socket, 256)
        Until $temp <> ""
        $array = StringSplit($temp, "|")
        $var  = IniRead("C:\temp\users.ini", "User", $array[1], "Not Found.")
        $mask = IniRead("C:\temp\users.ini", "privileges", $array[1], "0")
       
       $subject = IniRead("C:\temp\" & $array[1] & ".ini", "bericht1", "subject", "Not Found")
       $message = IniRead("C:\temp\" & $array[1] & ".ini", "bericht1", "message", "Not Found")
       $from    = IniRead("C:\temp\" & $array[1] & ".ini", "bericht1", "from", "Not Found")

$data2=$subject&"|"&$message&"|"&$from

        If $array[2] == $var Then
          
          TCPSend($socket, "Connected%"& $data&"^"&$mask&"|"&$data2)
            $loggedin = True
        Else
            TCPSend($socket, "Connection failed")
            TCPCloseSocket($socket)
            $socket = -1
        EndIf
    EndIf
   
      
   
   
Until $socket <> -1
WEnd

pleas help me with it muttley

i have added .txt because you arnt allowd to upload .ini

greetz Yucatan

users.ini.txt

yucatan.ini.txt

Edited by yucatan

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...