Forum BigDB Unique registration name

Discussion and help relating to the PlayerIO database solution, BigDB.

Unique registration name

Postby whitershores » July 20th, 2011, 2:44 am

Hi

I would like to have a system that lets people pick a unique username, that nobody uses.

This cant be the username that people use for registration, as my games database has both SimpleUsers and Facebook users which dont have a username, just a fb123456789 key for the PlayerObjects.

So This has to be set afterwards, and needs to be checked against the entire database, if someone has already picked this username?

Whats the best way of doing this?
whitershores
Paid Member
 
Posts: 88
Joined: June 21st, 2011, 4:19 pm

Re: Unique registration name

Postby Henrik » July 20th, 2011, 3:23 am

The best way would probably be to make a table in BigDB, and add one entry for each user with the username as a key, then you can do quick lookups by username to see if it's taken.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: Unique registration name

Postby garysimmons » July 20th, 2011, 10:59 am

I have't done an awful lot with BigDB just yet but i'm guessing you can just store a user name in the player objects and make it an index so that the server can run a query using that index. I think you would need to do the actual lookup on your server as the client wouldn't have access to other player's objects but the server itself has total read writes I believe.

So you could create some room type on the server for (username registration) which when called from the client runs a query on the player table (using LoadSingle) to find if a player already exists with that username. If none is found you know the username is safe to use and can save it to the player object.

Like I said I haven't used BigDB much for anything yet but I think this should work
garysimmons
 
Posts: 99
Joined: May 15th, 2011, 12:02 pm

Re: Unique registration name

Postby whitershores » July 20th, 2011, 12:04 pm

Thanks for the ideas, I was thinking of an Index as well, and have even made one, so I can load now PlayerObjects by their usernames, but thats not really useful? Like then i would need to download all Playerobjects and loop through them if they use that username, which would be rather inefficient if I would end up having tens of thousands of registered users.

The other idea of having a separate table with just the usernames, sounds also interesting, would you mean, that a table entry would be created for each User, so I could just simply try to do a load by key?

I know Everybody Edits, does this, that it lets people register, then asks for a username afterwards which must be unique?
whitershores
Paid Member
 
Posts: 88
Joined: June 21st, 2011, 4:19 pm

Re: Unique registration name

Postby garysimmons » July 20th, 2011, 12:30 pm

Hi,

Well you wouldn't need to download all player objects. I am assuming they create their unique usernames/display names after the account has been created. Therefore you can simply search for a single player object which has the user name they wish to use. If the query returns a valid object you know the username is already taken and can prompt them to choose another. You shouldn't need to do any looping through player objects using this method. Just a single LoadSingle query on the DB for a player object with that username. Only if the search is unsuccessful do you save the new username to the player object.

The only problem with having a separate table for usernames is you are essentially eating up your MaxDB objects allowance depending on what package you are on. For example, lets assume you are on the free package whilst developing which has a limit of 25,000 objects. If you were using just player objects this would allow you 25,000 users but if you need to create two objects per player (the player object and the username object) that would halve the number of users you can facilitate as I understand it. If this is not an issue then the username table is a fine idea but to me it just seems that the logical place to store usernames would be in the player object.
garysimmons
 
Posts: 99
Joined: May 15th, 2011, 12:02 pm

Re: Unique registration name

Postby Henrik » July 20th, 2011, 4:52 pm

whitershores wrote:Thanks for the ideas, I was thinking of an Index as well, and have even made one, so I can load now PlayerObjects by their usernames, but thats not really useful? Like then i would need to download all Playerobjects and loop through them if they use that username, which would be rather inefficient if I would end up having tens of thousands of registered users.

No, if you have a property called "username" on the PlayerObjects table you can do a simple index lookup for a single value, and if you get something back, someone took that username.

It's important to note though that BigDB indexes don't impose constraints, so if two people choose the same username at the same time so both lookups return nothing, then both will save that username.

whitershores wrote:The other idea of having a separate table with just the usernames, sounds also interesting, would you mean, that a table entry would be created for each User, so I could just simply try to do a load by key?

Yes. BigDB does enforce constraints on object keys though, so if you call CreateObject() with a key that already exists, you will get an error back, which means that you can be sure they are unique.

So either use a separate table and get guaranteed unique usernames at the cost of a bit more of storage and lookups (You need to read the username of each user when they log in somehow), or store it in the PlayerObjects table and use less storage and lookups, at the cost of only almost guaranteed uniqueness.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: Unique registration name

Postby whitershores » July 20th, 2011, 5:00 pm

I think im going to go for the second one, which is more difficult, coz I can only do that from the serverside, but on the other hand the other option would mean simply using exactly the double amount of BigDB Objects, as every user would have at least 2..


PS what would happen if I had 2 objects with the same index when I load a loadSingle? Would both objects be returned, or just the first one?
whitershores
Paid Member
 
Posts: 88
Joined: June 21st, 2011, 4:19 pm

Re: Unique registration name

Postby Henrik » July 20th, 2011, 5:09 pm

whitershores wrote:PS what would happen if I had 2 objects with the same index when I load a loadSingle? Would both objects be returned, or just the first one?

The first one.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: Unique registration name

Postby garysimmons » July 20th, 2011, 6:27 pm

I suppose (although getting a bit convoluted now) you could read back from the DB after saving the username again to see how many objects get returned. If two came back you would know that two names got written to the DB at the same time that were not unique and then take action :)
garysimmons
 
Posts: 99
Joined: May 15th, 2011, 12:02 pm


Return to BigDB



cron