实时策略游戏如何在PHP中运行? [英] How do Real Time Strategy games work in PHP?

查看:137
本文介绍了实时策略游戏如何在PHP中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

某些MMO实时策略游戏(例如Travian或oGame)是用PHP编码的.

您能否简要说明这种游戏在幕后的运作方式?游戏如何在没有玩家请求的情况下进行实时数据库更新?

还有,当运行具有1000位活跃玩家的RTS游戏(例如Travian)时,人们会期望什么样的服务器负载/带宽?

解决方案

即使这个话题比较老,我还是认为我对你的问题仍然有一个更好"的答案(如果我自己说的话),然后仍然含糊不清更新是由cronjobs完成的"答案.

Travian,即通过使用javascript给您带来实时的幻觉.后面实际发生的是以下情况:

播放器A向播放器B发送攻击.在MySQL数据库中,此记录带有到达时间戳.每当玩家A更改或刷新页面时,都会启动脚本(通过使用include)来启动脚本,该脚本检查与该玩家有关的任何活动(增援到达,攻击到达目标等).该脚本显然会检查当前时间,并以小于当前时间戳的时间戳查看所有活动.这意味着应该已经采取了行动.就在那一刻,该动作实际上已得到处理.

这还意味着,如果玩家A和玩家B都没有再次登录,则永远不会计算出攻击,除非其他人也攻击玩家B-则将处理玩家B和攻击玩家的所有活动.

Some MMO Real Time Strategy games such as Travian or oGame are coded in PHP.

Could you briefly explain how such a game works behind the scenes ? How does the game make real time DB updates without player requests ?

Also, what kind of server load / bandwidth would one have to expect when running a RTS game such as Travian with 1000 active players ?

解决方案

Even though this topic is rather old, I do think I still have a 'better' (if I may say so myself) answer to your question then the vague "the updates are done by cronjobs" answer.

Travian i.e. gives you the illusion of it being real-time through the use of javascript. What actually happens in the back is the following:

Player A sends an attack to player B. In the MySQL database this is recorded with a timestamp of arrival. Every time player A changes or refreshes a page a script gets launched (by using includes) that checks for any activity in regards to this player (reinforcements arriving, attacks arriving at targets etc.). The script obviously checks the current time and looks at all activities with a timestamp that is less than the current one. This means the action should have taken place. Right at that moment the action actually gets processed.

This also means that if neither player A nor player B ever log in again that the attack will never be calculated, unless someone else also attacks player B - then all activities for player B and the attacking player will be processed.

这篇关于实时策略游戏如何在PHP中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