use of com.gianlu.pyxreborn.Models.Game in project PretendYoureXyzzyReborn by devgianlu.
the class ConnectedUsers method kickUser.
/**
* Kicks an user from the server. Not allowing reconnection.
*/
@AdminOnly
public void kickUser(@NotNull User user, @Nullable KickReason reason) {
Game playingIn = server.games.playingIn(user);
if (playingIn != null) {
Player player = playingIn.findPlayerByNickname(user.nickname);
if (player != null)
server.games.kickPlayer(playingIn, player, reason);
}
WebSocket socket = server.findWebSocketByAddress(user.address);
if (socket == null)
return;
socket.close(CloseFrame.POLICY_VALIDATION, (reason == null ? KickReason.GENERAL_KICK : reason).toString());
}
use of com.gianlu.pyxreborn.Models.Game in project PretendYoureXyzzyReborn by devgianlu.
the class ConnectedUsers method removeUser.
/**
* Remove the specified {@link User}.
*
* @param remote if true the user won't be disconnected immediately.
* Its session can be restored by providing the session ID. See {@link PyxServerAdapter#onWebsocketHandshakeReceivedAsServer(WebSocket, Draft, ClientHandshake)}.
* The user will be permanently deleted after the reconnect delay. See {@link ConnectedUsers.GeneralTasks}.
*/
public void removeUser(User user, boolean remote) {
if (remote) {
// We're giving a chance to reconnect to the user
user.disconnectedAt = System.currentTimeMillis();
} else {
Game game = server.games.playingIn(user);
if (game != null)
server.games.leaveGame(game, user);
remove(user);
server.broadcastMessage(Utils.event(Events.USER_LEFT));
}
}
Aggregations