PHP Web Game Learning Xnova (ogame) Source code Interpretation (iii) _php instance

Source: Internet
Author: User

Iv. User Registration (reg.php)

Before I look at the user registration process, I will make a simple description of the purpose of the table, now just the approximate description, and then we carefully understand, you can write down this description.

Game_aks          joint Attack Group record table, attack complete Delete data
game_alliance      Federation table
game_annonce      Bulletin table, basic useless
game_banned        Ban player table
game_buddy        friend table
game_chat          chat record table
game_config        system parameter table
game_errors        Error log table
game_fleets        Fleet activity Record table, activity complete Delete data
game_galaxy        Galaxy table
Game_iraks        Interstellar missile activity table, activity complete Delete data
game_lunas        Moon list
game_messages      message table
game_notes        Note Table
game_planets      Planet List, Including the moon
game_rw            War report
game_statpoints    integral table
game_users        User table


Now we start the user registration process, and at the beginning we can see that we've defined two constants,

Define (' INSIDE ', true);

Inside is used to prevent attacks, the value of True;install is used to record whether it is now in the process of installing the game, the value is false. Next, include two files, Extension.inc and common.php, and then the load language file Reg.mo. In the following chapters, I no longer introduce the preceding code, as we all know.


The following two functions are declared to send the successful registration information, including user name and password.

function Sendpassemail ($emailaddress, $username, $password)


Now introduce the Xnova source code is often used in a structure, the following is pseudocode description,

if ($_post) {//If the user has input//There is a user input
after
the execution process}else{
//Here is no user input after the execution process, including the first time the page is displayed
}


We look at the user registration process, in order to illustrate the structure of the previous, deliberately affixed code. As we have said before, first gettemplate the file, and then parse out and display the page.

if ($_post) {
 //code slightly
} else {
 $parse = $lang;
 $parse [' servername '] = $game _config[' game_name '];
 $page = Parsetemplate (gettemplate (' Registry_form '), $parse);
 Display ($page, $lang [' Registry '], false);
 

The following is a look at the flow of user input information, a heap of if is to determine the user entered the information is legitimate, and the $errors variable to record the number of errors, $errorlist variables to log the wrong message. If the $errors is not zero, the error message is printed, and if there is no error, go to the following process:

1. Check that the user name has illegal characters

2. Check email for illegal characters

3. Check to see if the planet's name has illegal characters

4. Encrypt the user's password, MD5

5. Insert user information into table users

6. Get the user ID number that just inserted the build standby

7. A large section of code function, find an empty planet coordinates to this user as the parent star, and use function Createoneplanetrecord () to create the planet, here to use three system parameters Lastsettedgalaxypos, Lastsettedsystempos, Lastsettedplanetpos, the name should be clear, respectively, is the last galaxy, the last solar system, the last planet position

8. Update the planet ID in the users table for the planet ID just generated

9. Send a welcome message to this player

10. Send registration message to this player

11. Display Registration Success page, registration end

The above process, we can find the corresponding code, the code is not very difficult, so not listed. function Createoneplanetrecord () in detail later, now said instead of the head big, function sendsimplemessage () We now look at, declared in the sendsimplemessage.php file.

function Sendsimplemessage ($Owner, $Sender, $Time, $Type, $From, $Subject, $Message) {global $messfields;
 if ($Time = = ") {$Time = time ();
 } if ($Sender = = null) {$Sender = 0;
 $QryInsertMessage = "INSERT into {{table}}} SET"; $QryInsertMessage. = "' Message_owner ' =".
 $Owner. ","; $QryInsertMessage. = "' Message_sender ' =".
 $Sender. ","; $QryInsertMessage. = "' message_time ' =". $Time.
 ", "; $QryInsertMessage. = "' Message_type ' =".
 $Type. ","; $QryInsertMessage. = "' message_from ' = '".
 Addslashes ($From). "', '; $QryInsertMessage. = "' message_subject ' = '".
 Addslashes ($Subject). "', '; $QryInsertMessage. = "' message_text ' = '".
 Addslashes ($Message). "'; ';
 Doquery ($QryInsertMessage, ' messages ');
 $QryUpdateUser = "UPDATE {{table}}} SET";
 $QryUpdateUser. = "'. $messfields [$Type]. $messfields [$Type]." ' + 1, ';
 $QryUpdateUser. = "'. $messfields [M]. $messfields [100]." ' + 1 ";
 $QryUpdateUser. = "WHERE"; $QryUpdateUser. = "' id ' = '". $OWner. "';";
Doquery ($QryUpdateUser, ' users '); 

 }

The function of the

function is to insert a detailed message into the messages table and update the number of messages in the Users table, very clear, hehe. Another function of the message () and display () is basically the same, do not write in detail, look at it yourself. At this point, the user registration process is finished.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.