Skip to content

Instantly share code, notes, and snippets.

@Mkalo
Last active April 23, 2024 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Mkalo/a3b419f092ab394d7d226308f066ae5e to your computer and use it in GitHub Desktop.
Save Mkalo/a3b419f092ab394d7d226308f066ae5e to your computer and use it in GitHub Desktop.
diff --git a/config.lua b/config.lua
index 927cc2be..a363a381 100644
--- a/config.lua
+++ b/config.lua
@@ -29,6 +29,9 @@ statusTimeout = 5000
replaceKickOnLogin = true
maxPacketsPerSecond = 25
+-- Proxy List
+proxyList = "1,158.69.12.0,7000,USA;2,0.0.0.0,7000,BRA"
+
-- Deaths
-- NOTE: Leave deathLosePercent as -1 if you want to use the default
-- death penalty formula. For the old formula, set it to 10. For
diff --git a/src/account.h b/src/account.h
index 7cddb245..109e40b5 100644
--- a/src/account.h
+++ b/src/account.h
@@ -30,6 +30,7 @@ struct Account {
uint32_t id = 0;
uint16_t premiumDays = 0;
AccountType_t accountType = ACCOUNT_TYPE_NORMAL;
+ uint16_t proxyId = 0;
Account() = default;
};
diff --git a/src/configmanager.cpp b/src/configmanager.cpp
index 10a699b1..54d7d6c7 100644
--- a/src/configmanager.cpp
+++ b/src/configmanager.cpp
@@ -115,6 +115,23 @@ bool ConfigManager::load()
integer[STATUS_PORT] = getGlobalNumber(L, "statusProtocolPort", 7171);
integer[MARKET_OFFER_DURATION] = getGlobalNumber(L, "marketOfferDuration", 30 * 24 * 60 * 60);
+
+ // Load proxy list
+ string[PROXY_LIST] = getGlobalString(L, "proxyList", "");
+ StringVector proxies = explodeString(string[PROXY_LIST], ";");
+ for (const std::string& proxyInfo : proxies) {
+ StringVector info = explodeString(proxyInfo, ",");
+ if (info.size() == 4) {
+ const std::string& ip = info[1];
+ const std::string& name = info[3];
+ uint16_t proxyId = std::stoi(info[0]);
+ uint16_t port = std::stoi(info[2]);
+ auto it = proxyList.emplace(std::piecewise_construct, std::forward_as_tuple(proxyId), std::forward_as_tuple(ip, port, name));
+ if (it.second) {
+ std::cout << "> Loaded proxy with id: " << proxyId << ", ip: " << ip << ", port: " << port << ", name: " << name << std::endl;
+ }
+ }
+ }
}
boolean[ALLOW_CHANGEOUTFIT] = getGlobalBoolean(L, "allowChangeOutfit", true);
@@ -210,3 +227,13 @@ bool ConfigManager::getBoolean(boolean_config_t what) const
}
return boolean[what];
}
+
+static ConfigManager::ProxyInfo dummyInfo;
+std::pair<bool, const ConfigManager::ProxyInfo&> ConfigManager::getProxyInfo(uint16_t proxyId) {
+ auto it = proxyList.find(proxyId);
+ if (it == proxyList.end()) {
+ return {false, dummyInfo};
+ }
+
+ return {true, it->second};
+}
diff --git a/src/configmanager.h b/src/configmanager.h
index 944c7688..46384b89 100644
--- a/src/configmanager.h
+++ b/src/configmanager.h
@@ -23,6 +23,15 @@
class ConfigManager
{
public:
+ struct ProxyInfo {
+ std::string ip;
+ uint16_t port;
+ std::string name;
+
+ ProxyInfo() : ip(""), port(0), name("") {}
+ ProxyInfo(const std::string& ip, uint16_t port, const std::string& name) : ip(ip), port(port), name(name) {}
+ };
+
enum boolean_config_t {
ALLOW_CHANGEOUTFIT,
ONE_PLAYER_ON_ACCOUNT,
@@ -62,6 +71,7 @@ class ConfigManager
MYSQL_SOCK,
DEFAULT_PRIORITY,
MAP_AUTHOR,
+ PROXY_LIST,
LAST_STRING_CONFIG /* this must be the last one */
};
@@ -108,11 +118,13 @@ class ConfigManager
const std::string& getString(string_config_t what) const;
int32_t getNumber(integer_config_t what) const;
bool getBoolean(boolean_config_t what) const;
+ std::pair<bool, const ConfigManager::ProxyInfo&> getProxyInfo(uint16_t proxyId);
private:
std::string string[LAST_STRING_CONFIG] = {};
int32_t integer[LAST_INTEGER_CONFIG] = {};
bool boolean[LAST_BOOLEAN_CONFIG] = {};
+ std::map<uint16_t, ProxyInfo> proxyList;
bool loaded = false;
};
diff --git a/src/iologindata.cpp b/src/iologindata.cpp
index 986279e9..614be38c 100644
--- a/src/iologindata.cpp
+++ b/src/iologindata.cpp
@@ -86,7 +86,7 @@ bool IOLoginData::loginserverAuthentication(const std::string& name, const std::
Database& db = Database::getInstance();
std::ostringstream query;
- query << "SELECT `id`, `name`, `password`, `secret`, `type`, `premdays`, `lastday` FROM `accounts` WHERE `name` = " << db.escapeString(name);
+ query << "SELECT `id`, `name`, `password`, `secret`, `type`, `premdays`, `lastday`, `proxy_id` FROM `accounts` WHERE `name` = " << db.escapeString(name);
DBResult_ptr result = db.storeQuery(query.str());
if (!result) {
return false;
@@ -102,6 +102,7 @@ bool IOLoginData::loginserverAuthentication(const std::string& name, const std::
account.accountType = static_cast<AccountType_t>(result->getNumber<int32_t>("type"));
account.premiumDays = result->getNumber<uint16_t>("premdays");
account.lastDay = result->getNumber<time_t>("lastday");
+ account.proxyId = result->getNumber<uint16_t>("proxy_id");
query.str(std::string());
query << "SELECT `name`, `deletion` FROM `players` WHERE `account_id` = " << account.id;
diff --git a/src/luascript.cpp b/src/luascript.cpp
index caa1fe20..f3311627 100644
--- a/src/luascript.cpp
+++ b/src/luascript.cpp
@@ -1788,6 +1788,7 @@ void LuaScriptInterface::registerFunctions()
registerEnumIn("configKeys", ConfigManager::MYSQL_SOCK)
registerEnumIn("configKeys", ConfigManager::DEFAULT_PRIORITY)
registerEnumIn("configKeys", ConfigManager::MAP_AUTHOR)
+ registerEnumIn("configKeys", ConfigManager::PROXY_LIST)
registerEnumIn("configKeys", ConfigManager::SQL_PORT)
registerEnumIn("configKeys", ConfigManager::MAX_PLAYERS)
diff --git a/src/protocollogin.cpp b/src/protocollogin.cpp
index dea501c7..58f63a8f 100644
--- a/src/protocollogin.cpp
+++ b/src/protocollogin.cpp
@@ -89,9 +89,18 @@ void ProtocolLogin::getCharacterList(const std::string& accountName, const std::
output->addByte(1); // number of worlds
output->addByte(0); // world id
- output->addString(g_config.getString(ConfigManager::SERVER_NAME));
- output->addString(g_config.getString(ConfigManager::IP));
- output->add<uint16_t>(g_config.getNumber(ConfigManager::GAME_PORT));
+ auto proxyInfo = g_config.getProxyInfo(account.proxyId);
+ if (proxyInfo.first) {
+ std::ostringstream ss;
+ ss << g_config.getString(ConfigManager::SERVER_NAME) << " - " << proxyInfo.second.name;
+ output->addString(ss.str());
+ output->addString(proxyInfo.second.ip);
+ output->add<uint16_t>(proxyInfo.second.port);
+ } else {
+ output->addString(g_config.getString(ConfigManager::SERVER_NAME));
+ output->addString(g_config.getString(ConfigManager::IP));
+ output->add<uint16_t>(g_config.getNumber(ConfigManager::GAME_PORT));
+ }
output->addByte(0);
uint8_t size = std::min<size_t>(std::numeric_limits<uint8_t>::max(), account.characters.size());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment