lots of changes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include <sourcemod>
|
||||
#include <ripext>
|
||||
#include <geoip>
|
||||
#include <multicolors>
|
||||
|
||||
#define EVENTNOTIFIER_CORE
|
||||
#include <EventNotifier>
|
||||
@@ -8,7 +9,7 @@
|
||||
#pragma semicolon 1
|
||||
#pragma newdecls required
|
||||
|
||||
#define PLUGIN_VERSION "1.1"
|
||||
#define PLUGIN_VERSION "2.0"
|
||||
|
||||
#define TIMEZONE_FILE "configs/eventnotifier_timezones.cfg"
|
||||
#define TIMEZONE_NAME_LEN 64
|
||||
@@ -40,7 +41,7 @@ public Plugin myinfo =
|
||||
{
|
||||
name = "EventNotifier",
|
||||
author = "marisakirisame.net",
|
||||
description = "Fetches upcoming Unloze events and exposes them to other plugins",
|
||||
description = "Fetches upcoming Unloze events, shows them via sm_event and announces them in chat",
|
||||
version = PLUGIN_VERSION,
|
||||
url = "https://marisakirisame.net"
|
||||
};
|
||||
@@ -75,6 +76,9 @@ public void OnPluginStart()
|
||||
g_cvServer.AddChangeHook(OnSourceChanged);
|
||||
g_cvInterval.AddChangeHook(OnIntervalChanged);
|
||||
|
||||
Menu_OnPluginStart();
|
||||
Announce_OnPluginStart();
|
||||
|
||||
AutoExecConfig(true, "EventNotifier");
|
||||
|
||||
RegAdminCmd("sm_event_refresh", Command_EventRefresh, ADMFLAG_GENERIC, "Re-fetches the event list now");
|
||||
@@ -108,6 +112,7 @@ public void OnClientDisconnect(int client)
|
||||
public void OnConfigsExecuted()
|
||||
{
|
||||
RestartRefreshTimer();
|
||||
RestartAnnounceTimer();
|
||||
FetchEvents();
|
||||
}
|
||||
|
||||
@@ -134,37 +139,58 @@ public Action Timer_Refresh(Handle timer)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Natives
|
||||
// Public API
|
||||
//
|
||||
// The natives stay registered for other plugins. The menu and announcement
|
||||
// modules compiled into this plugin call these functions instead: with
|
||||
// EVENTNOTIFIER_CORE defined the include declares no natives, so the API
|
||||
// names resolve to the plain functions below.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
public any Native_GetEventCount(Handle plugin, int numParams)
|
||||
int EventNotifier_GetEventCount()
|
||||
{
|
||||
return g_Events.Length;
|
||||
}
|
||||
|
||||
public any Native_HasFetched(Handle plugin, int numParams)
|
||||
bool EventNotifier_HasFetched()
|
||||
{
|
||||
return g_bEverFetched;
|
||||
}
|
||||
|
||||
bool EventNotifier_GetEvent(int index, EventInfo ev)
|
||||
{
|
||||
if (index < 0 || index >= g_Events.Length)
|
||||
return false;
|
||||
|
||||
g_Events.GetArray(index, ev);
|
||||
return true;
|
||||
}
|
||||
|
||||
public any Native_GetEventCount(Handle plugin, int numParams)
|
||||
{
|
||||
return EventNotifier_GetEventCount();
|
||||
}
|
||||
|
||||
public any Native_HasFetched(Handle plugin, int numParams)
|
||||
{
|
||||
return EventNotifier_HasFetched();
|
||||
}
|
||||
|
||||
public any Native_FindEventByNumber(Handle plugin, int numParams)
|
||||
{
|
||||
return FindEventByNumber(GetNativeCell(1));
|
||||
return EventNotifier_FindEventByNumber(GetNativeCell(1));
|
||||
}
|
||||
|
||||
public any Native_GetEvent(Handle plugin, int numParams)
|
||||
{
|
||||
int index = GetNativeCell(1);
|
||||
int size = GetNativeCell(3);
|
||||
|
||||
if (size < sizeof(EventInfo))
|
||||
return ThrowNativeError(SP_ERROR_NATIVE, "EventInfo buffer too small (%d < %d), recompile against the current EventNotifier.inc", size, sizeof(EventInfo));
|
||||
|
||||
if (index < 0 || index >= g_Events.Length)
|
||||
EventInfo ev;
|
||||
if (!EventNotifier_GetEvent(GetNativeCell(1), ev))
|
||||
return false;
|
||||
|
||||
EventInfo ev;
|
||||
g_Events.GetArray(index, ev);
|
||||
SetNativeArray(2, ev, sizeof(EventInfo));
|
||||
return true;
|
||||
}
|
||||
@@ -183,7 +209,7 @@ public any Native_FormatClientTime(Handle plugin, int numParams)
|
||||
|
||||
int maxlen = GetNativeCell(4);
|
||||
char[] buffer = new char[maxlen];
|
||||
FormatClientTime(client, GetNativeCell(2), buffer, maxlen, GetNativeCell(5));
|
||||
EventNotifier_FormatClientTime(client, GetNativeCell(2), buffer, maxlen, GetNativeCell(5));
|
||||
SetNativeString(3, buffer, maxlen);
|
||||
return 0;
|
||||
}
|
||||
@@ -307,6 +333,7 @@ void ParseEvent(JSONObject obj, EventInfo ev)
|
||||
if (!ev.name[0])
|
||||
GetJsonString(obj, "title", ev.name, sizeof(ev.name));
|
||||
|
||||
GetJsonString(obj, "url", ev.url, sizeof(ev.url));
|
||||
GetJsonString(obj, "server", ev.server, sizeof(ev.server));
|
||||
GetJsonString(obj, "rewards", ev.rewards, sizeof(ev.rewards));
|
||||
GetJsonString(obj, "leader", ev.leader, sizeof(ev.leader));
|
||||
@@ -364,7 +391,7 @@ public Action Command_EventRefresh(int client, int args)
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
int FindEventByNumber(int number)
|
||||
int EventNotifier_FindEventByNumber(int number)
|
||||
{
|
||||
int count = g_Events.Length;
|
||||
for (int i = 0; i < count; i++)
|
||||
@@ -475,7 +502,7 @@ void GetClientZonePeriod(int client, int stamp, TzPeriod out)
|
||||
|
||||
// Formats stamp in the client's timezone as "Thu 01 Oct 2026, 20:00 BST"
|
||||
// (or without the year). FormatTime can't be used, it only knows the server's zone.
|
||||
void FormatClientTime(int client, int stamp, char[] buffer, int maxlen, bool withYear)
|
||||
void EventNotifier_FormatClientTime(int client, int stamp, char[] buffer, int maxlen, bool withYear = true)
|
||||
{
|
||||
static const char weekdays[][] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
|
||||
static const char months[][] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
|
||||
@@ -585,3 +612,10 @@ void CivilFromDays(int z, int &y, int &m, int &d)
|
||||
m = (mp < 10) ? mp + 3 : mp - 9;
|
||||
y = yoe + era * 400 + ((m <= 2) ? 1 : 0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Modules
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#include "EventNotifier/menu.sp"
|
||||
#include "EventNotifier/announcements.sp"
|
||||
|
||||
Reference in New Issue
Block a user