Skip to content

Commit

Permalink
Couple of changes to db_ settings support
Browse files Browse the repository at this point in the history
Also adds in deprecation warnings
  • Loading branch information
Pugmatt committed Aug 6, 2024
1 parent a8c7070 commit be8cfc3
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 26 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ The following is the full list of settings available:

| Setting | Description | Default Value |
|---------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|
| db_type | Database Type (accepts values *mysql*, *postgres*, *mariadb*, or *none*) | mysql |
| db_host | Database Host | localhost |
| db_db | Database Name | bedrock-connect |
| db_user | Database Username | root |
Expand All @@ -138,9 +139,6 @@ The following is the full list of settings available:
| port | Port of the server (Should only be changed for debugging on PC. Port needs to be on 19132 for the bypass to work on game consoles) | 19132 |
| bindip | IP that the BedrockConnect server will bind to | 0.0.0.0 |
| nodb | If true, use JSON files | true |
| mysql | If true, use Mysql | false |
| mairadb | If true, use MairaDB | false |
| postgres | If true, use Postgres | false |
| auto_reconnect | If true, Make Mysql and MairaDB auto reconnect to the database when disconnected | false |
| generatedns | If true, generate a DNS zone file using user input (Only needed if you're using the mod0Umleitung DNS software) | false |
| kick_inactive | If true, players will be kicked after 10 minutes of inactivity with the serverlist UI | true |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class BedrockConnect {

public static int globalPacketLimit = RakConstants.DEFAULT_GLOBAL_PACKET_LIMIT;

public static String release = "1.47";
public static String release = "1.48";

public static HashMap<String, String> featuredServerIps;

Expand All @@ -63,7 +63,7 @@ public static void main(String[] args) {
String password = "";
String port = "19132";
String bindIp = "0.0.0.0";
DatabaseTypes databaseType = DatabaseTypes.nosql;
DatabaseTypes databaseType = DatabaseTypes.mysql;
boolean autoReconnect = false;

String serverLimit = "100";
Expand Down Expand Up @@ -104,6 +104,9 @@ public static void main(String[] args) {
}
} catch(SecurityException e) {}

boolean nodbWarning = true;
boolean mysqlSettingWarning = false;

for (Map.Entry<String, String> setting : settings.entrySet()) {
switch(setting.getKey().toLowerCase()) {
case "db_host":
Expand All @@ -118,32 +121,56 @@ public static void main(String[] args) {
case "db_pass":
password = setting.getValue();
break;
case "db_type":
nodbWarning = false;
String dbType = setting.getValue().toLowerCase();
switch(dbType) {
case "none":
databaseType = DatabaseTypes.nosql;
break;
case "mysql":
databaseType = DatabaseTypes.mysql;
break;
case "mariadb":
databaseType = DatabaseTypes.mariadb;
break;
case "postgres":
databaseType = DatabaseTypes.postgres;
break;
}
break;
// Backwards-compatibility for legacy database/mysql settings
// db_ settings above should be used for any future setups/database-related changes
case "mysql_host":
mysqlSettingWarning = true;
hostname = setting.getValue();
break;
case "mysql_db":
mysqlSettingWarning = true;
database = setting.getValue();
break;
case "mysql_user":
mysqlSettingWarning = true;
username = setting.getValue();
break;
case "mysql_pass":
mysqlSettingWarning = true;
password = setting.getValue();
break;
//
case "server_limit":
serverLimit = setting.getValue();
break;
case "port":
port = setting.getValue();
break;
case "nodb":
//noDB = setting.getValue().equalsIgnoreCase("true");
if (setting.getValue().equalsIgnoreCase("true"))
{
nodbWarning = false;
databaseType = DatabaseTypes.nosql;
noDB = setting.getValue().equalsIgnoreCase("true");
noDB = true;
}

break;
case "mysql":
if (setting.getValue().equalsIgnoreCase("true"))
databaseType = DatabaseTypes.mysql;
break;
case "mairadb":
if (setting.getValue().equalsIgnoreCase("true"))
databaseType = DatabaseTypes.mairadb;
break;
case "postgres":
if (setting.getValue().equalsIgnoreCase("true"))
databaseType = DatabaseTypes.postgres;
break;
case "custom_servers":
customServers = setting.getValue();
Expand Down Expand Up @@ -241,10 +268,22 @@ public static void main(String[] args) {
}
}

if(!noDB)
System.out.println("Database Host: " + hostname + "\n" +
"Database: " + database + "\n" +
"Database User: " + username);

if(!noDB) {
if(nodbWarning || mysqlSettingWarning) {
System.out.println("----------------");
System.out.println("[!!DEPRECATION!!] Your current database settings may not work in future versions\n");
if(mysqlSettingWarning)
System.out.println("- mysql_* settings should be replaced with db_* settings");
if(nodbWarning)
System.out.println("- db_type should be manually set to mysql");
System.out.println("\nLearn more here: https://github.com/Pugmatt/BedrockConnect/wiki/Deprecated-Database-Settings");
System.out.println("----------------");
}
System.out.println("Database Host: " + hostname + "\n" +
"Database: " + database + "\n" +
"Database User: " + username);
}

System.out.println("\nServer Limit: " + serverLimit + "\n" + "Port: " + port + "\n");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
public enum DatabaseTypes {
nosql,
mysql,
mairadb,
mariadb,
postgres,
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Connection openConnection() {
Class.forName("com.mysql.cj.jdbc.Driver");
Driver = "jdbc:mysql://";
break;
case mairadb:
case mariadb:
Class.forName("org.mariadb.jdbc.Driver");
Driver = "jdbc:mariadb://";
break;
Expand Down

0 comments on commit be8cfc3

Please sign in to comment.