Home  >  Article  >  Backend Development  >  Xnova (ogame) source code interpretation for PHP web game learning (3)_PHP tutorial

Xnova (ogame) source code interpretation for PHP web game learning (3)_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:24:161106browse

4. User registration (reg.php)

Before looking at the user registration process, I will briefly explain the purpose of the table. Now it is just a rough explanation. We will learn more about it later. You can write down this explanation.

game_aks          联合攻击组记录表,攻击完成删除数据
game_alliance      联盟表
game_annonce      公告表,基本无用
game_banned        Ban玩家表
game_buddy        好友表
game_chat          聊天记录表
game_config        系统参数表
game_errors        错误日志表
game_fleets        舰队活动记录表,活动完成删除数据
game_galaxy        星系表
game_iraks        星际导弹活动表,活动完成删除数据
game_lunas        月球列表
game_messages      消息表
game_notes        笔记表
game_planets      星球列表,包括月球
game_rw            战报表
game_statpoints    积分表
game_users        用户表


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, the value is true; INSTALL is used to record whether it is in the process of installing the game, the value is false. Next are the Include files, extension.inc and common.php; and then the load language file reg.mo. In the following chapters, I will no longer introduce the previous code, everyone already understands it.


Two functions are declared below to send information after successful registration, including user name and password.

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


Now I will introduce a structure that is often used in the Xnova source code. The following is a pseudo code description,

if ($_POST) { //如果用户有输入
//这里是有用户输入后执行过程
}else{
//这里是无用户输入后的执行过程,包括页面第一次显示的时候
}


Let's look at the user registration process. In order to illustrate the previous structure, the code is specially posted. As we said before, first get the template file, then parse it out and display the page.

if ($_POST) {
 //代码略
} else {
 $parse = $lang;
 $parse['servername'] = $game_config['game_name'];
 $page = parsetemplate(gettemplate('registry_form'), $parse);
 display ($page, $lang['registry'], false);
} 

Let’s look at the process after the user inputs information. A bunch of ifs are used to determine whether the information entered by the user is legal, and the $errors variable is used to record the number of errors, and the $errorlist variable is used to record the error message. If $errors is not zero, the error message will be output; if there is no error, enter the following process:

1. Check whether the username has illegal characters

2. Check whether the email contains illegal characters

3. Check whether the planet name contains illegal characters

4. Encrypt user’s password, md5

5. INSERT user information into table users

6. Get the user ID number just inserted and generated as a backup

7. A large piece of code function, find an empty planet coordinate for this user as the home planet, and use the function CreateOnePlanetRecord() to create the planet. Here, three system parameters LastSettedGalaxyPos, LastSettedSystemPos, and LastSettedPlanetPos are used. The naming should be Clearly, they are the last galaxy, the last solar system, and the last planet position

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 registration information email to this player

11. The registration success page is displayed and the registration is completed

We can find the corresponding code for the above process. The code is not difficult, so it is not listed. The function CreateOnePlanetRecord() will be introduced in detail later, but it is too confusing to say now. Let’s take a look at the function SendSimpleMessage(), which is 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[100]."' = '".$messfields[100]."' + 1 ";
 $QryUpdateUser .= "WHERE ";
 $QryUpdateUser .= "'id' = '". $Owner ."';";
 doquery( $QryUpdateUser, 'users');
} 

The function of the function is to insert detailed messages into the messages table and update the number of messages in the users table. It is very clear, haha. The function of another function message() is basically the same as display(), so I won’t write it in detail. Just take a look at it yourself. At this point, the analysis of the user registration process is complete.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825517.htmlTechArticle4. User registration (reg.php) Before looking at the user registration process, let me make a list of the purpose of the table A brief explanation, now it is just a rough explanation, we will learn more about it later, you can remember...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn