-
Notifications
You must be signed in to change notification settings - Fork 1
/
shavit-newmaps.sp
110 lines (89 loc) · 2.61 KB
/
shavit-newmaps.sp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* Header files */
#include <shavit/rankings>
#include <convar_class>
/* Preprocessor directives */
#pragma semicolon 1
#pragma newdecls required
/* Globals */
ArrayList gA_NewestMaps;
ConVar gCV_MaxMapsToShow;
/* Plugin information */
public Plugin myinfo =
{
name = "Recently uploaded maps",
author = "Nairda",
/* Thank you so much, Deadwinter */
description = "Displays recently uploaded maps.",
url = "https://steamcommunity.com/id/nairda1339/"
}
enum struct MapInfo
{
int TimeStamp;
char MapName[PLATFORM_MAX_PATH];
}
public void OnPluginStart()
{
gA_NewestMaps = new ArrayList(sizeof(MapInfo));
RegConsoleCmd("sm_newmaps", NewestMaps, "List recently uploaded maps.");
gCV_MaxMapsToShow = CreateConVar("max_maps_to_show", "25", "Number of maps to display", 0, true, 1.0, true, 100.0);
AutoExecConfig(true, "recent_maps");
}
public Action NewestMaps(int client, int args)
{
UpdateMapsList();
NewMapsMenu(client);
return Plugin_Handled;
}
void NewMapsMenu(int client)
{
Menu menu = new Menu(Handler_NewestMaps);
int mapsToShow = (gCV_MaxMapsToShow.IntValue < gA_NewestMaps.Length) ? gCV_MaxMapsToShow.IntValue : gA_NewestMaps.Length;
menu.SetTitle("Newest Maps (Showing %i):", mapsToShow);
for (int i = 0; i < mapsToShow; i++)
{
MapInfo map;
gA_NewestMaps.GetArray(i, map);
char time[32], display[255];
FormatTime(time, sizeof(time), "%Y/%m/%d %H:%M", map.TimeStamp);
Format(display, sizeof(display), "%s | %s [T%i]", time, map.MapName, Shavit_GetMapTier(map.MapName));
menu.AddItem(map.MapName, display);
}
menu.Display(client, MENU_TIME_FOREVER);
}
public int Handler_NewestMaps(Menu menu, MenuAction action, int client, int choice)
{
if (action == MenuAction_Select)
{
char mapName[PLATFORM_MAX_PATH];
menu.GetItem(choice, mapName, sizeof(mapName));
FakeClientCommand(client, "sm_nominate %s", mapName);
NewMapsMenu(client);
}
else if (action == MenuAction_End)
{
delete menu;
}
return 0;
}
void UpdateMapsList()
{
gA_NewestMaps.Clear();
Handle dir = OpenDirectory("maps/");
if (dir == INVALID_HANDLE)
{
PrintToServer("Failed to open maps directory.");
return;
}
char mapName[PLATFORM_MAX_PATH], path[PLATFORM_MAX_PATH];
while (ReadDirEntry(dir, mapName, sizeof(mapName)) && StrContains(mapName, ".bsp", false) != -1)
{
Format(path, sizeof(path), "maps/%s", mapName);
MapInfo map;
map.TimeStamp = GetFileTime(path, FileTime_LastChange);
strcopy(map.MapName, sizeof(map.MapName), mapName);
ReplaceString(map.MapName, sizeof(map.MapName), ".bsp", "", false);
gA_NewestMaps.PushArray(map);
}
CloseHandle(dir);
gA_NewestMaps.Sort(Sort_Descending, Sort_Integer);
}