实施动态奖励制度
我一直在开发在线扑克游戏。但我总是碰壁。我想将奖项实施到系统中,但我希望它们是动态的。这意味着我不想为我想添加的每个奖项重新编译。
我曾考虑过每个奖项都使用Python代码。然后,当服务器检查用户是否有资格获得奖励时,它会使用 Jython 运行 python 脚本(服务器使用 Java 和 Netty NIO),如果该函数返回某个值,我会将奖励授予用户。这可以工作,但是是否有一种更有效的技术,不会迫使我每次需要检查用户是否获得奖励时运行数百个 python 脚本。
进行这些检查的最佳时间是什么时候?我已经考虑过一个钩子系统,我将在其中指定钩子( [onconnect][ondisconnect][chatmessage.received] )。这也可以工作,但感觉有点粗糙,我仍然必须运行数据库中的所有脚本。
I have been developing a Online Poker Game. But I keep hitting a wall. I want to implement Awards into the system, but I want them to be dynamic. Meaning I don't want to recompile for every award I would like to add.
I have thought about using Python code for each award. Then when the server checks to see if the user qualifies for the award it runs the python script with Jython (server is in Java and Netty NIO) and if the function returns a certain value I award the award to the user. Which could work but is there maybe a more efficient technique out there that will not force me to run hundreds of python scripts each time I need to check if a user got a award.
And when are the best times to do these checks? I have tought about a hook system where I will specify the hooks like ( [onconnect][ondisconnect][chatmessage.received] ). Which also could work but feels a bit crude and I will still have to run all the scripts from the database.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果我是你,我会有一个完全独立的颁奖流程。它可能每天在包含所有玩家/游戏数据的底层数据库上运行一次。
您的面向客户的核心应用程序了解奖项,但它所了解的只是从数据库加载的数据——例如标题、图像、描述,也许有多少人获得了奖项等,并且(基于数据库)表)谁获奖了。
您的“奖励授予者”流程只是以批处理模式运行,每天/每小时一次等,并向符合条件的玩家授予新奖励。然后,面向客户的核心应用程序会通知他们,但实际上并不需要知道如何授予他们权限。这使您可以随时重新编译和重新运行您的奖励授予者,而不会影响核心应用程序。
另一种方法是编写一个简单的规则接口,允许您在数据中定义规则,具体取决于您的奖励的限制程度。这对于实现你所描述的目标来说是理想的,但在我看来,这是一项相当多的工作,但回报并不多。
PS——在运行在线扑克服务器之类的东西时,你会一直遇到这个问题的版本。您绝对需要开发一种方法来部署新代码,而不会终止您的服务或产生停机时间窗口。从长远来看,围绕以 Java 为中心的奖励代码解决方案工作并不能解决您的问题。您应该查看有关运行真正的 24/7 服务的文献,有很多方法可以解决这个问题,而且现在实际上并不那么困难。
If I were you, I'd have a totally separate process that grants awards. It runs perhaps once a day on the underlying database that contains all your player/game data.
Your core customer-facing app knows about awards, but all it knows about them is data it loads from the DB -- something like a title, image, description, maybe how many people have the award, etc., and (based on DB tables) who has won the award.
Your "award granter" process simply runs in batch mode, once per day / hour etc, and grants new awards to eligible players. Then the core customer-facing app notifies them but doesn't actually have to know the smarts of how to grant them. This gives you the freedom to recompile and re-run your award granter any time you want with no core app impact.
Another approach, depending on how constrained your awards are, would be to write a simple rules interface that allows you to define rules in data. That would be ideal to achieve what you describe, but it's quite a bit of work for not much reward, in my opinion.
PS -- in running something like an online poker server, you're going to run into versions of this problem all the time. You are absolutely going to need to develop a way to deploy new code without killing your service or having a downtime window. Working around a java-centric code solution for awards is not going to solve that problem for you in the long run. You should look into the literature on running true 24/7 services, there are quite a few ways to address the issue and it's actually not that difficult these days.
我可以想到很多选项:
There are a number of options I can think of:
对批处理想法答案的一些评论:
实现动态奖励系统
批处理可以在单独的服务器上/机,以便您可以随时重新编译应用程序或重新启动服务器。拥有新的奖励可以使用例如提到的添加 jar 和重新启动服务器的方法来处理,也可以随时引入新的批处理作业等等。所以你的核心应用程序99%的时间都在运行,批处理服务器可以频繁地重新启动。因此,最好有单独的批量机器。
当您需要部署新版本的核心应用程序时,我认为您可以停止、部署并启动它,并向用户发出维护通知。这种方法甚至被拥有优秀软件的顶级扑克室所使用(例如 FullTiltPoker 就是这样做的,现在由于许可证丢失而关闭,但他们的网站上写着“系统更新”:))。
因此版本更新的一种方法是在非工作时间重新部署/重启。
另一种方法是实时更新。通常,这是通过将用户一批一批迁移到新版本来完成的。因此,同时有些用户使用旧版本,有些用户使用新版本。对于不同版本的用户可以交互的扑克软件来说,这并不是很酷。但是,如果您确定版本“兼容性”,您可以采用这种方法,例如在登录时检查用户的客户端版本。
在我的回答中,我试图说您不需要在代码中引入 24/7 支持逻辑。将系统可用性问题留给硬件(故障转移、负载平衡器等)。您可以遵循您用来编写代码的任何好的技术,只需记住您的关键核心逻辑部署不频繁(例如每周一次),并且批处理部分可以根据需要随时更新/重新启动。
Some comments to the answer with batch ideas:
Implementing a Dynamic Award System
That batch processes can be on separate server/machine, so you can recompile the app or restart the server at any time. Having that new awards can be handled using for example the mentioned approach with adding jars and restarting the server, also new batch jobs can be introduced at any time and so on. So your core application is running 99% of the time, batch server can be restarted frequently. So separate batch machines is good to have.
When you need to deploy new version of core app I think you can just stop, deploy and start it with maintenance notice to users. That approach is used even by top poker rooms with great software (e.g. FullTiltPoker did so, right now it is down due to the license loss, but their site says 'System Update' :) ).
So one approach for versions update is to redeploy/restart in off-hours.
Another approach is real time updates. As a rule it is done by migrating users bunch by bunch to new version. So at the same time some users are using old version, some - new. Not pretty cool for poker software were users with different versions can interact. But if you are sure in the versions 'compatibility' you can go with that approach, checking user's client version for example on login.
In my answer I tried to say that you need not introduce 24/7 support logic to your code. Leave that system availability problems for hardware (failovers, loadbalancers, etc.). You can follow any good techniques you used to write code, only you need to remember that your crucial core logic is deployed not frequently (for example once a week), and batch part can be updated/restarted at any time if needed.
据我了解,您可能不必从应用程序运行外部进程,也不必使用 OSGI。
只需创建一个简单的 Java 接口并将每个插件(“奖项”)实现为实现该接口的类。然后,您可以简单地编译任何新插件,并在运行时使用 Class.forName(String className) 将其作为类文件从应用程序加载。
您需要从此类插件中获得的任何逻辑都将包含在界面上的方法中。
http ://download.oracle.com/javase/1,5.0/docs/api/java/lang/Class.html#forName(java.lang.String)
As far as I understand you, you probably do not have to run external processes from your application nor use OSGI.
Just create a simple Java interface and implement each plugin ('award') as a class implementing the interface. You could then just simply compile any new plugin and load it in as a class file from your application at run-time using
Class.forName(String className)
.Any logic you need from such a plugin would be contained in methods on the interface.
http://download.oracle.com/javase/1,5.0/docs/api/java/lang/Class.html#forName(java.lang.String)