-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuga_youtube.sp
373 lines (302 loc) · 9.65 KB
/
fuga_youtube.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#include <clientprefs>
public Plugin:myinfo =
{
name = "뿌까 YouTube Song",
author = "뿌까",
description = "Youtube Song",
version = "1.3",
url = "x"
}
new Handle:kv[500] = {INVALID_HANDLE, ...};
new MaxItem;
new vol[MAXPLAYERS+1];
new lastTime[MAXPLAYERS+1];
new String:LastSearch[MAXPLAYERS+1][256];
new String:LastSong[MAXPLAYERS+1][256];
new bool:StopSong[MAXPLAYERS+1];
Handle:volume_cookie;
new Handle:Enabled = INVALID_HANDLE;
new String:g_url[256];
public OnPluginStart()
{
SetCover();
LoadTranslations("common.phrases");
RegAdminCmd("sm_ysearch", CommandSerach, 0);
RegAdminCmd("sm_yvol", CommandVolume, 0);
RegAdminCmd("sm_ymenu", CommandSongMenu, 0);
RegAdminCmd("sm_yopen", CommandSongOpen, 0);
RegAdminCmd("sm_yall", CommandSongMenuAll, ADMFLAG_KICK);
RegAdminCmd("sm_ystop", CommandStopSong, 0);
RegAdminCmd("sm_ystopall", CommandStopAllSong, ADMFLAG_KICK);
RegAdminCmd("sm_yreload", CommandReloaConfig, ADMFLAG_KICK);
Enabled = CreateConVar("sm_youtube", "x");
GetConVarString(Enabled, g_url, sizeof(g_url));
HookConVarChange(Enabled, ConVarChanged);
volume_cookie = RegClientCookie("sm_youtube_volume", "0 ~ 100", CookieAccess_Protected);
for(new i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i))
{
vol[i] = 75;
LastSearch[i] = "";
LastSong[i] = "";
if(AreClientCookiesCached(i)) OnClientCookiesCached(i);
}
}
}
public ConVarChanged(Handle:cvar, const String:oldVal[], const String:newVal[]) GetConVarString(cvar, g_url, sizeof(g_url));
public OnMapStart() SetCover();
public OnMapEnd() for(new i = 0 ; i < 500 && i < MaxItem; i++) if(kv[i] != INVALID_HANDLE) CloseHandle(kv[i])
public OnClientPutInServer(client)
{
lastTime[client] = 0;
LastSong[client] = "";
LastSearch[client] = "";
StopSong[client] = true;
vol[client] = 25;
if(AreClientCookiesCached(client)) OnClientCookiesCached(client);
}
public OnClientCookiesCached(client){
char temp[3];
GetClientCookie(client, volume_cookie, temp, sizeof(temp));
LogMessage("볼륨 쿠키 %N : %s", client, temp);
if(!StrEqual(temp, "")) vol[client] = StringToInt(temp);
}
public Action:CommandSerach(client, args)
{
decl String:arg[256];
GetCmdArgString(arg, sizeof(arg));
if(StrEqual(arg, ""))
{
ReplyToCommand(client, "Usage: sm_ysearch <song>");
return Plugin_Handled;
}
SearchMusic(client, arg, 0, true);
return Plugin_Handled;
}
public Action:CommandVolume(client, args)
{
decl String:arg[256];
GetCmdArgString(arg, sizeof(arg));
if(StrEqual(arg, ""))
{
ReplyToCommand(client, "Usage: sm_yvolume <0 ~ 100> (현재: %d)", vol[client]);
return Plugin_Handled;
}
vol[client] = StringToInt(arg);
PrintToChat(client, "\x03볼륨 설정이되었습니다. (%d)", vol[client]);
Format(arg, sizeof(arg), "%d", StringToInt(arg));
SetClientCookie(client, volume_cookie, arg);
if(!StrEqual(LastSong[client], "")) PlayMusic(client, LastSong[client], GetTime()-lastTime[client]-8, false);
if(!StrEqual(LastSearch[client], "")) SearchMusic(client, LastSearch[client], GetTime()-lastTime[client]-8, false);
return Plugin_Handled;
}
public Action:CommandSongMenu(client, args) // 여기서 손 보면 댐
{
SongMenu(client, 0);
return Plugin_Handled;
}
public Action:CommandSongMenuAll(client, args)
{
SongMenu(client, 1);
return Plugin_Handled;
}
public Action:CommandSongOpen(client, args)
{
if(StopSong[client])
{
ReplyToCommand(client, "\x03노래를 키지 않았습니다.");
return Plugin_Handled;
}
if(!StrEqual(LastSong[client], "")) PlayMusic(client, LastSong[client], GetTime()-lastTime[client]-8, true);
if(!StrEqual(LastSearch[client], "")) SearchMusic(client, LastSearch[client], GetTime()-lastTime[client]-8, true);
return Plugin_Handled;
}
public Action:CommandReloaConfig(client, args)
{
SetCover();
PrintToChat(client, "\x03리로드되었습니다.");
return Plugin_Handled;
}
stock SongMenu(client, num)
{
decl String:SearchWord[16], SearchValue, String:name[256], String:SongName[256], open;
GetCmdArgString(SearchWord, sizeof(SearchWord));
new Handle:menu;
if(num == 0) menu = CreateMenu(song_select);
else menu = CreateMenu(song_select2);
SetMenuTitle(menu, "추천 노래 리스트", client);
AddMenuItem(menu, "랜덤", "랜덤");
for(new i = 0 ; i < MaxItem ; i++)
{
if(kv[i] != INVALID_HANDLE)
{
GetArrayString(kv[i], 0, name, sizeof(name));
GetArrayString(kv[i], 1, SongName, sizeof(SongName));
open = GetArrayCell(kv[i], 2);
}
new String:temp[256];
Format(temp, sizeof(temp), "%s**%s**%d", name, SongName, open);
if(StrContains(name, SearchWord, false) > -1)
{
AddMenuItem(menu, temp, name);
SearchValue++;
}
}
if(!SearchValue) PrintToChat(client, "\x03이름이 잘못되었거나 없는 이름입니다.");
DisplayMenu(menu, client, MENU_TIME_FOREVER);
}
public song_select(Handle:menu, MenuAction:action, client, select)
{
if(action == MenuAction_Select)
{
decl String:name[256], String:aa[3][256];
GetMenuItem(menu, select, name, sizeof(name));
ExplodeString(name, "**", aa, 3, 256);
new open = StringToInt(aa[2]);
if(StrEqual(name, "랜덤")) SetRandomSong(client);
else
{
PlayMusic(client, aa[1]);
if(open == 1) CreateTimer(0.5, oopen, client);
PrintToChatAll("\x04%N\x07FFFFFF님이 \x04%s \x07FFFFFF노래를 듣습니다.", client, aa[0]);
}
}
else if(action == MenuAction_End) CloseHandle(menu);
}
public song_select2(Handle:menu, MenuAction:action, client, select)
{
if(action == MenuAction_Select)
{
decl String:name[256], String:aa[3][256];
GetMenuItem(menu, select, name, sizeof(name));
ExplodeString(name, "**", aa, 3, 256);
new open = StringToInt(aa[2]);
if(StrEqual(name, "랜덤")) SetRandomSong(client, true);
else
{
for(new i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i))
{
PlayMusic(i, aa[1]);
if(open == 1) CreateTimer(0.5, oopen, i);
}
}
PrintToChatAll("\x04Admin\x07FFFFFF님이 \x04%s \x07FFFFFF노래를 틀었습니다.", aa[0]);
}
}
else if(action == MenuAction_End) CloseHandle(menu);
}
public Action:oopen(Handle:timer, any:client) FakeClientCommandEx(client, "sm_yopen");
public Action:CommandStopSong(client, args)
{
SetUrl(client, "about:blank");
StopSong[client] = true;
PrintToChat(client, "\x03노래를 중지했습니다.");
return Plugin_Handled;
}
public Action:CommandStopAllSong(client, args)
{
for(int i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i))
{
SetUrl(i, "about:blank");
StopSong[i] = true;
}
}
PrintToChatAll("\x03어드민이 노래를 중지했습니다.");
return Plugin_Handled;
}
stock SetRandomSong(client, bool:check = false)
{
decl String:SongName[256], String:SongTitle[256];
new random = GetRandomInt(0, MaxItem);
GetArrayString(kv[random], 0, SongTitle, sizeof(SongTitle));
GetArrayString(kv[random], 1, SongName, sizeof(SongName));
if(!check)
{
PlayMusic(client, SongName);
PrintToChatAll("\x04%N\x07FFFFFF님이 \x04%s \x07FFFFFF노래를 듣습니다.", client, SongTitle);
}
else
{
for(int i = 1; i <= MaxClients; i++) if(IsValidClient(i)) PlayMusic(i, SongName);
PrintToChatAll("\x04Admin\x07FFFFFF님이 \x04%s \x07FFFFFF노래를 틀었습니다.", SongTitle);
}
}
stock SearchMusic(client, String:text[], time = 0, bool:open = false)
{
new String:temp[256];
if(time == 0) Format(temp, sizeof(temp), "%s?q=%s&vol=%d", g_url, text, vol[client]);
else Format(temp, sizeof(temp), "%syousearch.php?q=%s&vol=%d&time=%d", g_url, text, vol[client], time);
SetUrl(client, temp, open);
StopSong[client] = false;
Format(LastSearch[client], 256, "%s", text);
LastSong[client] = "";
lastTime[client] = GetTime();
}
stock PlayMusic(client, String:text[], time = 0, bool:open = false)
{
new String:temp[256];
Format(temp, sizeof(temp), "%syoutube.php?q=%s&vol=%d&time=%d", g_url, text, vol[client], time);
SetUrl(client, temp, open);
StopSong[client] = false;
Format(LastSong[client], 256, "%s", text);
LastSearch[client] = "";
lastTime[client] = GetTime();
}
stock SetUrl(client, String:url[256], bool:open = false)
{
new Handle:site = CreateKeyValues("data");
KvSetString(site, "title", "tts");
KvSetNum(site, "type", MOTDPANEL_TYPE_URL);
KvSetString(site, "msg", url);
ShowVGUIPanel(client, "info", site, open);
CloseHandle(site);
}
stock Float:Convert_Time(const String:buffer[])
{
decl String:part[5];
new pos = SplitString(buffer, ":", part, sizeof(part));
if (pos == -1)
return StringToFloat(buffer);
else
{
// Convert from mm:ss to seconds
return (StringToFloat(part)*60.0) +
StringToFloat(buffer[pos]);
}
}
stock SetCover()
{
decl String:strPath[192], String:szBuffer[256];
BuildPath(Path_SM, strPath, sizeof(strPath), "configs/youtube.cfg");
new count = 0;
new Handle:DB = CreateKeyValues("youtube");
FileToKeyValues(DB, strPath);
if(KvGotoFirstSubKey(DB))
{
do
{
kv[count] = CreateArray(540);
KvGetSectionName(DB, szBuffer, sizeof(szBuffer));
PushArrayString(kv[count], szBuffer);
KvGetString(DB, "video", szBuffer, sizeof(szBuffer));
PushArrayString(kv[count], szBuffer);
PushArrayCell(kv[count], KvGetNum(DB, "open"));
count++;
}
while(KvGotoNextKey(DB));
}
CloseHandle(DB);
MaxItem = count;
}
stock bool:IsValidClient(client)
{
if(client <= 0 ) return false;
if(client > MaxClients) return false;
if(!IsClientConnected(client)) return false;
return IsClientInGame(client);
}