Commit 99542e84 authored by Neoony's avatar Neoony
Browse files

v0.1 WIP5

Added command l_redirect 'Redirect all the players manually one time. Use IP:PORT as argument.'
Added ConVar l_backupserver 'IP of the server to get redirected into, in case of failing to connect to DB, or if no servers are found (IP:PORT)'
Added ConVar l_forceredirect 'If this is not Zero, players will be immediately redirected to this server and will keep redirecting (IP:PORT)'
Added failsafe measures in case of connecting to DB fail, or if no servers are found while the vote wants to start'
Added dependencies in README.md
Updated copyright year in LICENSE
parent d9f293a3
Pipeline #3871 passed with stages
......@@ -621,7 +621,7 @@ copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
{Lobby} {Create a vote to join a server on certain player count}
Copyright (C) {2018} {Neoony}
Copyright (C) {2019} {Neoony}
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......
......@@ -3,18 +3,26 @@
Latest **dev** version: https://sourcemod.docs.empiresmod.com/Lobby/addons/sourcemod/plugins/Lobby.smx
*Created by* **Neoony**
--
# DEPENDENCIES
Linux server needs: apt-get install lib32z1
More info for different linux editions:
https://gaming.stackexchange.com/questions/172407/sourcebans-smx-database-failure-could-not-find-driver-mysql/172408#172408
--
**Server Commands:**
**"l_query"**
*"Debug, query the servers status"*
**"l_queryx"**
*"Debug, query the servers status and print data to server console"*
**"l_startvote"**
*"Force start the server vote"*
**"l_query"**
*"Debug, query the servers status"*
**"l_queryx"**
*"Debug, query the servers status and print data to server console"*
**"l_startvote"**
*"Force start the server vote"*
**"l_redirect"**
*"Redirect all the players manually one time. Use IP:PORT as argument."*
**Cvars:**
**"l_minplayers"** *"def. 8"*
......@@ -29,6 +37,12 @@ Latest **dev** version: https://sourcemod.docs.empiresmod.com/Lobby/addons/sourc
**"l_restrictvote"** *"def. 30"*
*"For how long to restrict the vote starting, after a vote happened (Seconds)"*
**"l_backupserver"** *"def. 185.165.242.40:17701"*
*"IP of the server to get redirected into, in case of failing to connect to DB, or if no servers are found (IP:PORT)"*
**"l_forceredirect"** *"def. 0"*
*"If this is not Zero, players will be immediately redirected to this server and will keep redirecting (IP:PORT)"*
--
**Changelog:**
......
......@@ -20,7 +20,7 @@
#include <sdkhooks>
//#include <emputils>
#define PluginVer "v0.1 WIP4"
#define PluginVer "v0.1 WIP5"
public Plugin myinfo =
{
......@@ -45,7 +45,7 @@ public Plugin myinfo =
VoteInfo[3];
//ConVars
ConVar l_minplayers, l_votetimer, l_threshold, l_restrictvote;
ConVar l_minplayers, l_votetimer, l_threshold, l_restrictvote, l_backupserver, l_forceredirect;
int PlayersNumber;
int votestarted = 0;
......@@ -73,6 +73,11 @@ char ServerVoteItem[10][256];
char redirectAddress[128];
char ForceRedirectAddr[256];
char BackupServerAddr[256];
Handle BackupRedirectTimer = INVALID_HANDLE;
float Thresholdflt;
public void OnPluginStart()
......@@ -86,10 +91,12 @@ public void OnPluginStart()
//RegServerCmd("l_le", SCommand_LEnable);
//RegServerCmd("l_ld", SCommand_LDisable);
RegServerCmd("l_query", SCommand_LQuery);
RegServerCmd("l_queryx", SCommand_LQueryx);
RegServerCmd("l_redirect", SCommand_LOneTimeForceRedirect, "Redirect all the players manually one time. Use IP:PORT as argument.");
RegServerCmd("l_startvote", SCommand_StartVote);
RegServerCmd("l_query", SCommand_LQuery, "Test Query from DB");
RegServerCmd("l_queryx", SCommand_LQueryx, "Test Query from DB");
RegServerCmd("l_startvote", SCommand_StartVote, "Start the vote manually");
StartSQL();
......@@ -100,6 +107,10 @@ public void OnPluginStart()
l_threshold = CreateConVar("l_threshold", "50", "Percantage needed for successful vote (Percentage, max 100)");
l_restrictvote = CreateConVar("l_restrictvote", "30", "For how long to restrict the vote starting, after a vote happened (Seconds)");
l_backupserver = CreateConVar("l_backupserver", "185.165.242.40:17701", "IP of the server to get redirected into, in case of failing to connect to DB, or if no servers are found (IP:PORT)");
l_forceredirect = CreateConVar("l_forceredirect", "0", "If this is not Zero, players will be immediately redirected to this server and will keep redirecting (IP:PORT)");
//Updater
if (LibraryExists("updater"))
{
......@@ -140,11 +151,87 @@ public void OnClientPutInServer(int Client)
public bool OnClientConnect(int Client)
{
GetConVarString(l_forceredirect, ForceRedirectAddr, sizeof(ForceRedirectAddr));
PrintToServer("Client %i connecting", Client);
CheckPopulatedServersSinglePlayer(Client);
if (ForceRedirectAddr[255] != 0)
{
ForceRedirectSingle(Client);
}
if (ForceRedirectAddr[255] == 0)
{
CheckPopulatedServersSinglePlayer(Client);
}
return true;
}
public Action SCommand_LOneTimeForceRedirect(int args)
{
char full[256];
GetCmdArgString(full, sizeof(full));
for (int client = 1; client <= MaxClients; client++)
{
if (IsClientConnected(client))
{
ClientCommand(client, "lobby_redirect %s", full);
PrintToServer("[L] Force Redirecting client %i", client);
}
}
}
public void ForceRedirectSingle(int Client)
{
GetConVarString(l_forceredirect, ForceRedirectAddr, sizeof(ForceRedirectAddr));
PrintToServer("[L] Force Redirecting single client %i", Client);
ClientCommand(Client, "lobby_redirect %s", ForceRedirectAddr);
}
public void ForceRedirectAll()
{
GetConVarString(l_forceredirect, ForceRedirectAddr, sizeof(ForceRedirectAddr));
for (int client = 1; client <= MaxClients; client++)
{
if (IsClientConnected(client))
{
ClientCommand(client, "lobby_redirect %s", ForceRedirectAddr);
PrintToServer("[L] Force Redirecting client %i", client);
}
}
}
public void BackupRedirectSingle(int Client)
{
GetConVarString(l_backupserver, BackupServerAddr, sizeof(BackupServerAddr));
PrintToServer("[L] Redirecting single client %i to a Backup Server", Client);
ClientCommand(Client, "lobby_redirect %s", BackupServerAddr);
}
public void BackupRedirectAll()
{
GetConVarString(l_backupserver, BackupServerAddr, sizeof(BackupServerAddr));
for (int client = 1; client <= MaxClients; client++)
{
if (IsClientConnected(client))
{
ClientCommand(client, "lobby_redirect %s", BackupServerAddr);
PrintToServer("[L] Force Redirecting client %i", client);
}
}
}
public Action BackupRedirectTmr(Handle timer)
{
//Clear timer
if (BackupRedirectTimer != INVALID_HANDLE)
{
KillTimer(BackupRedirectTimer);
BackupRedirectTimer = INVALID_HANDLE;
}
BackupRedirectAll();
}
public void CheckPopulatedServersSinglePlayer(int Client)
{
// Query for servers with more or equal than l_minplayers players.
......@@ -160,6 +247,7 @@ public void RedirectToPopulatedServerSinglePlayerCallback(Handle hDriver, Handle
// The result is invalid -> an error occured
LogError("[Database] SQL-Query failed! Error: %s", sError);
PopulatedServerAlive = false;
return;
}
int fullServerCount = SQL_GetRowCount(hResult);
......@@ -388,6 +476,8 @@ public void QNumberOfServers(Handle hDriver, Handle hResult, const char[] sError
if (hResult == INVALID_HANDLE) {
// The result is invalid -> an error occured
LogError("[Database] SQL-Query failed! Error: %s", sError);
PrintToChatAll("\x04[L] \x01Could not connect to Database, Redirecting players to a Backup server in\x073399ff 5\x01 seconds");
BackupRedirectTimer = CreateTimer(5.0, BackupRedirectTmr);
}
else
{
......@@ -433,8 +523,9 @@ public Action QueryServersData(int args)
if (rowCount == 0)
{
PrintToServer("[L] No servers online");
PrintToChatAll("\x04[L] \x01No servers show up online, Redirecting players to a Backup server in\x073399ff 5\x01 seconds");
BackupRedirectTimer = CreateTimer(5.0, BackupRedirectTmr);
}
}
public Action SCommand_LQuery(int args)
......@@ -458,6 +549,8 @@ public void InfoOfServer(Handle hDriver, Handle hResult, const char[] sError, in
if (hResult == INVALID_HANDLE) {
// The result is invalid -> an error occured
LogError("[Database] SQL-Query failed! Error: %s", sError);
PrintToChatAll("\x04[L] \x01Could not connect to Database, Redirecting players to a Backup server in\x073399ff 5\x01 seconds");
BackupRedirectTimer = CreateTimer(5.0, BackupRedirectTmr);
}
else
{
......@@ -492,6 +585,14 @@ public void InfoOfServer(Handle hDriver, Handle hResult, const char[] sError, in
public Action PlayerCountChk(Handle timer)
{
CheckPopulatedServers();
if (ForceRedirectAddr[255] != 0)
{
ForceRedirectAll();
}
if (ForceRedirectAddr[255] == 0)
{
CheckPopulatedServers();
}
}
public void PlayersNumberCheck()
......
......@@ -4,7 +4,7 @@
{
"Version"
{
"Latest" "v0.1 WIP4"
"Latest" "v0.1 WIP5"
}
"Notes" "First release"
......@@ -14,6 +14,10 @@
"Notes" "WIP2: Changed lobby redirect command to client command"
"Notes" "WIP3: Added auto redirect when some of the candidate servers meet l_minplayers"
"Notes" "WIP4: Reworked automated joining to populated servers"
"Notes" "WIP5: Added command l_redirect 'Redirect all the players manually one time. Use IP:PORT as argument.'"
"Notes" "WIP5: Added ConVar l_backupserver 'IP of the server to get redirected into, in case of failing to connect to DB, or if no servers are found (IP:PORT)'"
"Notes" "WIP5: Added ConVar l_forceredirect 'If this is not Zero, players will be immediately redirected to this server and will keep redirecting (IP:PORT)'"
"Notes" "WIP5: Added failsafe measures in case of connecting to DB fail, or if no servers are found while the vote wants to start'"
}
"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