PHP Web Game Learning Xnova (Ogame) source Interpretation (vi) _php example

Source: Internet
Author: User
Ix. Public Code (common.php)

Common.php is Xnova's public code, almost every click will be executed, so if the optimization of the good, then the overall efficiency of the program will be improved, of course, the file calls the other code is also optimized.

$game _config  = Array (), $user     = Array (), $lang     = Array (), $link     

Variable $game_config Store the parameters of the entire game data, every time to read the database, you can optimize, optimize the way such as saved in the file; Variable $user store the user data of the login; $lang store local language data; $ Isuserchecked record whether the user was check. Then set up some system constants to be used in future code, and include some function files, there are small functions that we have previously introduced in the inside and so on.


The next step is to use a constant install, which is defined at the time of installation, and will be entered in addition to the installation. After entering, include some documents, in which the includes/vars.php file is very important, I will specifically explain, now continue. The data is also obtained from the database, and the variable $game_config is populated.

if ($InLogin! = True) {$Result    = Checktheuser ($IsUserChecked); $IsUserChecked = $Result [' state ']; $user     = $Res ult[' record ';} ElseIf ($InLogin = = False) {if ($game _config[' game_disable ')} {if ($user [' Authlevel '] < 1) {  message (Stripslash ES ($game _config[' Close_reason '), $game _config[' game_name ']); } }}

The above is to check the user login data stored in the cookie, in $inlogin = True, will not be executed; now we are talking about the user's usual operation, so here the value of $inlogin is false. First call the function Checktheuser (), the value of the parameter $isuserchecked is False;checktheuser () declared in the includes/functions/checkuser.php file, and it calls the declaration in the The Checkcookies () function in includes/functions/checkcookies.php. And the function of Checkcookies () is to use the information in the cookie to check the user, the code I will not list.

If Checktheuser () succeeds, then the variable $user fills the user's data and executes the following branch. This branch checks the server parameter settings, checks the user's permissions if the server is set to shutdown by the administrator, and displays an error message if the permissions are insufficient.


Then we have to deal with the fleet in the user's activity, divided into two sections of logic:

1. The current time is greater than the time the fleet arrives at the destination and needs to handle the logic of fighting, transportation, etc.

2. The current time is greater than the time at which the fleet returns to the departure point, and the return logic of the post-battle, post-shipment fleet is also handled

Each activity is called the function Flyingfleethandler () to handle, this function we later analysis, now just know the function is OK. If the user clicks frequently, this logic will be very resource-intensive, so it can also be optimized, such as caching or not every time the execution and so on.

When the fleet is finished, what about the missile's activities? The next rak.php file is used to deal with interstellar missiles. File features include missile interception, missile-destroyed defenses, sending messages to attackers, and more. Specific logic We also skip, later analysis.

Then call the function setselectedplanet () to get the player's last planet, note that the function parameter, is the address, function declaration in includes/functions/setsellectplanet.php. The next step is to get two variables, $planetrow the data of the user's current planet, $galaxyrow the galactic coordinate data for the current planet.

The last Call to function Checkplanetusedfields () updates the space used for the current planet, and the same parameter is transmitted, declared in includes/functions/checkplanetusedfields.php.

common.php file Analysis, if you understand, you should know that the efficiency here is very important, I hope everyone to optimize together, the rest of the same.

  • Related Article

    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.