Converted some of the management server to kotlin

Added json configs for management server
Cleaned up some files
This commit is contained in:
Woah 2021-03-08 03:55:45 -05:00
parent ca2e5520b0
commit 439b2e9ef8
114 changed files with 820 additions and 1476 deletions

View file

@ -1,100 +0,0 @@
package ms.system.mysql;
import ms.ServerConstants;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
* Manages the sql connections.
* @author Vexia
*
*/
public final class SQLManager {
/**
* If the sql manager is locally hosted.
*/
public static final boolean LOCAL = true;
/**
* The database URL.
*/
public static final String DATABASE_URL = (LOCAL ? "127.0.0.1" : "keldagrim.org") + ":3306/" + (SQLManager.LOCAL ? "global" : ServerConstants.DATABASE_NAMES[1]);
/**
* The username of the user.
*/
private static final String USERNAME = (LOCAL ? "root" : "keldagr1_user");
/**
* The password of the user.
*/
private static final String PASSWORD = (LOCAL ? "" : "2jf4wkz$");
/**
* IF the sql manager is initialized.
*/
private static boolean initialized;
/**
* Constructs a new {@code SQLManager} {@code Object}
*/
public SQLManager() {
/**
* empty.
*/
}
/**
* Initializes the sql manager.
*/
public static void init() {
initialized = true;
WorldListSQLHandler.clearWorldList();
}
/**
* Gets a connection from the pool.
* @return The connection.
*/
public static Connection getConnection() {
try {
return DriverManager.getConnection("jdbc:mysql://" + DATABASE_URL + "?useTimezone=true&serverTimezone=UTC", USERNAME, PASSWORD);
} catch (SQLException e) {
System.out.println("Error: Mysql error message=" + e.getMessage() + ".");
}
return null;
}
/**
* Releases the connection so it's available for usage.
* @param connection The connection.
*/
public static void close(Connection connection) {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* Gets the initialized.
* @return the initialized
*/
public static boolean isInitialized() {
return initialized;
}
/**
* Sets the bainitialized.
* @param initialized the initialized to set.
*/
public static void setInitialized(boolean initialized) {
SQLManager.initialized = initialized;
}
}

View file

@ -0,0 +1,64 @@
package ms.system.mysql
import ms.system.util.ManagementConstants
import ms.system.util.ManagementConstants.Companion.DATABASE_HOST_ADDRESS
import ms.system.util.ManagementConstants.Companion.DATABASE_NAME
import ms.system.util.ManagementConstants.Companion.DATABASE_PASSWORD
import ms.system.util.ManagementConstants.Companion.DATABASE_PORT
import ms.system.util.ManagementConstants.Companion.DATABASE_USERNAME
import java.sql.Connection
import java.sql.DriverManager
import java.sql.SQLException
/**
* Manages the sql connections.
* @author Vexia
*/
object SQLManager {
/**
* IF the sql manager is initialized.
*/
var isInitialized = false
/**
* Initializes the sql manager.
*/
@JvmStatic
fun init() {
isInitialized = true
WorldListSQLHandler.clearWorldList()
}
/**
* Gets a connection from the pool.
* @return The connection.
*/
@JvmStatic
val connection: Connection?
get() {
try {
return DriverManager.getConnection(
"jdbc:mysql://$DATABASE_HOST_ADDRESS:$DATABASE_PORT/$DATABASE_NAME?useTimezone=true&serverTimezone=UTC",
DATABASE_USERNAME,
DATABASE_PASSWORD
)
} catch (e: SQLException) {
println("Error: Mysql error message=" + e.message + ".")
}
return null
}
/**
* Releases the connection so it's available for usage.
* @param connection The connection.
*/
@JvmStatic
fun close(connection: Connection) {
try {
connection.close()
} catch (e: SQLException) {
e.printStackTrace()
}
}
}