Garry's Mod Wiki

Revision Difference

Serving_Content#561651

<cat>Play.Hosting</cat>⤶ <title>Serving Content</title>⤶ ⤶ # Serving content to players⤶ ⤶ For a player to be able to see custom content on a server they need to have the content downloaded. You can send your server content in various different ways to them, below are some different ways to achieve this.⤶ <note>.lua files are NOT considered content, they are downloaded through separate processes and require no additional setup.</note>⤶ ⤶ Keep in mind that clients can change which types of files they download by going into the settings menu.⤶ <upload src="b3c8c/8dc54cb1833cffc.png" size="62262" name="image.png" />⤶ ⤶ A simple oversight of the different methods:⤶ ⤶ | | ServerDL | FastDL |WorkshopDL|⤶ |-:|:--------:|:------:|:--------:|⤶ | **Speed**: | Slow 64kb/s limit, file by file | As fast as the client can download, file by file | As fast as the client can download, up to ~2gb (gma) at once|⤶ | **Method**: | Source networking | HTTP | Steam workshop |⤶ | **Downside**: | Extremely slow, you need to enable `sv_allowdownload` | Can be slow for lots of smaller files as it downloads one by one for each file. Files aren't checked for their contents so updating files on the server wont make the client redownload updated files. | You have to put the content pack on the workshop |⤶ | **Requirements**: | Requires sv_allowdownload 1 and resource.AddFile | Requires a FastDL webserver + resource.AddFile | Requires the content to be put on the workshop and added with resource.AddWorkshop |⤶ ⤶ More detailed explanations:⤶ - [ServerDL](https://wiki.facepunch.com/gmod/Serving_Content#ServerDL)⤶ - [FastDL](https://wiki.facepunch.com/gmod/Serving_Content#FastDL)⤶ - [WorkshopDL](https://wiki.facepunch.com/gmod/Serving_Content#WorkshopDL)⤶ - [Alternative options](https://wiki.facepunch.com/gmod/Serving_Content#Alternatives)⤶ ⤶ # Content serving options⤶ ## ServerDL⤶ Using ServerDL is rather simple, you need to have `sv_allowdownload` enabled and you need to mark the files that you want to be downloadable with <page>resource.AddFile</page> and <page>resource.AddSingleFile</page> after that clients will automatically download the content when they join your server. However this is considered obsolete as its incredibly slow at 64kb/s.⤶ <warning>Having `sv_allowdownload` enabled opens you up to exploits. Players with modified clients can spam request files to severely lag your server.</warning>⤶ ## FastDL⤶ For FastDL you need a separate webserver for players to download from and you need to set `sv_downloadurl` to the url of your website. Files can be marked for downloading with <page>resource.AddFile</page> and <page>resource.AddSingleFile</page> after that the client will automatically try to request the marked files from the webserver. Clients will first try to request a compressed version .bz2 version of the file and if that doesn't exist they will try the regular file, an example of this behavior can be seen below.⤶ ⤶ Example:⤶ ⤶ `sv_downloadurl` is set to `https://mycoolwebsite.com` and you've marked `materials/hud/killicon.vmt` for download. The client will first run a request to `https://mycoolwebsite.com/materials/hud/killicon.vmt.bz2` and then `https://mycoolwebsite.com/materials/hud/killicon.vmt`.⤶ ## WorkshopDL⤶ WorkshopDL effectively downloads straight from the steam workshop. So to use WorkshopDL you need to upload your content to the workshop. Make sure when you upload that you mark your addons type as `ServerContent` to prevent unnecessary clutter on the workshop. Once you've done this you can now use the lua function <page>resource.AddWorkshop</page>.⤶ ⤶ Example:⤶ ⤶ You have the following addon in your collection and mounted to your server but clients see them as errors: https://steamcommunity.com/sharedfiles/filedetails/?id=150455514⤶ To add it you can add a serverside only lua file that marks this workshop addon to be downloaded for clients. Example folder structure `garrysmod/lua/autorun/server/workshop.lua` or as legacy addon `garrysmod/addons/workshop/lua/autorun/server/workshop.lua`⤶ In this file you can put `resource.AddWorkshop("150455514")`⤶ ⤶ <note>Many server owners use workshop lua generators, these are NOT efficient as they will also mark addons with only lua to be downloaded thus increasing join times. Only mark addons that have files that aren't lua for download!</note>⤶ ## Alternatives⤶ Some servers download content on the fly, this can be done through various methods but the most common are:⤶ - <page>HTTP</page> and storing downloaded files in the `DATA` folder.⤶ - <page>steamworks.DownloadUGC</page> downloading steamworkshop content and mounting it with <page>game.MountGMA</page>⤶ ⤶ These methods wont work for everything, for example this will never work for a map. Some addons that precache or store Materials on autorun might also have issues with this.⤶