对于真人游戏,MMO 将如何处理每一刻为数千名玩家计算和发送数据包?

How would an MMO deal with calculating and sending packets for thousands of players every tick for a live action game?(对于真人游戏,MMO 将如何处理每一刻为数千名玩家计算和发送数据包?)

本文介绍了对于真人游戏,MMO 将如何处理每一刻为数千名玩家计算和发送数据包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款游戏,并且正在考虑进入网络.我已经编程了大约 5 年,并在过去 2 年进入了游戏开发.我只是在自己的时间里真正在网上和书本上学习.我正计划为 Amazon AWS EC2 制作一个 java 服务器,但我只是想知道 MMO 是如何处理多个玩家的.

仅仅是服务器的强大功能吗?我不是在寻找代码或任何东西,只是在寻找服务器的一般工作方式.

服务器是否只是为所有玩家和数万或数十万个对象进行所有计算,然后每次发送和接收数千个数据包?单台计算机处理起来似乎很多,但它确实是一台服务器.

解决方案

服务器的工作原理和工作是什么?

  • 您的服务器创建一个套接字并打开一个端口.

  • 在线游戏的协议通常使用 UDP,因为它更快.

  • 您的服务器必须处理所有客户端连接.

  • 您可以添加一个能够登录帐户并将他重定向到游戏服务器的服务器(所有大型 MMO 都是这种情况).

  • 你的服务器必须管理数据库中的所有计算:当一个敌人击中另一个敌人时,当你购买一些东西时减去一部分钱......

  • 所以服务器是在线游戏的主要部分.

事实上,计算机做一些计算真的很快,现代电子游戏最重的部分是物理和图形......幸运的是,这两个部分都在客户端部分.

但是,服务器必须强大!不像客户端,因为他不需要大 GPU,但他需要大量 RAM/CPU(取决于游戏),而且他还需要保持冷静.

事实上,游戏服务器能够处理大量连接是因为 UDP 协议,并且因为程序的所有繁重的部分都在 客户端>.您可以在这里查看:在 python 中创建多人游戏 并在我解释 UDP 和 TCP 协议之间的区别时阅读部分.

关于 MMO 服务器如何工作的所有其他信息都链接在本主题的末尾.

现在我们可以尝试构建一个服务器了!

首先,你知道如何创建服务器吗?

  • 编程或下载服务器以进行测试(例如:TeamSpeak 或 Mumble).

  • 从您的计算机启动他并允许他从您的防火墙进行输入连接.

  • 登录您的调制解调器并将您的服务器端口转发/重定向到您的计算机.

对于最后一部分,你需要做一些研究:我的服务器使用了哪个端口以及如何用我的调制解调器转发一个端口(每个调制解调器都不一样).

现在您可以尝试登录到您的服务器.但是……!

