简体   繁体   English

多人游戏大厅和配对系统的架构?

[英]Architecture of a multiplayer lobby and matchmaking system?

I am looking to design a system where a player can 我期待设计一个玩家可以的系统

  1. Run the game, hit a button to enter the arena, which will send his IP Address/player profile/network stats up to the server. 运行游戏,点击按钮进入竞技场,这将把他的IP地址/玩家资料/网络统计数据发送到服务器。

  2. The matchmaking/lobby server will maintain a collection of all available players. 配对/大厅服务器将保留所有可用玩家的集合。 It will continuously look for pairs of players that are a "match" (algorithm not important right now). 它会不断寻找一对“匹配”的玩家(算法现在不重要)。

  3. When it finds two queued players that are a "match", based on the player profile data it will pick one of the players as the server and will then notify the game clients that a match has been found. 当它找到两个排队的“匹配”玩家时,根据玩家资料数据,它将选择一个玩家作为服务器,然后通知游戏客户已找到匹配。 Based on the notification the client receives, the client who was selected as the server will launch a server and the other player's client will connect to that initialized server when it's ready. 根据客户端收到的通知,被选为服务器的客户端将启动服务器,而另一个玩家的客户端将在准备好时连接到该初始化服务器。

What is a good way to set this up? 设置它的好方法是什么? My first thought was to send the player stats up via an HTTP POST. 我的第一个想法是通过HTTP POST发送玩家统计数据。 But it could be minutes in some cases before the server finds a match and responds with what type of connection the player will have and who their opponent will be. 但在某些情况下,在服务器找到匹配项之前可能需要几分钟,并响应玩家将拥有什么类型的连接以及他们的对手将是谁。 Would HTTP be appropriate for this? HTTP适合这个吗? Or should this be a lower level customized socket based approach? 或者这应该是一个较低级别的定制套接字方法? Or am I completely off here? 还是我完全离开这里?

PS The game is a being developed in Unity. PS游戏是在Unity中开发的。 I'd prefer answers that weren't just, "here's a link to a plugin that works" as I'm interested in understanding the architecture behind how this is typically implemented. 我更喜欢不仅仅是答案的答案,“这里是一个有效插件的链接”,因为我有兴趣了解这通常实现的架构背后的架构。

Any guidance would be appreciated. 任何指导将不胜感激。

I've done quite a bit of work with these types of systems. 我已经对这些类型的系统做了很多工作。 If I was you, I would already have a http end point setup to handle situations like this. 如果我是你,我会有一个http端点设置来处理这样的情况。 In game http post/get is a terrible idea, but in user interface it's really not bad. 在游戏中http post / get是一个糟糕的主意,但在用户界面中它真的不错。 You could poll every 5 seconds, or have the server tell the client when to ask again. 您可以每5秒轮询一次,或让服务器告诉客户端何时再次询问。

You could also use UDP and send pings back and forth to determine if a client is connected instead of falling into the TCP well with timmy(It feels so safe, but don't let that hair fool you). 您还可以使用UDP并来回发送ping以确定客户端是否已连接而不是使用timmy进入TCP井(感觉非常安全,但不要让那个头发欺骗你)。 The nice thing about this is the overhead is way less than http post/gets, the down side is fragmentation and order(of course if you have a proper state machine going the order isn't going to matter much). 关于这一点的好处是开销比http post /得到的方式少,缺点是碎片和顺序(当然如果你有一个合适的状态机,那么顺序并不重要)。

So, taking all that into consideration, here are my suggestions using http(the same could be applied using udp with a few tweaks, but I'll go with http because then I don't have to get into the fragmentation stuff). 所以,考虑到所有这些,这里是我使用http的建议(同样可以使用udp进行一些调整,但我会使用http,因为那时我不必进入碎片的东西)。

Set up and IIS server with a hosted {insert framework here (WCF, WebAPI, aspx pages, php even)}. 设置和IIS服务器与托管{插入框架在这里(WCF,WebAPI,aspx页面,甚至PHP)}。

To make life easier, create a wrapper class with every possible api call you need. 为了让生活更轻松,请创建一个包装类,其中包含您需要的每个可能的api调用。

I would imagine the calls you'd want would be something like this(-> Means to the server, <- is the http response from a get/post). 我想你想要的电话会是这样的( - >表示服务器,< - 是来自get / post的http响应)。

  • 1 -> Hello (player data. This is an initial arena handshake) 1 - > Hello(玩家数据。这是初始竞技场握手)
  • 1 R.1. 1 R.1。 <- Welcome (If the server likes the player, this tells them they're accepted) < - 欢迎(如果服务器喜欢播放器,这告诉他们已被接受)
  • 1 R.2. 1 R.2。 <- Error (This player was banned for lude behavior, no games for you) < - 错误(此玩家因为粗鲁的行为被禁止,没有游戏给你)
  • 2 -> FindMatch (Matchmaking starts looking as soon as they say 'Hello', this is asking the server if it found anything yet. You can also bundle in stats like 'Expected Wait Time' etc. This acts as a ping to check if the client is still alive. The response to this will act as a ping to the user to tell them they're still connected to the server. You could implement a separate 'ping' call as well, it's really up to you) 2 - > FindMatch(一旦他们说“你好”,匹配就会开始寻找,这是询问服务器是否找到了任何东西。你也可以捆绑“预期等待时间”等数据。这可以作为ping来检查是否客户端仍然活着。对此的响应将作为ping用户告诉他们他们仍然连接到服务器。你可以实现一个单独的'ping'调用,这取决于你)
  • 2 R.1 <- NothingYet (We found nothing, chill out and wait) 2 R.1 < - NothingYet(我们什么都没发现,冷静等待)
  • 2 R.2 <- GotOne (We found a match. You would tell the client if they should start up a server or connect at this point.) 2 R.2 < - GotOne(我们找到了一个匹配。您可以告诉客户端他们是否应该启动服务器或此时连接。)
  • 3 -> Leave (Wave goodbye to matchmaking) 3 - >离开(挥手告别配对)

Hopefully this helps. 希望这会有所帮助。 Also like I said, you could accomplish the same with UDP. 也像我说的那样,你可以用UDP完成同样的事情。 I really wouldn't go into TCP though(from experience). 我真的不会进入TCP(从经验)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM