jonatan1024 / latedl

SourceMod Extension that allows file transfers to players that are already in the game.
GNU General Public License v3.0
14 stars 2 forks source link

Late Downloads

What is this?

This is a SourceMod extension that allows file transfers to players that are already in the game.

How to build this?

Just as any other AMBuild project:

  1. Install AMBuild
  2. Download Half-Life 2 SDK, Metamod:Source and SourceMod
  3. mkdir build && cd build
  4. python ../configure.py --hl2sdk-root=??? --mms-path=??? --sm-path=??? --sdks=csgo
  5. ambuild

    How to use this?

    Simply copy the extension binary to the extensions folder and the include file into the scripting/include folder.

Now just create a new plugin and include latedl.inc.

Sample script

#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>
#include <latedl>

public Plugin myinfo = 
{
    name = "My First Plugin", 
    author = "Me", 
    description = "My first plugin ever", 
    version = "1.0", 
    url = "http://www.sourcemod.net/"
};

public void OnPluginStart()
{
    RegAdminCmd("testdl", Command_TestDL, ADMFLAG_SLAY);
}

public void OnDownloadSuccess(int iClient, char[] filename) {
    if (iClient > 0)
        return;
    PrintToServer("All players successfully downloaded file '%s'!", filename);
}

public Action Command_TestDL(int client, int args)
{
    //create arbitrary file
    int time = GetTime();
    char tstr[64];
    FormatEx(tstr, 64, "%d.txt", time);
    File file = OpenFile(tstr, "wt", true, NULL_STRING);
    WriteFileString(file, tstr, false);
    CloseHandle(file);

    //send
    AddLateDownload(tstr);
    return Plugin_Handled;
}

Extension configuration

The extension exposes following cvars:

The first two cvars limit the maximal time that the download can take. The maximal duration (in seconds) is computed using following formula: maximalDelay / 1000 + (fileSizeInBytes * 8) / (minimalBandwidth * 1000)

If the player fails to download the file in time, he's kicked.

The last cvar kicks any player that rejects incoming files.

Additional information