BBGameZone.net PBBG Network | BuildingBrowserGames | Top-PBBG
March 11, 2010, 07:09:53 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Our Scripts Vault contains many game scripts that you can use to create your own game!
 
  Home   Forum   Help Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Are player's IDs always numeric in your games?  (Read 320 times)
Blacklava
Level 10
*

Reputation: 1
Offline Offline

Posts: 57


View Profile WWW
« on: February 07, 2010, 01:26:56 PM »

Hi,

working on some code and wondering if player key/ID used on your games are most of the time numeric and if you have a guess of the % of alphanumeric ones?
Just checking if my is_numeric function test won't be a problem... Perhaps some use directly nicknames as unique key?
Not that I'm lazy but it's a bit of pain to modify and complete sql injections protects if I need to change Tongue

Thanks
Logged

CitySlaves browser RPG
(Fully home made script, comments more than welcome! Smiley)
bbgames
Level 15
*

Reputation: 1
Online Online

Posts: 121


View Profile WWW
« Reply #1 on: February 07, 2010, 01:31:29 PM »

Generally I tend to track user IDs and usernames - while usernames have to be unique, users never see or interact with their user IDs. I leave the IDs numeric, to take advantage of having an auto_increment field in my database that I can use as a primary key.
Logged

Blacklava
Level 10
*

Reputation: 1
Offline Offline

Posts: 57


View Profile WWW
« Reply #2 on: February 07, 2010, 01:35:03 PM »

yes same here, I'm wondering if almost everybody doing so or if I need to bother with alphanumeric IDs... If 95% uses numeric IDs I'll skip the extra pain  Undecided
Logged

CitySlaves browser RPG
(Fully home made script, comments more than welcome! Smiley)
Nox
Level 28
**

Reputation: 10
Offline Offline

Posts: 416



View Profile
« Reply #3 on: February 07, 2010, 03:13:13 PM »

http://community.bbgamezone.net/index.php/topic,2527.0.html
Logged

Bookmark worthy: Sirlin.net (game design)

dsheroh
Level 10
*

Reputation: 4
Offline Offline

Posts: 65


Perl Vicar


View Profile WWW
« Reply #4 on: February 08, 2010, 05:57:56 AM »

working on some code and wondering if player key/ID used on your games are most of the time numeric and if you have a guess of the % of alphanumeric ones?

When I'm dealing with an SQL database directly under a relational(ish) model, I use numeric ids for everything.  It's more efficient, plus autoincrement/serial id fields are just too convenient to pass up.

In my current game project, I'm using object graph storage rather than an SQL database[1] and, for items with names, I have chosen to derive their ids from the type of object and its name.  So, for example, my test user has id "user:dave" and owns the character with id "char:dave".  (Objects without names get default ids like "4796A8BA-36C2-47D4-9916-345E263D2BC5".)

Not that I'm lazy but it's a bit of pain to modify and complete sql injections protects if I need to change Tongue

Use SQL placeholders/parameters and you don't have to worry about SQL injection.  Period.  No matter what you change.  It's 20-freaking-10 and there is no excuse for trying to escape strings instead of using placeholders.

http://bobby-tables.com/ has language-specific guidance on how to do this for most of the currently-popular web development languages.  (Although I just checked and the PHP page only has examples for the PostgrSQL and ODBC extensions.  If you regularly use parametrized queries with PDO, please fork the site on github and submit a patch adding a PDO example.)


[1]  Well, technically, KiokuDB implements object graph storage on top of an SQL database, so SQL is ultimately still involved, but I'm not interacting with the database as SQL.
Logged
JGadrow
Level 35
**

Reputation: 16
Offline Offline

Posts: 871



View Profile
« Reply #5 on: February 08, 2010, 09:19:53 AM »

