AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Extensions (https://forums.alliedmods.net/forumdisplay.php?f=134)
-   -   [EXTENSION] Late Downloads (https://forums.alliedmods.net/showthread.php?t=305153)

Backup 02-09-2018 15:24

[EXTENSION] Late Downloads
 
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. Code:

    mkdir build && cd build
  4. Code:

    python ../configure.py --hl2sdk-root=??? --mms-path=??? --sm-path=??? --sdks=csgo
  5. Code:

    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
PHP Code:

#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_TestDLADMFLAG_SLAY);
}

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

public 
Action Command_TestDL(int clientint args)
{
    
//create arbitrary file
    
int time GetTime();
    
char tstr[64];
    
FormatEx(tstr64"%d.txt"time);
    
File file OpenFile(tstr"wt"trueNULL_STRING);
    
WriteFileString(filetstrfalse);
    
CloseHandle(file);
    
    
//send
    
AddLateDownload(tstr);
    return 
Plugin_Handled;


Extension configuration
The extension exposes following cvars:
  • latedl_minimalbandwidth (default = 64) - Kick clients with lower bandwidth (in kbps). Zero to disable.
  • latedl_maximaldelay (default = 500) - Acceptable additional delay (in ms) when sending files.
  • latedl_requireupload (default = 1) - Kick clients with "sv_allowupload" = 0. Zero to disable.

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
  • This was tested only in CS:GO, but any modern Source game (OrangeBox+) should be ok.
  • This extension used to be a part of the Gorme project.
  • YESTERDAY Valve changed the default settings for sv_allowupload (now disabled by default), torpedoing this extension. :cry:


Sources and binaries
Latest sources are availabe at github:
https://github.com/jonatan1024/latedl
Binaries for windows and linux should be availabe at the github releases page:
https://github.com/jonatan1024/latedl/releases

ALiV 02-12-2018 08:00

Re: [EXTENSION] Late Downloads
 
this plugin will work for download zip or rar archive?

CrazyHackGUT 02-12-2018 14:36

Re: [EXTENSION] Late Downloads
 
Nope. Source don't supports zip archives.

GHartmann 02-12-2018 14:50

Re: [EXTENSION] Late Downloads
 
This is pretty neat, wasn't aware it was possible!

I built it against TF2 with a few small changes:

Code:

179c179
<                      resendSuccess = chan->SendFile(activeDownload.filename, g_TransferID++);
---
>                      resendSuccess = chan->SendFile(activeDownload.filename, g_TransferID++, false);
301c301
<                      if (chan->SendFile(filename, g_TransferID)) {
---
>                      if (chan->SendFile(filename, g_TransferID, false)) {
334c334
<                              g_ActiveDownloads.Remove(g_ActiveDownloads.Count() - 1);
---
>                              g_ActiveDownloads.RemoveMultipleFromTail(1);
413c413
< }
---
> }
\ No newline at end of file

And tested it in-game, downloaded the text file.
Seems like this would be very useful for downloading non-essential files.

Edit: Actually, it seems it adds the files to the download list for new clients connecting, which means anyone connecting after a late download is added will still have to sit through the downloading of files. Wonder if there's a way around that?

ALiV 02-12-2018 15:35

Re: [EXTENSION] Late Downloads
 
Quote:

Originally Posted by CrazyHackGUT (Post 2577844)
Nope. Source don't supports zip archives.

what plugin can download zip archive?

Papero 02-13-2018 17:21

Re: [EXTENSION] Late Downloads
 
Quote:

Originally Posted by ALiV (Post 2577848)
what plugin can download zip archive?

No-one, (it isn't supported by the source(engine)...)

Backup 02-14-2018 18:34

Re: [EXTENSION] Late Downloads
 
Quote:

Originally Posted by GHartmann (Post 2577846)
I built it against TF2 with a few small changes
...

Thanks, I've added these changes into the source!

Quote:

Originally Posted by GHartmann (Post 2577846)
Actually, it seems it adds the files to the download list for new clients connecting, which means anyone connecting after a late download is added will still have to sit through the downloading of files. Wonder if there's a way around that?

Yep, during the "latedl call", the file is also added into the download table (see function AddStaticDownloads). The reasoning behind this behaviour is simple - some player might connect while everybody else is getting the ingame download.
I might add a boolean parameter for cases when you don't need file consistency amongst the players and one more native for file removal from the download table. I'm curious - what exactly is your use case? How the fact that some players doesn't have the needed files doesn't break their experience?

GHartmann 02-14-2018 19:11

Re: [EXTENSION] Late Downloads
 
Quote:

Originally Posted by Backup (Post 2578228)
what exactly is your use case?

My thought was, you could have certain files that aren't required download in the background so new players joining the server won't have to sit through all those files being downloaded.

For example as a donor perk on a server I play on, each player has a texture that floats above their head at the end of the round. These sorts of files would be fine to load as needed in the background since they aren't essential for players to have.

Backup 02-15-2018 16:22

Re: [EXTENSION] Late Downloads
 
Quote:

Originally Posted by GHartmann (Post 2578232)
My thought was, you could have certain files that aren't required download in the background so new players joining the server won't have to sit through all those files being downloaded.

For example as a donor perk on a server I play on, each player has a texture that floats above their head at the end of the round. These sorts of files would be fine to load as needed in the background since they aren't essential for players to have.

I've added parameters that can enable this behavior (set addAsStatic to false).

I'm not sure what the players that won't download the texture will see, my guess is pink-black checkerboard and console full of errors. :D Some network entity filtering should solve this quite easily tho.

GHartmann 02-16-2018 05:40

Re: [EXTENSION] Late Downloads
 
Change for latest version to build against TF2:

Code:

257,259c257
<      for ( int i = 0; i < g_BatchDeadlines.Count(); i++ ) {
<              g_BatchDeadlines[i] = 0;
<      }
---
>      g_BatchDeadlines.FillWithValue(0);

Which is just the same code provided by that function.

Or like this, but I dunno if there's a cleaner way to do this without inheriting:
Code:

template< class T, class A = CUtlMemory<T> >
class CUtlVectorExt : public CUtlVector<T, A>
{
public:
        void FillWithValue( const T& src );
};

template< typename T, class A >
void CUtlVectorExt<T, A>::FillWithValue( const T& src )
{
        for ( int i = 0; i < this->Count(); i++ )
        {
                this->Element(i) = src;
        }
}



All times are GMT -4. The time now is 03:08.

Powered by vBulletin®
Copyright ©2000 - 2018, vBulletin Solutions, Inc.