如何通过id获取用户并断开用户连接

时间:2016-11-08 10:40:52

标签: java smartfoxserver smartfox

  

这是我的代码。但是user = null
  如何通过id获取用户并断开用户连接?

Zone zone = (Zone)event.getParameter(SFSEventParam.ZONE);
User user = zone.getUserById(1);
this.getApi().disconnectUser(user,ClientDisconnectionReason.IDLE);

1 个答案:

答案 0 :(得分:0)

你通过id = 1获得用户,id可能无效,SFS为每个用户提供的id可能会有所不同,它不像是从0开始的数组,每次有人连接时都可能会改变或断开连接,当玩家连接到sfs时,它需要一个id,当他断开连接时,其他人可能会接受它,你可以通过这个获得用户ID:

        Collection<User> users =  getParentExtension().getParentZone().getUserList();
        while (users.iterator().hasNext())
        {
            int id = users.iterator().next().getId();
        }

然后使用disconnect功能断开连接,或者只是将用户与收集用户断开连接。