您的计算机拥有三个 IP:

  • Loopback地址:localhost,127.0.0.0(0"可以改变)

  • 内网地址(与你的电脑相连的IP):192.168.0.0、172.16.0.0、10.0.0.0

  • 互联网地址(与您的调制解调器相关的 IP):0.0.0.0

如何知道您的 Intranet/Internet IP?这取决于您的操作系统和调制解调器.对于 Intranet,使用您的终端并写入ifconfig"或ipconfig".对于您的 Internet 地址,有时会在您登录调制解调器时写入,或者您必须访问能够向您显示您的 IP 的网站.

如果您创建了一个服务器并且您没有从调制解调器转发端口,您仍然可以使用您的 Loopback 地址在本地访问您的服务器,并且连接到同一调制解调器的其他计算机也可以使用内网地址.此外,如果您需要测试您的服务器是否可以从 Internet 访问,则必须测试与您的 Internet IP 的连接,但是某些调制解调器不允许来自 Intranet 的外部连接...因此,如果您与 Internet IP 的连接不起作用,请尝试将您从另一个调制解调器(朋友的 PC、Cyber​​-Coffee...)登录到您的服务器.

最后,如何保护您的服务器?

这真的很难,而且您无法创建完美的安全性...尤其是如果您遵循我的建议,但您没有通过自己的研究完成我的知识.

  • 根访问

这是最重要的部分.当一个lamer试图访问你的服务器时,他可以尝试一个简单的连接,比如http/ssh/ftp.如果他可以访问您的硬盘并且您没有选择强限制,他可以简单地读取/修改/删除您游戏的数据库.数据库包含有关帐户的所有信息.

  • 防火墙

我们已经讨论了服务器必须处理的连接/计算量.在某些攻击中,lamer 尝试创建大量连接并且没有关闭它们.我们称之为 DOS(有 1 台计算机)或 DDOS(多于 1 台计算机).所以你需要一个好的防火墙:只允许你服务器的端口,只允许来自一个唯一 IP 的 X 个连接,并且每分钟只允许 X 个新连接.

  • 更新

这是最简单的部分:让您的操作系统(和其他应用程序)保持最新.

  • 越少越好

不要在您的服务器上安装许多无用的软件.如果某个软件不是为您的服务器导入的,您不应该安装他,因为:首先,这可能是病毒.其次,恶意软件可以利用该软件安装病毒或窃取 root 访问权限.

  • 加密

加密对于阻止黑客非常重要.例如,使用 https 协议,您可以保护用户的密码免受 MITM 攻击.使用 Bluefish/SHA/others,您可以加密您的数据库以保护她,即使黑客可以读取它.最重要的是始终阻止黑客的写/修改/删除/执行权限(实际上,您游戏的所有客户端都需要读取权限).

  • 防病毒?

对于在线游戏来说,杀毒软件并不是很重要(但仍然推荐用于所有操作系统,也适用于 Linux/Unix).

  • 有一个好的服务器

如果您的服务器在没有考虑安全性的情况下进行编程,您可能会遇到麻烦.示例:C/C++ 中的缓冲区溢出攻击.

如果您需要有关 MMO 工作原理的更多信息,我建议您:

  • http://electronics.howstuffworks.com/mmorpg6.htmp>

  • https://en.wikipedia.org/wiki/Server_%28computing%29

  • https://en.wikipedia.org/wiki/Game_server

  • https://www.quora.com/How-do-I-create-an-MMORPG

提示 - 如果你对创建一个在线游戏感兴趣,你必须做很多研究,我无法真正回答这个问题,因为这不是主题的目的.而且这个题目太大了,不能在每个问题上写一个新的答案……哪个软件用于编写游戏?如何建立一个套接字?从哪里开始?但我已经回答了一些类似的问题.即使编程语言有时不同,我给你链接,逻辑总是一样的,所以它可能对你有帮助:

  • 用python创建多人游戏

  • Xcode Mass Multiplayer(不是什么)你可能在想)

  • Java 多人游戏.将客户端(玩家)连接到其他客户端创建的游戏

I am working on a game and I am thinking about getting into networking. I have been programming for about 5 years and got into game development the last 2 years. I only really learn online and from books on my own time. I am planning to make a java server for Amazon AWS EC2, but I am just wondering how MMO's handle multiple players each tick.

Is it just the sheer power of servers? I am not looking for code or anything, just in general how the servers work.

Does the server just do all of the calculations for all of the players and the tens or hundreds of thousands of objects and then send and receive thousands of packets every tick? It just seems like a lot for a single computer to handle, but it is indeed a server.

解决方案

How work and what is the job of a server?

  • Your server create a socket and open a port.

  • The protocol for an online game is generally in UDP because it is faster.

  • Your server have to handle ALL the clients connections.

  • You can add a server who is able to log an account and redirect him into a game server (this is the case for all the big MMO).

  • Your server have to manage all the calculations from the Data Base: when an enemy hit another enemy, subtract a part of your money when you buy some stuffs...

  • So the server is the main part of an online game.

In fact, a computer is really fast for do some calculations, the most heavy part for a modern video game is the physics and graphics... Fortunately, these both parts are on the client part.

But, a server have to be strong! Not like a client because he doesn't need a big GPU, but he need a big amount of RAM/CPU (depend of the game) and he also need to stay cold.

In fact, a game server is able to handle a large amounts of connections because of the UDP protocol and because all the heavy parts of the program are on the client side. You can take a look here: Creating a Multiplayer game in python and read the part when I explain the difference between the UDP and the TCP protocol.

