Sign in to follow this  
Followers 0
H5O2OH

Client/Server packet identification help!

7 posts in this topic

#1 ·  Posted (edited)

Hello,

I badly need some help on my server

It will do the if ,only if the received packet is equal to "Username.password.$102x1",else it won't do.

What if the received packet is "Username.password" + some string that always changes

Example -> "Username.password.$10xsa3" ; "Username.password.$9xkash1"

My question is,how to make the program to search only for the first few strings in the packet,like

If $temp = "Username.password..."(don't check rest of packet)

Then TcpSend...

Any ideas,please?

Thank you,

H5O2OH

Edited by H5O2OH

Share this post


Link to post
Share on other sites



Bump,please help!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Use the String functions to examine the string.

Something like this perhaps:

Dim $RandomString ; Just to make the random string
For $i = 1 To Random(5, 7, 1) ; Just to make the random string
    $RandomString &= Chr(Random(32, 126, 1)) ; Just to make the random string
Next ; Just to make the random string

$packet = "username.password.$" & $RandomString ; the packet with correct format+random string at the end



$tmp = StringLeft($packet, StringInStr($packet, "$", 0, 1)-2) ; trim away the random characters -2 leaves out the .$ part

$username = StringLeft($tmp, StringInStr($tmp, ".")-1) ; gets all chars from the left to the first . -1 excludes the first .
$password = StringMid($tmp, StringInStr($tmp, ".")+1) ; gets all chars from the first . to the end +1 excludes the first .

MsgBox(0, "Packet data:", "Username: " & $username & @CRLF & "Password: " & $password & @CRLF & "Packet: " & $packet)

Edit:

Another example(to check if username and password is correct(and the packet format too):

Dim $RandomString; Just to make the random string
For $i = 1 To Random(5, 7, 1); Just to make the random string
    $RandomString &= Chr(Random(32, 126, 1)); Just to make the random string
Next; Just to make the random string

$packet = "username.password.$" & $RandomString; the packet with correct format+random string at the end


$temp = StringLeft($packet, StringInStr($packet, "$", 0, 1)); trim away the random chars, but keeps the .$ at the end

If $temp == "username.password.$" Then; note the double equal signs, that makes it case sensitive too.
    MsgBox(0, "OK", "Format is ok, and username and password is ok")
; do something more
Else
    MsgBox(0, "Error", "Wrong packet packet format, or username and/or password is wrong")
EndIf
Edited by FreeFry

Share this post


Link to post
Share on other sites

maybe this way?

$username = "Username"
$password = "password"
$check = "Username.password.$10xsa3" ; "Username.password.$9xkash1"
; Find the 2nd occurance of "." or the first occurance of "$" like in help file of stringinstr
$location = StringInStr($check, "$")
consolewrite ("! $location = "&$location&@lf)
; then extrackt it until the ocurence "." or "$" ;)

$user_pass = stringmid ($check,1,$location-2)
consolewrite ("- $userpass = "&$user_pass&@lf)

;then check if user and pass is ok
$auth = stringsplit ($user_pass,".")
if $auth[0] = 2 Then
    if $auth[1] = $username and $auth[2] = $password Then
        consolewrite ("+ auth ok"&@lf)
        consolewrite ("+ TCP send bla bla"&@lf)
    Else
        consolewrite ("! auth wrong, do nothing"&@lf)
    EndIf
EndIf

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

maybe this way?

$username = "Username"
$password = "password"
$check = "Username.password.$10xsa3" ; "Username.password.$9xkash1"
; Find the 2nd occurance of "." or the first occurance of "$" like in help file of stringinstr
$location = StringInStr($check, "$")
consolewrite ("! $location = "&$location&@lf)
; then extrackt it until the ocurence "." or "$" ;)

$user_pass = stringmid ($check,1,$location-2)
consolewrite ("- $userpass = "&$user_pass&@lf)

;then check if user and pass is ok
$auth = stringsplit ($user_pass,".")
if $auth[0] = 2 Then
    if $auth[1] = $username and $auth[2] = $password Then
        consolewrite ("+ auth ok"&@lf)
        consolewrite ("+ TCP send bla bla"&@lf)
    Else
        consolewrite ("! auth wrong, do nothing"&@lf)
    EndIf
EndIf
Problem with using StringSplit is that you cannot let the users have periods in their names/passwords.

Personally I more like the idea to compose the expected string on the server(which would be "username.password.$abc123", username being the username, password being the pass, then comparing it to the string received).

Perhaps there's better ways, but that's what I can come up with atm. :-#

Edited by FreeFry

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Okay,thank you very much.

Now there is another problem,it accepts the login only one time! >.<

TCPSTARTUP()
$LISTEN = TCPListen("127.0.0.1", 1337)

Do
    Sleep(10)
    $socket = TCPAccept($listen)
    If $socket <> -1 Then
       While 1
            Sleep(100)
            $TEMP = TCPRecv($SOCKET, 256)        
            if StringLeft($TEMP, 4) = "Hell" Then TCPSend($Socket,"Hey!")
            if $Temp = "What's up?" Then TCPSend($Socket,"Nothing much,you?")
        Wend
    EndIf
Until $Socket <> -1

I tried it with Do/Until and While,both cases the effect is same - it does say "Hey",but it doesnt check for it anymore,you may say the problem is in the "Whats'up" packet,but seriously ,I start the server,I start the client - server reply "Hello",i restart the client and there is no responce from server,but client is connected to server.

That bug made my day very bad :)

Edited by H5O2OH

Share this post


Link to post
Share on other sites

Try:

TCPSTARTUP()
$LISTEN = TCPListen("127.0.0.1", 1337)

While 1
    Sleep(10)
    $socket = TCPAccept($listen)
    If $socket <> -1 Then
       Do
            Sleep(100)
            $TEMP = TCPRecv($SOCKET, 256)      
            if StringLeft($TEMP, 4) = "Hell" Then TCPSend($Socket,"Hey!")
            if $Temp = "What's up?" Then TCPSend($Socket,"Nothing much,you?")
        Until $Socket <> -1
    EndIf
WEnd

Untested, but I believe it should work..

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0