JApplet 写入安全吗?

发布于 2024-12-01 11:24:35 字数 91 浏览 1 评论 0原文

因此,我正在创建一个 JApplet 游戏,并将用户信息保存到 APPDATA 中的 .txt 文件中。有没有更安全的方法来保存他们的信息,不允许他们编辑信息进行作弊?

So I am creating a JApplet Game, and I am saving the users info to a .txt file in the APPDATA. Is there a safer way to save their info, that won't allow them to edit it to cheat?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枕头说它不想醒 2024-12-08 11:24:35

基本上,防止作弊的唯一方法是让您控制的服务器计算分数并以其他方式执行游戏规则。如果您正在编写点对点游戏,可能会有一些协议允许用户在不涉及您的情况下确定其他玩家是否作弊。 ACM sigecom 定期发布有关此类协议的研究报告。但是,由于小程序安全模型的限制,用户需要授予您的小程序特殊权限才能使其直接与其他用户通信。

说到这里,我建议不要“将用户信息保存到 .txt 文件”。 %APPDATA% 仅适用于 Windows,因此打破了“一次写入,随处运行”的原则;并且默认的小程序沙箱不允许读取或写入本地文件,因此您必须对小程序进行签名并说服您的用户它足够特别,值得如此提升的权限。

但是,您确实有一些用于小程序/服务器通信的选项:

  • 使用 java.net.URL 的 REST 调用
  • SOAP 调用(有多个用于此目的的库)
  • RMI(仅当服务器是用 Java 编写时)
  • 您自己的 TCP

Applet 自定义协议无法直接读取和写入 Cookie,但 JavaScript 可以,并且 JavaScript 可以调用 Applet 上的方法。将信息从服务器传递到小程序(但不能返回)的最后一种方法是通过 PARAM 标记。您甚至可以传递由服务器私钥签名的初始游戏状态数据以及 PARAM 标签中编码的 base64;这将阻止任何人“编辑”它,尽管如果有关游戏状态的某些内容应该对玩家隐藏但在小程序代码中已知,我想不出任何方法可以完全防止作弊。

Basically, the only way to prevent cheating is to have a server under your control calculate the score and otherwise enforce game rules. If you were writing a peer-to-peer game, there might be some protocol to allow users to determine if another player was cheating without involving you. ACM sigecom regularly publishes research about such protocols. However, because of the restrictions of the applet security model, users would need to grant your applet special permission for it to talk directly to other users anyway.

Speaking of that, I would advise against "saving the user's info to a .txt file". %APPDATA% is Windows-only, thus breaking "write once run anywhere"; and the default applet sandbox does not allow reading or writing local files, so you'd have to sign the applet and convince your users that it was special enough to merit such elevated privileges.

However, you do have a few options for applet/server communication:

  • REST calls using java.net.URL
  • SOAP calls (there are several libraries for this)
  • RMI (only if the server is written in Java)
  • Your own custom protocol over TCP

Applets can't read and write cookies directly, but JavaScript can, and JavaScript can call methods on applets. One last way to pass information from the server to the applet (but not back out) is through PARAM tags. You could even pass initial game-state data signed by the server's private key and base64 encoded in a PARAM tag; which would prevent anyone from "editing" it, although I can't think of any way to completely prevent cheating if something about the game-state is supposed to be hidden from the player but known within the applet code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文