Skip to content

Commit 551f0ae

Browse files
authored
Restore MySQL Connection Settings (#118)
* Restore MySQL connection settings - Restore original connection strings for MySQL database - Removed silly MySQL connection string method in "configuration.json" that was added in by another user that should have never been changed. - Reset Character and Mangos (World) Revision to default of Rel1.0.0. Note: This will temp as I rebuild the Character and World Database for Mangos C#. Realm Revision will remain the same at Rel21.2.1. * Use the mangosSharp term instead of VB.
1 parent 62e77e5 commit 551f0ae

8 files changed

Lines changed: 88 additions & 59 deletions

File tree

src/server/Mangos.Common/Globals/MangosGlobalConstants.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public MangosGlobalConstants()
3636
public readonly int RevisionDbCharactersStructure;
3737
public readonly int RevisionDbCharactersContent;
3838

39-
public readonly int RevisionDbMangosVersion = 21;
40-
public readonly int RevisionDbMangosStructure = 7;
41-
public readonly int RevisionDbMangosContent = 77;
39+
public readonly int RevisionDbMangosVersion = 1;
40+
public readonly int RevisionDbMangosStructure;
41+
public readonly int RevisionDbMangosContent;
4242

4343
public readonly int RevisionDbRealmVersion = 21;
4444
public readonly int RevisionDbRealmStructure = 2;

src/server/Mangos.Configuration/ConfigurationLoader.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,13 @@ private static string ReadConfiguration(string path)
6262

6363
private static void ApplyEnvironmentOverrides(JsonNode root)
6464
{
65-
OverrideString(root, "AccountDataBaseConnectionString", $"{EnvironmentVariablePrefix}ACCOUNT_DB");
65+
OverrideString(root, "Realm", "AccountDatabase", $"{EnvironmentVariablePrefix}ACCOUNT_DB");
6666
OverrideString(root, "Realm", "RealmServerEndpoint", $"{EnvironmentVariablePrefix}REALM_ENDPOINT");
6767
OverrideString(root, "Cluster", "ClusterServerEndpoint", $"{EnvironmentVariablePrefix}CLUSTER_ENDPOINT");
6868
OverrideString(root, "Cluster", "ClusterListenAddress", $"{EnvironmentVariablePrefix}CLUSTER_LISTEN_ADDRESS");
6969
OverrideString(root, "World", "ClusterConnectHost", $"{EnvironmentVariablePrefix}WORLD_CLUSTER_HOST");
7070
}
7171

72-
private static void OverrideString(JsonNode root, string key, string envVar)
73-
{
74-
var value = Environment.GetEnvironmentVariable(envVar);
75-
if (value != null)
76-
{
77-
root[key] = value;
78-
}
79-
}
80-
8172
private static void OverrideString(JsonNode root, string section, string key, string envVar)
8273
{
8374
var value = Environment.GetEnvironmentVariable(envVar);
@@ -91,29 +82,45 @@ private static void Validate(MangosConfiguration config)
9182
{
9283
var errors = new List<string>();
9384

94-
if (string.IsNullOrWhiteSpace(config.AccountDataBaseConnectionString))
95-
errors.Add("AccountDataBaseConnectionString is required");
85+
if (string.IsNullOrWhiteSpace(config.Realm.AccountDatabase))
86+
{
87+
errors.Add("Realm.AccountDatabase is required");
88+
}
9689

9790
if (string.IsNullOrWhiteSpace(config.Realm.RealmServerEndpoint))
91+
{
9892
errors.Add("Realm.RealmServerEndpoint is required");
93+
}
9994

10095
if (string.IsNullOrWhiteSpace(config.Cluster.ClusterServerEndpoint))
96+
{
10197
errors.Add("Cluster.ClusterServerEndpoint is required");
98+
}
10299

103100
if (config.Cluster.ClusterListenPort <= 0 || config.Cluster.ClusterListenPort > 65535)
101+
{
104102
errors.Add($"Cluster.ClusterListenPort must be between 1 and 65535, got {config.Cluster.ClusterListenPort}");
103+
}
105104

106105
if (config.Cluster.ServerPlayerLimit < 0)
106+
{
107107
errors.Add("Cluster.ServerPlayerLimit cannot be negative");
108+
}
108109

109110
if (config.World.ClusterConnectPort <= 0 || config.World.ClusterConnectPort > 65535)
111+
{
110112
errors.Add($"World.ClusterConnectPort must be between 1 and 65535, got {config.World.ClusterConnectPort}");
113+
}
111114

112115
if (config.World.XPRate < 0)
116+
{
113117
errors.Add("World.XPRate cannot be negative");
118+
}
114119

115120
if (config.World.MapResolution < 64 || config.World.MapResolution > 256)
121+
{
116122
errors.Add($"World.MapResolution must be between 64 and 256, got {config.World.MapResolution}");
123+
}
117124

118125
if (errors.Count > 0)
119126
{

src/server/Mangos.Configuration/MangosConfiguration.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ namespace Mangos.Configuration;
2020

2121
public sealed class MangosConfiguration
2222
{
23-
public required string AccountDataBaseConnectionString { get; init; }
24-
public string? CharacterDataBaseConnectionString { get; init; }
25-
public string? WorldDataBaseConnectionStrings { get; init; }
26-
2723
public required RealmConfiguration Realm
2824
{
2925
get; init;

src/server/Mangos.Configuration/RealmConfiguration.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@ public required string RealmServerEndpoint
2424
{
2525
get; init;
2626
}
27+
28+
public required string AccountDatabase
29+
{
30+
get; init;
31+
}
2732
}

src/server/Mangos.Configuration/configuration.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
{
2-
"AccountDataBaseConnectionString": "Server=localhost;Port=3306;User ID=root;Password=rootpass;Database=mangosVBaccounts;Compress=false;Connection Timeout=5;",
32
"Realm": {
4-
"RealmServerEndpoint": "127.0.0.1:3724"
3+
"RealmServerEndpoint": "127.0.0.1:3724",
4+
"AccountDatabase": "root;rootpass;localhost;3306;mangosSharpaccounts;MariaDB"
55
},
66
"Cluster": {
77
"ClusterServerEndpoint": "127.0.0.1:8085",
88
"ClusterListenAddress": "127.0.0.1",
99
"ClusterListenPort": 50001,
1010
"ServerPlayerLimit": 100,
11-
"AccountDatabase": "root;rootpass;localhost;3306;mangosVBaccounts;MariaDB",
12-
"CharacterDatabase": "root;rootpass;localhost;3306;mangosVBcharacters;MariaDB",
13-
"WorldDatabase": "root;rootpass;localhost;3306;mangosVBworld;MariaDB"
11+
"AccountDatabase": "root;rootpass;localhost;3306;mangosSharpaccounts;MariaDB",
12+
"CharacterDatabase": "root;rootpass;localhost;3306;mangosSharpcharacters;MariaDB",
13+
"WorldDatabase": "root;rootpass;localhost;3306;mangosSharpworld;MariaDB"
1414
},
1515
"World": {
1616
"ClusterConnectHost": "127.0.0.1",
1717
"ClusterConnectPort": 50001,
1818
"LocalConnectHost": "127.0.0.1",
1919
"LocalConnectPort": 50002,
20-
"AccountDatabase": "root;rootpass;localhost;3306;mangosVBaccounts;MariaDB",
21-
"CharacterDatabase": "root;rootpass;localhost;3306;mangosVBcharacters;MariaDB",
22-
"WorldDatabase": "root;rootpass;localhost;3306;mangosVBworld;MariaDB",
20+
"AccountDatabase": "root;rootpass;localhost;3306;mangosSharpaccounts;MariaDB",
21+
"CharacterDatabase": "root;rootpass;localhost;3306;mangosSharpcharacters;MariaDB",
22+
"WorldDatabase": "root;rootpass;localhost;3306;mangosSharpworld;MariaDB",
2323
"Maps": [ 1, 0 ],
2424
"ScriptsCompiler": [
2525
"System.dll",

src/server/Mangos.MySql/ConnectionFactory.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public ConnectionFactory(MangosConfiguration mangosConfiguration, IMangosLogger
3636

3737
public AccountConnection ConnectToAccountDataBase()
3838
{
39-
var connectionString = mangosConfiguration.AccountDataBaseConnectionString;
39+
var connectionString = BuildConnectionString(mangosConfiguration.Realm.AccountDatabase, "Account");
4040
if (string.IsNullOrWhiteSpace(connectionString))
4141
{
4242
throw new InvalidOperationException("Account database connection string is not configured");
@@ -68,7 +68,7 @@ public AccountConnection ConnectToAccountDataBase()
6868

6969
public CharacterConnection ConnectToCharacterDataBase()
7070
{
71-
var connectionString = mangosConfiguration.CharacterDataBaseConnectionString;
71+
var connectionString = BuildConnectionString(mangosConfiguration.Cluster.CharacterDatabase, "Character");
7272
if (string.IsNullOrWhiteSpace(connectionString))
7373
{
7474
throw new InvalidOperationException("Character database connection string is not configured");
@@ -100,7 +100,7 @@ public CharacterConnection ConnectToCharacterDataBase()
100100

101101
public WorldConnection ConnectToWorldDataBase()
102102
{
103-
var connectionString = mangosConfiguration.WorldDataBaseConnectionStrings;
103+
var connectionString = BuildConnectionString(mangosConfiguration.Cluster.WorldDatabase, "World");
104104
if (string.IsNullOrWhiteSpace(connectionString))
105105
{
106106
throw new InvalidOperationException("World database connection string is not configured");
@@ -130,6 +130,25 @@ public WorldConnection ConnectToWorldDataBase()
130130
}
131131
}
132132

133+
private string BuildConnectionString(string databaseConfig, string databaseName)
134+
{
135+
// Format: user;pass;host;port;db;type
136+
var parts = databaseConfig.Split(';');
137+
if (parts.Length < 5)
138+
{
139+
logger.Error($"Invalid {databaseName} database configuration format. Expected: user;pass;host;port;db;type");
140+
return string.Empty;
141+
}
142+
143+
var user = parts[0];
144+
var pass = parts[1];
145+
var host = parts[2];
146+
var port = parts[3];
147+
var db = parts[4];
148+
149+
return $"Server={host};Port={port};User ID={user};Password={pass};Database={db};Compress=false;Connection Timeout=5;";
150+
}
151+
133152
private bool TestConnection(MySqlConnection connection)
134153
{
135154
try

src/server/Mangos.MySql/DbVersionChecker.cs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -144,57 +144,57 @@ private bool ValidateVersion(string dbName, DbVersionInfo actual, DbVersionInfo
144144
// Perfect match
145145
if (actual.Version == expected.Version && actual.Structure == expected.Structure && actual.Content == expected.Content)
146146
{
147-
_logger.Database($"Database version matched for '{dbName}'");
147+
_logger?.Database($"Database version matched for '{dbName}'");
148148
return true;
149149
}
150150

151151
// Content mismatch but compatible (warning level)
152152
if (actual.Version == expected.Version && actual.Structure == expected.Structure && actual.Content != expected.Content)
153153
{
154-
_logger.Warning("--------------------------------------------------------------");
155-
_logger.Warning("-- WARNING: CONTENT VERSION MISMATCH --");
156-
_logger.Warning("--------------------------------------------------------------");
157-
_logger.Warning($"Your database '{dbName}' requires updating.");
158-
_logger.Warning($"You have: Rev{actual.Version}.{actual.Structure}.{actual.Content}, " +
154+
_logger?.Warning("--------------------------------------------------------------");
155+
_logger?.Warning("-- WARNING: CONTENT VERSION MISMATCH --");
156+
_logger?.Warning("--------------------------------------------------------------");
157+
_logger?.Warning($"Your database '{dbName}' requires updating.");
158+
_logger?.Warning($"You have: Rev{actual.Version}.{actual.Structure}.{actual.Content}, " +
159159
$"however the core expects Rev{expected.Version}.{expected.Structure}.{expected.Content}");
160-
_logger.Warning("The server will run, but you may be missing some database fixes");
160+
_logger?.Warning("The server will run, but you may be missing some database fixes");
161161
return true;
162162
}
163163

164164
// Version or structure mismatch (fatal)
165-
_logger.Critical("--------------------------------------------------------------");
166-
_logger.Critical("-- CRITICAL ERROR: DATABASE VERSION MISMATCH --");
167-
_logger.Critical("--------------------------------------------------------------");
168-
_logger.Critical($"Your database '{dbName}' requires updating.");
169-
_logger.Critical($"You have: Rev{actual.Version}.{actual.Structure}.{actual.Content}, " +
165+
_logger?.Critical("--------------------------------------------------------------");
166+
_logger?.Critical("-- CRITICAL ERROR: DATABASE VERSION MISMATCH --");
167+
_logger?.Critical("--------------------------------------------------------------");
168+
_logger?.Critical($"Your database '{dbName}' requires updating.");
169+
_logger?.Critical($"You have: Rev{actual.Version}.{actual.Structure}.{actual.Content}, " +
170170
$"but the core requires Rev{expected.Version}.{expected.Structure}.{expected.Content}");
171-
_logger.Critical("The server is unable to run until the required updates are applied.");
172-
_logger.Critical("--------------------------------------------------------------");
173-
_logger.Critical($"Please apply all updates after Rev{expected.Version}.{expected.Structure}.{expected.Content}");
174-
_logger.Critical("These updates are located in the sql/updates folder.");
175-
_logger.Critical("--------------------------------------------------------------");
171+
_logger?.Critical("The server is unable to run until the required updates are applied.");
172+
_logger?.Critical("--------------------------------------------------------------");
173+
_logger?.Critical($"Please apply all updates after Rev{expected.Version}.{expected.Structure}.{expected.Content}");
174+
_logger?.Critical("These updates are located in the sql/updates folder.");
175+
_logger?.Critical("--------------------------------------------------------------");
176176
return false;
177177
}
178178

179179
// Logs when the database version check fails.
180180
private void LogDatabaseCheckFailure(string dbName, string reason)
181181
{
182-
_logger.Failed("--------------------------------------------------------------");
183-
_logger.Failed("-- DATABASE VERSION CHECK FAILURE --");
184-
_logger.Failed("--------------------------------------------------------------");
185-
_logger.Failed($"Failed to check version for database '{dbName}': {reason}");
186-
_logger.Failed("--------------------------------------------------------------");
182+
_logger?.Failed("--------------------------------------------------------------");
183+
_logger?.Failed("-- DATABASE VERSION CHECK FAILURE --");
184+
_logger?.Failed("--------------------------------------------------------------");
185+
_logger?.Failed($"Failed to check version for database '{dbName}': {reason}");
186+
_logger?.Failed("--------------------------------------------------------------");
187187
}
188188

189189
// Logs when the db_version table is missing.
190190
private void LogMissingVersionTable(string dbName, DbVersionInfo expected)
191191
{
192-
_logger.Alert("--------------------------------------------------------------");
193-
_logger.Alert("-- MISSING VERSION TABLE --");
194-
_logger.Alert("--------------------------------------------------------------");
195-
_logger.Alert($"The table 'db_version' is missing in database '{dbName}'");
196-
_logger.Alert("This database is likely not properly set up or is too old.");
197-
_logger.Alert($"The core requires database schema Rev{expected.Version}.{expected.Structure}.{expected.Content}");
198-
_logger.Alert("--------------------------------------------------------------");
192+
_logger?.Alert("--------------------------------------------------------------");
193+
_logger?.Alert("-- MISSING VERSION TABLE --");
194+
_logger?.Alert("--------------------------------------------------------------");
195+
_logger?.Alert($"The table 'db_version' is missing in database '{dbName}'");
196+
_logger?.Alert("This database is likely not properly set up or is too old.");
197+
_logger?.Alert($"The core requires database schema Rev{expected.Version}.{expected.Structure}.{expected.Content}");
198+
_logger?.Alert("--------------------------------------------------------------");
199199
}
200200
}

src/server/Mangos.MySql/MySqlModule.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ protected override void Load(ContainerBuilder builder)
3030
{
3131
builder.RegisterType<ConnectionFactory>().SingleInstance();
3232
builder.Register(context => context.Resolve<ConnectionFactory>().ConnectToAccountDataBase()).SingleInstance();
33+
builder.Register(context => context.Resolve<ConnectionFactory>().ConnectToCharacterDataBase()).SingleInstance();
34+
builder.Register(context => context.Resolve<ConnectionFactory>().ConnectToWorldDataBase()).SingleInstance();
3335

3436
RegisterQueries(builder);
3537
}

0 commit comments

Comments
 (0)