aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/extra/m_mysql.cpp
diff options
context:
space:
mode:
authorGravatar Sadie Powell2024-05-10 13:54:05 +0100
committerGravatar Sadie Powell2024-05-10 13:54:05 +0100
commit0af89e55d24f50b3dd08717358d97a79ee3d1b04 (patch)
tree3d70622180b88adebb9fcee5dd709f94ec3138ee /src/modules/extra/m_mysql.cpp
parentFix opmoderated messages appearing in the channel history. (diff)
Add SRV record support to the mysql module.
Diffstat (limited to 'src/modules/extra/m_mysql.cpp')
-rw-r--r--src/modules/extra/m_mysql.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp
index e840bd851..a8c13a4fd 100644
--- a/src/modules/extra/m_mysql.cpp
+++ b/src/modules/extra/m_mysql.cpp
@@ -334,8 +334,23 @@ public:
const std::string user = config->getString("user");
const std::string pass = config->getString("pass");
const std::string dbname = config->getString("name");
- unsigned int port = config->getNum<unsigned int>("port", 3306, 1, 65535);
- if (!mysql_real_connect(connection, host.c_str(), user.c_str(), pass.c_str(), dbname.c_str(), port, nullptr, CLIENT_IGNORE_SIGPIPE))
+
+ MYSQL* result;
+#if defined LIBMYSQL_VERSION_ID && LIBMYSQL_VERSION_ID > 80000
+ if (config->getBool("srv"))
+ {
+ result = mysql_real_connect_dns_srv(connection, host.c_str(), user.c_str(),
+ pass.c_str(), dbname.c_str(), CLIENT_IGNORE_SIGPIPE);
+ }
+ else
+#endif
+ {
+ auto port = config->getNum<unsigned int>("port", 3306, 1, 65535);
+ result = mysql_real_connect(connection, host.c_str(), user.c_str(), pass.c_str(),
+ dbname.c_str(), port, nullptr, CLIENT_IGNORE_SIGPIPE);
+ }
+
+ if (!result)
{
ServerInstance->Logs.Critical(MODNAME, "Unable to connect to the {} MySQL server: {}",
GetId(), mysql_error(connection));