Jump to content

Recommended Posts

Posted

ok heres my code, its broken on line 106, Please post updated script or tell me what is wrong...

; Origanl code is AU3Chat server
;Updates by ashley
;new featuers-----
;Set IP Connection
;Updated send Func
;Updated PM Func
;New regester Func
;Login Func Broken
#include <GUIConstants.au3>
#include <Date.au3>
Opt("GUIOnEventMode", 1)

Global Const $PORT = 31758
Global $list, $sock, $edit, $Reguser, $Regpass
Global $userlist[17][2]     ; [ index ][ username, ctrl id ]
Global $tCur = _Date_Time_GetLocalTime()

TCPStartUp()

$gui = GUICreate("Login", 260, 100)
GUICtrlCreateLabel("Username", 10, 10, 60, 20)
GUICtrlCreateLabel("Password", 10, 40, 60, 20)
$userctrl = GUICtrlCreateInput("", 80, 10, 170, 20)
$passctrl = GUICtrlCreateInput("", 80, 40, 170, 20)
$login = GUICtrlCreateButton("Login", 170, 70, 80, 20, $BS_DEFPUSHBUTTON)
$regester = GUICtrlCreateButton("Regester", 80, 70, 80, 20, $BS_DEFPUSHBUTTON)

GUICtrlSetOnEvent($login, "_Login")
GUICtrlSetOnEvent($regester, "_Regester")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

GUISetState()
$loop = True

While $loop
   Sleep(20)
WEnd

$gui = GUICreate("Autoit Messenger. Logged in as " & $User, 460, 230)
$list = GUICtrlCreateListView("         Users       ", 350, 10, 100, 210)
$edit = GUICtrlCreateEdit("", 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()
WEnd

Func _Regester()
    $reguser = GUICtrlRead($userctrl)
    $regpass = GUICtrlRead($passctrl)
    IniWrite("Databace.ini", "usernames", $Reguser, $regpass)

    Msgbox(48, "Thank you", "You have been regesterd as " & $reguser & ". Your password is " & $regpass & ".")
    Msgbox(48, "Important", "Please Reload Autoit Messenger, and login")
    Exit
EndFunc

Func _Login()
   $loop = False
   Global Const $IP = "169.254.154.240"
   Global Const $USER = GUICtrlRead($userctrl)
   GUIDelete($gui)
   ;check user
     $Reguser = GUICtrlRead($userctrl)
     $Regpass = GUICtrlRead($passctrl)

If Not IniRead("Databace.ini", "usernames", $reguser, $regpass)  Then
   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("Unable to connect.", 1)
      TCPSend($sock, Chr(1) & $USER & Chr(2) & Hex(BinaryString(_RC4($pass, _Time()))))
  Else
      $sock = TCPConnect($IP, $PORT)
      If $sock = -1 Then mError("Unable to connect.", 1)
      TCPSend($sock, $USER)
  EndIf
Else
    MsgBox(48, "Error", "Either you have typed your username or password incorrect or the account does not exist")
EndIf
EndFunc

Func _Send()
    $read1 = GUICtrlRead($input)
    $read2 = GUICtrlRead($Edit)
   If not GUICtrlRead($input) Then Return 0
   TCPSend($sock, StringReplace(StringReplace(GUICtrlRead($input), Chr(1), ""), Chr(2), ""))
   GUICtrlSetData($input, "")
   GUICtrlSetData($edit, $read2 & @CRLF & $read1)
   Return 1
EndFunc

Func _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, @CRLF & "<:PM sent to " & $user &" "& ":>" & "<:" & $data & ":>" & @CRLF, 1)
   Return 1
EndFunc

Func _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 1
EndFunc

Func _AddUser( $user )
   If $user = "Admin" and not $userlist[16][0] Then
      $userlist[16][0] = $user
      $userlist[16][1] = GUICtrlCreateListViewItem($user, $list)
    GUICtrlSetData($edit, @CRLF & "<: " & $user &" logged in at "& _Date_Time_SystemTimeToDateTimeStr($tCur) &":>" & @CRLF, 1)
      Return 1
   EndIf
   For $i = 0 to 15
      If not $userlist[$i][0] Then
         $userlist[$i][0] = $user
         $userlist[$i][1] = GUICtrlCreateListViewItem($user, $list)
    GUICtrlSetData($edit, @CRLF & "<: " & $user &" logged in at "& _Date_Time_SystemTimeToDateTimeStr($tCur) & ":>" & @CRLF, 1)
         Return 1
      EndIf
   Next
   Return 0
EndFunc

Func _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 0
EndFunc

Func _ReduceMemory()
   DllCall("psapi.dll", "int", "EmptyWorkingSet", "long", -1)
EndFunc

Func mError( $sText, $iFatal = 0, $sTitle = "Error", $iOpt = 0 )
   Local $ret = MsgBox(48 + 4096 + 262144 + $iOpt, $sTitle, $sText)
   If $iFatal Then Exit
   Return $ret
EndFunc

Func _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 $s
EndFunc

Func _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)
EndFunc

Func _Exit()
   Exit
EndFunc

Func OnAutoItExit()
   TCPSend($sock, Chr(1) & "bye")
   TCPShutdown()
   Exit
EndFunc
Posted

Suggestions:

1 - post a reproducer, by which I mean a small program that is specifically meant to show your error

2 - post code that doesn't fail to compile except for your one error - you have multiple errors that you should fix like double-declaring Const's in your code so it's hard to troubleshoot quickly

3 - run Tidy to tidy your script so it's more readable

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Posted

I think your statement is wrong:

If Not IniRead("Databace.ini", "usernames", $reguser, $regpass) Then

If not what? I think it should be:

If Not IniRead..... = "" then.

I think you sould use Case and select here.

Posted

I think your statement is wrong:

If Not IniRead("Databace.ini", "usernames", $reguser, $regpass) Then

If not what? I think it should be:

If Not IniRead..... = "" then.

I think you sould use Case and select here.

dude i connot believe i missed that

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...