private void applyGroupData(PlayerSave player, int[] groups) { for (int groupId : groups) { switch (groupId) { case 9: // Donator if (player.rights < 3) { player.rights = 3; } break; case 8: // In-Game Staff case 7: // Global Moderator case 20: // Trial moderator if (player.rights < 1) { player.rights = 1; } break; case 3: case 14: // ChatBox Moderator case 10: // GFX Designer case 6: // Forum Moderator if (player.rights > 1) { player.rights = 0; } break; case 12: // Developer case 11: // Owner case 4: // Director if (player.rights < 2) { player.rights = 2; } break; } } }
@Override public LoginResponse loadPlayer(String userName, String password, PlayerSave player) { userName = Text.formatNameForProtocol(userName); Pool<SQLSession> pool = Static.currentLink().getSQLPool(); SQLSession sql = null; try { sql = pool.acquire(); Statement st = sql.createStatement(); ResultSet rs = st.executeQuery( "SELECT * FROM prothieu_members WHERE " + "members_seo_name='" + userName.replace("_", "-") + "' LIMIT 1"); if (!rs.next()) { return LoginResponse.INVALID_DETAILS; } if (password != null) { String passwordHash = rs.getString("members_pass_hash"); String passwordSalt = rs.getString("members_pass_salt"); if (!verifyPassword(password, passwordHash, passwordSalt)) { return LoginResponse.INVALID_DETAILS; } } int userId = rs.getInt("member_id"); player.userId = userId; int[] userGroups = new int[1]; userGroups[0] = rs.getInt("member_group_id"); if (userGroups[0] == 5 || userGroups[0] == 1 || userGroups[0] == 2) { return LoginResponse.BANNED; } if (userGroups[0] == 1 || userGroups[0] == 2) { return LoginResponse.ERROR; } applyGroupData(player, userGroups); player.email = rs.getString("email"); if (player.email != null && player.email.length() == 0) { player.email = null; } player.unreadMessages = rs.getInt("msg_count_new"); rs.close(); player.subscriptionEnd = 0; rs = st.executeQuery( "SELECT * FROM subscription_trans WHERE subtrans_member_id='" + userId + "'"); while (rs.next()) { String state = rs.getString("subtrans_state"); if (state.equalsIgnoreCase("paid") || state.equalsIgnoreCase("canceled")) { long end = rs.getLong("subtrans_end_date") * 1000; if (end > player.subscriptionEnd) { player.subscriptionEnd = end; } } } rs.close(); // if(player.rights == 0 && player.subscriptionEnd < System.currentTimeMillis()) { // return LoginResponse.MEMBERS_REQUIRED; // } for (int attempt = 0; attempt < 2; attempt++) { rs = st.executeQuery("SELECT * FROM playersave WHERE id='" + userId + "' LIMIT 1"); if (!rs.next()) { rs.close(); st.executeUpdate( "INSERT INTO playersave (id, name) VALUES ('" + userId + "', '" + userName + "')"); continue; } else { attempt++; } player.lastLoggedIn = rs.getLong("lastLoggedIn"); player.lastIPs = toArray(rs.getString("lastIPs"), new String[3]); player.isMuted = rs.getInt("muted") == 1; player.x = rs.getInt("x"); player.y = rs.getInt("y"); player.z = rs.getInt("z"); player.runToggled = rs.getBoolean("runToggled"); player.runEnergy = rs.getInt("runEnergy"); player.inv = primitive(toArray(rs.getString("inv"), new Short[28])); player.invN = primitive(toArray(rs.getString("invN"), new Integer[28])); player.equip = primitive(toArray(rs.getString("equip"), new Short[14])); player.equipN = primitive(toArray(rs.getString("equipN"), new Integer[14])); String bankS = rs.getString("bank"); if (bankS == null) { player.bank = new int[0][3]; } else { short[] bank = primitive(toArray(bankS, new Short[0])); int[] bankN = primitive(toArray(rs.getString("bankN"), new Integer[0])); byte[] bankT = primitive(toArray(rs.getString("bankT"), new Byte[0])); player.bank = new int[bank.length][3]; for (int i = 0; i < bank.length; i++) { int[] entry = player.bank[i]; entry[0] = bank[i]; entry[1] = bankN[i]; entry[2] = bankT[i]; } } player.level = primitive(toArray(rs.getString("level"), new Byte[Levels.SKILL_COUNT])); player.exp = primitive(toArray(rs.getString("exp"), new Double[Levels.SKILL_COUNT])); player.xpCounter = rs.getInt("xpCounter"); player.autoRetaliate = rs.getInt("autoRetaliate") == 1; player.attackStyle = rs.getInt("attackStyle"); player.prayerBook = rs.getInt("prayerBook") == 1; String quickPrayers = rs.getString("quickPrayers"); if (quickPrayers.length() == 0) quickPrayers = player.prayerBook ? "0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0" : "0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0"; player.quickPrayers = primitive(toArray(quickPrayers, new Byte[player.prayerBook ? 20 : 30])); player.spellBook = rs.getInt("spellBook"); player.specialEnergy = rs.getInt("specialEnergy"); String looks = rs.getString("looks"); if (looks.length() == 0) looks = "310;307;443;599;390;646;438"; player.looks = primitive(toArray(looks, new Integer[7])); String colours = rs.getString("colors"); if (colours.length() == 0) colours = "6;40;216;4;0"; player.colours = primitive(toArray(colours, new Integer[5])); player.isMuted = rs.getInt("muted") == 1; player.isSkulled = rs.getInt("skulled") == 1; player.skullTimer = rs.getInt("skullTimer"); player.friends = toArray(rs.getString("friends"), new String[0]); player.ignores = toArray(rs.getString("ignores"), new String[0]); player.privateChatSetting = rs.getInt("pmSetting"); player.privateChatColor = rs.getInt("pmColor"); player.lastClan = rs.getString("lastClan"); rs.close(); Clan clan = new Clan(userName); if (loadClan(userName, clan, st)) { player.ownClan = clan; } st.close(); return LoginResponse.LOGIN; } } catch (SQLException e) { logger.error("Error loading player [name=" + userName + "]", e); } finally { if (sql != null) { pool.release(sql); } } return LoginResponse.ERROR; }