Jump to content


Photo

Parsing with a script


  • Please log in to reply
No replies to this topic

#1 RaythXC

RaythXC

    GMC Member

  • GMC Member
  • 38 posts
  • Version:GM8

Posted 17 June 2012 - 02:03 AM

Ok I have this code that runs when a button is clicked to log someone in using httpdll2.
var email,password,state,http,contents;
http_dll_init();
global.loggedin="no";
email=obj_textbox_email.text;
password=obj_textbox_pass.text;
http = httprequest_create();
httprequest_set_post_parameter(http,"email",email);
httprequest_set_post_parameter(http,"pass",password);
httprequest_connect(http,"http://www.somewhere.com/path/file.php?act=login",true)
while true {
    httprequest_update(http);
    state=httprequest_get_state(http);
    if (state=4 or state=5){
        break;
    }
    sleep(10);
}
if (state=5) {
    obj_text_error.text="Could not connect to server.";
} else {
    contents = httprequest_get_message_body(http);
    parsestring(contents,"|");
    if (data[0]="0") {
        var error;
        if (data[1]="1") { obj_text_error.text="This account is not Verified. Check Email"; }
        if (data[1]="2") { obj_text_error.text="Incorrect Login Information Supplied"; }
    }
    else if (data[0]="1") {
        global.loggedin="yes";
        global.userid=contents[1];
        global.displayname=contents[2];
        room_goto_next();
    }
    else { obj_text_error.text="Error: "+contents; }
}
httprequest_destroy(http);

parsestring script:
var i,s,p;
s=argument0;
for (i=0;i<string_count(argument1,argument0);i+=1){
    p=string_pos(argument1,s);
    data[i]=string_copy(s,0,p-1);
    s=string_delete(s,1,p);
}
data[i]=string_replace(s,argument1,"");
This I found from searching on the forum for howto parse.

Now, on this particular part of the PHP script, it has 4 possible ways it can return.
1: 0|1 Unverified Account
2: 0|2 Login Info Wrong
3: 0|3 MySQL Query failed
4: 1|userid|displayname

When I type my login info correct it gives me this in my custom error log:
Error: Rayth

By all technicalities, this says I successfully logged in, since it's showing me the last data in the return. If i type wrong it shows up Error: 2.

I'm guessing i'm not parsing the data correctly from the script but I can't think of how to do this. All variables are separated by |.



Edit: got it working. Updated above with the working code.

Edited by RaythXC, 17 June 2012 - 03:03 AM.

  • 1




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users