Search in sources :

Example 6 with Game

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());
}
Also used : Player(com.gianlu.pyxreborn.Models.Player) Game(com.gianlu.pyxreborn.Models.Game) WebSocket(org.java_websocket.WebSocket) AdminOnly(com.gianlu.pyxreborn.Annotations.AdminOnly)

Example 7 with Game

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));
    }
}
Also used : Game(com.gianlu.pyxreborn.Models.Game)

Aggregations

Game (com.gianlu.pyxreborn.Models.Game)7 GeneralException (com.gianlu.pyxreborn.Exceptions.GeneralException)3 Player (com.gianlu.pyxreborn.Models.Player)2 JsonObject (com.google.gson.JsonObject)2 AdminOnly (com.gianlu.pyxreborn.Annotations.AdminOnly)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 Random (java.util.Random)1 WebSocket (org.java_websocket.WebSocket)1