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"
|
||||
|
||||
+9
-34
@@ -1,12 +1,3 @@
|
||||
#include <sourcemod>
|
||||
#include <multicolors>
|
||||
#include <EventNotifier>
|
||||
|
||||
#pragma semicolon 1
|
||||
#pragma newdecls required
|
||||
|
||||
#define PLUGIN_VERSION "1.1"
|
||||
|
||||
// Shortest automatic announcement interval, in seconds. Values below this are
|
||||
// raised to it; 0 or below disables the timer entirely.
|
||||
#define MIN_ANNOUNCE_INTERVAL 60.0
|
||||
@@ -16,41 +7,25 @@
|
||||
// Visible characters allowed for the map list before " +N more" is appended.
|
||||
#define ANNOUNCE_MAPS_BUDGET 120
|
||||
|
||||
ConVar g_cvInterval;
|
||||
ConVar g_cvCount;
|
||||
ConVar g_cvAnnounceInterval;
|
||||
ConVar g_cvAnnounceCount;
|
||||
|
||||
Handle g_hAnnounceTimer;
|
||||
int g_iRotation;
|
||||
|
||||
public Plugin myinfo =
|
||||
void Announce_OnPluginStart()
|
||||
{
|
||||
name = "EventNotifier Announcements",
|
||||
author = "marisakirisame.net",
|
||||
description = "Periodically announces upcoming Unloze events in chat",
|
||||
version = PLUGIN_VERSION,
|
||||
url = "https://marisakirisame.net"
|
||||
};
|
||||
|
||||
public void OnPluginStart()
|
||||
{
|
||||
g_cvInterval = CreateConVar("sm_event_announce_interval", "120",
|
||||
g_cvAnnounceInterval = CreateConVar("sm_event_announce_interval", "120",
|
||||
"Seconds between event announcements in chat, -1 to disable automatic announcements (sm_event_announce still works)", _, true, -1.0);
|
||||
g_cvCount = CreateConVar("sm_event_announce_count", "3",
|
||||
g_cvAnnounceCount = CreateConVar("sm_event_announce_count", "3",
|
||||
"Rotate announcements through the next N upcoming events, one per announcement", _, true, 1.0, true, 20.0);
|
||||
|
||||
g_cvInterval.AddChangeHook(OnIntervalChanged);
|
||||
|
||||
AutoExecConfig(true, "EventNotifierAnnouncements");
|
||||
g_cvAnnounceInterval.AddChangeHook(OnAnnounceIntervalChanged);
|
||||
|
||||
RegAdminCmd("sm_event_announce", Command_Announce, ADMFLAG_GENERIC, "sm_event_announce [event number] - Posts an event announcement in chat now (next in rotation if no number given)");
|
||||
}
|
||||
|
||||
public void OnConfigsExecuted()
|
||||
{
|
||||
RestartAnnounceTimer();
|
||||
}
|
||||
|
||||
public void OnIntervalChanged(ConVar convar, const char[] oldValue, const char[] newValue)
|
||||
public void OnAnnounceIntervalChanged(ConVar convar, const char[] oldValue, const char[] newValue)
|
||||
{
|
||||
RestartAnnounceTimer();
|
||||
}
|
||||
@@ -59,7 +34,7 @@ void RestartAnnounceTimer()
|
||||
{
|
||||
delete g_hAnnounceTimer;
|
||||
|
||||
float interval = g_cvInterval.FloatValue;
|
||||
float interval = g_cvAnnounceInterval.FloatValue;
|
||||
if (interval <= 0.0)
|
||||
return;
|
||||
|
||||
@@ -124,7 +99,7 @@ bool PostAnnouncement()
|
||||
if (count <= 0)
|
||||
return false;
|
||||
|
||||
int window = g_cvCount.IntValue;
|
||||
int window = g_cvAnnounceCount.IntValue;
|
||||
if (window > count)
|
||||
window = count;
|
||||
|
||||
+32
-19
@@ -1,27 +1,15 @@
|
||||
#include <sourcemod>
|
||||
#include <EventNotifier>
|
||||
|
||||
#pragma semicolon 1
|
||||
#pragma newdecls required
|
||||
|
||||
#define PLUGIN_VERSION "1.2"
|
||||
#define CHAT_PREFIX "\x04[Events]\x01"
|
||||
|
||||
#define PANEL_LINE_WIDTH 60
|
||||
|
||||
#define KEY_FORUM 1
|
||||
#define KEY_BACK 8
|
||||
#define KEY_EXIT 10
|
||||
|
||||
public Plugin myinfo =
|
||||
{
|
||||
name = "EventNotifier Menu",
|
||||
author = "marisakirisame.net",
|
||||
description = "Shows upcoming Unloze events in-game via sm_event",
|
||||
version = PLUGIN_VERSION,
|
||||
url = "https://marisakirisame.net"
|
||||
};
|
||||
// Event number shown on each client's details panel, for EventDetails_Handler.
|
||||
static int g_iDetailsNumber[MAXPLAYERS + 1];
|
||||
|
||||
public void OnPluginStart()
|
||||
void Menu_OnPluginStart()
|
||||
{
|
||||
RegConsoleCmd("sm_event", Command_EventMenu, "Shows upcoming Unloze events. Usage: sm_event [event number]");
|
||||
RegConsoleCmd("sm_events", Command_EventMenu, "Shows upcoming Unloze events. Usage: sm_events [event number]");
|
||||
@@ -174,21 +162,46 @@ void ShowEventDetails(int client, int index)
|
||||
panel.DrawText(line);
|
||||
|
||||
panel.DrawText(" ");
|
||||
if (ev.url[0])
|
||||
{
|
||||
panel.CurrentKey = KEY_FORUM;
|
||||
panel.DrawItem("View forum post");
|
||||
}
|
||||
panel.CurrentKey = KEY_BACK;
|
||||
panel.DrawItem("Back");
|
||||
panel.CurrentKey = KEY_EXIT;
|
||||
panel.DrawItem("Exit");
|
||||
|
||||
g_iDetailsNumber[client] = ev.number;
|
||||
panel.Send(client, EventDetails_Handler, MENU_TIME_FOREVER);
|
||||
delete panel;
|
||||
}
|
||||
|
||||
public int EventDetails_Handler(Menu menu, MenuAction action, int param1, int param2)
|
||||
{
|
||||
if (action == MenuAction_Select && param2 == KEY_BACK)
|
||||
if (action != MenuAction_Select || !IsClientInGame(param1))
|
||||
return 0;
|
||||
|
||||
if (param2 == KEY_BACK)
|
||||
{
|
||||
if (IsClientInGame(param1))
|
||||
Command_EventMenu(param1, 0);
|
||||
Command_EventMenu(param1, 0);
|
||||
}
|
||||
else if (param2 == KEY_FORUM)
|
||||
{
|
||||
int index = EventNotifier_FindEventByNumber(g_iDetailsNumber[param1]);
|
||||
|
||||
EventInfo ev;
|
||||
if (index == -1 || !EventNotifier_GetEvent(index, ev) || !ev.url[0])
|
||||
{
|
||||
PrintToChat(param1, "%s That event is no longer in the upcoming list.", CHAT_PREFIX);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ShowMOTDPanel(param1, ev.name, ev.url, MOTDPANEL_TYPE_URL);
|
||||
|
||||
// Keep the details panel underneath so Back/Exit still work after
|
||||
// the MOTD window is closed.
|
||||
ShowEventDetails(param1, index);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
#define _EventNotifier_included
|
||||
|
||||
#define EVENT_STR_LEN 128
|
||||
#define EVENT_URL_LEN 192
|
||||
#define EVENT_MAPS_LEN 1024
|
||||
|
||||
enum struct EventInfo
|
||||
@@ -12,6 +13,7 @@ enum struct EventInfo
|
||||
int number;
|
||||
int start; // unix timestamp (UTC), 0 if unknown
|
||||
int end; // unix timestamp (UTC), 0 if unknown
|
||||
char url[EVENT_URL_LEN]; // forum thread URL, empty if unknown
|
||||
char name[EVENT_STR_LEN];
|
||||
char server[EVENT_STR_LEN];
|
||||
char rewards[EVENT_STR_LEN];
|
||||
|
||||
Reference in New Issue
Block a user