zoukankan      html  css  js  c++  java
  • 添加自动下载功能

    可以使用此功能为客户端补充必要的文件,例如声音文件、模型文件、等
    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] == '
    ') {
    			buffer[--len] = ''
    		}
    		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] == '
    ') {
    			buffer[--len] = ''
    		}
    		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"
    
  • 相关阅读:
    register变量
    register变量
    const和volatile是否可以同时修饰一个变量?有什么特殊含义?
    关于多态性和虚函数的理解
    static全局变量与普通的全局变量有什么区别
    《c专家编程》学习笔记
    正则表达式入门学习
    mvc ActionResult
    ASP.NET MVC:通过 FileResult 向 浏览器 发送文件(传)
    Asp.net mvc 中的HttpContext
  • 原文地址:https://www.cnblogs.com/jkcx/p/9569185.html
Copyright © 2011-2022 走看看