Commit 6382061a authored by Neoony's avatar Neoony
Browse files

v0.1 WIP3

Added auto redirect when some of the candidate servers meet l_minplayers
parent bacbc4f3
Pipeline #3539 passed with stages
in 1 minute and 49 seconds
......@@ -20,7 +20,7 @@
#include <sdkhooks>
//#include <emputils>
#define PluginVer "v0.1 WIP2"
#define PluginVer "v0.1 WIP3"
public Plugin myinfo =
{
......@@ -54,6 +54,7 @@ int rowCount;
Handle PlayerCountCheck;
Handle StartVoteTimer;
Handle ConnectDialogTimer;
Handle ConnectDialogToFullTimer;
Handle RestrictVote;
Handle VoteHandle = INVALID_HANDLE;
Handle Timer1 = INVALID_HANDLE;
......@@ -132,6 +133,45 @@ public void OnClientPutInServer(int Client)
}
PrintToChat(Client, "\x04[L] \x01This server is running\x04 [Lobby]\x01 %s by\x07ff6600 Neoony", PluginVer);
Timer1 = CreateTimer(5.0, Tmr1, Client, TIMER_REPEAT);
RedirectToPopulatedServer();
}
public void RedirectToPopulatedServer()
{
// Query for servers with more or equal than l_minplayers players.
char populatedServerQuery[256];
int minplayers = GetConVarInt(l_minplayers);
Format(populatedServerQuery, sizeof(populatedServerQuery), "SELECT addr FROM `LobbyDB`.`servers` WHERE players >= %i AND password=0 AND isenabled=1 AND name NOT LIKE '%%LOBBY%%' ORDER BY players DESC LIMIT 1;", minplayers);
SQL_TQuery(hDatabase, RedirectToPopulatedServerCallback, populatedServerQuery);
}
public void RedirectToPopulatedServerCallback(Handle hDriver, Handle hResult, const char[] sError, int iData)
{
if (hResult == INVALID_HANDLE) {
// The result is invalid -> an error occured
LogError("[Database] SQL-Query failed! Error: %s", sError);
return;
}
int fullServerCount = SQL_GetRowCount(hResult);
if (fullServerCount == 0)
return; // No full server found.
char redirectAddress[128];
SQL_FetchRow(hResult);
SQL_FetchString(hResult, 0, redirectAddress, sizeof(redirectAddress));
// Found populated server, redirect everyone
for (int client = 1; client <= MaxClients; client++) {
if (!IsClientInGame(client))
continue;
//PrintToChatAll("Redirecting full server");
//PrintToServer("Redirecting full server");
//ClientCommand(client, "lobby_redirect %s", redirectAddress);
RestrictVote = CreateTimer(GetConVarFloat(l_restrictvote), RestrictVt, _, TIMER_REPEAT);
ConnectDialogToFullTimer = CreateTimer(5.0, ConnectDialogToFullTmr, redirectAddress[127], TIMER_REPEAT);
PrintToChatAll("\x04[L] \x01Server with enough players has been\x07008000 chosen\x01, players will be redirected in\x073399ff 5\x01 seconds");
//PrintToChatAll("Redirecting full server %s", redirectAddress);
}
}
public Action Tmr1(Handle timer, int Client)
......@@ -511,6 +551,28 @@ public Action VoteSuccessful(int param1)
RestrictVote = CreateTimer(GetConVarFloat(l_restrictvote), RestrictVt, _, TIMER_REPEAT);
}
public Action StartConnectDialogToFull(char redirectAddress)
{
for (int client = 1; client <= MaxClients; client++)
if (IsClientInGame(client))
{
ClientCommand(client, "lobby_redirect %s", redirectAddress);
}
}
public Action ConnectDialogToFullTmr(Handle timer, char redirectAddress)
{
//int value1 = 1;
StartConnectDialogToFull(redirectAddress);
//Clear timer
if (ConnectDialogToFullTimer != INVALID_HANDLE)
{
KillTimer(ConnectDialogToFullTimer);
ConnectDialogToFullTimer = INVALID_HANDLE;
}
PrintToChatAll("\x04[L] \x01Redirecting\x07008000 players...");
}
public Action StartConnectDialog(int param1)
{
for (int client = 1; client <= MaxClients; client++)
......@@ -566,4 +628,4 @@ public Action SCommand_StartVote(int args)
RestrictVote = INVALID_HANDLE;
}
}
}
\ No newline at end of file
}
......@@ -4,7 +4,7 @@
{
"Version"
{
"Latest" "v0.1 WIP2"
"Latest" "v0.1 WIP3"
}
"Notes" "First release"
......@@ -12,6 +12,7 @@
"Notes" "WIP1.1: Downgraded SM version for compile on git"
"Notes" "WIP2: Fixed fail to start the vote first time"
"Notes" "WIP2: Changed lobby redirect command to client command"
"Notes" "WIP3: Added auto redirect when some of the candidate servers meet l_minplayers"
}
"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