PHP网页游戏学习之Xnova(ogame)源码解读(三)
这篇文章主要介绍了PHP网页游戏Xnova(ogame)源码解读的用户注册页面,需要的朋友可以参考下
四、 用户注册(reg.php)
在看用户注册之流程之前,我把表的用途做个简单说明,现在只是大概的说明,后面我们再仔细了解,大家可以记下这个说明。
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 用户表
现在我们开始用户注册流程,一开始又可以看到定义了两个常量,
define('INSIDE' , true); define('INSTALL' , false);
INSIDE是用来防止攻击的,值为true;INSTALL是用来记录现在是否处于安装游戏的进程中,值为false。接下来又是Include两个文件,extension.inc和common.php;然后又是load语言文件reg.mo。在后面的章节里,我不再介绍了前面这段代码,大家已经明了了。
下面声明了两个函数,用来发送注册成功后的信息,包括用户名和密码等。
function sendpassemail($emailaddress, $username, $password) function mymail($to, $title, $body, $from = '')
现在介绍Xnova源码里面经常用到的一个结构,下面是伪代码说明,
if ($_POST) { //如果用户有输入 //这里是有用户输入后执行过程 }else{ //这里是无用户输入后的执行过程,包括页面第一次显示的时候 }
我们看用户注册流程,为了说明前面的结构,特意贴了代码。和前面我们讲过的一样,先gettemplate文件,然后parse出来并显示页面。
if ($_POST) { //代码略 } else { $parse = $lang; $parse['servername'] = $game_config['game_name']; $page = parsetemplate(gettemplate('registry_form'), $parse); display ($page, $lang['registry'], false); }
下面看用户输入信息后的流程,一堆的if都是判断用户输入的信息是否合法,并用$errors变量记录错误的数量,$errorlist变量记录错误的消息。如果$errors不为零就输出错误信息;如果没有错误,就进入下面的流程:
1. 检查用户名是否有非法字符
2. 检查Email是否有非法字符
3. 检查星球名是否有非法字符
4. 加密用户的密码,md5
5. 往表users中INSERT用户信息
6. 取得刚刚插入生成的用户ID号备用
7. 一大段代码功能,找一个空的星球坐标给这个用户作为母星,并使用函数CreateOnePlanetRecord()创建星球,,这里要使用三个系统参数LastSettedGalaxyPos、LastSettedSystemPos、LastSettedPlanetPos,看命名就应该清楚,分别是最后星系、最后太阳系、最后行星位置
8. 更新users表中的星球ID为刚刚生成的星球ID
9. 向这个玩家发送欢迎信息
10. 向这个玩家发送注册信息邮件
11. 显示注册成功页面,注册结束
以上流程,我们都可以找到对应的代码,代码难度不大,所以没有列出来。函数CreateOnePlanetRecord()以后详细介绍,现在说了反而头大,函数SendSimpleMessage()我们现在看一下,声明在SendSimpleMessage.php文件中。
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'); }
函数的功能是往messages表中插入详细消息,并更新users表的消息数量,很明了,呵呵。另外一个函数message()的功能和display()基本相同,就不详细写了,自己看下吧。至此,用户注册流程就分析完了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.
