# legendsCaching

![Status](https://img.shields.io/badge/status-active-success.svg) [![GitHub Issues](https://img.shields.io/github/issues/legendsSystems/legendsCaching.svg)](https://github.com/legendsSystems/legendsCaching/issues) [![GitHub Pull Requests](https://img.shields.io/github/issues-pr/legendsSystems/legendsCaching.svg)](https://github.com/legendsSystems/legendsCaching/pulls) ![License](https://img.shields.io/badge/license-MIT-blue.svg)

***

## Getting Started <a href="#getting_started" id="getting_started"></a>

These instructions will get you a copy of the project up and running on your VPS for hosting files separate from you game server. It will load the files from your game server and cache them, so they are ready to stream to players.

***Build script only compatible with ubuntu systems, should be used on a fresh dedicated box with minimal resources and high bandwidth/throughput***

## On VPS Dedicated Cache Server

### Prerequisites

#### Install curl

```
sudo apt install curl
```

#### Clone Repository

```
git clone https://github.com/legendsSystems/legendsCaching.git
cd legendsCaching
```

### Installing

#### Execute build script

```
sudo chmod +x build.sh && sudo ./build.sh
```

Follow the prompts and enter the required info. Script can be run multiple times until successful if needed, just do a 'git stash && git stash drop'.

Logout and back into the ssh session to refresh perms or prepend sudo below

### Usage <a href="#usage" id="usage"></a>

TO check if the container booted properly

```
docker ps -a
```

#### Check logs

```
docker logs legendscaching-cache-1
```

```
docker stop legendscaching-cache-1
```

### Setup SSL

```
sudo apt update
sudo apt install -y nginx
sudo apt install -y python3-certbot-nginx
```

```
sudo certbot certonly --nginx -d FQDN
sudo cp /etc/letsencrypt/live/FQDN/* certs/
systemctl stop nginx.service
docker compose up -d --build
```

## On Game Server

### Edit / Add to server.cfg

```
set sv_forceIndirectListing true
set sv_listingHostOverride "server-cache-1.example.com" # both here and the IP's below can be that of a geo based global load balancer.  Azure's Traffic Manager offering does this for next to free.
set sv_listingIPOverride "LIVE_SERVER_IP"
set sv_proxyIPRanges "CACHING_SERVER_IP_1/32" "CACHING_SERVER_IP_2/32" "CACHING_SERVER_IP_3/32" # if only one caching server, only use one entry, but can support more with a load balancer
set sv_endpoints "LIVE_SERVER_IP:LIVE_SERVER_PORT"
set adhesive_cdnKey "fv67v67gyubit67tv6767v7"  # make it up, but never change afterwards unless you want to invalidate all players cache
fileserver_add ".*" "https://server-cache-1.example.com/files"
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.legends.systems/guides/legendscaching.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
