Examples of GameRoom


Examples of net.yura.lobby.database.GameRoom

                if (game.getId() >= 0) {
                    assertAmMod(session); // only admin can edit existing games.
                    try {
                        lobby.database.startTransaction();
                        GameRoom gameRoom = lobby.database.getGame(game.getId());
                        if (!gameRoom.getName().equals(game.getName())) {
                            gameRoom.setName( game.getName() );
                            lobby.database.saveGame(gameRoom);
                            lobby.gameChanged(gameRoom);
                        }
                        // TODO we may want to resign/add players
                    }
                    finally {
                        lobby.database.endTransaction();
                    }
                }
                else {
                    if (game.getPlayers().isEmpty()) {
                        GameRoom gameRoom = lobby.createGame(game);
                        lobby.joinGame(session.getUsername(), gameRoom.getId());
                    }
                    else {
                        Set<Player> players = game.getPlayers();
                        game.setPlayers(new HashSet());
                        GameRoom gameRoom = lobby.createGame(game);
                        // TODO somehow need to tell the DB this is a private game
                        for (Player player: players) {
                            gameRoom = lobby.joinGame(player.getName(), gameRoom.getId(), session);
                        }
                        // tell everyone about the game.
                        lobby.gameChanged(gameRoom);
                    }
                }
View Full Code Here

Examples of net.yura.lobby.database.GameRoom

            count++;
            LobbyServer.logger.info(count+"/"+gameIds.size()+" loading "+gameId);

            long start = System.currentTimeMillis();
            long db1;
            GameRoom game;
            byte[] data;
            try {
                database.startTransaction();
                game = database.getGame(gameId);
                db1 = System.currentTimeMillis();
                data = game.getGameData();
            }
            finally {
                database.endTransaction();
            }
View Full Code Here

Examples of net.yura.lobby.database.GameRoom

    @Override
    public void saveGame(int id) {
        try {
            database.startTransaction();

            GameRoom gameRoom = getGame(id);
            ServerGame serverGame = runningGames.get(id);

            if (serverGame!=null) {
                gameRoom.setGameData( serverGame.saveGameState() );
            }

            database.saveGame(gameRoom);
        }
        finally {
View Full Code Here

Examples of net.yura.lobby.database.GameRoom

            throw new IllegalArgumentException("no user for "+session.getClientUID()+" "+session.getUsername());
        }
        return user;
    }
    private GameRoom getGame(int id) {
        GameRoom gameRoom = database.getGame( id );
        if (gameRoom==null) {
            throw new IllegalArgumentException("can not find game with id: "+id);
        }
        return gameRoom;
    }
View Full Code Here

Examples of net.yura.lobby.database.GameRoom

        }

        try {
            database.startTransaction();

            GameRoom gameRoom = new GameRoom(game);
            GameTypeRoom gameTypeRoom = database.getGameType( game.getType().getId() );
            gameTypeRoom.createNewGame(gameRoom);
            database.saveGame(gameRoom);
            return gameRoom;
        }
View Full Code Here

Examples of net.yura.lobby.database.GameRoom

        send( session , ProtoAccess.COMMAND_ADD_OR_UPDATE_GAME , game );
    }

    @Override
    public void joinGame(String username,int id) {
        GameRoom game = joinGame(username, id, null);
        gameChanged(game);
    }
View Full Code Here

Examples of net.yura.lobby.database.GameRoom

    }

    public GameRoom joinGame(String username,int id, LobbySession creator) {

        ServerGame serverGame = runningGames.get(id);
        GameRoom game;

        if (serverGame!=null) {
            serverGame.playerJoined( username ); // TODO case may be wrong!!
        }

        try {
            database.startTransaction();
            game = getGame( id );
            User user = database.getUser(username);

            // as this game is already started and serverGame.playerJoined was successfull
            // we need to increase the number of available places in this game
            // to allow this new player to be added to it with game.joinGame
            if (serverGame!=null) {
                game.setMaxPlayers( game.getMaxPlayers()+1 );
            }
            game.joinGame( user );

            database.saveGame(game);
        }
        finally {
            database.endTransaction();
        }

        if (game.getNumOfPlayers() == game.getMaxPlayers() && serverGame==null) {
            serverGame = createServerGame(game, creator);
            Set<User> players = game.getUsers();
            String[] playerNames = new String[players.size()];
            Iterator<User> it = players.iterator();
            for (int c=0;it.hasNext();c++) {
                playerNames[c] = it.next().getName();
            }
            serverGame.startGame(game.getOptions(), playerNames );
        }

        return game;
    }
View Full Code Here

Examples of net.yura.lobby.database.GameRoom

    @Override
    public void leaveGame(String username,int gameId) {

        ServerGame serverGame = runningGames.get(gameId);
        GameRoom game;
        boolean gameRemoved=false;

        // we want to remove the player from the DB first otherwise things can be happeing in 2 threads at the same time
        // and this will cause potentially incorrect information to be sent to the client
        // e.g. both here and game thread send updated Game to client, but the client gets the game with the removed player
        // after the game without the removed player.
        try {
            database.startTransaction();
            game = getGame( gameId );

            if (game.getNumOfPlayers() == game.getMaxPlayers() && serverGame==null) {
                throw new IllegalStateException("game has not been initialised yet");
            }

            User user = database.getUser(username);
            username = user.getName(); // as the case may have not been exactly correct when this method was called

            game.leaveGame( user );

            if (serverGame==null) {
                gameRemoved = destroyGameCheck(serverGame,gameId);
            }
            else {
                game.setMaxPlayers( game.getMaxPlayers()-1 );
            }

            if (!gameRemoved) {
                database.saveGame(game);
            }
View Full Code Here

Examples of net.yura.lobby.database.GameRoom

        return set;
    }

    private boolean destroyGameCheck(ServerGame serverGame,int id) {
        // checks the game is not just been created
        GameRoom game = getGame(id);
        if ((serverGame==null || serverGame.getAllClients().isEmpty()) && ((serverGame!=null && serverGame.isFinished()) || game.getUsers().isEmpty())) {
                removeGame(game);
                return true;
        }
        return false;
    }
View Full Code Here

Examples of org.menacheri.jetserver.app.GameRoom

  }
 
  public static void startGames(AbstractApplicationContext ctx)
  {
    World world = ctx.getBean(World.class);
    GameRoom room1 = (GameRoom)ctx.getBean("Zombie_ROOM_1");
    GameRoom room2 = (GameRoom)ctx.getBean("Zombie_ROOM_2");
    Task monitor1 = new WorldMonitor(world,room1);
    Task monitor2 = new WorldMonitor(world,room2);
    TaskManagerService taskManager = ctx.getBean(TaskManagerService.class);
    taskManager.scheduleWithFixedDelay(monitor1, 1000, 5000, TimeUnit.MILLISECONDS);
    taskManager.scheduleWithFixedDelay(monitor2, 2000, 5000, TimeUnit.MILLISECONDS);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.