目前是想做一款纯文字类网页游戏,战斗模式采用文字播报模式
看到过一个别人写的是,本地进行战斗计算,最后把战斗结果post到服务器上,这种很容易造成漏洞,直接在本地修改结果不停的post
如果同步战斗状态的,感觉会太复杂,有没有方便的方法不容易出漏洞
我将php和c#用socket连接在一起,可以进行数据交换计算,可以利用这个做吗?
回复内容:
战斗过程中如果玩家不能介入的话,直接服务端算好整场战斗过程,一次性下发到客户端慢慢播文字就是了,你指的复杂是什么。用socket的话,需要实现一套基于socket的游戏协议,好处是省流量、通信灵活,服务器主动推送信息容易。如果想简单点,可考虑直接用http短连接通信,但对于一些服务器主动下行的功能不好实现。 矮油,我觉得我应该很有资格回答这个问题,因为我做的游戏就是这样的。
看到楼主是用php,那么觉得我更有资格了。
首先分为两种情况。
1. 所有战斗都在服务器一次性完成,客户端只是简单的播报结果
这是最简单的,也是我现在用的方案,也是绝大多数古典页游用的方法。
客户端提交一个战斗请求,然后在服务器完全全部计算,将结果用json或者其他什么方法传给客户端,然后浏览器再用js解析出来。
注意:这种方法也不能完全的杜绝客户端作弊,最典型的例子,对于一些有消耗的战斗(无论是有冷却时间,还是入场需要消费资源),玩家开两个窗口然后同时点击战斗按钮,可能会出现双份奖励。我的游戏就曾经出现过这种bug。
此外,还存在我在后台改了数据没有刷新缓存导致前台用户玩的时候出现崩溃的问题。
总之这种方法难度不高,对服务器压力也小(因为是集中计算)。
缺点是无法响应玩家输入,也就是玩家并不能在战斗中进行控制,这就要看你的游戏是否要求玩家在战斗中进行操作了。
2.战斗会一边进行一边回传到客户端,响应客户端输入之后再传到服务器。
这种会比较难,其实这里麻烦的问题反而不是作弊,而是服务器负载……只要做好负载反而就没有什么问题。
方法有很多种,你说的socket是一种,但我不懂……(-_-|||)。
此外还有node.js系列的http://socket.io,更轻量,毕竟涉及C#就要涉及.net那种大而厚的东西,node.js相比之下更轻。
当然如果不选PHP的话,也有更多其他方案,比如纯http://asp.net或者纯java,甚至可以用现代的手段比如unity,当然这就扯远了……
所以如果要我来做的话,估计还是会选传统的js轮询ajax的办法,不断去服务器查。会更吃一点服务器资源(毕竟每次玩家操作都要走一次完整的http request),所以对于我们这种VPS放国外的屌丝可能会遭遇延迟问题。因此,我大概会把游戏做成延迟不影响游戏体验的模式。
举例就是做一个万智牌游戏,我点击出牌的时候,动画直接播放出牌效果(但此时还处于http request中),然后画面出现“电脑正在思考中”,然后播放电脑的出牌结果。
当然还有个办法就是你说的,把一些简单的东西放到客户端,但实际上这些内容必须还是要传到服务器在计算一次,最终回来的时候覆盖客户端算的结果,并且要保证从头到尾不使用客户端的数据。客户端计算的数据“仅仅是处于让玩家感受速度快”。
这点其实很常见,比如大型网站点赞,点赞的瞬间就+1了,其实只是客户端计算而已。刷新之后就会变成真实数据。
如果负载实在扛不住,可以考虑把游戏的一部分做成不消耗服务器的模式(例如你的游戏设定,在上面玩2小时可以获得100点游戏内战斗力,那么你就设置一个2小时的远征任务,这个任务挂好了之后就获得100点战斗力,又或者刷1天怪物平均可以获得3件装备,那么你可以设置一个副本,冷却时间24小时,必掉3件装备)。
总体上玩家的收益是相同的。
我倾向于把游戏做成不那么肝(也就是不需要反复算时间,一直在屏幕前点点点)。因此服务器负载倒不是那么大,512M1核的低配VPS,长期负载也就0.0x,所以还跑了几个其他业余利用资源……
有想到再补充
利益相关:RPG类型纯文字类网页游戏 莉诺达斯 - Linodas.com 制作人。
(PS:前几天打通了奥里与迷失森林,所以在首页放了一个全屏跳转推荐这款游戏,不要以为进错网站了。。 不要本地计算,用服务端计算后下发客户端就好。

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

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.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Chinese version
Chinese version, very easy to use

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software