Search in sources :

Example 1 with AdminOnly

use of com.gianlu.pyxreborn.Annotations.AdminOnly 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 2 with AdminOnly

use of com.gianlu.pyxreborn.Annotations.AdminOnly in project PretendYoureXyzzyReborn by devgianlu.

the class Games method killGame.

/**
 * Kills the game, kicking everyone and deleting the game
 */
@AdminOnly
public void killGame(@NotNull Game game, KickReason majorReason) {
    GameManager manager = managedGames.findGameManagerByGameId(game.gid);
    if (manager != null) {
        try {
            manager.stop();
        } catch (GeneralException ignored) {
        }
    }
    if (!game.players.isEmpty()) {
        for (Player player : game.players) {
            kickPlayer(game, player, majorReason);
        }
    }
    if (!game.spectators.isEmpty()) {
        for (User spectator : game.spectators) {
            kickSpectator(game, spectator, majorReason);
        }
    }
    if (manager != null)
        managedGames.remove(manager);
    remove(game);
    server.broadcastMessage(Utils.event(Events.GAME_REMOVED));
}
Also used : Player(com.gianlu.pyxreborn.Models.Player) GeneralException(com.gianlu.pyxreborn.Exceptions.GeneralException) User(com.gianlu.pyxreborn.Models.User) GameManager(com.gianlu.pyxreborn.server.GameManager) AdminOnly(com.gianlu.pyxreborn.Annotations.AdminOnly)

Aggregations

AdminOnly (com.gianlu.pyxreborn.Annotations.AdminOnly)2 Player (com.gianlu.pyxreborn.Models.Player)2 GeneralException (com.gianlu.pyxreborn.Exceptions.GeneralException)1 Game (com.gianlu.pyxreborn.Models.Game)1 User (com.gianlu.pyxreborn.Models.User)1 GameManager (com.gianlu.pyxreborn.server.GameManager)1 WebSocket (org.java_websocket.WebSocket)1