Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(allowed && request.getParameter("process") != null && request.getParameter("process").compareTo("sqlsync") == 0)
- {
- try
- {
- // { faction-id , [(String)name , (Integer)level, (Integer)member-count] }
- HashMap<Integer, Object[]> factions = loadFactions(pw_server_path);
- // { role-id , [faction-id , faction-rank] }
- HashMap<Integer, Integer[]> faction_members = loadFactionMembers(pw_server_path);
- // { faction-id , "domain_1;domain_2;domain_3" }
- HashMap<Integer, String> faction_domains = loadFactionDomains(pw_server_path);
- // { role-id , [kills , deaths] }
- HashMap<Integer, Integer[]> pvp = loadPvP(pw_server_path + "logs/world2.formatlog");
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- Connection connection = DriverManager.getConnection("jdbc:mysql://" + db_host + ":" + db_port + "/" + db_database, db_user, db_password);
- Statement statement = connection.createStatement();
- Statement update = connection.createStatement();
- ResultSet rs;
- // drop table and re-create it (autoincrement reset)
- //statement.execute("TRUNCATE TABLE roles");
- statement.executeUpdate("DROP TABLE IF EXISTS roles");
- statement.executeUpdate
- (
- "CREATE TABLE roles(" +
- "account_id int(11) NOT NULL, " +
- "role_id int(11) NOT NULL, " +
- "role_name varchar(32) NOT NULL, " +
- "role_level smallint(6) NOT NULL, " +
- "role_race tinyint(4) NOT NULL, " +
- "role_occupation tinyint(4) NOT NULL, " +
- "role_gender tinyint(4) NOT NULL, " +
- "role_spouse int(11) NOT NULL, " +
- "faction_id int(11) NOT NULL, " +
- "faction_name varchar(32) NOT NULL, " +
- "faction_level int(11) NOT NULL, " +
- "faction_domains varchar(132) NOT NULL, " +
- "role_faction_rank int(11) NOT NULL, " +
- "pvp_time int(11) NOT NULL, " +
- "pvp_kills int(11) NOT NULL, " +
- "pvp_deads int(11) NOT NULL" +
- ") " +
- "ENGINE=InnoDB DEFAULT CHARSET=utf8;"
- );
- rs = (statement.executeQuery("SELECT ID FROM users"));
- // go through all account id's and fetch roles + properties
- Integer roleid;
- RoleBean chr;
- String rolename;
- Object[] faction_entry;
- Integer[] faction_member_entry;
- String domains;
- Integer[] pvp_entry;
- while(rs.next())
- {
- // Get all character of current userid
- DataVector dv = GameDB.getRolelist(rs.getInt("ID"));
- if(dv != null)
- {
- Iterator itr = dv.iterator();
- while(itr.hasNext())
- {
- IntOctets ios = (IntOctets)itr.next();
- chr = GameDB.get(ios.m_int);
- roleid = new Integer(ios.m_int);
- rolename = StringEscapeUtils.escapeHtml(chr.base.name.getString());
- if(pvp.containsKey(roleid))
- {
- pvp_entry = pvp.get(roleid);
- }
- else
- {
- pvp_entry = new Integer[]{0, 0};
- }
- if(faction_members.containsKey(roleid))
- {
- faction_member_entry = faction_members.get(roleid);
- }
- else
- {
- faction_member_entry = new Integer[]{0, 0};
- }
- if(factions.containsKey(faction_member_entry[0]))
- {
- faction_entry = factions.get(faction_member_entry[0]);
- faction_entry[0] = new String();
- }
- else
- {
- faction_entry = new Object[]{new String(), (Integer)0, (Integer)0};
- }
- if(faction_domains.containsKey(faction_member_entry[0]))
- {
- domains = faction_domains.get(faction_member_entry[0]);
- }
- else
- {
- domains = "";
- }
- // insert row into table
- update.executeUpdate("INSERT INTO roles VALUES (" + chr.user.userid + ", " + roleid + ", '" + rolename + "', " + chr.status.level + ", " + chr.base.race + ", " + chr.base.cls + ", " + chr.base.gender + ", " + chr.base.reserved1 + ", " + faction_member_entry[0] + ", '" + (String)(faction_entry[0]) + "', " + (Integer)(faction_entry[1]) + ", '" + domains + "', " + faction_member_entry[1] + ", " + chr.status.invader_time + ", " + pvp_entry[0] + ", " + pvp_entry[1] + ")");
- }
- }
- }
- update.close();
- rs.close();
- statement.close();
- connection.close();
- message = "<font color=\"#00cc00\"><b>Roles Imported to MySQL Table</b></font>";
- }
- catch(Exception e)
- {
- message = "<font color=\"#ee0000\"><b>Importing Roles to MySQL Failed</b></font>";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement