[LOOKING FOR] Simple Database API & Authentication

Discussion in 'Miscellaneous' started by Quartzic, Mar 17, 2016.

  1. I need someone to write me a very simple script that hooks into a MySQL database.

    It will use GET requests as an API so I can hook it into macros.
    I need these functions:

    set <parent> <variable> <value> <type>
    EXAMPLE: set Quartzic OfferRedeemed t bool
    Function sets the <parent>'s <variable> to a <type> <value>.
    Returns "set" if successfully set, otherwise "invalid".
    Creates a Variable and Parent if they do not exist.

    get <parent> <variable> <type> <create>
    EXAMPLE: get Quartzic OfferRedeemed
    Function returns the <parent>'s <variable> of <type>.
    If the Parent or Variable does not exist, if <create> is set as y, it will create the required Parent or Variable and return the default. Otherwise, it will return "invalid".

    toggle <parent> <variable>
    EXAMPLE: toggle Quartzic OfferRedeemed
    Toggles a Boolean value from True to False and vice versa.
    Returns "true" if toggled to true, "false" if toggled to false, "invalid" if not a Boolean.

    add <parent> <variable> <value>
    EXAMPLE: add Quartzic OfferBalance 56
    Adds the <value> to <parent>'s <variable>.
    This will concatenate if <variable> is a string, or add if <variable> is a decimal or integer.

    remove <parent> <variable> <value> <negative>
    EXAMPLE: remove Quartzic OfferBalance 35
    Removes <value> from <parent>'s <variable>.
    This will delete all instances of <value> if a string, or deduct if <variable> is a decimal or integer.
    If <negative> is set to y, an attempt to set the value below 0 will return "negative" and not do anything. Otherwise, the <value> can be set below 0.

    delete [parent] [variable]
    EXAMPLE: del Quartzic OfferRedeemed
    Deletes <parent>'s [variable] if present. Otherwise, deletes all of <parent>'s variables.
    If a variable is present but not a parent, it will delete that variable from everyone who has it.
    Returns "deleted" if the deletion was successful, "invalid" if neither a parent or variable are specified or otherwise.

    clear [parent] [variable]
    EXAMPLE: clear Quartzic OfferRedeemed
    Sets the <parent>'s [variable] to its default if present. Otherwise, sets all of <parent>'s variables to their defaults.
    If a variable is present but not a parent, it will set that variable to its default for everyone who has it.
    Returns "cleared" if the clear was successful, "invalid" if neither a parent or variable are specified or otherwise.

    list <parent>
    EXAMPLE: list Quartzic
    Returns a comma-delimited list of variables for that Parent.
    Returns "invalid" if there are none.

    addfunc <parent> <function>
    EXAMPLE: addauth Quartzic list
    Gives the <parent> the permissions to use the <function> with their Auth Key.
    If the <parent> has the function "all", they by default can use every function.

    addparent <parent> <parentadd>
    EXAMPLE: addparent Quartzic Quartzic2
    Gives the <parent> the permission to use their permitted functions on <parentadd>.
    If the <parent> has the parent "everyone", they by default can use their permitted functions on everyone.

    delfunc <parent> <function>
    EXAMPLE: delauth Quartzic list
    Removes from <parent> the permissions to use the <function> with their Auth Key.
    If removing the function "all", they will still keep individual functions.

    delparent <parent> <parentadd>
    EXAMPLE: delparent Quartzic Quartzic2
    Removes from <parent> the permission to use their permitted functions on <parentadd>.
    If removing the parent "everyone", they will still keep individual parents.

    getauthkey <parent>
    EXAMPLE: getauthkey Quartzic
    Returns <parent>'s authentication key. If they do not have one associated with their account,
    it will create one as a 16-character alphanumeric lowercase string, associate it with their account, and return it.

    And these variable types:

    Defaults to nothing.

    Defaults to 0.
    Setting it as a decimal will round it.

    Defaults to 0.

    Defaults to false.

    Like so:
    Quartzic has the function "list" and the parent "Quartzic2".
    If the "list" function is called for Krysyy with Quartzic's authentication key, it will return "authfail".

    Krysyy has the function "all" and the parent "Quartzic".
    If the "set" function is called for Krysyy with Krysyy's authentication key, it will return "authfail".

    Quartzic2 has the function "get" and the parent "Quartzic".
    If the "get" function is called for Quartzic's OfferBalance as Integer with Quartzic2's authentication key, it will return Quartzic's OfferBalance.
    GET elucidator.one/api?auth=ec7muhjo54u3cfhj&function=get&parent=Quartzic&type=int

    Whenever a variable or parent is stored, created, or modified, its name and values will be converted to lowercase.

    Any requests will be converted to lowercase first. Basically, this API needs to be non-case-sensitive.

    Thanks for reading the entire post. PM or post a quote for how much you would do this for :)
    If you have any questions or need clarification, post them here and I'll answer them.

    I am paying in rupees, promos, or items. RMT trading is strictly forbidden on EMC.

    I do dabble in PHP myself, so make sure to comment your code so I can read it and make small modifications.
  2. I'd be willing to do this for you. :) I do have some questions, however:
    • When it comes to getauthkey, you say that it should return an authentication key, or create one. It should also be associated with their account, it says. Where do these "accounts" come from? It's the only place you mention "account", and it's not clear whether getauthkey creates accounts, or merely associates authentication keys with accounts. I take it this is meant to work against an already existing database structure? If so, I'm going to need a copy of the database structure, and some example (or real) data to work with.
    • I don't really understand the purpose of authentication keys if it's as easy as doing getauthkey through your API for anyone to get a hold of them. I mean, if I were an evil outsider who learned of your API, I could just grab any authentication key for any parent I wanted to simply by calling getauthkey. Either I've missed something, you haven't explained enough or you haven't thought this through enough. ;)
    • Your list command lists variables. I assume you mean variable names? Does it also list functions? If not, would you want a listfunctions command or similar?
    • Speaking of missing commands, you don't seem to have one for showing parent relationships.
    • Is this going to be integrated with an existing framework, or will it be standalone? I'd want to use a framework to create the API, would this be fine with you? I mostly use Symfony in my work, but I'd be fine with using something entirely different too. I'm actually thinking Silex would be appropriate for this project.
    • What version of PHP is supported on the server this will run?
    As for payment, I'm not particularly greedy or needy. Just give me whatever you find my work to be worth when you receive it, should you accept me as your developer.
    JesusPower2 likes this.
    • Basically, when I say "accounts", I mean the parent's parents and functions they have permissions to access. So I can assign a bunch of parents and/or functions to Quartzic, and then those can be accessed with Quartzic's authentication key. But if I remove some, the authentication key stays the same and simply can't access those functions or parents anymore.
    • getauthkey will only return an authentication key if you have proper permissions, just like the other functions. As well, you can't do anything with an empty authentication key: You'd have to add parents and functions, which you need proper permissions to do as well. So, you'd manually put in a code for me so that I can control everything. Then, I can assign permissions as I see fit.
    • Yes, it would list variable names assigned to the specified parent. A listfunctions function would also be useful, although I'm not sure whether you mean all functions, or functions that the parent has permission to access. Probably the latter would be more useful.
    • Well, a search in reverse wouldn't be as useful. But perhaps some sort of variablecheck command to list all parents that have a specific variable could work.
    • This will be standalone. I don't care if you use a framework, to be honest. If it makes it easier for you, go for it.
    • The server I'll be running this on can support PHP 7.0.
    As for money, I'm actually a bit low on Rupees right now. If you're interested in Rupees, let me know and I will liquidate some of my promotional items to pay you with :) If you're interested in promotional items for payment, view my collection @ 2223 on smp1.
  3. Work on the project has begun! :D
    Gotcha. So there's going to be a default account for you with all permissions, basically. And then you'll go from there, using the API to add all the other parents and the values and so forth. At least that's how I have interpreted it. Let me know if I'm off.
    Yeah, it all makes sense now.
    I was thinking it would list the permitted functions. Listing all functions wouldn't be much help.
    I'll leave this one out for now, unless you can specify more clearly what you'd want that command to do. I can always add more to your API as time goes on, should you want more features.
    Yeah, I'm a big fan of using frameworks. Conversely, I'm not a very big fan of writing messy spaghetti code. As you requested, I'll make sure to include plenty of comments in my code so that people who are not me (most likely you, eh?) can understand what's going on if they're not familiar with what I'm doing.
    Don't worry too much about the money. If you're low right now, you can pay me later. I like these little projects, so they're sort of rewarding on their own. I will take a look at your collection, though. Maybe there's something I'd want. :)
  4. Explain to me how the clear/delete functions are going to deal with being called without a specific parent. It says "it will delete that variable from everyone who has it/set that variable to its default for everyone who has it." How does that work with the authentication system? Will it only work on those parents you have access to, or do you literally mean everyone? Which is to say that the clear/delete functions will only check for permission to use the functions and not care otherwise?
  5. Even though there's an offer of rupee payments, still doesn't relate to in game business and services - so moved it to Misc.
  6. The clear/delete functions should respect permissions for parents, too. The only way to clear/delete all variables should be if you have the "everyone" parent.