All the others informations about how work an MMO server are linked at the end of this topic.

Now we can try to build a server!

Firstly, do you know how to create a server?

  • Program or download a server for do a test (example: TeamSpeak or Mumble).

  • Launch him from your computer and allow his input connections from your firewall.

  • Log you on your modem and forward/redirect the port of your server into your computer.

For the last part, you need to do some research: Which port is used by my server and how to forward a port with my modem (each modem is different).

Now you can try to log you into your server. But...!

Your computer have three IPs:

  • The Loopback address: localhost, 127.0.0.0 (The "0" can change)

  • The Intranet address (IP linked to your computer): 192.168.0.0, 172.16.0.0, 10.0.0.0

  • And the internet address (IP linked to your modem): 0.0.0.0

How to know your Intranet/internet IP? That depend of your Operating System and your modem. For the Intranet use your terminal and write "ifconfig" or "ipconfig". For your internet address, it is sometime write when you log you to your modem, or you have to visit a website who is able to show you your IP.

If you create a server and you didn't forward the port from your modem, you can still access to your server in local with your Loopback address and the others computers connected to the same modem can also access to the server with the Intranet address. Also, if you need to test if your server is accessible from internet, you have to test the connection with your internet IP, but some modem don't allow the externals connections from the Intranet... So if your connection with the internet IP doesn't work, try to log you to your server from another modem (friend's PC, Cyber-Coffee...).

Lastly, how to protect your server?

This is really difficult and you cannot create a perfect security... Especially if you follow my advices but you didn't complete my knowledge with your own research.

  • Root access

This is the most important part. When a lamer try to access to your server, he can just try a simple connection like the http/ssh/ftp. If he can access to your hard disk and you haven't chose a strong restriction, he can simply read/modify/delete the Data Base of your game. The Data Base contain all the informations about the accounts.

  • Firewall

We have already talk about the amount of connections/calculation than a server have to handle. In some attack, the lamer try to create a big amount of connections and didn't close them. We call that a DOS (with 1 computer) or DDOS (more than 1 computer). So you need a good firewall for: allow only the port of your server, allow only X numbers of connections from an unique IP and allow only X numbers of new connections every minutes.

  • Updates

This is the easiest part: keep your Operating System (and the others applications) up to date.

  • Less is better

Don't install many useless software to your server. If a software is not import for your server, you shouldn't install him because: firstly, that can be a virus. Secondly, a malware can exploit this software for install a virus or steal the root access.

  • Encryption

The encryption is really important for block an Hacker. For example, with the https protocol you can protected the user's passwords from the MITM attack. And with the Bluefish/SHA/others, you can encrypt your Data Base for protect her even if an Hacker can read it. The most important is always to block the write/modify/deletion/execute right of the Hacker (in fact, all the clients of your game need the read access).

  • Anti-virus?

In the case of an online-game, an anti-virus is not really important (But still recommended for all Operating System, Linux/Unix also).

  • Have a good server

If your server is programmed without take care of the security, you can be in trouble. Example: Buffer Overflow attack in C/C++.

If you need more informations about how work an MMO, I recommend you:

  • http://electronics.howstuffworks.com/mmorpg6.htm

  • https://en.wikipedia.org/wiki/Server_%28computing%29

  • https://en.wikipedia.org/wiki/Game_server

  • https://www.quora.com/How-do-I-create-an-MMORPG

Hint - If you are interesting by create an online game, you have to do many research, I cannot really answer in this question because is not the purpose of the subject. And this subject is too large for write a new answer at each question... Which software use for program a game? How to build a socket? Where started? But I have already answer at some similar questions. Even if the programming language are sometime different, I give you the link, the logic is always the same so it can maybe help you:

  • Creating a Multiplayer game in python

  • Xcode Mass Multiplayer (Not What You're Probably Thinking)

  • Multiplayer game in Java. Connect client (player) to game that was created by other client

这篇关于对于真人游戏,MMO 将如何处理每一刻为数千名玩家计算和发送数据包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:对于真人游戏,MMO 将如何处理每一刻为数千名玩家计算和发送数据包?

基础教程推荐