login
March 28, 2024, 05:52:06 pm

Author Topic: A Registering System in SQL?  (Read 1374 times)

0 Members and 1 Guest are viewing this topic.

morphine

  • Crazy Man
  • *****
  • Posts: 1908
  • Country: lt
    • View Profile
A Registering System in SQL?
« on: October 15, 2011, 05:04:28 pm »
I've been reading line by line the sample stats script that VRocker had made for scripters using SQL, the only problem I face is how to possibly link a register and login system to such a script, or how to make one for SQL anyway.

Can anyone perhaps give a short documentation on how to make a register system for SQL?

Thanks in advance.
« Last Edit: October 15, 2011, 05:15:28 pm by Morphine »
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor


Thijn

  • Forum Administrator
  • Crazy Man
  • *
  • *
  • *
  • Posts: 2946
  • Country: nl
    • View Profile
Re: A Registering System in SQL?
« Reply #1 on: October 16, 2011, 08:44:06 am »
Here is a nice example of a stats script. You could expand it to make it into a register system.

If you need help, give a shout.
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor

I'm not totally useless,
I can be used as an bad example ;)

"Never do Today, What you can do Tomorrow"


Charley

  • Vice Underdog
  • Crazy Man
  • *
  • *
  • Posts: 4749
  • Country: 00
    • View Profile
Re: A Registering System in SQL?
« Reply #2 on: October 16, 2011, 11:25:07 am »
Thijn, what Morphine is saying is that he's read that over and over but still can't see how it would work as a registration system.

Ok Morph I'll give you the basic outline,

Set up a table with the columns Name, IP, Password and then any others you want. (I integrate stats into my accounts table so I'd have kills, deaths and joins as well as those)

Also set up a class in your script to hold the data once the player has logged in. You don't need to hold their name or IP, but it is useful to hold their password, kills, deaths, joins. Also make 2 extra values in the class, one indicating whether they're registered and one indicating whether they're logged in.

Now onPlayerJoin you query the table to see if the player has any existing data. "SELECT FROM Accounts WHERE Name = '"+player.Name+"'" if there is no data returned, prompt the player to register. If there is, then proceed with the log in system. Also set the registered indicator to true and assign their password to the relevant class value.

For the log in system, check whether their IP (player.IP) matches the IP that you've got in the database. So in this case it would be if (player.IP == GetSQLColumnData(q,1)). If it does match, initiate auto login. Set all their class values to the data that you've queried and both registered and logged in indicators to true.

If it doesn't match, prompt the player to login using a command. Check whether the password they use is the same one that you've assigned into their class value. If it is, then perform the query again selecting all the data, then fill in their class accordingly. If it isn't, use your imagination.

All that's left is a method to save the data when a player leaves, or when they're ingame and a register command.

First off the register command:

When it's performed check that their registered indicator is negative, otherwise tell them the nick is already registered. If it isn't then, assuming they've written the correct syntax, save all their data into the table in the appropriate fashion.

As for saving data, use the UPDATE SQL function, it is your choice when you want to save people's new data. A couple of pieces of advice though: Don't do it on every kill. Don't only do it when they leave. Don't save the whole server's data at once. In XE we save 1 player's data every 3 seconds, cycling through all the players ingame.
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor

Writer of excessively long posts