Use SQL placeholders/parameters and you don't have to worry about SQL injection.  Period.  No matter what you change.  It's 20-freaking-10 and there is no excuse for trying to escape strings instead of using placeholders.
Woo hoo! Another advocate of better security! In MySQL this is called "prepared statements" look it up, you'll be glad you did. Oh, and welcome to 2005. lol Wink

+1 dsher.
Logged

Idiocy - Never underestimate the power of stupid people in large groups.

133794m3r
Level 17
*

Reputation: 1
Offline Offline

Posts: 158

Designer, Coder, Tester, Cynic, Critic.


View Profile
« Reply #6 on: February 09, 2010, 12:19:48 PM »

I know it's really off topic and all, but i went to that page to learn about well what it said since i'm always up for making myself more secure. and it reminded me of when i first saw the comic, i had no idea that it was really saying what it was. Till, i looked up sanitizing your inputs and came to mysql injection. Which was a little thing i saw on hackthissite. And also wow dsheroh. Never heard of that site before or new that anything like that existed... i just thought sanitizing the input was a good measure.
Logged
codestryke
Administrator
Level 31
*****

Reputation: 18
Offline Offline

Posts: 519



View Profile WWW
« Reply #7 on: February 09, 2010, 01:21:34 PM »

Use SQL placeholders/parameters and you don't have to worry about SQL injection.  Period.  No matter what you change.  It's 20-freaking-10 and there is no excuse for trying to escape strings instead of using placeholders.
Woo hoo! Another advocate of better security! In MySQL this is called "prepared statements" look it up, you'll be glad you did. Oh, and welcome to 2005. lol Wink

+1 dsher.
Unfortunately using prepared statements requires the use of the mysqli extension. Normally this would not be a problem, however, mysqli does NOT support persistent connections. Without careful testing just saying "use mysqli and prepared statements" could put someone in a database nightmare depending on there server setup and what they are pulling for traffic.

Secondly although the security is superior with prepared statements you have to know what the server is doing. When you prepare a statement that is one trip to the db server, then you execute the statement and that is another trip to the db server. So now you've doubled your load to the database server.

Yes it is 2010 but the fact remains (as always with programming) one solution doesn't fit every developers  needs.

Logged

Creating online addictions, one game at a time:
www.extremecast.com
Nox
Level 28
**

Reputation: 10
Offline Offline

Posts: 416



View Profile
« Reply #8 on: February 09, 2010, 01:24:11 PM »

It does not have to be necessarily via prepaired statements, you can create your own version of replacing placeholders with given escaped values
Logged

Bookmark worthy: Sirlin.net (game design)

dsheroh
Level 10
*

Reputation: 4
Offline Offline

Posts: 65


Perl Vicar


View Profile WWW
« Reply #9 on: February 10, 2010, 08:02:00 AM »

I know it's really off topic and all, but i went to that page to learn about well what it said since i'm always up for making myself more secure. and it reminded me of when i first saw the comic, i had no idea that it was really saying what it was. Till, i looked up sanitizing your inputs and came to mysql injection. Which was a little thing i saw on hackthissite. And also wow dsheroh. Never heard of that site before or new that anything like that existed... i just thought sanitizing the input was a good measure.

You never heard of bobby-tables.com before because it's fairly new.  Smiley  IIRC, Andy just set it up within the last month or so.
Logged
133794m3r
Level 17
*

Reputation: 1
Offline Offline

Posts: 158

Designer, Coder, Tester, Cynic, Critic.


View Profile
« Reply #10 on: February 10, 2010, 08:06:45 AM »

I know it's really off topic and all, but i went to that page to learn about well what it said since i'm always up for making myself more secure. and it reminded me of when i first saw the comic, i had no idea that it was really saying what it was. Till, i looked up sanitizing your inputs and came to mysql injection. Which was a little thing i saw on hackthissite. And also wow dsheroh. Never heard of that site before or new that anything like that existed... i just thought sanitizing the input was a good measure.

You never heard of bobby-tables.com before because it's fairly new.  Smiley  IIRC, Andy just set it up within the last month or so.

