Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package kernel;
- import java.sql.*;
- /**
- *
- * @author Neo-Craft
- */
- public class Main {
- /**
- * @param args the command line arguments
- */
- public static String DB_HOST;
- public static String DB_USER;
- public static String DB_PASS;
- public static String DB_NAME;
- static {
- Runtime.getRuntime().addShutdownHook(new Thread() {
- @Override
- public void run() {
- Main.stop();
- }
- });
- }
- public static void stop() {
- System.out.println("Closing patcher...");
- }
- public static void main(String[] args) {
- System.out.println("NEO-Patcher");
- System.out.println("========================");
- if (args.length != 4) {
- System.out.println("Bad args, you must use : [DB_HOST] [DB_USER] [DB_PASS] [DB_NAME]");
- return;
- } else {
- DB_HOST = args[0];
- DB_USER = args[1];
- if (!args[2].equalsIgnoreCase("null")) {
- DB_PASS = args[2];
- }
- DB_NAME = args[3];
- System.out.println("Parsing args...");
- System.out.println("DB_HOST : " + args[0]);
- System.out.println("DB_USER : " + args[1]);
- System.out.println("DB_PASS : " + args[2]);
- System.out.println("DB_NAME : " + args[3]);
- System.out.println("Args loaded.");
- }
- System.out.println("Patching.....");
- try {
- String connectionURL = "jdbc:mysql://" + DB_HOST + ":3306/" + DB_NAME;
- Connection connection = null;
- Statement statement = null;
- ResultSet rs = null;
- ResultSet rs2 = null;
- int updateQuery = 0;
- // Load JBBC driver "com.mysql.jdbc.Driver".
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- /* Create a connection by using getConnection()
- method that takes parameters of string type
- connection url, user name and password to
- connect to database. */
- connection = DriverManager.getConnection(connectionURL, DB_USER, DB_PASS);
- /* createStatement() is used for create
- statement object that is used for sending sql
- statements to the specified database. */
- statement = connection.createStatement();
- // sql query of string type to create a data base.
- String QueryString = "CREATE TABLE `realmlist` ( `id` int(11) NOT NULL,`address` varchar(255) NOT NULL, `port` int(11) NOT NULL, `player_limit` int(11) NOT NULL,`allowedSecurityLevel` int(11) NOT NULL,`key` varchar(255) NOT NULL,PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
- updateQuery = statement.executeUpdate(QueryString);
- // sql query to insert values in the specified table.
- QueryString = "INSERT INTO `realmlist` VALUES ('1', '199.83.49.35', '5552', '2000', '0', 'jiva');";
- updateQuery = statement.executeUpdate(QueryString);
- if (updateQuery != 0) {
- System.out.println("Realmlist table is created successfully and " + updateQuery + " row is inserted. ");
- }
- QueryString = "ALTER TABLE `personnages` ADD COLUMN `server_id` INT(11) NOT NULL DEFAULT '1', ADD COLUMN `logged` INT(11) NOT NULL DEFAULT '0';";
- updateQuery = statement.executeUpdate(QueryString);
- System.out.println("COLUMN `server_id`,`logged` added to personnages tables");
- QueryString = "CREATE TABLE `accounts_data` (`guid` int(11) NOT NULL AUTO_INCREMENT,`bank` text NOT NULL,`bankkamas` bigint(32) NOT NULL,`stables` text NOT NULL,`friends` text NOT NULL,`enemys` text NOT NULL,`seeFriend` tinyint(3) NOT NULL DEFAULT '0',PRIMARY KEY (`guid`)) ENGINE=InnoDB AUTO_INCREMENT=160870 DEFAULT CHARSET=latin1;";
- updateQuery = statement.executeUpdate(QueryString);
- // sql query to retrieve values from the specified table.
- QueryString = "SELECT guid,bank,bankKamas,stable,friends,enemy from accounts";
- rs = statement.executeQuery(QueryString);
- Statement nstaement = connection.createStatement();
- Statement vstaement = connection.createStatement();
- int Row = 0;
- while (rs.next()) {
- //TODO Map of Guid,Pseudo accounts to don't lose time to query many time x)
- String Friends = "";
- String Ennemys ="";
- int guid;
- for(String a : rs.getString(5).split(";")){
- try{
- if(a.isEmpty()){
- continue;
- }
- guid = Integer.parseInt(a);
- rs2 = vstaement.executeQuery("select pseudo from accounts where guid ="+guid+";");
- if(rs2.first()){
- Friends += guid+"|"+rs2.getString(1).trim()+";";
- }
- else{
- continue;
- }
- }
- catch(Exception e){
- e.printStackTrace();
- continue;
- }
- }
- for(String a : rs.getString(6).split(";")){
- try{
- if(a.isEmpty()){
- continue;
- }
- guid = Integer.parseInt(a);
- rs2 = vstaement.executeQuery("select pseudo from accounts where guid ="+guid+";");
- if(rs2.first()){
- Ennemys += guid+"|"+rs2.getString(1).trim()+";";
- }
- else{
- continue;
- }
- }
- catch(Exception e){
- e.printStackTrace();
- continue;
- }
- }
- nstaement.executeUpdate("INSERT INTO `accounts_data` VALUES ('"+rs.getInt(1)+"', '"+rs.getString(2)+"', '"+rs.getLong(3)+"', '"+rs.getString(4)+"', '"+Friends+"', '"+Ennemys+"', '1');");
- Row++;
- //System.out.println(rs.getInt(1) + " " + rs.getString(2) + " " + rs.getLong(3) + " " + rs.getString(4) + " " + rs.getString(5) + " " + rs.getString(6) + " \n ");
- }
- System.out.println("AccountData table is created successfully and " + Row + " row is inserted. ");
- // close all the connections.
- if(rs2 != null)
- rs2.close();
- rs.close();
- nstaement.close();
- vstaement.close();
- statement.close();
- connection.close();
- } catch (Exception ex) {
- System.out.println("Unable to connect to batabase.");
- ex.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement