Using dataserver to check date of birth
|
|
Ricky Shaftoe
Owner, "Rickymations"
Join date: 27 May 2005
Posts: 366
|
06-30-2006 11:52
I'm trying to add birthdate-verification to my vendors as a temporary measure until SL adds a way to query for account status. Unfortunately, the dataserver event is rather slow, and I'm not sure what the best way is to "wait" for it to transpire. Right now my code looks something like this:
integer verified = FALSE; ...
dataserver(key queryid, string data) { // get DOB from data by chopping string and typecasting to integer string year = llGetSubString(data, 0,3); string month = llGetSubString(data, 5,6); string day = llGetSubString(data, 8,9); string DOB = year + month + day; if ((integer)DOB > 20060605) { verified = FALSE; } else { verified = TRUE; } // might add a AGE_CHECK_DONE variable here? money(key id, integer amount) { // ADDING AGE VERIFICATION CODE HERE llRequestAgentData(id, DATA_BORN); llWhisper(0, "Please stand by while I verify your date of birth. I've insituted this as a temporary age-verification check until SL gives us a better tool.");
// how to tell when dataserver is done? // do-while loop testing for AGE_CHECK_DONE? // just pause and hope for best?? // user timer() somehow? // change states somehow?
if (verified ) // take money and give item else // return money and say stuff
Any advice on how to handle this?
|
|
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
|
06-30-2006 12:08
From: Ricky Shaftoe Any advice on how to handle this? In the money event, store the person's details, amount they paid, item they're trying to get etc in variables. Then trigger age check from there. Do the actual handing out the item i.e. the things you'd normally do in the money() event... in the dataserver event, after the age check is passed (or return money etc if it's not) There should be code for something similar available in the script library i think, though it's used to do the opposite i.e. allow new people to buy things while older players cannot.
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
06-30-2006 12:34
A loop in the money event won't work, because the money event has to end before the dataserver event can run. So a loop will be stuck forever, waiting for the variable to change. Ditto for a pause/sleep - that locks the script in place. You have to let the money event run to completion for this to work.
Here's what I would do:
money event: - give them a "Please wait while I collect your info..." message - save the amount and avatar key to global variables - send out the av data request - start a guard timer, say 10 seconds to allow for some really serious lag - set a flag that says 'waiting' or 'transaction pending' or something
dataserver event: - check if the 'waiting/pending' flag is set. If it's not set, then this is a dataserver event that came in too late (i.e. after the timer), and you've already cancelled the transaction. do nothing. if not... - stop the timer - clear the 'waiting' flag - do the check, and give inventory or refund money here (so this code moves here from its usual place which is the money event handler). you know the av's key and refund amount because you saved them to global variables in the money event
timer event: - check if 'waiting/pending' flag is set, in case you got the dataserver event and the timer event *right* one after the other, so the timer 'slipped in' before you were able to stop it - if the flag is cleared, then it's a bogus timeout, so there's nothing to do. Maybe stop the timer againt just for safety - if the flag is set, that means you timed out waiting for the dataserver. so stop the timer, say "Sorry we couldn't retrieve your information due to lag, please try again later", refund the money, and clear the 'pending' flag
Basically, you need to be prepared for the timer or the dataserver to come in together, dataserver come in late, dataserver never arrive, and so on... think of all the ways this could break, and make sure you've covered them.
|
|
Ricky Shaftoe
Owner, "Rickymations"
Join date: 27 May 2005
Posts: 366
|
06-30-2006 13:04
Well, I moved the purchasing stuff into the dataserver event, and that seems to work fine. I haven't put in the "guard timer" Ziggy mentioned. Is that strictly speaking necessary? It's working fine so far. But what happens if dataserver lags so badly that the player gets bored and wanders away?
|
|
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
|
06-30-2006 13:13
From: Ricky Shaftoe Well, I moved the purchasing stuff into the dataserver event, and that seems to work fine. I haven't put in the "guard timer" Ziggy mentioned. Is that strictly speaking necessary? It's working fine so far. But what happens if dataserver lags so badly that the player gets bored and wanders away? A guard thing is convenient to deal with situation where your script is 'idling' while dataserver looks up answer to its request, and someone other than your original buyer also deposits the money. Because when they do so, the money event is triggered, details of new person overwrite details of your previous customer and this means when the answer to original question comes, your script is in danger of treating it as answer to inquiry about details of most recent customer... while your original buyer winds up all forgotten with no money and no item. (it's possible to protect yourself against it by storing purchase requests in queue of sorts, but that'll require more memory and is more tricky) Players can receive items and money no matter if they're in one sim with the object that gives them, so even if someone gets bored they'll still get either their item or refund.
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
06-30-2006 13:23
Good point, Joannah, that's another situation I didn't think of. If a 2nd person pays while the script is waiting for the 1st person's data, you want to refund the money immediately and say "Sorry, busy processing someone else's request, please try again later", and make sure the saved key/amount information doesn't get over-written. So you'll need a status flag to keep track of that, even if you don't use a timer. But once you have a status flag, if you lose a dataserver event, your script gets stuck, it'll never accept money again, because the status flag will only get cleared in the dataserver event. Which brings you back to a guard timer.
Is it strictly necessary? That depends upon you. I tend to be paranoid when I'm writing a script that deals with money, so I err on the side of cautious/defensive programming. So it totally depends on how safe you want it to be. Will you be selling this to others? Is there a chance that more than one person might try to use it at the same time? Could it be placed in a laggy area? Do you care if someone IM's you and says "This thing took my money and didn't give me anything in return"? All of that will decide what kind of safety checks you build into your script.
So, if I were in your place... if this was something I was writing for my own amusement, to play with my friends... I wouldn't bother. If I was writing it for a client, or I planned to sell it, I'd put in as many checks as I could think of.
|
|
Ricky Shaftoe
Owner, "Rickymations"
Join date: 27 May 2005
Posts: 366
|
06-30-2006 16:13
Well, I don't plant to sell this vendor; I'm using it for myself. But I am indeed using the vendor to sell stuff. So far it's working fine after just a few hours, and I don't mind answering the occasional customer-service call; I'm used to that already. My items average 200L or so each, so they aren't big-ticket items that get people really riled if something goes amiss. I'm inclined to think my current script ain't broken so far, so I'm not sure I want to fix it. But we'll see how it holds up in the busy weekend shopping period. If I have trouble, I'll add a guard timer.
I confess I'm still not sure how a guard timer would work; I've only used a timer event once. Would the guard timer require that every transaction take 10 seconds? That would not be good! Still, if adding a timer event wouldn't add more lag, I'd consider it. I'll play around with it.
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
06-30-2006 16:32
From: someone Well, I don't plant to sell this vendor; I'm using it for myself. But I am indeed using the vendor to sell stuff. So far it's working fine after just a few hours, and I don't mind answering the occasional customer-service call; I'm used to that already. My items average 200L or so each, so they aren't big-ticket items that get people really riled if something goes amiss. Yeah, doesn't look like a very strong case for putting in a lot of checks and balances then. I'd say you're fine. From: someone Would the guard timer require that every transaction take 10 seconds? Not at all. What it means is that if a transaction has *not* completed in a certain amount of time, you have a means of taking some recovery action. So for the vast majority of the transactions, they'll complete in a fraction of a second, and you cancel the timer and you're done. The timer code only activates if something goes wrong somewhere.
|
|
Ricky Shaftoe
Owner, "Rickymations"
Join date: 27 May 2005
Posts: 366
|
07-01-2006 06:13
Many thanks. After a day of sales, no glitches. I'll see how it goes.
|