i was speaking mostly of the idea of sql prepares and such things as that. And also the entire comic itself. It made no sense to me at the time till i went to hts which showed me a few things well for as far as i was able to get on how to not allow things to go over the hill to help myself be protected. And also what code said, i doubt it'll be right for me though then until i get a nice stable playerbase set up, since 2 database connections per page request is definately going to put a hamper on my performance. Especially when i'm attempting to do some semi-open testing as the performance hit on a plain old hosted site will be low enough already.
Logged
dsheroh
Level 10
*

Reputation: 4
Offline Offline

Posts: 65


Perl Vicar


View Profile WWW
« Reply #11 on: February 10, 2010, 08:25:28 AM »

Unfortunately using prepared statements requires the use of the mysqli extension. Normally this would not be a problem, however, mysqli does NOT support persistent connections. Without careful testing just saying "use mysqli and prepared statements" could put someone in a database nightmare depending on there server setup and what they are pulling for traffic.

http://bobby-tables.com/php.html now shows examples for using prepared statements in PHP under the mysqli, ADODB, ODBC, and PDO extensions.  Do all of those options fail to support persistent connections?  (And, for that matter, does PHP really only give access to persistent connections at the database library level?  When I think about persistent db connections for web apps in Perl, I generally think of them being managed by apache, not by DBI.  But, then, I generally think in terms of persistent applications rather than persistent db connections anyhow...)

Secondly although the security is superior with prepared statements you have to know what the server is doing. When you prepare a statement that is one trip to the db server, then you execute the statement and that is another trip to the db server. So now you've doubled your load to the database server.

If you only use each prepared statement once, sure.  But database-intensive apps generally run basically the same query several times, differing only in WHERE clause conditions or values to INSERT/UPDATE, all of which can be parameters for a pre-prepared statement.  Reuse the prepared statement and the number of trips to the database only increases to n+1, not 2n.

Also take into account that, even if you don't explicitly prepare the statement before executing it, the server still has to implicitly prepare it.  By reusing the prepared statement, you avoid repeating that overhead and will, in most cases, reduce the overall load on the database server.


And also what code said, i doubt it'll be right for me though then until i get a nice stable playerbase set up, since 2 database connections per page request is definately going to put a hamper on my performance.

You misunderstood his second point.  Doing a separate prepare, then execute requires an additional request to the database server, not an additional connection.
Logged
133794m3r
Level 17
*

Reputation: 1
Offline Offline

Posts: 158

Designer, Coder, Tester, Cynic, Critic.


View Profile
« Reply #12 on: February 10, 2010, 08:59:03 AM »

Unfortunately using prepared statements requires the use of the mysqli extension. Normally this would not be a problem, however, mysqli does NOT support persistent connections. Without careful testing just saying "use mysqli and prepared statements" could put someone in a database nightmare depending on there server setup and what they are pulling for traffic.

http://bobby-tables.com/php.html now shows examples for using prepared statements in PHP under the mysqli, ADODB, ODBC, and PDO extensions.  Do all of those options fail to support persistent connections?  (And, for that matter, does PHP really only give access to persistent connections at the database library level?  When I think about persistent db connections for web apps in Perl, I generally think of them being managed by apache, not by DBI.  But, then, I generally think in terms of persistent applications rather than persistent db connections anyhow...)

Secondly although the security is superior with prepared statements you have to know what the server is doing. When you prepare a statement that is one trip to the db server, then you execute the statement and that is another trip to the db server. So now you've doubled your load to the database server.

If you only use each prepared statement once, sure.  But database-intensive apps generally run basically the same query several times, differing only in WHERE clause conditions or values to INSERT/UPDATE, all of which can be parameters for a pre-prepared statement.  Reuse the prepared statement and the number of trips to the database only increases to n+1, not 2n.

Also take into account that, even if you don't explicitly prepare the statement before executing it, the server still has to implicitly prepare it.  By reusing the prepared statement, you avoid repeating that overhead and will, in most cases, reduce the overall load on the database server.


And also what code said, i doubt it'll be right for me though then until i get a nice stable playerbase set up, since 2 database connections per page request is definately going to put a hamper on my performance.

You misunderstood his second point.  Doing a separate prepare, then execute requires an additional request to the database server, not an additional connection.

well, even if it's only using 2 requests per page though, that page would then have to do additional read/writes to the database. And if it's something such as a page where someone buys an item perse from the item shop. Then it'd normally have then buying one or how many they wish to input, it'd then go pull the cost of the item from the one table and get that, then it'd subtract the  amount from the players current amount in their inventory in the database section. So using prepared statements in such a situation such as that one which'll be the most common type of database requests i have. Would they result in n+1 requests? Since it's mostly going to be select from where, and also i'm going to of course going to have to pull in some data from it and the update for the player. In that situation in your professional opinion how much of an increase of requests should i expect?

Also my main worry for this is that i've yet to benchmark any of this on my server yet so i have no idea what type of performance i should expect. And if it can only do let's say 20 requests per second, and if i have 200 players online(also a high estimation for this purpose and a man can dream), and if they're randomly clicking around doing things. This'd mean that i currently with x number of requests per page be able to serve y people. If it's 2x the amount of requests. Then that'd mean that i'd only be able to server y/2 number of people per second which would then result in decreased performance which may then make them leave my game.
Logged
Nox
Level 28
**

Reputation: 10
Offline Offline

Posts: 416



View Profile
« Reply #13 on: February 10, 2010, 09:25:02 AM »

As I said - make your own placeholder replacement/whatever and you'll have no request increase
Say something like this http://dibiphp.com/en/quick-start
Logged

Bookmark worthy: Sirlin.net (game design)

Chris
Game Owner
Level 35
*

Reputation: 8
Offline Offline

Posts: 1,021


View Profile
« Reply #14 on: February 10, 2010, 09:43:03 AM »

Also my main worry for this is that i've yet to benchmark any of this on my server yet so i have no idea what type of performance i should expect. And if it can only do let's say 20 requests per second, and if i have 200 players online(also a high estimation for this purpose and a man can dream), and if they're randomly clicking around doing things. This'd mean that i currently with x number of requests per page be able to serve y people. If it's 2x the amount of requests. Then that'd mean that i'd only be able to server y/2 number of people per second which would then result in decreased performance which may then make them leave my game.
SQL performance is not about site speed but server stability. It is not that if you have plenty of DB requests it will slow down your site, it will crash it. If you have more requests SQL can process it starts queueing them, queues uses memory, it makes the server slower and slower... and then it crashes Smiley
At least that's how it works in my case, I do not recall any slowdowns, but crashes yes. It is either blazing fast or total crash, never anything inbetween.
Also the number of players that cause this is not linear. With 2500 I got everything working smoothly, but one day I got 2700 (less than 5% increase) and everything crashed. It's similar to a drop of water that over-something (forgot the word) the ocean Cheesy
Logged

JGadrow
Level 35
**

Reputation: 16
Offline Offline

Posts: 871



View Profile
« Reply #15 on: February 11, 2010, 09:46:35 AM »

@codestryke
I'm surprised, sir, you've seen me countless times state that there is never a "single solution" to any problem. Nowhere did I state that it was the only thing that you should ever do. Only that it was preferable and that some research should be conducted into it by those who are not "in the know."

It is the fact that there is not a single solution to every problem that keeps me interested in programming. If every question only had a single answer, then it wouldn't really be necessary to have more than a handful of developers. Smiley
Logged

Idiocy - Never underestimate the power of stupid people in large groups.

Pages: [1]   Go Up
  Print  
 
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC
SimplePortal 2.2 © 2008-2009
Valid XHTML 1.0! Valid CSS!