PHP webpage game learning-explanation of Xnova (ogame) source code (6) _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
PHP web game learning-Xnova (ogame) source code (6 ). 9. public code (common. php) Common. php is the public code of Xnova and will be executed almost every time you click it. Therefore, if the optimization is good, the efficiency of the entire program will be improved by 9. php)

Common. php is the public code of Xnova and will be executed almost every time you click it. Therefore, if the optimization is good, the efficiency of the entire program will be improved; of course, other code called for this file must be optimized together.

$game_config  = array();$user     = array();$lang     = array();$link     = "";$IsUserChecked = false; 

The variable $ game_config stores the parameter data of the entire game and reads the database each time. it can be optimized. the optimization method is as follows: save the variable $ user to store the login user data; $ lang stores local language data; $ whether the IsUserChecked record has checked the user. Then set some system constants, which will be used in future code; then include some function files, including small functions that we have previously introduced.


Next, we need to use a constant INSTALL, which is defined during installation. this judgment will be made in addition to installation. After entering the page, I will include some files, of which the mongodes/vars. php file is very important. I will explain it here and continue. Here we also need to retrieve data from the database and fill in the variable $ game_config.

if ($InLogin != true) { $Result    = CheckTheUser ( $IsUserChecked ); $IsUserChecked = $Result['state']; $user     = $Result['record'];} elseif ($InLogin == false) { if( $game_config['game_disable']) { if ($user['authlevel'] < 1) {  message ( stripslashes ( $game_config['close_reason'] ), $game_config['game_name'] ); } }}

The above checks the user login data stored in the cookie. it is not executed when $ InLogin = true. now we are talking about user operations at ordinary times, therefore, the value of $ InLogin is false. First, call the function CheckTheUser (). The value of $ IsUserChecked is false. the CheckTheUser () parameter is declared in includes/functions/CheckUser. in the php file, it calls the declaration in the program des/functions/CheckCookies. the CheckCookies () function in php. The function CheckCookies () is to use the information in cookies to check the user, and I will not list the code.

If CheckTheUser () is successful, the user data is filled in the variable $ user, and the following branch is executed. This branch checks server parameter settings. if the server is disabled by the administrator, the user's permissions are checked. if the permission is insufficient, an error message is displayed.


Next, we need to deal with the fleet in the user activity, which is divided into two logics:

1. the current time is later than the time when the ship arrived at its destination. logic such as combat and transportation needs to be processed.

2. the current time is later than the time when the ship returns to the departure location. it is also necessary to handle the return logic of the ship after and after the battle.

Every activity calls the FlyingFleetHandler () function for processing. we will analyze this function later. now we only need to know the function. If the user clicks frequently, this logic will consume a lot of resources, so it can be optimized here, such as caching or not every execution.

What if missile activities are completed after fleet activities are completed? The following rak. php file is used to process interstellar missiles. The file function includes the interception of missiles, the number of defenses destroyed by missiles, and the sending of messages to attacked parties. We also skipped the specific logic for further analysis.

Then call the SetSelectedPlanet () function to obtain the planet where the player was last located. Note that the parameter of this function is the address transfer. the function declaration is in node des/functions/SetSellectPlanet. php. The following two variable values will be obtained: $ planetrow stores the user's data on the current planet; $ galaxyrow stores the Galaxy coordinate data of the current planet.

Finally, call the CheckPlanetUsedFields () function to update the space used by the current planet. Similarly, the parameter is stored as an address, and the declaration is in includes/functions/CheckPlanetUsedFields. php.

The Common. php file has been analyzed. if you understand it, you should know that the efficiency here is very important. I hope you can optimize it together, and the other parts will be the same.

Common. php (Common. php) common. php is the public code of Xnova and will be executed almost every time you click it. Therefore, if the optimization is good, the efficiency of the entire program will be improved...

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.