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

Source: Internet
Author: User
This article mainly introduces the installation file source code interpreted by the PHP web game Xnova (ogame) Source Code. For more information, see

This article mainly introduces the installation file source code interpreted by the PHP web game Xnova (ogame) Source Code. For more information, see

3. install (install/index. php)

This file is the installation page. Two constants are defined at the beginning:

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


Because these two constants are always used in the subsequent code, we should first describe them here. INSIDE is used to prevent attacks; INSTALL is used to record whether the game is currently being installed.

The following two files are included: extension. inc and common. Both are authentic PHP files. First, extension. inc adds the code to prevent attacks and hides the php file extension, which is $ phpEx = "php ". Then, 'common. '. $ phpEx is actually common. php.

IncludeLang ('Install/install ');


This is the load language file. The delang () function declaration is in the DES/unlocalised. php file. There are many small functions in this file.

Function compute delang ($ filename, $ ext = '. Mo') {global $ xnova_root_path, $ lang, $ user; if ($ user ['lang']! = '') {$ SelLanguage = $ user ['lang '];} else {$ SelLanguage = DEFAULT_LANG;} include ($ xnova_root_path. "language /". $ SelLanguage. "/". $ filename. $ ext );}

Function functions include the corresponding code based on the user's language. XnovaTC3 supports different languages for each user.

Continue to get the page content to be displayed, which is the installation step. Then, enter a large switch. Before that, there is a statement like this:

$ MainTPL = gettemplate ('Install/ins_body ');

The Gettemplate () function is also declared in the uplodes/unlocalised. php file,

Function gettemplate ($ templatename) {global $ xnova_root_path; $ filename = $ xnova_root_path. TEMPLATE_DIR. TEMPLATE_NAME. '/'. $ templatename. ". tpl "; return ReadFromFile ($ filename );}

The function retrieves the content of a specified file. The specified file is composed of the following:

$ Ugamela_root_path. TEMPLATE_DIR. TEMPLATE_NAME. '/'. $ templatename. ". tpl ";

The value of TEMPLATE_DIR is 'templates/', and the value of TEMPLATE_NAME is 'opengame'.

('Install/ins_body') is to get the content in the templates/OpenGame/install/ins_body.tpl file. There are several other such functions that you should remember and will often use later.

Case 'intro ':

At first glance, we should know that it is the description page, but there is a function parsetemplate () that we saw for the first time, which is declared in the replicdes/unlocalised. php file,

Function parsetemplate ($ template, $ array) {return preg_replace ('#\{ ([a-z0-9 \-_] *?) \}# Ssie ',' (isset ($ array [\ '\ 1 \'])? $ Array [\ '\ 1 \']: \ ');', $ template );}

The function uses a regular expression to replace the value of $ array with a specific string in $ template (that is, the content included in {}) to implement the multi-language function.

Case 'ins ':

This branch is a specific installation process. It is divided into four step pages, which are controlled by the $ page variable to display.

1. when the value of $ page is 1, make some error judgments first. If there is no error, read the templates/install/ins_form.tpl template, parse generates a page that contains the server address, database name, table name prefix, user name, and password. After the installer enters the data, click install to go to the next step.

2. when the value of $ page is 2, get the data entered in the first step and try to connect to the database. If the database cannot be connected, an error is prompted. If the database cannot be connected, the subsequent process will continue, including: in config. write the database connection information in the PHP file. create a table structure in the PHP file.

3. When the value of $ page is 3, check whether an error has occurred in the previous step. If no error occurs, the system displays some information and parse the form for creating the Administrator account to go to the next process.

4. when the value of $ page is 4, the data entered in the previous step is obtained, including the account, password, and email. After some judgments, the Administrator account is created, the process of creation will be detailed after registration.

At this point, the installation process is complete. The main steps are as follows, and the code is not hard to understand. There is another function to explain, that is, display (), which is declared in the includes/function. php file,

Function display ($ page, $ title = '', $ topnav = true, $ administrative AGS ='', $ AdminPage = false) {global $ link, $ game_config, $ debug, $ user, $ planetrow; if (! $ AdminPage) {$ DisplayPage = StdUserHeader ($ title, $ shortags);} else {$ DisplayPage = AdminUserHeader ($ title, $ shortags);} if ($ topnav) {$ DisplayPage. = ShowTopNavigationBar ($ user, $ planetrow);} $ DisplayPage. ="

\ N ". $ page." \ n \ N "; // Affichage du Debug si necessaireif ($ user ['authlevel'] = 1 | $ user ['authlevel'] = 3) {if ($ game_config ['debug'] = 1) $ debug-> echo_log ();} $ DisplayPage. = StdFooter (); if (isset ($ link) {@ mysql_close ($ link);} echo $ DisplayPage; die ();}

The function is used to display the distinction between common user headers and administrator headers, and whether to display the information column at the top. Other functions, such as StdUserHeader () and AdminUserHeader (), are called in this function () showTopNavigationBar () and StdFooter () are not complex. Their implementations are the parsetempalte () and gettemplate () described earlier.

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.