diff --git a/README.md b/README.md index 2822654..3dbd7ba 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,376 @@ # megastructure.surf -## todo -- fastdl -- influx -- psql -- momfix? \ No newline at end of file +A Docker-based Counter-Strike: Source surf server with Shavit BHopTimer and community physics fix plugins. + +## Overview + +This repository contains a complete CSS surf server setup using Docker containers. The setup includes: + +- **CSS Dedicated Server (CSSDS)** - Running on 64-bit binaries for improved performance +- **Shavit BHopTimer** - Actively maintained timer system (v4.0.1) with MySQL support +- **MariaDB** - Database backend for timer records and player data +- **MetaMod:Source** - Plugin loader framework +- **SourceMod** - Server administration and plugin platform +- **Community Physics Plugins** - Essential surf/bhop fixes and enhancements + +## Architecture + +### Docker Services + +#### `cssds` (CSS Dedicated Server) +- Based on Debian Bookworm +- Runs SteamCMD to download/update CSS DS and TF2 DS (for 64-bit binaries) +- Installs MetaMod:Source and SourceMod +- Installs surf-specific plugins and timer system +- Uses 64-bit server binaries for better performance +- Port: 27015 (configurable via `SRCDS_PORT`) + +#### `mariadb` (Database) +- MariaDB 10.11 for timer data persistence +- Stores player records, map times, rankings +- Port: 3306 (internal) +- Data persisted in `./sql:/var/lib/mysql` + +### Key Files + +``` +. +├── docker-compose.yaml # Service orchestration +├── etc/ +│ ├── cssds.dockerfile # CSS DS container definition +│ ├── mariadb.dockerfile # MariaDB container definition +│ ├── run.sh # Main setup and launch script +│ ├── update_cssds.txt # SteamCMD script for CSS DS +│ ├── update_tf2ds.txt # SteamCMD script for TF2 DS (64-bit libs) +│ └── cfg/ +│ └── server.cfg # Server configuration +└── sql/ # MariaDB data directory (volume mount) +``` + +## Installed Plugins + +### Timer System + +**Shavit BHopTimer v4.0.1** ([GitHub](https://github.com/shavitush/bhoptimer)) +- Actively maintained (last update: February 2026) +- Full surf/bhop timer with MySQL backend +- Replays, rankings, zone system, statistics +- Better SQL schema design than archived alternatives +- Config location: `addons/sourcemod/configs/shavit/` +- **Configured to use JSON zones** from [surf-zones](https://github.com/wrldspawn/surf-zones) repository + - Zones loaded from `https://wrldspawn.github.io/surf-zones/z/{map}.json` + - Includes stripper configurations and mapfixes + - Matches KSF (Kreedz Surf Federation) server behavior + - Use `!setmaxvel` in-game to configure max velocity per map + +### Physics Fix Plugins + +**MomSurfFix v1.1.5** ([GitHub](https://github.com/GAMMACASE/MomSurfFix)) +- Fixes Source engine surf physics to match Momentum Mod behavior +- Essential for proper surf mechanics + +**PushFix Definitive Edition v1.0.0** ([GitHub](https://github.com/GAMMACASE/PushFixDE)) +- Fixes player collision and push mechanics +- Prevents physics exploits + +**EventQueue Fix v1.3.2** ([GitHub](https://github.com/hermansimensen/eventqueue-fix)) +- Fixes map entity timing issues +- Ensures triggers and outputs work correctly + +**RNGFix v1.1.3** ([GitHub](https://github.com/jason-e/rngfix)) +- Fixes Source engine RNG determinism issues +- Ensures consistent physics behavior + +### Base Plugins + +SourceMod includes built-in plugins for server administration: +- Admin Menu, Basic Commands, Player Commands +- Rock The Vote, Map Nominations, MapChooser +- Reserved Slots, Basic Bans +- And more (see `etc/run.sh` comments for full list) + +## Setup & Usage + +### Prerequisites + +- Docker +- Docker Compose +- ~10GB disk space for server files + +### Environment Variables + +Configure in `docker-compose.yaml`: + +```yaml +METAMOD_VERSION: "1.11" # MetaMod:Source version +SOURCEMOD_VERSION: "1.11" # SourceMod version +SRCDS_PORT: 27015 # Server port +SRCDS_MAXPLAYERS: 32 # Max player slots +SRCDS_STARTMAP: "surf_ski_2" # Starting map +``` + +### Building & Running + +```bash +# Build the containers +docker-compose build + +# Start the services +docker-compose up -d + +# View logs +docker-compose logs -f cssds + +# Stop the services +docker-compose down +``` + +### First-Time Database Configuration + +After the first build, configure Shavit to use MariaDB: + +1. Edit `addons/sourcemod/configs/databases.cfg`: +``` +"Databases" +{ + "shavit" + { + "driver" "mysql" + "host" "mariadb" + "database" "shavit" + "user" "root" + "pass" "your_password" + } +} +``` + +2. Shavit will automatically create tables on first connection + +### JSON Zones Configuration + +The server is **automatically configured** to use JSON zones instead of SQL-based zones. This provides several advantages: + +**Automatic Setup:** +- Zones are loaded from the community-maintained [surf-zones](https://github.com/wrldspawn/surf-zones) repository +- Includes 400+ maps with pre-configured zones, stripper configs, and mapfixes +- No manual zone creation needed for supported maps +- Automatically downloads: `https://wrldspawn.github.io/surf-zones/z/{map}.json` + +**Configuration Files Created:** +- `cfg/sourcemod/plugin.shavit-zones.cfg` - Disables SQL zones (`shavit_zones_usesql "0"`) +- `cfg/sourcemod/plugin.shavit-zones-json.cfg` - Sets JSON URL +- `addons/stripper/` - Map entity fixes and modifications +- `addons/sourcemod/configs/shavit-mapfixes.cfg` - Map-specific settings +- `addons/sourcemod/configs/shavit-styles.cfg` - KSF-style configurations + +**Benefits:** +- ✅ No manual zone editing required for popular maps +- ✅ Community-maintained and regularly updated +- ✅ Includes map fixes for common issues +- ✅ Matches KSF server behavior and standards +- ✅ Faster deployment (no SQL import needed) + +**Important Note:** The `sv_maxvelocity` settings in mapfixes won't auto-apply. After loading a map, use the in-game command: +``` +!setmaxvel +``` +For most surf maps, use `!setmaxvel 3500`. Some maps may require different values (check surf-zones repo for specific maps). + +### Server Configuration + +Edit `etc/cfg/server.cfg` for server settings: +- Hostname, rcon password +- Game settings (gravity, air accelerate, etc.) +- SourceMod configurations + +## Development Notes + +### Plugin Installation Pattern + +All plugins follow an idempotent installation pattern in `etc/run.sh`: + +```bash +if [ ! -f "$CSTRIKE/addons/sourcemod/plugins/plugin.smx" ]; then + wget "https://github.com/author/repo/releases/download/version/plugin.zip" + unzip "plugin.zip" + rm "plugin.zip" + echo "Installed Plugin vX.Y.Z" +fi +``` + +This allows safe re-runs without reinstalling existing plugins. + +### Version Strategy + +**Fixed versions are used** (not dynamic `latest` detection) for: +- **Stability** - Known working versions prevent unexpected breaks +- **Reproducibility** - Docker builds are deterministic +- **No API dependencies** - Avoids GitHub API rate limits +- **Easy rollback** - Can revert to specific versions if issues arise + +### 64-bit Binary Support + +The server uses 64-bit binaries for improved performance: +1. TF2 DS is downloaded for its 64-bit libraries +2. `libsteam_api.so` and `srcds_linux64` are copied from TF2 to CSS +3. `_srv.so` binaries are symlinked to regular `.so` names +4. `steamclient.so` is located and symlinked to expected paths + +### Run Script Flow + +The `etc/run.sh` script executes in this order: + +1. **update_cssds()** - Download/update CSS DS via SteamCMD +2. **update_tf2ds()** - Download/update TF2 DS for 64-bit binaries +3. **copy_64bit()** - Copy 64-bit libraries from TF2 to CSS +4. **symlink_binaries()** - Create symlinks for server binaries +5. **steamclient_binary()** - Locate and symlink steamclient.so +6. **install_metamod()** - Install MetaMod:Source if missing +7. **install_sourcemod()** - Install SourceMod if missing +8. **install_surf()** - Install timer and physics plugins +9. **configure_shavit_zones()** - Download and configure JSON zones, stripper configs, and mapfixes +10. **cfg()** - Copy server configuration +11. **run_cssds()** - Launch the dedicated server + +## Verification + +### Check Installed Plugins + +```bash +docker exec -it surf_megastructure-cssds-1 \ + ls -la /home/steam/cssds/cstrike/addons/sourcemod/plugins/*.smx +``` + +### Check Shavit Configuration + +```bash +docker exec -it surf_megastructure-cssds-1 \ + ls -la /home/steam/cssds/cstrike/addons/sourcemod/configs/shavit/ +``` + +### Check JSON Zones Configuration + +```bash +# Check zone configuration files +docker exec -it surf_megastructure-cssds-1 \ + cat /home/steam/cssds/cstrike/cfg/sourcemod/plugin.shavit-zones.cfg + +# Check JSON URL configuration +docker exec -it surf_megastructure-cssds-1 \ + cat /home/steam/cssds/cstrike/cfg/sourcemod/plugin.shavit-zones-json.cfg + +# Check stripper configs installed +docker exec -it surf_megastructure-cssds-1 \ + ls -la /home/steam/cssds/cstrike/addons/stripper/ + +# Check mapfixes +docker exec -it surf_megastructure-cssds-1 \ + cat /home/steam/cssds/cstrike/addons/sourcemod/configs/shavit-mapfixes.cfg +``` + +### In-Game Verification + +Connect to the server and run: +``` +sm plugins list +``` + +You should see: +- Shavit BHopTimer (multiple modules) +- momsurffix2 +- pushfix_de +- eventqueuefix +- rngfix +- Standard SourceMod plugins + +## Troubleshooting + +### Plugins Not Loading + +1. Check MetaMod is loaded: `meta list` +2. Check SourceMod is loaded: `sm version` +3. Check plugin errors: `sm plugins list` and look for "Failed" or "Error" +4. Check logs: `addons/sourcemod/logs/` + +### Database Connection Issues + +1. Verify MariaDB container is running: `docker ps` +2. Check database credentials in `databases.cfg` +3. Check Shavit logs: `addons/sourcemod/logs/shavit/` +4. Test connection: `sm_sql_query shavit "SELECT 1"` + +### Zones Not Loading / Map Has No Zones + +**Symptoms:** Map loads but no start/end zones, timer doesn't work + +**Solutions:** + +1. **Check if map is in surf-zones repository:** + - Visit: https://github.com/wrldspawn/surf-zones/tree/main/z + - Search for your map name (e.g., `surf_ski_2.json`) + - Not all maps have pre-made zones + +2. **Verify JSON zones are enabled:** + ``` + // In console + sm_cvar shavit_zones_usesql + // Should show: "shavit_zones_usesql" = "0" + ``` + +3. **Check zone loading errors:** + - Check `addons/sourcemod/logs/shavit/` + - Look for HTTP errors or JSON parsing failures + +4. **Create zones manually (if map not in repo):** + ``` + // In-game + !zones // Open zone editor + !start // Create start zone + !end // Create end zone + ``` + - Zones created in-game are saved to the database (not JSON) + +5. **Network connectivity:** + - Verify container can reach GitHub: `docker exec -it surf_megastructure-cssds-1 curl -I https://wrldspawn.github.io/` + - Check firewall/proxy settings + +**Note:** If a map doesn't exist in the surf-zones repository, you'll need to create zones manually using the in-game zone editor (`!zones`). These will be saved to your MariaDB database. + +### Server Won't Start + +1. Check logs: `docker-compose logs cssds` +2. Verify port 27015 is available +3. Check disk space for server files +4. Verify SteamCMD downloaded files successfully + +## Future Enhancements + +### Potential Additions + +- **FastDL** - Fast map download server (HTTP/Web server for map downloads) +- **SourceBans** - Web-based ban management system +- **Map rotation** - Automated map cycling configuration +- **GOTV** - Source TV for spectating/recording matches +- **Workshop maps** - Steam Workshop integration for map downloads +- **Backup system** - Automated database and config backups + +### Maintenance + +- Update plugin versions periodically +- Monitor Shavit GitHub for new releases +- Check for MetaMod/SourceMod updates +- Review server logs for errors or exploits + +## Credits + +- **Shavit BHopTimer** - [shavitush](https://github.com/shavitush/bhoptimer) +- **MomSurfFix** - [GAMMACASE](https://github.com/GAMMACASE/MomSurfFix) +- **PushFix DE** - [GAMMACASE](https://github.com/GAMMACASE/PushFixDE) +- **EventQueue Fix** - [hermansimensen](https://github.com/hermansimensen/eventqueue-fix) +- **RNGFix** - [jason-e](https://github.com/jason-e/rngfix) +- **MetaMod:Source** - [AlliedModders](https://www.metamodsource.net/) +- **SourceMod** - [AlliedModders](https://www.sourcemod.net/) + +## License + +This setup configuration is provided as-is. Individual components (Shavit, SourceMod, etc.) retain their original licenses. \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index d007410..9639939 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,6 +1,6 @@ services: cssds: - image: megastructure/cssds + image: registry.ntwl.xyz/megastructure-surf build: dockerfile: cssds.dockerfile @@ -11,7 +11,9 @@ services: env_file: - .env - command: sleep 5000000 + # command: sleep 5000000 + + network_mode: host ports: - "27015:27015" diff --git a/etc/cfg/server.cfg b/etc/cfg/server.cfg index 02343fc..ae347c1 100644 --- a/etc/cfg/server.cfg +++ b/etc/cfg/server.cfg @@ -1,66 +1,139 @@ +// ================================================================ +// megastructure.surf - CSS Surf Server Configuration +// ================================================================ + hostname "megastructure.surf" -// surf specific -sv_accelerate 10 -sv_airaccelerate 800 -mp_falldamage 0 -sv_enablebunnyhopping 1 -sv_autobunnyhopping 1 -sv_staminamax 0 -sv_staminajumpcost 0 -sv_staminalandcost 0 -sv_staminarecoveryrate 0 -sv_accelerate_use_weapon_speed 0 +// ================================================================ +// SURF PHYSICS - Critical settings for proper surf mechanics +// ================================================================ -// server stuff -sv_visiblemaxplayers 24 -mp_maxrounds 1 -host_framerate 0 -setpause 0 -sv_pure 0 -sv_pausable 0 -sv_lan 0 -sv_stats 1 +sv_gravity 800 // Default gravity (standard for surf) +sv_accelerate 10 // Ground acceleration +sv_airaccelerate 800 // Air acceleration (high for surf) +sv_friction 4 // Surface friction +sv_maxvelocity 3500 // Max velocity (can be changed per-map with !setmaxvel) -// Execute Banned Users // -exec banned_user.cfg -exec banned_ip.cfg -writeid -writeip +// Stamina (disable for surf) +sv_staminamax 0 // No stamina limit +sv_staminajumpcost 0 // No stamina cost for jumping +sv_staminalandcost 0 // No stamina cost for landing +sv_staminarecoveryrate 0 // No stamina recovery needed -// Contact & Region // -sv_contact ntr@megastructure.games -sv_region 5 +// Bunnyhopping +sv_enablebunnyhopping 1 // Enable bunnyhop +sv_autobunnyhopping 0 // Disable autobhop (hold space) - players must time jumps +sv_accelerate_use_weapon_speed 0 // Weapon weight doesn't affect acceleration -// Rcon Settings // -rcon_password changeme -sv_rcon_banpenalty 1440 -sv_rcon_maxfailures 5 +// Fall damage and movement +mp_falldamage 0 // No fall damage +phys_pushscale 1000 // Push force multiplier -// Log Settings // -log on -sv_log_onefile 0 -sv_logfile 1 -sv_logbans 1 -sv_logecho 1 +// ================================================================ +// GAME MODE SETTINGS +// ================================================================ -// Rate Settings // -fps_max 600 -sv_minrate 0 -sv_maxrate 20000 -sv_minupdaterate 66 -sv_maxupdaterate 66 +mp_teamplay 0 // Not team-based +mp_friendlyfire 0 // No friendly fire +mp_autoteambalance 0 // Don't force team balance +mp_limitteams 0 // No team limits +mp_freezetime 0 // No freeze time at round start +mp_roundtime 60 // 60 minute rounds (effectively infinite) +mp_maxrounds 1 // One continuous round +mp_timelimit 0 // No time limit +mp_winlimit 0 // No win limit -// Download Settings // -sv_allowupload 1 -sv_allowdownload 1 -net_maxfilesize 500 +// Respawn settings +mp_respawn_on_death_ct 1 // CT respawns instantly +mp_respawn_on_death_t 1 // T respawns instantly +mp_respawnwavetime_ct 0 // Instant respawn for CT +mp_respawnwavetime_t 0 // Instant respawn for T -sv_cheats 0 -sv_timeout 900 -mp_idlemaxtime 60 -mp_idledealmethod 2 +// ================================================================ +// SERVER SETTINGS +// ================================================================ -// Communications // -sv_voiceenable 1 -sv_alltalk 0 +sv_lan 0 // Internet server +sv_pure 0 // Allow custom files +sv_cheats 0 // No cheats +sv_pausable 0 // Can't pause +sv_alltalk 1 // Players can talk across teams (standard for surf) +sv_voiceenable 1 // Enable voice chat +sv_enableoldqueries 1 // Support legacy server queries +sv_contact "ntr@megastructure.games" // Admin contact +sv_region 5 // Region: Asia (0=US East, 1=US West, 2=South America, 3=Europe, 4=Asia, 5=Australia, 6=Middle East, 7=Africa) + +// Player settings +sv_visiblemaxplayers -1 // Show actual max players (-1 = use maxplayers) +mp_idlemaxtime 0 // No idle kick (let Shavit handle this) +mp_idledealmethod 0 // Don't deal with idle players +sv_timeout 900 // 15 minute timeout + +// ================================================================ +// RCON SETTINGS +// ================================================================ + +rcon_password "changeme" // CHANGE THIS! +sv_rcon_banpenalty 1440 // Ban for 24 hours after failed attempts +sv_rcon_maxfailures 5 // Max failed rcon attempts + +// ================================================================ +// NETWORK & RATE SETTINGS +// ================================================================ + +// Server rates +fps_max 600 // Server FPS limit (0 = unlimited, but 600 is good) +sv_mincmdrate 66 // Min client command rate +sv_maxcmdrate 128 // Max client command rate +sv_minupdaterate 66 // Min client update rate +sv_maxupdaterate 128 // Max client update rate +sv_minrate 20000 // Min client data rate (20KB/s) +sv_maxrate 0 // Max client data rate (0 = unlimited) + +// Network settings +net_maxfilesize 64 // Max download file size (MB) +sv_allowupload 1 // Allow uploads +sv_allowdownload 1 // Allow downloads +sv_downloadurl "" // FastDL URL (set this if you have FastDL) + +// ================================================================ +// BOT SETTINGS +// ================================================================ + +bot_quota 0 // No bots +bot_kick // Kick any existing bots + +// ================================================================ +// LOGGING +// ================================================================ + +log on // Enable logging +sv_logfile 1 // Log to file +sv_log_onefile 0 // Separate log files per map +sv_logbans 1 // Log bans +sv_logecho 0 // Don't echo logs to console (reduces spam) +sv_logflush 0 // Don't flush logs every line (better performance) + +// ================================================================ +// SOURCEMOD / METAMOD +// ================================================================ + +// These are loaded automatically via metamod/sourcemod +// No manual commands needed here + +// ================================================================ +// EXECUTE ADDITIONAL CONFIGS +// ================================================================ + +exec banned_user.cfg // Load banned users +exec banned_ip.cfg // Load banned IPs +writeid // Write user IDs +writeip // Write banned IPs + +// ================================================================ +// MESSAGES +// ================================================================ + +echo "==========================================" +echo "megastructure.surf loaded successfully" +echo "==========================================" diff --git a/etc/cssds.dockerfile b/etc/cssds.dockerfile index e4e876c..961c177 100644 --- a/etc/cssds.dockerfile +++ b/etc/cssds.dockerfile @@ -23,6 +23,8 @@ ENV CSSDS="/home/steam/cssds" ENV TF2DS="/home/steam/tf2ds" ENV STEAMCMD="/home/steam/steamcmd" ENV ETC="/home/steam/etc" +ENV METAMOD_VERSION=1.12 +ENV SOURCEMOD_VERSION=1.12 # ensure gamedirs exist and have been chowned to steam # before they potentially get setup as docker volumes @@ -35,8 +37,5 @@ FROM build AS steam USER steam WORKDIR /home/steam -ENV METAMOD_VERSION 1.12 -ENV SOURCEMOD_VERSION 1.12 - COPY . /home/steam/etc CMD ["bash", "./etc/run.sh"] \ No newline at end of file diff --git a/etc/mariadb.dockerfile b/etc/mariadb.dockerfile new file mode 100755 index 0000000..961c177 --- /dev/null +++ b/etc/mariadb.dockerfile @@ -0,0 +1,41 @@ +FROM cm2network/steamcmd AS build +LABEL maintainer="ntr@megastructure.games" + +EXPOSE 27015/tcp \ + 27015/udp \ + 27020/udp + +USER root +RUN apt-get update +RUN apt-get install -y \ + wget \ + ca-certificates \ + zlib1g \ + lib32gcc-s1 \ + libncurses5 \ + libbz2-1.0 \ + libtinfo5 \ + libcurl3-gnutls \ + unzip \ + rcon + +ENV CSSDS="/home/steam/cssds" +ENV TF2DS="/home/steam/tf2ds" +ENV STEAMCMD="/home/steam/steamcmd" +ENV ETC="/home/steam/etc" +ENV METAMOD_VERSION=1.12 +ENV SOURCEMOD_VERSION=1.12 + +# ensure gamedirs exist and have been chowned to steam +# before they potentially get setup as docker volumes +# which would otherwise cause them to be owned by root +RUN mkdir -p "$CSSDS" "$TF2DS" "$STEAMCMD" "$ETC" +RUN chown -R steam:steam /home/steam + +FROM build AS steam + +USER steam +WORKDIR /home/steam + +COPY . /home/steam/etc +CMD ["bash", "./etc/run.sh"] \ No newline at end of file diff --git a/etc/run.sh b/etc/run.sh index 0c70d30..8ab835b 100755 --- a/etc/run.sh +++ b/etc/run.sh @@ -47,24 +47,211 @@ install_sourcemod() { install_surf() { cd $CSTRIKE - if [ ! -d "$CSTRIKE/cfg/influx" ]; then - wget "https://influxtimer.com/dl/influx_2_surf.zip" - unzip "influx_2_surf.zip" - rm "influx_2_surf.zip" + # Install Shavit BHopTimer (replaces InfluxTimer) + if [ ! -d "$CSTRIKE/addons/sourcemod/configs/shavit" ]; then + wget "https://github.com/shavitush/bhoptimer/releases/download/v4.0.1/bhoptimer-v4.0.1.zip" + unzip "bhoptimer-v4.0.1.zip" + rm "bhoptimer-v4.0.1.zip" echo "--------------------------------------------------------------" - echo "Installed InfluxTimer" + echo "Installed Shavit BHopTimer v4.0.1" echo "--------------------------------------------------------------" fi - if [ ! -d "$CSTRIKE/addons/sourcemod/scripting/momsurffix" ]; then - wget "https://influxtimer.com/dl/influx_2_surf.zip" + # Install MomSurfFix + if [ ! -f "$CSTRIKE/addons/sourcemod/plugins/momsurffix2.smx" ]; then wget "https://github.com/GAMMACASE/MomSurfFix/releases/download/1.1.5/MomSurfFix2v1.1.5.zip" unzip "MomSurfFix2v1.1.5.zip" rm "MomSurfFix2v1.1.5.zip" echo "--------------------------------------------------------------" - echo "Installed MomSurfFix2v1.1.5" + echo "Installed MomSurfFix v1.1.5" echo "--------------------------------------------------------------" fi + + # Install PushFix Definitive Edition + if [ ! -f "$CSTRIKE/addons/sourcemod/plugins/pushfix_de.smx" ]; then + wget "https://github.com/GAMMACASE/PushFixDE/releases/download/1.0.0/pushfix_de_1.0.0.zip" + unzip "pushfix_de_1.0.0.zip" + rm "pushfix_de_1.0.0.zip" + echo "--------------------------------------------------------------" + echo "Installed PushFix Definitive Edition v1.0.0" + echo "--------------------------------------------------------------" + fi + + # Install EventQueue Fix + if [ ! -f "$CSTRIKE/addons/sourcemod/plugins/eventqueuefix.smx" ]; then + wget "https://github.com/hermansimensen/eventqueue-fix/releases/download/1.3.2/eventqueuefix-1.3.2.zip" + unzip "eventqueuefix-1.3.2.zip" + rm "eventqueuefix-1.3.2.zip" + echo "--------------------------------------------------------------" + echo "Installed EventQueue Fix v1.3.2" + echo "--------------------------------------------------------------" + fi + + # Install RNGFix + if [ ! -f "$CSTRIKE/addons/sourcemod/plugins/rngfix.smx" ]; then + wget "https://github.com/jason-e/rngfix/releases/download/v1.1.3/rngfix_1.1.3.zip" + unzip "rngfix_1.1.3.zip" + rm "rngfix_1.1.3.zip" + echo "--------------------------------------------------------------" + echo "Installed RNGFix v1.1.3" + echo "--------------------------------------------------------------" + fi +} + +configure_shavit_zones() { + cd $CSTRIKE + + # Check if already configured + if [ -f "$CSTRIKE/addons/sourcemod/configs/shavit-mapfixes.cfg" ]; then + echo "--------------------------------------------------------------" + echo "Shavit zones already configured" + echo "--------------------------------------------------------------" + return + fi + + echo "--------------------------------------------------------------" + echo "Configuring Shavit to use JSON zones from surf-zones repo" + echo "--------------------------------------------------------------" + + # Download surf-zones repository + cd /tmp + wget "https://github.com/wrldspawn/surf-zones/archive/refs/heads/main.zip" -O surf-zones.zip + unzip -q surf-zones.zip + + # Copy stripper directory + if [ -d "surf-zones-main/addons/stripper" ]; then + mkdir -p "$CSTRIKE/addons/stripper" + cp -r surf-zones-main/addons/stripper/* "$CSTRIKE/addons/stripper/" + echo "Copied stripper configurations" + fi + + # Copy mapfixes configuration + if [ -f "surf-zones-main/addons/sourcemod/configs/shavit-mapfixes.cfg" ]; then + mkdir -p "$CSTRIKE/addons/sourcemod/configs" + cp surf-zones-main/addons/sourcemod/configs/shavit-mapfixes.cfg "$CSTRIKE/addons/sourcemod/configs/" + echo "Copied shavit-mapfixes.cfg" + fi + + # Copy styles configuration (optional - removes irrelevant styles, matches KSF behavior) + if [ -f "surf-zones-main/addons/sourcemod/configs/shavit-styles.cfg" ]; then + cp surf-zones-main/addons/sourcemod/configs/shavit-styles.cfg "$CSTRIKE/addons/sourcemod/configs/" + echo "Copied shavit-styles.cfg" + fi + + # Cleanup + rm -rf surf-zones-main surf-zones.zip + + # Create cfg directory for plugin configs if it doesn't exist + mkdir -p "$CSTRIKE/cfg/sourcemod" + + # Configure zones plugin to use JSON instead of SQL + cat > "$CSTRIKE/cfg/sourcemod/plugin.shavit-zones.cfg" <<'EOF' +// Shavit Zones Plugin Configuration +// Set to 0 to use JSON zones instead of SQL database +shavit_zones_usesql "0" +EOF + + # Configure JSON zones URL + cat > "$CSTRIKE/cfg/sourcemod/plugin.shavit-zones-json.cfg" <<'EOF' +// Shavit JSON Zones Configuration +// URL template for loading zone data - {map} will be replaced with map name +shavit_zones_json_url "https://wrldspawn.github.io/surf-zones/z/{map}.json" +EOF + + echo "--------------------------------------------------------------" + echo "Configured Shavit to use JSON zones" + echo "JSON URL: https://wrldspawn.github.io/surf-zones/z/{map}.json" + echo "Note: Use !setmaxvel in-game to set max velocity per map" + echo "--------------------------------------------------------------" +} + +configure_shavit_database() { + cd $CSTRIKE + + # Check if database config already exists + if [ -f "$CSTRIKE/addons/sourcemod/configs/databases.cfg" ]; then + # Check if shavit database entry already exists + if grep -q '"shavit"' "$CSTRIKE/addons/sourcemod/configs/databases.cfg"; then + echo "--------------------------------------------------------------" + echo "Shavit database already configured" + echo "--------------------------------------------------------------" + return + fi + fi + + echo "--------------------------------------------------------------" + echo "Configuring Shavit database connection" + echo "--------------------------------------------------------------" + + # Set defaults if environment variables are not set + DB_HOST="${MYSQL_HOST:-mariadb}" + DB_PORT="${MYSQL_PORT:-3306}" + DB_NAME="${MYSQL_DATABASE:-shavit}" + DB_USER="${MYSQL_USER:-root}" + DB_PASS="${MYSQL_ROOT_PASSWORD:-changeme}" + + # Create or append to databases.cfg + mkdir -p "$CSTRIKE/addons/sourcemod/configs" + + # If databases.cfg doesn't exist, create it with full structure + if [ ! -f "$CSTRIKE/addons/sourcemod/configs/databases.cfg" ]; then + cat > "$CSTRIKE/addons/sourcemod/configs/databases.cfg" <> "$CSTRIKE/addons/sourcemod/configs/databases.cfg" <