diff options
| author | 2024-05-10 13:54:05 +0100 | |
|---|---|---|
| committer | 2024-05-10 13:54:05 +0100 | |
| commit | 0af89e55d24f50b3dd08717358d97a79ee3d1b04 (patch) | |
| tree | 3d70622180b88adebb9fcee5dd709f94ec3138ee /src/modules/extra/m_mysql.cpp | |
| parent | Fix 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.cpp | 19 |
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)); |
