This article mainly introduces the public code for interpreting the source code of PHP Web Game Xnova (ogame). For more information, see
This article mainly introduces the public code for interpreting the source code of PHP Web Game Xnova (ogame). For more information, see
9. 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; 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.