PHP web game learning-Explanation of Xnova (ogame) source code (III)

Source: Internet
Author: User
This article mainly introduces the user registration page for interpreting the PHP web game Xnova (ogame) Source Code. For more information, see

This article mainly introduces the user registration page for interpreting the PHP web game Xnova (ogame) Source Code. For more information, see

Iv. User Registration (reg. php)

Before looking at the user registration process, I will give a brief description of the table's usage. Now it is just a rough description. We will take a closer look at it later. You can write down this description.

Game_aks combined attack group record table. After the attack is completed, the game_alliance Alliance table game_annonce announcement table is deleted. It is useless, activity completed deletion data game_galaxy galaxy table interstellar missile activity table, activity completed deletion data game_lunas lunar list game_messages message table game_notes note table game_planets planet list, including lunar game_rw war report table Seasonal Integration table game_users User table


Now we start the user registration process. At the beginning, we can see that two constants are defined,

Define ('inside ', true); define ('install', false );

INSIDE is used to prevent attacks, and the value is true; INSTALL is used to record whether the game is currently in the installation process, and the value is false. The following two files are included: extension. inc and common. php, and the load language file reg.mo. In the subsequent sections, I will not introduce the previous sections of code.


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

Function sendpassemail ($ emailaddress, $ username, $ password) function mymail ($ to, $ title, $ body, $ from = '')


Now we will introduce a frequently used structure in Xnova source code. The following is a description of pseudocode,

If ($ _ POST) {// if the user has input // here is the execution process after user input} else {// here is the execution process after no user input, including when the page is displayed for the first time}


We look at the user registration process. In order to illustrate the previous structure, we specially pasted the code. As we mentioned above, first gettemplate file, then parse out and display the page.

If ($ _ POST) {// Code omitted} else {$ parse = $ lang; $ parse ['servername'] = $ game_config ['game _ name']; $ page = parsetemplate (gettemplate ('registry _ form'), $ parse); display ($ page, $ lang ['registry '], false );}

Next, let's look at the process after the user inputs information. A bunch of if statements are used to determine whether the user input information is legal, and the $ errors variable is used to record the number of errors, and the $ errorlist variable is used to record error messages. If $ errors is not zero, an error message is output. If no error exists, proceed to the following process:

1. Check whether the user name contains invalid characters

2. Check whether the Email contains invalid characters.

3. Check whether the planet name contains invalid characters.

4. encrypt the user's password, md5

5. INSERT user information to the users table

6. Obtain the user ID Id just inserted.

7. for a large part of the code function, find an empty planet coordinate for this user as the parent star, and use the CreateOnePlanetRecord () function to create a planet ,, here we need to use the three system parameters LastSettedGalaxyPos, LastSettedSystemPos, and LastSettedPlanetPos. The names should be clear, including the last Galaxy, the last Solar System, and the last planetary location.

8. Update the planet ID in the users table to the newly generated planet ID.

9. Send a welcome message to this player

10. Send a registration email to the player

11. The registration successful page is displayed. Registration is complete.

In the above process, we can find the corresponding code, the code is not difficult, so it is not listed. The CreateOnePlanetRecord () function will be described in detail later. Now, the header is too big. Let's take a look at the SendSimpleMessage () function. The declaration is 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 _ subobject' = '". addslashes ($ Subject ). "',"; $ QryInsertMessage. = "'message _ text' = '". addslashes ($ Message ). "';"; doquery ($ QryInsertMessage, 'messages'); $ QryUpdateUser = "UPDATE {table} SET"; $ QryUpdateUser. = "'". $ messfields [$ Type]. "'= '". $ messfields [$ Type]. "'+ 1,"; $ QryUpdateUser. = "'". $ messfields [100]. "'= '". $ messfields [100]. "'+ 1"; $ QryUpdateUser. = "WHERE"; $ QryUpdateUser. = "'id' = '". $ Owner. "';"; doquery ($ QryUpdateUser, 'users ');}

The function inserts detailed messages into the messages table and updates the number of messages in the users table. The message () function of another function is basically the same as that of display (), so I won't write it in detail. Let's take a look at it. Now, the user registration process has been analyzed.

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.