mirror of
https://codeberg.org/spire/sm_whitelist.git
synced 2026-06-03 10:14:07 +02:00
don't download existing whitelists, download to tmp file
This commit is contained in:
parent
6a1837dbd4
commit
333c506551
2 changed files with 29 additions and 15 deletions
Binary file not shown.
|
|
@ -7,7 +7,7 @@ public Plugin:myinfo = {
|
|||
name = "whitelist.tf downloader",
|
||||
author = "Icewind",
|
||||
description = "Download whitelists from whitelist.tf",
|
||||
version = "0.2",
|
||||
version = "0.3",
|
||||
url = "https://whitelist.tf"
|
||||
};
|
||||
|
||||
|
|
@ -35,14 +35,14 @@ public OnPluginStart() {
|
|||
|
||||
public Action:DownloadWhiteListAction(client, args) {
|
||||
new String:arg[128];
|
||||
|
||||
|
||||
if(args != 1) {
|
||||
PrintToServer("Usage: sm_whitelist_tf %whitelistid%");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
|
||||
GetCmdArg(1, arg, sizeof(arg));
|
||||
|
||||
|
||||
new intId = StringToInt(arg);
|
||||
if(intId > 0) {
|
||||
Format(arg, sizeof(arg), "custom_whitelist_%s", arg);
|
||||
|
|
@ -54,19 +54,25 @@ public Action:DownloadWhiteListAction(client, args) {
|
|||
|
||||
public DownloadWhiteList(String:whiteListId[128], bool:exec) {
|
||||
decl String:fullUrl[512];
|
||||
decl String:targetPath[128];
|
||||
decl String:targetPath[PLATFORM_MAX_PATH];
|
||||
decl String:downloadPath[PLATFORM_MAX_PATH];
|
||||
decl String:BaseUrl[128];
|
||||
GetConVarString(g_hCvarUrl, BaseUrl, sizeof(BaseUrl));
|
||||
new Handle:curl = curl_easy_init();
|
||||
CURL_DEFAULT_OPT(curl);
|
||||
|
||||
Format(fullUrl, sizeof(fullUrl), "%s/%s.txt", BaseUrl, whiteListId);
|
||||
|
||||
Format(targetPath, sizeof(targetPath), "cfg/%s.txt", whiteListId);
|
||||
|
||||
Format(targetPath, sizeof(targetPath), "cfg/%s.txt", whiteListId);
|
||||
if (FileExists(targetPath)) {
|
||||
execWhiteList(whiteListId);
|
||||
return;
|
||||
}
|
||||
|
||||
Format(downloadPath, sizeof(downloadPath), "cfg/%s.txt.part", whiteListId);
|
||||
new Handle:output_file = INVALID_HANDLE;
|
||||
|
||||
output_file = curl_OpenFile(targetPath, "w");
|
||||
output_file = curl_OpenFile(downloadPath, "w");
|
||||
|
||||
new Handle:hDLPack = CreateDataPack();
|
||||
WritePackCell(hDLPack, _:output_file);
|
||||
|
|
@ -75,16 +81,25 @@ public DownloadWhiteList(String:whiteListId[128], bool:exec) {
|
|||
|
||||
curl_easy_setopt_handle(curl, CURLOPT_WRITEDATA, output_file);
|
||||
curl_easy_setopt_string(curl, CURLOPT_URL, fullUrl);
|
||||
|
||||
WritePackString(hDLPack, downloadPath);
|
||||
WritePackString(hDLPack, targetPath);
|
||||
|
||||
|
||||
curl_easy_perform_thread(curl, onComplete, hDLPack);
|
||||
}
|
||||
|
||||
public onComplete(Handle:hndl, CURLcode:code, any hDLPack) {
|
||||
decl String:whiteListId[128];
|
||||
decl String:targetPath[PLATFORM_MAX_PATH];
|
||||
decl String:downloadPath[PLATFORM_MAX_PATH];
|
||||
|
||||
ResetPack(hDLPack);
|
||||
CloseHandle(Handle:ReadPackCell(hDLPack)); // output_file
|
||||
ReadPackString(hDLPack, whiteListId, sizeof(whiteListId));
|
||||
bool exec = ReadPackCell(hDLPack);
|
||||
ReadPackString(hDLPack, downloadPath, sizeof(downloadPath));
|
||||
ReadPackString(hDLPack, targetPath, sizeof(targetPath));
|
||||
|
||||
CloseHandle(hDLPack);
|
||||
|
||||
|
|
@ -94,10 +109,11 @@ public onComplete(Handle:hndl, CURLcode:code, any hDLPack) {
|
|||
PrintToChatAll("cURL error: %d", code);
|
||||
} else {
|
||||
new status_code;
|
||||
curl_easy_getinfo_int(hndl, CURLINFO_RESPONSE_CODE, status_code);
|
||||
|
||||
curl_easy_getinfo_int(hndl, CURLINFO_RESPONSE_CODE, status_code);
|
||||
|
||||
if (status_code == 200) {
|
||||
ok = true;
|
||||
RenameFile(downloadPath, targetPath);
|
||||
if (exec) {
|
||||
execWhiteList(whiteListId);
|
||||
}
|
||||
|
|
@ -108,15 +124,13 @@ public onComplete(Handle:hndl, CURLcode:code, any hDLPack) {
|
|||
PrintToChatAll("HTTP error: %d", status_code);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CloseHandle(hndl);
|
||||
|
||||
|
||||
if (!ok) {
|
||||
decl String:targetPath[128];
|
||||
Format(targetPath, sizeof(targetPath), "cfg/%s.txt", whiteListId);
|
||||
DeleteFile(targetPath);
|
||||
DeleteFile(downloadPath);
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue