Search in sources :

Example 1 with GeneralException

use of com.gianlu.pyxreborn.Exceptions.GeneralException in project PretendYoureXyzzyReborn by devgianlu.

the class GameManager method start.

/**
 * Starts the game.
 *
 * @throws GeneralException if the can't be started.
 */
public void start() throws GeneralException {
    if (game.players.size() < 3)
        throw new GeneralException(ErrorCodes.GAME_NOT_ENOUGH_PLAYERS);
    loadCards();
    nextRound();
}
Also used : GeneralException(com.gianlu.pyxreborn.Exceptions.GeneralException)

Example 2 with GeneralException

use of com.gianlu.pyxreborn.Exceptions.GeneralException in project PretendYoureXyzzyReborn by devgianlu.

the class BaseHandlerWithGame method handleRequest.

@Override
public final JsonObject handleRequest(Server server, @NotNull User user, JsonObject request, JsonObject response) throws GeneralException {
    JsonElement gid = request.get(Fields.GID.toString());
    if (gid == null)
        throw new GeneralException(ErrorCodes.INVALID_REQUEST);
    Game game = server.games.findGameById(gid.getAsInt());
    if (game == null)
        throw new GeneralException(ErrorCodes.GAME_DOESNT_EXIST);
    return handleRequest(server, user, game, request, response);
}
Also used : GeneralException(com.gianlu.pyxreborn.Exceptions.GeneralException) Game(com.gianlu.pyxreborn.Models.Game) JsonElement(com.google.gson.JsonElement)

Example 3 with GeneralException

use of com.gianlu.pyxreborn.Exceptions.GeneralException in project PretendYoureXyzzyReborn by devgianlu.

the class BaseHandlerWithUser method handleRequest.

@Override
public final JsonObject handleRequest(Server server, JsonObject request, JsonObject response) throws GeneralException {
    JsonElement sid = request.get(Fields.SESSION_ID.toString());
    if (sid == null)
        throw new GeneralException(ErrorCodes.INVALID_REQUEST);
    User user = server.users.findBySessionId(sid.getAsString());
    if (user == null)
        throw new GeneralException(ErrorCodes.NOT_CONNECTED);
    return handleRequest(server, user, request, response);
}
Also used : GeneralException(com.gianlu.pyxreborn.Exceptions.GeneralException) User(com.gianlu.pyxreborn.Models.User) JsonElement(com.google.gson.JsonElement)

Example 4 with GeneralException

use of com.gianlu.pyxreborn.Exceptions.GeneralException in project PretendYoureXyzzyReborn by devgianlu.

the class ChatHandler method handleRequest.

@Override
public JsonObject handleRequest(Server server, @NotNull User user, JsonObject request, JsonObject response) throws GeneralException {
    JsonElement text = request.get(Fields.TEXT.toString());
    if (text == null)
        throw new GeneralException(ErrorCodes.INVALID_REQUEST);
    JsonObject obj = Utils.event(Events.CHAT);
    obj.addProperty(Fields.NICKNAME.toString(), user.nickname);
    obj.add(Fields.TEXT.toString(), text);
    server.broadcastMessage(obj);
    return successful(response);
}
Also used : GeneralException(com.gianlu.pyxreborn.Exceptions.GeneralException) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject)

Example 5 with GeneralException

use of com.gianlu.pyxreborn.Exceptions.GeneralException in project PretendYoureXyzzyReborn by devgianlu.

the class GameChatHandler method handleRequest.

@Override
public JsonObject handleRequest(Server server, @NotNull User user, @NotNull Game game, JsonObject request, JsonObject response) throws GeneralException {
    JsonElement text = request.get(Fields.TEXT.toString());
    if (text == null)
        throw new GeneralException(ErrorCodes.INVALID_REQUEST);
    JsonObject obj = Utils.event(Events.GAME_CHAT);
    obj.addProperty(Fields.NICKNAME.toString(), user.nickname);
    obj.addProperty(Fields.GID.toString(), game.gid);
    obj.add(Fields.TEXT.toString(), text);
    server.broadcastMessageToPlayers(game, obj);
    return successful(response);
}
Also used : GeneralException(com.gianlu.pyxreborn.Exceptions.GeneralException) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject)

Aggregations

GeneralException (com.gianlu.pyxreborn.Exceptions.GeneralException)24 JsonElement (com.google.gson.JsonElement)10 JsonObject (com.google.gson.JsonObject)7 User (com.gianlu.pyxreborn.Models.User)5 Player (com.gianlu.pyxreborn.Models.Player)4 Game (com.gianlu.pyxreborn.Models.Game)3 GameManager (com.gianlu.pyxreborn.server.GameManager)3 AdminOnly (com.gianlu.pyxreborn.Annotations.AdminOnly)1 CardSet (com.gianlu.pyxreborn.Models.CardSet)1 Operations (com.gianlu.pyxreborn.Operations)1 BaseHandler (com.gianlu.pyxreborn.server.Handlers.BaseHandler)1 Random (java.util.Random)1 InvalidDataException (org.java_websocket.exceptions.InvalidDataException)1 ServerHandshakeBuilder (org.java_websocket.handshake.ServerHandshakeBuilder)1 Nullable (org.jetbrains.annotations.Nullable)1