Package model

Examples of model.Player


    @Override
    public void doBusiness() throws Exception {
        System.out.println("User '" + user_id + "' is connecting...");

        Player player = null;

        if (version.compareTo(Constants.CLIENT_VERSION) >= 0) {
            if (!user_id.isEmpty() && password.matches("[a-fA-F0-9]{32}")) {
                player = PlayerDAO.getAccount(user_id, password);
            }

            if (player == null) {
                responseLogin.setStatus((short) 1);//Username/password is wrong.
                System.out.println("User '" + user_id + "' has failed to log in.");
            } else {
                if (client.getPlayer() == null || player.getID() != client.getPlayer().getID()) {
                    GameClient thread = client.getServer().getThreadByPlayerID(player.getID());

                    if (thread != null) {
                        responseLogin.setStatus((short) 2);//Account is being used.
                        thread.stopClient();
                    } else {
                        PlayerDAO.updateLogin(player.getID(), client.getIP());
                        GameServer.getInstance().setActivePlayer(player);
                        player.setClient(client);
                        player.setLastSaved(System.currentTimeMillis());
                        player.startSaveTimer();
                        //Put the current user in its thread.
                        //Add the thread to active threads.
                        client.setPlayer(player);
                        client.getServer().addToActiveThreads(client);
                        //Set response information.
                        responseLogin.setStatus((short) 0);//Login succeeds!
                        responseLogin.setPlayer(player);

                        List<Avatar> avatarList = AvatarDAO.getAvatars(client.getPlayer().getID());
                        responseLogin.setAvatarList(avatarList);
                       
                        List<World> worldList = WorldDAO.getPlayerWorlds(client.getPlayer().getID());
                        List<Integer> scoreList = new ArrayList<Integer>();

                        for (World world : worldList) {
                            List<Environment> envList = EnvironmentDAO.getEnvironmentByWorldID(world.getID());

                            if (!envList.isEmpty()) {
                                for (Environment env : envList) {
                                    scoreList.add(env.getEnvironmentScore());
                                }
                            } else {
                                scoreList.add(0);
                            }
                        }

                        responseLogin.setWorldList(worldList, scoreList);

                        //Set the player's current position 0(0 means in the main lobby.)
                        client.getServer().trackPlayerPosition(player.getID(), Constants.LOCATION_MAIN_LOBBY);

                        System.out.println("User '" + player.getUsername() + "' has successfully logged in.");
                    }
                } else {
                    responseLogin.setStatus((short) 4);
                }
            }
View Full Code Here


        max_biomass = Math.max(max_biomass, totalBiomass);

        if (totalBiomass >= max_biomass && totalBiomass >= 1000) {
            if (String.valueOf((int) totalBiomass).length() > String.valueOf((int) max_biomass).length()) {
                Player player = GameServer.getInstance().getActivePlayer(gameEngine.getWorld().getEnvByID(env_id).getOwnerID());
                GameServer.getInstance().updateExperience(player, 1000);
            }
        }
    }
View Full Code Here

    public boolean setEnable(boolean status) {
        return this.isEnable = status;
    }

    public void startTimeActiveTimer() {
        Player player = GameServer.getInstance().getActivePlayer(gameEngine.getWorld().getEnvByID(env_id).getOwnerID());
        timeActiveTimer.schedule(new GameTimerCollection.ZoneTimeTimer(player, this), 60000, 60000);
    }
View Full Code Here

     * @return Returns PlayerType by matching player_id if found in the
     * database.  If not found then returns null.
     * @throws SQLException
     */
    public static Player getByPlayerID(int player_id) throws SQLException {
        Player returnPlayer = null;

        String query = "SELECT * FROM `player` WHERE `player_id` = ?";

        Connection connection = null;
        PreparedStatement pstmt = null;

        try {
            connection = DAO.getDataSource().getConnection();
            pstmt = connection.prepareStatement(query);
            pstmt.setInt(1, player_id);
            ResultSet rs = pstmt.executeQuery();

            if (rs.next()) {
                returnPlayer = new Player(rs.getInt("player_id"));
                returnPlayer.setUsername(rs.getString("username"));
                returnPlayer.setPassword(rs.getString("password"));
                returnPlayer.setEmail(rs.getString("email"));
            }

            rs.close();
            pstmt.close();
        } finally {
View Full Code Here

     * @return Returns a player by matching userName in database.  If none
     * found returns null.
     * @throws SQLException
     */
    public static Player getByUsername(String username) throws SQLException {
        Player returnPlayer = null;

        String query = "SELECT * FROM `player` WHERE `username` = ?";

        Connection connection = null;
        PreparedStatement pstmt = null;

        try {
            connection = DAO.getDataSource().getConnection();
            pstmt = connection.prepareStatement(query);
            pstmt.setString(1, username);
            ResultSet rs = pstmt.executeQuery();

            if (rs.next()) {
                returnPlayer = new Player(rs.getInt("player_id"));
                returnPlayer.setUsername(rs.getString("username"));
                returnPlayer.setPassword(rs.getString("password"));
                returnPlayer.setEmail(rs.getString("email"));
            }

            rs.close();
            pstmt.close();
        } finally {
View Full Code Here

     * @return Returns a player by matching userName and password, both
     * extracted from player, in database.  If none found returns null.
     * @throws SQLException
     */
    public static Player getAccount(String email, String password) throws SQLException {
        Player player = null;

        String query = "SELECT * FROM `player` WHERE `email` = ? AND `password` = ?";

        Connection connection = null;
        PreparedStatement pstmt = null;

        try {
            connection = DAO.getDataSource().getConnection();
            pstmt = connection.prepareStatement(query);
            pstmt.setString(1, email);
            pstmt.setString(2, password);
            ResultSet rs = pstmt.executeQuery();

            if (rs.next()) {
                player = new Player(rs.getInt("player_id"));
                player.setUsername(rs.getString("username"));
                player.setEmail(rs.getString("email"));
                player.setPassword(rs.getString("password"));
                player.setPlayTime(rs.getLong("play_time"));
                player.setLastLogout(rs.getString("last_logout"));
            }

            rs.close();
            pstmt.close();
        } finally {
View Full Code Here

                        }
                    } catch (SQLException ex) {
                        System.err.println(ex.getMessage());
                    }

                    Player player = GameServer.getInstance().getActivePlayer(zone.getEnvironment().getOwnerID());
                    SpeciesType species = GameServer.getInstance().getSpecies(species_id);
                    GameServer.getInstance().updateExperience(player, (int) Math.ceil(species.getCost() * 0.75));
                }
            }
        }
View Full Code Here

            }
        }
    }

    public short buyOrganism(int organism_type, int player_id, int species_id, int amount, int zone_id, float xCoor, float yCoor) {
        Player player = GameServer.getInstance().getActivePlayer(player_id);
        Avatar avatar = player.getAvatar();

        if (avatar != null) {
            SpeciesType species = null;

            if (organism_type == Constants.ORGANISM_TYPE_PLANT) {
View Full Code Here

TOP

Related Classes of model.Player

Copyright © 2018 www.massapicom. 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.