iPhone 游戏中心重新连接
我有一个四人乒乓球游戏,当一个玩家断开连接(由于任何原因,来电,无聊,赶公共汽车)时,其他玩家可以继续玩。然而,我希望那个人能够在通话结束后重新连接,有谁知道我该如何实现这一点?
当两个玩家进化时,我会重新邀请那个人,但在这种情况下我该怎么做?
编辑: 我忘了提及我正在使用 Game Center API。因此,我使用比赛对象向玩家发送数据,但是在玩家断开连接后,比赛仍然有效,如果没有,是否有办法重新加入比赛?
I got a four player pong game and when one player disconnects (because of any reason, incomming call, bored, catch a bus) the other players can continue playing. However I want that person to be able to reconnect after his call is finished, does anyone have an idea how I can pull that off?
When two players were evolved I would just reinvite that person but how must I do it in this situation?
Edit:
I forgot to mention that I am using the Game Center API. So I am using the match object to send data to the players, but after a player gets disconnected will the match still work and if not is there a way to rejoin the match?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
1) 创建一个密钥,将该用户定义为该游戏的一部分(也许是与该游戏的所有玩家共享的 UUID 以及用户 x 或 y 组件?)
2) 搜索在应用程序中断后重新启动应用程序的方法
3 ) 重新启动,将唯一密钥发送到服务器,重新加入游戏
1) create a key that defines this user as part of this game (maybe a UUID shared with all players of this game along with a user x of y component?)
2) search for the methodology to relaunch your app after it's been interrupted
3) relaunch, send the unique key to the server, rejoin the game
也许您的游戏有用户名?因此,如果玩家断开连接,然后在连接到服务器时再次出现,请检查该用户名是否在之前的任何游戏/房间中?注意:这意味着用户名应该是唯一的。
否则,执行某种 userId 系统,其中每个注册游戏的新用户都会获得一个从前一个用户递增的数字,以便注册将该数字保存在客户端,例如来自浏览器的 cookie,并在断开连接的玩家再次加入时将该数字发送到服务器。
例如,通过对保存的文件进行逆向工程或挑选在不同手机上断开连接的用户名,这两种方法都可以轻松利用。
最好的方法是使用某种用户名/密码系统,使所有用户名都是唯一的。
如果用户第二/第三次连接,那么服务器应该发出某种消息,说明该人当前已登录?
如果那个人被打断,那么要么发送一个断开连接数据包,要么如果不能,服务器可以处理这个问题。要么与服务器的连接丢失,从而用户的状态变为断开连接。或者不知何故连接仍然存在?也许是UDP套接字?如果没有响应,服务器将尝试发送乒乓类型的数据包,那么显然用户已与该应用程序断开连接,因此将状态设置为断开连接等。
Maybe your game has usernames? so if a player disconnects then comes around again when he connects to server check if that username is in any previous games/rooms? note: this means the usernames should be unique.
Otherwise do some kind of a userId system where each new user to register to your game is given a number incremented from the previous user to register save that number clientsided like cookies from browsers and send the number to server when disconnected player is joining again.
Both methods can easily be exploited by reverse engineering the saved file or picking out a username that disconnected on a different phone for example.
Best method would be to use some kind of a username/password system which makes all usernames unique.
If a user connects a 2nd/3rd time then the server should give out a message of some sort saying the person is currently logged in?
If that person gets interrupted then either send a disconnect packet or if you can't the server can take care of this. Either the connection will be lost with server so the user's state goes disconnected. Or somehow the connection is still alive? maybe UDP socket? the server will attempt to send a ping-pong type of packet if no response then obviously user is disconnected from that app so set state to disconnected etc..