Raised This Month: $99 Target: $400
 24% 

A cookie system


Post New Thread Reply   
 
Thread Tools Display Modes
sslice
Senior Member
Join Date: Feb 2005
Location: Texas, USA
Old 05-13-2007 , 19:43   Re: A cookie system
Reply With Quote #11

Hmm, there is the possibility of making sub-cookies, where cookies can also hold a subset of other cookies.. where one or more of those cookies could also possibly hold a subset of cookies, just like KeyValues does. If I did this, though, it would resemble KeyValues in so many ways.
__________________
sslice is offline
BAILOPAN
Join Date: Jan 2004
Old 05-13-2007 , 19:47   Re: A cookie system
Reply With Quote #12

Yeah I wouldn't do that. As long as cookies are serializable in someway then it should be good. I.e. let's say you have 10 data types you want to stuff into a cookie, 5 floats and 5 ints, you could say "store all of these in one value for me."

Then later those values could be expanded back.
__________________
egg
BAILOPAN is offline
sslice
Senior Member
Join Date: Feb 2005
Location: Texas, USA
Old 05-13-2007 , 21:00   Re: A cookie system
Reply With Quote #13

Ok, I think I have decided on the final implementation: http://www.ampaste.net/11424

It will be completely string-based, with the ability to serialize data into it using 'PackCookie' and 'UnpackCookie'.
Here are the prototypes along with examples:
Code:
/**
 * Serialize data to the cookie's string
 * 
 * Symbol             Representation 
 *  i                  var
 *  f                  Float:var
 *  s                  String:var[]
 *  b                  bool:var
 *  
 * Example:
 *  new String:name[] = "Maggie";
 *  new height = 32;
 *  new Float:weight = 19;
 *  new bool:female = true;
 *  PackCookie(dogProperties, "sifb", name, height, weight, female);   
 *
 * @param cookie      Handle to the cookie
 * @param format      Formatting rules
 * @param ...         Variables corresponding to the format to be written
 * @return            How many variables were read from
 */
native PackCookie(Handle:cookie, const String:format[], any:...);

/**
 * Sets the expiration time of the cookie
 * 
 * Symbol             Representation 
 *  i                  var
 *  f                  Float:var
 *  s#                 String:var[#]
 *  b                  bool:var   
 *
 * Example:
 *  new String:name[50];
 *  new height;
 *  new Float:weight;
 *  new bool:female;
 *  UnpackCookie(dogProperties, "s50ifb", name, &height, &weight, &female);
 *  
 * @param cookie      Handle to the cookie
 * @param format      Formatting rules
 * @param ...         Variables corresponding to the format to be written (must be able to reference)
 * @return            How many variables were written to
 */
native UnpackCookie(Handle:cookie, const String:format[], any:...);
Let me know what you all think.
__________________
sslice is offline
BAILOPAN
Join Date: Jan 2004
Old 05-13-2007 , 21:21   Re: A cookie system
Reply With Quote #14

Nifty!
__________________
egg
BAILOPAN is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:51.


Powered by vBulletin®
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Theme made by Freecode