Commit 0ce780b8 authored by Neoony's avatar Neoony
Browse files

v0.5.2 -Lobby will no longer redirect to servers with different version than Lobby server

parent 6f707f24
Pipeline #14897 failed with stages
in 8 minutes and 49 seconds
......@@ -114,4 +114,7 @@
- Many small improvements
**v0.5.1**
- Fixed lobby going into backup redirect on vote start
\ No newline at end of file
- Fixed lobby going into backup redirect on vote start
**v0.5.2**
- Lobby will no longer redirect to servers with different version than Lobby server
\ No newline at end of file
......@@ -23,7 +23,7 @@
#include <cURL>
#include <SteamWorks>
#define PluginVer "v0.5.1"
#define PluginVer "v0.5.2"
public Plugin myinfo =
{
......@@ -125,6 +125,7 @@ char mapSQL[10][256];
int RSbots[10];
int appidSQL[10];
char versionSQL[10][256];
//XP
char XPaddrx[10][256];
......@@ -142,6 +143,7 @@ int botsintS[10];
char mapNameS[10][256];
int appIdS[10];
char versionS[10][256];
//Socket related
Handle socketx[10] = INVALID_HANDLE;
......@@ -181,6 +183,10 @@ enum struct ServerData {
ServerData serverData;
//Lobby Version
char lobby_version[256] = "-1";
char lobby_version_addr[64];
public void OnPluginStart()
{
//LoadTranslations("common.phrases");
......@@ -702,7 +708,7 @@ public void CheckPopulatedServersSinglePlayer(int Client)
if (GetClientCount(true) == 0 && PreferredServerActive == true)
{
char preferredServerQuerySP[1024];
Format(preferredServerQuerySP, sizeof(preferredServerQuerySP), "SELECT servers.addr FROM `LobbyDB`.`servers` LEFT JOIN `LobbyDB`.`appid` ON servers.addr = appid.addr WHERE servers.addr = '%s' AND appid.appid = '17740' AND servers.players >= %i AND servers.players != servers.maxplayers AND servers.password=0 AND servers.isenabled=1 AND servers.name NOT LIKE '%%LOBBY%%' AND servers.addr!='80.112.155.100:27015' AND servers.addr!='80.112.155.100:27017' ORDER BY servers.players DESC LIMIT 1;", PreferredServerAddr, GetConVarInt(l_preferredservermp));
Format(preferredServerQuerySP, sizeof(preferredServerQuerySP), "SELECT servers.addr FROM `LobbyDB`.`servers` LEFT JOIN `LobbyDB`.`appid` ON servers.addr = appid.addr LEFT JOIN `LobbyDB`.`version` ON servers.addr = version.addr WHERE servers.addr = '%s' AND appid.appid = '17740' AND version.version = '%s' AND servers.players >= %i AND servers.players != servers.maxplayers AND servers.password=0 AND servers.isenabled=1 servers.name NOT LIKE '%%LOBBY%%' AND servers.addr!='80.112.155.100:27015' AND servers.addr!='80.112.155.100:27017' ORDER BY servers.players DESC LIMIT 1;", PreferredServerAddr, lobby_version, GetConVarInt(l_preferredservermp));
SQL_TQuery(hDatabase, RedirectToPopulatedServerSinglePlayerCallback, preferredServerQuerySP, Client);
if (GetConVarInt(l_debug) == 1)
{
......@@ -713,7 +719,7 @@ public void CheckPopulatedServersSinglePlayer(int Client)
if (GetClientCount(true) == 0 && PreferredServerActive == false)
{
char populatedServerQuerySP[1024];
Format(populatedServerQuerySP, sizeof(populatedServerQuerySP), "SELECT servers.addr FROM `LobbyDB`.`servers` LEFT JOIN `LobbyDB`.`appid` ON servers.addr = appid.addr WHERE appid.appid = '17740' AND servers.players >= %i AND servers.players != servers.maxplayers AND servers.password=0 AND servers.isenabled=1 AND servers.name NOT LIKE '%%LOBBY%%' AND servers.addr!='80.112.155.100:27015' AND servers.addr!='80.112.155.100:27017' ORDER BY servers.players DESC LIMIT 1;", GetConVarInt(l_minplayersext));
Format(populatedServerQuerySP, sizeof(populatedServerQuerySP), "SELECT servers.addr FROM `LobbyDB`.`servers` LEFT JOIN `LobbyDB`.`appid` ON servers.addr = appid.addr LEFT JOIN `LobbyDB`.`version` ON servers.addr = version.addr WHERE appid.appid = '17740' AND version.version = '%s' AND servers.players >= %i AND servers.players != servers.maxplayers AND servers.password=0 AND servers.isenabled=1 AND servers.name NOT LIKE '%%LOBBY%%' AND servers.addr!='80.112.155.100:27015' AND servers.addr!='80.112.155.100:27017' ORDER BY servers.players DESC LIMIT 1;", lobby_version, GetConVarInt(l_minplayersext));
SQL_TQuery(hDatabase, RedirectToPopulatedServerSinglePlayerCallback, populatedServerQuerySP, Client);
if (GetConVarInt(l_debug) == 1)
{
......@@ -803,7 +809,7 @@ public void CheckPopulatedServers()
if (PreferredServerActive == true)
{
char preferredServerQuery[1024];
Format(preferredServerQuery, sizeof(preferredServerQuery), "SELECT servers.addr, servers.name FROM `LobbyDB`.`servers` LEFT JOIN `LobbyDB`.`appid` ON servers.addr = appid.addr WHERE servers.addr = '%s' AND appid.appid = '17740' AND servers.players >= %i AND servers.players <= servers.maxplayers - %i AND servers.password=0 AND servers.isenabled=1 AND servers.name NOT LIKE '%%LOBBY%%' AND servers.addr!='80.112.155.100:27015' AND servers.addr!='80.112.155.100:27017' ORDER BY servers.players DESC LIMIT 1;", PreferredServerAddr, GetConVarInt(l_preferredservermp), GetClientCount(false));
Format(preferredServerQuery, sizeof(preferredServerQuery), "SELECT servers.addr, servers.name FROM `LobbyDB`.`servers` LEFT JOIN `LobbyDB`.`appid` ON servers.addr = appid.addr LEFT JOIN `LobbyDB`.`version` ON servers.addr = version.addr WHERE servers.addr = '%s' AND appid.appid = '17740' AND version.version = '%s' AND servers.players >= %i AND servers.players <= servers.maxplayers - %i AND servers.password=0 AND servers.isenabled=1 AND servers.name NOT LIKE '%%LOBBY%%' AND servers.addr!='80.112.155.100:27015' AND servers.addr!='80.112.155.100:27017' ORDER BY servers.players DESC LIMIT 1;", PreferredServerAddr, lobby_version, GetConVarInt(l_preferredservermp), GetClientCount(false));
SQL_TQuery(hDatabase, RedirectToPopulatedServerCallback, preferredServerQuery);
if (GetConVarInt(l_debug) == 1)
{
......@@ -816,7 +822,7 @@ public void CheckPopulatedServers()
// Query for servers with more or equal than l_minplayers players.
char populatedServerQuery[1024];
//int minplayers = GetConVarInt(l_minplayers);
Format(populatedServerQuery, sizeof(populatedServerQuery), "SELECT servers.addr, servers.name FROM `LobbyDB`.`servers` LEFT JOIN `LobbyDB`.`appid` ON servers.addr = appid.addr WHERE appid.appid = '17740' AND servers.players >= %i AND servers.players <= servers.maxplayers - %i AND servers.password=0 AND servers.isenabled=1 AND servers.name NOT LIKE '%%LOBBY%%' AND servers.addr!='80.112.155.100:27015' AND servers.addr!='80.112.155.100:27017' ORDER BY servers.players DESC LIMIT 1;", GetConVarInt(l_minplayersext), GetClientCount(false));
Format(populatedServerQuery, sizeof(populatedServerQuery), "SELECT servers.addr, servers.name FROM `LobbyDB`.`servers` LEFT JOIN `LobbyDB`.`appid` ON servers.addr = appid.addr LEFT JOIN `LobbyDB`.`version` ON servers.addr = version.addr WHERE appid.appid = '17740' AND version.version = '%s' AND servers.players >= %i AND servers.players <= servers.maxplayers - %i AND servers.password=0 AND servers.isenabled=1 AND servers.name NOT LIKE '%%LOBBY%%' AND servers.addr!='80.112.155.100:27015' AND servers.addr!='80.112.155.100:27017' ORDER BY servers.players DESC LIMIT 1;", lobby_version, GetConVarInt(l_minplayersext), GetClientCount(false));
SQL_TQuery(hDatabase, RedirectToPopulatedServerCallback, populatedServerQuery);
if (GetConVarInt(l_debug) == 1)
{
......@@ -1290,6 +1296,13 @@ public void OnConfigsExecuted()
PrintToServer("%s", serverData.port);
}
//Server version related
Format(lobby_version_addr, sizeof(lobby_version_addr), "%s:%s", serverData.ip, serverData.port);
if (GetConVarInt(l_debug) == 1)
{
PrintToServer("%s", lobby_version_addr);
}
//Empires Backup Lobby disabled (by adding Vanilla at the end of hostname)
//I guess Vanilla should no longer happen
if (StrEqual(hostname, "Empires Backup Lobby Vanilla") == true)
......@@ -1397,7 +1410,7 @@ public Action QueryServersData()
if (hDatabase != null)
{
char GetInfoOfServer[1024];
Format(GetInfoOfServer, sizeof(GetInfoOfServer), "SELECT servers.name as name, servers.addr as addr, servers.players as players, servers.maxplayers as maxplayers, servers.map as map, xpdata.xp as xp FROM `LobbyDB`.`servers` LEFT JOIN `LobbyDB`.`xpdata` ON servers.addr = xpdata.addr LEFT JOIN `LobbyDB`.`appid` ON servers.addr = appid.addr WHERE appid.appid = '17740' AND servers.players <= servers.maxplayers - %i AND servers.password=0 AND servers.isenabled=1 AND servers.name NOT LIKE '%%LOBBY%%' AND servers.addr!='80.112.155.100:27015' AND servers.addr!='80.112.155.100:27017' AND servers.addr!='80.112.155.100:27016' ORDER BY RAND() LIMIT 10;", GetClientCount(false));
Format(GetInfoOfServer, sizeof(GetInfoOfServer), "SELECT servers.name as name, servers.addr as addr, servers.players as players, servers.maxplayers as maxplayers, servers.map as map, xpdata.xp as xp FROM `LobbyDB`.`servers` LEFT JOIN `LobbyDB`.`xpdata` ON servers.addr = xpdata.addr LEFT JOIN `LobbyDB`.`appid` ON servers.addr = appid.addr LEFT JOIN `LobbyDB`.`version` ON servers.addr = version.addr WHERE appid.appid = '17740' AND version.version = '%s' AND servers.players <= servers.maxplayers - %i AND servers.password=0 AND servers.isenabled=1 AND servers.name NOT LIKE '%%LOBBY%%' AND servers.addr!='80.112.155.100:27015' AND servers.addr!='80.112.155.100:27017' AND servers.addr!='80.112.155.100:27016' ORDER BY RAND() LIMIT 10;", lobby_version, GetClientCount(false));
//PrintToServer("%s", ServerIndexChar);
SQL_TQuery(hDatabase, InfoOfServer, GetInfoOfServer);
......@@ -2167,7 +2180,7 @@ public Action RefreshServersTmr(Handle timer)
{
char RSGetAllServersAddrEach[1024];
Format(RSGetAllServersAddrEach, sizeof(RSGetAllServersAddrEach), "SELECT servers.addr as addr, servers.players as players, servers.maxplayers, servers.map, servers.bots as bots, IFNULL(xpdata.xp,'-1') as xp, IFNULL(appid.appid,'-1') as appid FROM `LobbyDB`.`servers` LEFT JOIN `LobbyDB`.`xpdata` ON servers.addr = xpdata.addr LEFT JOIN `LobbyDB`.`appid` ON servers.addr = appid.addr WHERE servers.password=0 AND servers.isenabled=1 AND servers.addr!='80.112.155.100:27017' ORDER BY players DESC LIMIT 10;");
Format(RSGetAllServersAddrEach, sizeof(RSGetAllServersAddrEach), "SELECT servers.addr as addr, servers.players as players, servers.maxplayers, servers.map, servers.bots as bots, IFNULL(xpdata.xp,'-1') as xp, IFNULL(appid.appid,'-1') as appid, IFNULL(version.version,'-1') as version FROM `LobbyDB`.`servers` LEFT JOIN `LobbyDB`.`xpdata` ON servers.addr = xpdata.addr LEFT JOIN `LobbyDB`.`appid` ON servers.addr = appid.addr LEFT JOIN `LobbyDB`.`version` ON servers.addr = version.addr WHERE servers.password=0 AND servers.isenabled=1 AND servers.addr!='80.112.155.100:27017' ORDER BY players DESC LIMIT 10;");
//PrintToServer("%s", ServerIndexChar);
SQL_TQuery(hDatabase, RSInfoOfServer, RSGetAllServersAddrEach);
}
......@@ -2225,6 +2238,7 @@ public void RSInfoOfServer(Handle RShDriver, Handle RShResult, const char[] sErr
RSbots[rowNumber] = SQL_FetchInt(RShResult, 4);
RSXPsqlon[rowNumber] = SQL_FetchInt(RShResult, 5);
appidSQL[rowNumber] = SQL_FetchInt(RShResult, 6);
SQL_FetchString(RShResult, 7, versionSQL[rowNumber], 256);
if (GetConVarInt(l_debug) == 2)
{
......@@ -2235,6 +2249,7 @@ public void RSInfoOfServer(Handle RShDriver, Handle RShResult, const char[] sErr
PrintToServer("RSbots[%i]: %i", rowNumber, RSbots[rowNumber]);
PrintToServer("RSXPsqlon[%i]: %i", rowNumber, RSXPsqlon[rowNumber]);
PrintToServer("appidSQL[%i]: %i", rowNumber, appidSQL[rowNumber]);
PrintToServer("versionSQL[%i]: %s", rowNumber, versionSQL[rowNumber]);
}
if (XPcheckcounter[rowNumber] == 0)
......@@ -2268,6 +2283,12 @@ public void RSInfoOfServer(Handle RShDriver, Handle RShResult, const char[] sErr
}
XPcheckcounter[rowNumber] = 1;
}
//Get version of lobby
if (StrEqual(RSaddrx[rowNumber], lobby_version_addr))
{
Format(lobby_version, sizeof(lobby_version), versionSQL[rowNumber]);
}
//Vanilla server IP replacement, as it is a local server
//Vanilla IP:
......@@ -2310,6 +2331,12 @@ public void RSInfoOfServer(Handle RShDriver, Handle RShResult, const char[] sErr
RefreshServerInfo(rowNumber);
rowNumber++;
}
//Print version of lobby
if (GetConVarInt(l_debug) == 1)
{
PrintToServer("[L]lobby_version: %s", lobby_version);
}
// Use SQL_FetchRow(RShResult) to fetch a row
// and then SQL_FetchInt(RShResult, 0) to get the first column in the fetched row of the result
......@@ -2455,7 +2482,7 @@ public OnSocketReceive(Handle socket, char[] receiveData, const int dataSize, in
int type;
char os[160];
char version[160];
char version[256];
int UE4appID;
......@@ -2556,6 +2583,7 @@ public OnSocketReceive(Handle socket, char[] receiveData, const int dataSize, in
maxPlayersS[ServerIndexx] = StringToInt(maxPlayers);
botsintS[ServerIndexx] = StringToInt(bots);
mapNameS[ServerIndexx] = mapName;
versionS[ServerIndexx] = version;
//Appid detection
if (appID == 17740 && StrEqual(gameDir, "empires"))
......@@ -2595,14 +2623,14 @@ public OnSocketReceive(Handle socket, char[] receiveData, const int dataSize, in
//XPCheckURL(ServerIndexx);
if (curPlayersSQL[ServerIndexx] != numPlayersS[ServerIndexx] || maxPlayersSQL[ServerIndexx] != maxPlayersS[ServerIndexx] || RSbots[ServerIndexx] != botsintS[ServerIndexx] || !StrEqual(mapSQL[ServerIndexx], mapNameS[ServerIndexx]) || appidSQL[ServerIndexx] != appIdS[ServerIndexx])
if (curPlayersSQL[ServerIndexx] != numPlayersS[ServerIndexx] || maxPlayersSQL[ServerIndexx] != maxPlayersS[ServerIndexx] || RSbots[ServerIndexx] != botsintS[ServerIndexx] || !StrEqual(mapSQL[ServerIndexx], mapNameS[ServerIndexx]) || appidSQL[ServerIndexx] != appIdS[ServerIndexx] || !StrEqual(versionSQL[ServerIndexx], versionS[ServerIndexx]))
{
UpdateSQL(ServerIndexx);
if (GetConVarInt(l_debug) == 1)
{
PrintToServer("[L] SQL Update!!");
PrintToServer("[L] %i != %i || %i != %i || %i != %i || %s != %s || %i != %i", curPlayersSQL[ServerIndexx], numPlayersS[ServerIndexx], maxPlayersSQL[ServerIndexx], maxPlayersS[ServerIndexx], RSbots[ServerIndexx], botsintS[ServerIndexx], mapSQL[ServerIndexx], mapNameS[ServerIndexx], appidSQL[ServerIndexx], appIdS[ServerIndexx]);
PrintToServer("[L] %i != %i || %i != %i || %i != %i || %s != %s || %i != %i || %s != %s", curPlayersSQL[ServerIndexx], numPlayersS[ServerIndexx], maxPlayersSQL[ServerIndexx], maxPlayersS[ServerIndexx], RSbots[ServerIndexx], botsintS[ServerIndexx], mapSQL[ServerIndexx], mapNameS[ServerIndexx], appidSQL[ServerIndexx], appIdS[ServerIndexx], versionSQL[ServerIndexx], versionS[ServerIndexx]);
}
}
......@@ -2706,12 +2734,22 @@ public Action UpdateSQL(int ServerIndexx)
Format(UpdateServer, sizeof(UpdateServer), "UPDATE `LobbyDB`.`servers` SET players = '%i', maxplayers = '%i', bots = '%i', map = '%s' WHERE addr = '%s';", numPlayersS[ServerIndexx], maxPlayersS[ServerIndexx], botsintS[ServerIndexx], mapNameS[ServerIndexx], RSaddrx[ServerIndexx]);
SQL_TQuery(hDatabase, UpdateServer_Handle, UpdateServer, ServerIndexx);
//Update appid
if (appidSQL[ServerIndexx] != appIdS[ServerIndexx])
{
char UpdateServerAppID[512];
Format(UpdateServerAppID, sizeof(UpdateServerAppID), "INSERT INTO `LobbyDB`.`appid` (`addr`, `appid`) VALUES ('%s', '%i') ON DUPLICATE KEY UPDATE addr = '%s', appid = '%i';", RSaddrx[ServerIndexx], appIdS[ServerIndexx], RSaddrx[ServerIndexx], appIdS[ServerIndexx]);
SQL_TQuery(hDatabase, UpdateServer_Handle, UpdateServerAppID, ServerIndexx);
}
//Update version
if (!StrEqual(versionSQL[ServerIndexx], versionS[ServerIndexx]))
{
char UpdateServerVersion[512];
Format(UpdateServerVersion, sizeof(UpdateServerVersion), "INSERT INTO `LobbyDB`.`version` (`addr`, `version`) VALUES ('%s', '%s') ON DUPLICATE KEY UPDATE addr = '%s', version = '%s';", RSaddrx[ServerIndexx], versionS[ServerIndexx], RSaddrx[ServerIndexx], versionS[ServerIndexx]);
SQL_TQuery(hDatabase, UpdateServer_Handle, UpdateServerVersion, ServerIndexx);
}
}
if (hDatabase == null && GetConVarInt(l_debug) == 1)
{
......
......@@ -4,10 +4,10 @@
{
"Version"
{
"Latest" "v0.5.1"
"Latest" "v0.5.2"
}
"Notes" "Fixed lobby going into backup redirect on vote start"
"Notes" "Lobby will no longer redirect to servers with different version than Lobby server"
}
"Files"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment