Hey, 

Pro tip : return -1 to a CONNECT hook and use
Ape.addUser(cmd.user) in your SQL callback. 

Exemple here :


https://github.com/APE-Project/APE_Server/blob/master/scripts/framework/http_auth.js


Therefore the connect process will be delayed until the call of
Ape.addUser. 

On Mon, 5 Mar 2012 21:40:57 -0500, Pablo Tejada wrote:


> Sure no problem, Unfortunately the whole process is victim of the
same rule. And that is that JavasScript will not wait for an
asynchronous request to finish and continue execution. 
> So the
'connect' hook will finish and return 1 weather the user properties are
set or not. 
> 
> While working with JS in the client side i use the
method of re-running a function when im in similar situation: 
> 
>
//Global variable 
> var cache; 
> function buildUserCard(user_id){ 
>
if(!cache){ 
> //Get the template from the server 
>
$.get("request/UserCard.tpl", function(data){ 
> //export the value of
'data' to the global 'cache' 
> cache = data; 
> //Re-Run the same
function to continue building our UserCard 
> buildUserCard(user_id); 
>
}); 
> //kill function exceution 
> return false; 
> } 
> //We got the
template in 'cache' so continue builing our UserCard 
> var UserCard =
... 
> ... 
> } 
> But in server side like APE is different because im
not sure if we could trigger commands. I have two alternatives in mind
you could try: 
> 1) return 0 instead of 1 in the 'connect' hook to kill
it, and try to send a custom response from the sql.query() callback
using sendResponse() [7] or sendRaw() [8] not sure which one is more
appropriate. 
> 2) keep returning 1 in the 'connect' hook, in the
sql.query() callback send a custom RAW to the channels the user is
part-of using sendRaw() [9]. This would required extra code in the
client side to handle the custom RAW and update the user object
accordingly. 
> Happy coding :) 
> If you are having more headaches then
solutions consider using inlinepush instead, you could also avoid having
to deal with the clumsy MySql in APE server, this thread has some good
information about it
https://groups.google.com/forum/?fromgroups#!searchin/ape-project/inlinepush$20ptejada26/ape-project/5pJwbIdbNGY/hOGJ5FRdpYwJ
[10] 
> 
> On Mon, Mar 5, 2012 at 8:30 PM, UTAN wrote:
> 
>> On this
try I was trying to return, but is not how I had before it
>> very
similar to the one you posted in your last post..
>> 
>> On Mar 5, 5:15
pm, Pablo Tejada wrote:
>> > Just for the record is not the APE server's
fault, is the way JS works and
>> > the way you have structured your
application. For example this function:
>> >
>> > function
setloggedinProperties(user){
>> > var usernick =
user.getProperty('name').toLowerCase();
>> >
>> > sql.query('SELECT *
FROM pfc_login WHERE BINARY
>> >
username="'+Ape.MySQL.escape(usernick)+'"',function(res,error){
>> >
if(error){
>> > Ape.log('There was an error in the
query'+this.errorString()+'');
>> > }else{
>> > if(res != ''){
>> >
return res[0].isauthorized;
>> > }
>> > }
>> > });
>> >
>> > }
>> >
>>

>> --
>> You received this message because you are subscribed to the
Google
>> Groups "APE Project" group.
>> To post to this group, send
email to [email protected] [2]
>> To unsubscribe from this
group, send email to
>> [email protected] [3]
>>
For more options, visit this group at
>>
http://groups.google.com/group/ape-project?hl=en [4]
>> ---
>> APE
Project (Ajax Push Engine)
>> Official website :
http://www.ape-project.org/ [5]
>> Git Hub :
http://github.com/APE-Project/ [6]
> 
> -- 
> You received this message
because you are subscribed to the Google
> Groups "APE Project" group.
>
To post to this group, send email to [email protected]
> To
unsubscribe from this group, send email to
>
[email protected]
> For more options, visit this
group at
> http://groups.google.com/group/ape-project?hl=en [12]
> ---
>
APE Project (Ajax Push Engine)
> Official website :
http://www.ape-project.org/ [13]
> Git Hub :
http://github.com/APE-Project/ [14]

  

Links:
------
[1]
mailto:[email protected]
[2] mailto:[email protected]
[3]
mailto:ape-project%[email protected]
[4]
http://groups.google.com/group/ape-project?hl=en
[5]
http://www.ape-project.org/
[6] http://github.com/APE-Project/
[7]
http://www.ape-project.org/docs/server/raws/sendresponse.html
[8]
http://www.ape-project.org/docs/server/more/pipe.sendraw.html
[9]
http://www.ape-project.org/docs/server/more/pipe.sendraw.html
[10]
https://groups.google.com/forum/?fromgroups#!searchin/ape-project/inlinepush$20ptejada26/ape-project/5pJwbIdbNGY/hOGJ5FRdpYwJ
[11]
mailto:[email protected]
[12]
http://groups.google.com/group/ape-project?hl=en
[13]
http://www.ape-project.org/
[14] http://github.com/APE-Project/

-- 
You received this message because you are subscribed to the Google
Groups "APE Project" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/ape-project?hl=en
---
APE Project (Ajax Push Engine)
Official website : http://www.ape-project.org/
Git Hub : http://github.com/APE-Project/

Reply via email to