Raised This Month: $106 Target: $400
 26% 

[EXTENSION] Late Downloads


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Backup
Senior Member
Join Date: Jul 2010
Location: Česká Republika
Old 02-09-2018 , 15:24   [EXTENSION] Late Downloads
Reply With Quote #1

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.


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
__________________
Sorry for my english.

Last edited by Backup; 02-09-2018 at 15:25.
Backup is offline
ALiV
Junior Member
Join Date: Oct 2015
Old 02-12-2018 , 08:00   Re: [EXTENSION] Late Downloads
Reply With Quote #2

this plugin will work for download zip or rar archive?
ALiV is offline
CrazyHackGUT
AlliedModders Donor
Join Date: Feb 2016
Location: Izhevsk, Russia
Old 02-12-2018 , 14:36   Re: [EXTENSION] Late Downloads
Reply With Quote #3

Nope. Source don't supports zip archives.
__________________
My english is very bad. I am live in Russia. Learning english language - very hard task for me...
CrazyHackGUT is offline
Send a message via ICQ to CrazyHackGUT Send a message via Skype™ to CrazyHackGUT
GHartmann
Junior Member
Join Date: Feb 2018
Old 02-12-2018 , 14:50   Re: [EXTENSION] Late Downloads
Reply With Quote #4

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?

Last edited by GHartmann; 02-12-2018 at 16:16.
GHartmann is offline
ALiV
Junior Member
Join Date: Oct 2015
Old 02-12-2018 , 15:35   Re: [EXTENSION] Late Downloads
Reply With Quote #5

Quote:
Originally Posted by CrazyHackGUT View Post
Nope. Source don't supports zip archives.
what plugin can download zip archive?
ALiV is offline
Papero
Veteran Member
Join Date: Aug 2016
Location: Rimini, Italy
Old 02-13-2018 , 17:21   Re: [EXTENSION] Late Downloads
Reply With Quote #6

Quote:
Originally Posted by ALiV View Post
what plugin can download zip archive?
No-one, (it isn't supported by the source(engine)...)
__________________

Last edited by Papero; 02-13-2018 at 17:22.
Papero is offline
Send a message via Skype™ to Papero
Backup
Senior Member
Join Date: Jul 2010
Location: Česká Republika
Old 02-14-2018 , 18:34   Re: [EXTENSION] Late Downloads
Reply With Quote #7

Quote:
Originally Posted by GHartmann View Post
I built it against TF2 with a few small changes
...
Thanks, I've added these changes into the source!

Quote:
Originally Posted by GHartmann View Post
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?
__________________
Sorry for my english.
Backup is offline
GHartmann
Junior Member
Join Date: Feb 2018
Old 02-14-2018 , 19:11   Re: [EXTENSION] Late Downloads
Reply With Quote #8

Quote:
Originally Posted by Backup View Post
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.
GHartmann is offline
Backup
Senior Member
Join Date: Jul 2010
Location: Česká Republika
Old 02-15-2018 , 16:22   Re: [EXTENSION] Late Downloads
Reply With Quote #9

Quote:
Originally Posted by GHartmann View Post
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. Some network entity filtering should solve this quite easily tho.
__________________
Sorry for my english.
Backup is offline
GHartmann
Junior Member
Join Date: Feb 2018
Old 02-16-2018 , 05:40   Re: [EXTENSION] Late Downloads
Reply With Quote #10

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;
        }
}
GHartmann is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:27.


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