1. 程式人生 > >添加自動下載功能

添加自動下載功能

size read 文件 desc ring stat class dmi missing

可以使用此功能為客戶端補充必要的文件,例如聲音文件、模型文件、等
autotabledownloader.sp

#include <sourcemod>
#include <sdktools>
static String:DownloadPath[64]
public Plugin:myinfo = {
    name = "Auto Table Downloader",
    author = "Master(D)",
    description = "Auto Table Downloader",
    version = "1.1.1",
    url = ""
}
public Action:Command_CheakDownloadTables(Client,Args) {  
    PrintToConsole(Client,"Cheaking Download Table...")
    new Handle:fileh = OpenFile(DownloadPath, "r")
    new String:buffer[256]
    while (ReadFileLine(fileh, buffer, sizeof(buffer))) {
        new len = strlen(buffer)
        if (buffer[len-1] == ‘\n‘) {
            buffer[--len] = ‘\0‘
        }
        if (FileExists(buffer)) {
            PrintToConsole(Client,"Download: %s",buffer)
        } else {
            PrintToConsole(Client,"Ignore: %s",buffer)
        }
        if (IsEndOfFile(fileh)) {
            break
        }
    }
    return Plugin_Handled   
}
public OnMapStart(){
    BuildPath(Path_SM, DownloadPath, 64, "configs/download.txt")
    if(FileExists(DownloadPath) == false) SetFailState("[SM] ERROR: Missing file ‘%s‘", DownloadPath)
    new Handle:fileh = OpenFile(DownloadPath, "r")
    new String:buffer[256]
    while (ReadFileLine(fileh, buffer, sizeof(buffer))) {
        new len = strlen(buffer)
        if (buffer[len-1] == ‘\n‘) {
            buffer[--len] = ‘\0‘
        }
        if (FileExists(buffer)){
            AddFileToDownloadsTable(buffer)
        }
        if (IsEndOfFile(fileh)) {
            break;
        }
    }
}
public OnPluginStart() {
        RegAdminCmd("sm_dlcheck", Command_CheakDownloadTables, ADMFLAG_SLAY, "<Name> <Id> - Checks download.txt")
        CreateConVar("dlversion", "1.1.1", "auto table downloader version",FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_UNLOGGED|FCVAR_DONTRECORD|FCVAR_REPLICATED|FCVAR_NOTIFY)

}

此外,需要在服務端添加需要檢測下載的列表文件
遊戲目錄/left4dead2/addons/sourcemod/config/download.txt





Example Sounds:
Sound/masters_opening.mp3
Sound/consnd/city.mp3

Example Models:
Models/Player/headcrab.mdl
Models/Player/Headcrab.dx80.vtx
Models/Player/Headcrab.sw.vtx
Models/Player/Headcrab.dx90.vtx
Models/Player/headcrab.vvd
Models/Player/Headcrab.phy

///////////////////////////////////////////////////////////////////////////////////

        Remember To Remove All Of The Content Of This Page

///////////////////////////////////////////////////////////////////////////////////

最後,客戶端需要設置為允許下載的類型,才會自動下載

cl_allowdownload 1
cl_downloadfilter all
其他選項還有:
all, none, nosounds

下載服務端與遊戲服務器分離的方法:
服務端通過設置 sv_downloadurl 指定到可下載的遊戲目錄,來實現下載與服務器分離。例如:

sv_downloadurl "http://d.l4dol.com/left4dead2_v2121/left4dead2"

添加自動下載功能