Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikMinekus committed Jul 30, 2020
1 parent 1b79956 commit 89a7da0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 37 deletions.
50 changes: 24 additions & 26 deletions addons/sourcemod/scripting/advertisements.sp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#pragma newdecls required
#pragma semicolon 1

#define PL_VERSION "2.0.3"
#define PL_VERSION "2.0.4"
#define UPDATE_URL "http://ErikMinekus.github.io/sm-advertisements/update.txt"

public Plugin myinfo =
Expand Down Expand Up @@ -53,11 +53,10 @@ public void OnPluginStart()
}
}

public void OnMapStart()
public void OnConfigsExecuted()
{
ParseAds();

g_hTimer = CreateTimer(g_hInterval.IntValue * 1.0, Timer_DisplayAd, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
RestartTimer();
}

public void OnLibraryAdded(const char[] name)
Expand All @@ -74,11 +73,7 @@ public void ConVarChange_File(ConVar convar, const char[] oldValue, const char[]

public void ConVarChange_Interval(ConVar convar, const char[] oldValue, const char[] newValue)
{
if (g_hTimer) {
KillTimer(g_hTimer);
}

g_hTimer = CreateTimer(g_hInterval.IntValue * 1.0, Timer_DisplayAd, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
RestartTimer();
}


Expand Down Expand Up @@ -107,7 +102,7 @@ public Action Timer_DisplayAd(Handle timer)
return;
}

char sCenter[1024], sChat[1024], sHint[1024], sMenu[1024], sTop[1024], sFlags[16];
char sCenter[1024], sChat[1024], sHint[1024], sMenu[1024], sTop[1024], sFlags[22];
g_hAdvertisements.GetString("center", sCenter, sizeof(sCenter));
g_hAdvertisements.GetString("chat", sChat, sizeof(sChat));
g_hAdvertisements.GetString("hint", sHint, sizeof(sHint));
Expand All @@ -122,9 +117,7 @@ public Action Timer_DisplayAd(Handle timer)
ProcessVariables(sCenter);

for (int i = 1; i <= MaxClients; i++) {
if (IsClientInGame(i) && !IsFakeClient(i) &&
((!bAdmins && !(bFlags && (GetUserFlagBits(i) & (iFlags|ADMFLAG_ROOT)))) ||
(bAdmins && (GetUserFlagBits(i) & (ADMFLAG_GENERIC|ADMFLAG_ROOT))))) {
if (IsValidClient(i, bAdmins, bFlags, iFlags)) {
PrintCenterText(i, sCenter);

DataPack hCenterAd;
Expand All @@ -138,9 +131,7 @@ public Action Timer_DisplayAd(Handle timer)
ProcessVariables(sHint);

for (int i = 1; i <= MaxClients; i++) {
if (IsClientInGame(i) && !IsFakeClient(i) &&
((!bAdmins && !(bFlags && (GetUserFlagBits(i) & (iFlags|ADMFLAG_ROOT)))) ||
(bAdmins && (GetUserFlagBits(i) & (ADMFLAG_GENERIC|ADMFLAG_ROOT))))) {
if (IsValidClient(i, bAdmins, bFlags, iFlags)) {
PrintHintText(i, sHint);
}
}
Expand All @@ -153,9 +144,7 @@ public Action Timer_DisplayAd(Handle timer)
hPl.CurrentKey = 10;

for (int i = 1; i <= MaxClients; i++) {
if (IsClientInGame(i) && !IsFakeClient(i) &&
((!bAdmins && !(bFlags && (GetUserFlagBits(i) & (iFlags|ADMFLAG_ROOT)))) ||
(bAdmins && (GetUserFlagBits(i) & (ADMFLAG_GENERIC|ADMFLAG_ROOT))))) {
if (IsValidClient(i, bAdmins, bFlags, iFlags)) {
hPl.Send(i, Handler_DoNothing, 10);
}
}
Expand All @@ -170,9 +159,7 @@ public Action Timer_DisplayAd(Handle timer)
ProcessVariables(sBuffer);

for (int i = 1; i <= MaxClients; i++) {
if (IsClientInGame(i) && !IsFakeClient(i) &&
((!bAdmins && !(bFlags && (GetUserFlagBits(i) & (iFlags|ADMFLAG_ROOT)))) ||
(bAdmins && (GetUserFlagBits(i) & (ADMFLAG_GENERIC|ADMFLAG_ROOT))))) {
if (IsValidClient(i, bAdmins, bFlags, iFlags)) {
if (bTeamColor) {
SayText2(i, sBuffer);
} else {
Expand All @@ -194,9 +181,7 @@ public Action Timer_DisplayAd(Handle timer)
hKv.SetNum("time", 10);

for (int i = 1; i <= MaxClients; i++) {
if (IsClientInGame(i) && !IsFakeClient(i) &&
((!bAdmins && !(bFlags && (GetUserFlagBits(i) & (iFlags|ADMFLAG_ROOT)))) ||
(bAdmins && (GetUserFlagBits(i) & (ADMFLAG_GENERIC|ADMFLAG_ROOT))))) {
if (IsValidClient(i, bAdmins, bFlags, iFlags)) {
CreateDialog(i, hKv, DialogType_Msg);
}
}
Expand Down Expand Up @@ -232,6 +217,13 @@ public Action Timer_CenterAd(Handle timer, DataPack pack)
/**
* Stocks
*/
bool IsValidClient(int iClient, bool bAdmins, bool bFlags, int iFlags)
{
return IsClientInGame(iClient) && !IsFakeClient(iClient)
&& ((!bAdmins && !(bFlags && CheckCommandAccess(iClient, "Advertisements", iFlags)))
|| (bAdmins && CheckCommandAccess(iClient, "Advertisements", ADMFLAG_GENERIC)));
}

void ParseAds()
{
delete g_hAdvertisements;
Expand Down Expand Up @@ -285,7 +277,7 @@ void ProcessVariables(char sText[1024])
}

ConVar hConVar;
char sConVar[64], sSearch[64], sReplace[64];
char sConVar[64], sSearch[64], sReplace[256];
int iEnd = -1, iStart = StrContains(sText, "{"), iStart2;
while (iStart != -1) {
iEnd = StrContains(sText[iStart + 1], "}");
Expand All @@ -309,3 +301,9 @@ void ProcessVariables(char sText[1024])
iStart += iStart2 + 1;
}
}

void RestartTimer()
{
delete g_hTimer;
g_hTimer = CreateTimer(float(g_hInterval.IntValue), Timer_DisplayAd, _, TIMER_REPEAT);
}
22 changes: 11 additions & 11 deletions addons/sourcemod/scripting/include/updater.inc
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
* @param url URL to your plugin's update file.
* @noreturn
*/
native Updater_AddPlugin(const String:url[]);
native void Updater_AddPlugin(const char[] url);

/**
* Removes your plugin from the updater. This does not need to
* be called during OnPluginEnd.
*
* @noreturn
*/
native Updater_RemovePlugin();
native void Updater_RemovePlugin();

/**
* Forces your plugin to be checked for updates. The behaviour
Expand All @@ -27,21 +27,21 @@ native Updater_RemovePlugin();
* @return True if an update was triggered. False otherwise.
* @error Plugin not found in updater.
*/
native bool:Updater_ForceUpdate();
native bool Updater_ForceUpdate();

/**
* Called when your plugin is about to be checked for updates.
*
* @return Plugin_Handled to prevent checking, Plugin_Continue to allow it.
*/
forward Action:Updater_OnPluginChecking();
forward Action Updater_OnPluginChecking();

/**
* Called when your plugin is about to begin downloading an available update.
*
* @return Plugin_Handled to prevent downloading, Plugin_Continue to allow it.
*/
forward Action:Updater_OnPluginDownloading();
forward Action Updater_OnPluginDownloading();

/**
* Called when your plugin's update files have been fully downloaded
Expand All @@ -52,31 +52,31 @@ forward Action:Updater_OnPluginDownloading();
*
* @noreturn
*/
forward Updater_OnPluginUpdating();
forward void Updater_OnPluginUpdating();

/**
* Called when your plugin's update has been completed. It is safe
* to reload your plugin at this time.
*
* @noreturn
*/
forward Updater_OnPluginUpdated();
forward void Updater_OnPluginUpdated();

/**
* @brief Reloads a plugin.
*
* @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
* @noreturn
*/
stock ReloadPlugin(Handle:plugin=INVALID_HANDLE)
stock void ReloadPlugin(Handle plugin = INVALID_HANDLE)
{
decl String:filename[64];
char filename[64];
GetPluginFilename(plugin, filename, sizeof(filename));
ServerCommand("sm plugins reload %s", filename);
}


public SharedPlugin:__pl_updater =
public SharedPlugin __pl_updater =
{
name = "updater",
file = "updater.smx",
Expand All @@ -88,7 +88,7 @@ public SharedPlugin:__pl_updater =
};

#if !defined REQUIRE_PLUGIN
public __pl_updater_SetNTVOptional()
public void __pl_updater_SetNTVOptional()
{
MarkNativeAsOptional("Updater_AddPlugin");
MarkNativeAsOptional("Updater_RemovePlugin");
Expand Down

0 comments on commit 89a7da0

Please sign in to comment.