· 7 years ago · Oct 20, 2018, 08:36 PM
1 if(allowed && request.getParameter("process") != null && request.getParameter("process").compareTo("sqlsync") == 0)
2 {
3 try
4 {
5 // { faction-id , [(String)name , (Integer)level, (Integer)member-count] }
6 HashMap<Integer, Object[]> factions = loadFactions(pw_server_path);
7
8 // { role-id , [faction-id , faction-rank] }
9 HashMap<Integer, Integer[]> faction_members = loadFactionMembers(pw_server_path);
10
11 // { faction-id , "domain_1;domain_2;domain_3" }
12 HashMap<Integer, String> faction_domains = loadFactionDomains(pw_server_path);
13
14 // { role-id , [kills , deaths] }
15 HashMap<Integer, Integer[]> pvp = loadPvP(pw_server_path + "logs/world2.formatlog");
16
17 Class.forName("com.mysql.jdbc.Driver").newInstance();
18 Connection connection = DriverManager.getConnection("jdbc:mysql://" + db_host + ":" + db_port + "/" + db_database, db_user, db_password);
19 Statement statement = connection.createStatement();
20 Statement update = connection.createStatement();
21 ResultSet rs;
22
23 // drop table and re-create it (autoincrement reset)
24 //statement.execute("TRUNCATE TABLE roles");
25 statement.executeUpdate("DROP TABLE IF EXISTS roles");
26 statement.executeUpdate
27 (
28 "CREATE TABLE roles(" +
29 "account_id int(11) NOT NULL, " +
30 "role_id int(11) NOT NULL, " +
31 "role_name varchar(32) NOT NULL, " +
32 "role_level smallint(6) NOT NULL, " +
33 "role_race tinyint(4) NOT NULL, " +
34 "role_occupation tinyint(4) NOT NULL, " +
35 "role_gender tinyint(4) NOT NULL, " +
36 "role_spouse int(11) NOT NULL, " +
37 "faction_id int(11) NOT NULL, " +
38 "faction_name varchar(32) NOT NULL, " +
39 "faction_level int(11) NOT NULL, " +
40 "faction_domains varchar(132) NOT NULL, " +
41 "role_faction_rank int(11) NOT NULL, " +
42 "pvp_time int(11) NOT NULL, " +
43 "pvp_kills int(11) NOT NULL, " +
44 "pvp_deads int(11) NOT NULL" +
45 ") " +
46 "ENGINE=InnoDB DEFAULT CHARSET=utf8;"
47 );
48
49 rs = (statement.executeQuery("SELECT ID FROM users"));
50
51 // go through all account id's and fetch roles + properties
52 Integer roleid;
53 RoleBean chr;
54 String rolename;
55 Object[] faction_entry;
56 Integer[] faction_member_entry;
57 String domains;
58 Integer[] pvp_entry;
59 while(rs.next())
60 {
61 // Get all character of current userid
62 DataVector dv = GameDB.getRolelist(rs.getInt("ID"));
63 if(dv != null)
64 {
65 Iterator itr = dv.iterator();
66 while(itr.hasNext())
67 {
68 IntOctets ios = (IntOctets)itr.next();
69 chr = GameDB.get(ios.m_int);
70 roleid = new Integer(ios.m_int);
71 rolename = StringEscapeUtils.escapeHtml(chr.base.name.getString());
72
73 if(pvp.containsKey(roleid))
74 {
75 pvp_entry = pvp.get(roleid);
76 }
77 else
78 {
79 pvp_entry = new Integer[]{0, 0};
80 }
81
82 if(faction_members.containsKey(roleid))
83 {
84 faction_member_entry = faction_members.get(roleid);
85 }
86 else
87 {
88 faction_member_entry = new Integer[]{0, 0};
89 }
90
91 if(factions.containsKey(faction_member_entry[0]))
92 {
93 faction_entry = factions.get(faction_member_entry[0]);
94 faction_entry[0] = new String();
95 }
96 else
97 {
98 faction_entry = new Object[]{new String(), (Integer)0, (Integer)0};
99 }
100
101 if(faction_domains.containsKey(faction_member_entry[0]))
102 {
103 domains = faction_domains.get(faction_member_entry[0]);
104 }
105 else
106 {
107 domains = "";
108 }
109
110 // insert row into table
111 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] + ")");
112 }
113 }
114 }
115
116 update.close();
117 rs.close();
118 statement.close();
119 connection.close();
120
121 message = "<font color=\"#00cc00\"><b>Roles Imported to MySQL Table</b></font>";
122 }
123 catch(Exception e)
124 {
125 message = "<font color=\"#ee0000\"><b>Importing Roles to MySQL Failed</b></font>";
126 }
127 }