Skip to content

Commit

Permalink
Merge pull request #41 from startersclan/enhancement/add-cs2-support
Browse files Browse the repository at this point in the history
Enhancement: Add CS2 support
  • Loading branch information
leojonathanoh committed Dec 6, 2023
2 parents 683c762 + 76520fc commit 16289aa
Show file tree
Hide file tree
Showing 516 changed files with 819 additions and 172 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Edition uses a Perl daemon to parse the log streamed from the
game server. The data is stored in a MySQL Database and has
a PHP frontend.

Counter-Strike 2 is supported (mostly).

## :loudspeaker: Important changes

| Date | Description | Additional information |
Expand All @@ -37,14 +39,14 @@ a PHP frontend.
`web` image (See [./src/web/config.php](./src/web/config.php) for supported environment variables):

```sh
docker run --rm -it -e DB_ADDR=db -e DB_NAME=hlstatsxce -e DB_USER=hlstatsxce -e DB_PASS=hlstatsxce -p 80:80 startersclan/hlstatsx-community-edition:1.10.0-web
docker run --rm -it -e DB_ADDR=db -e DB_NAME=hlstatsxce -e DB_USER=hlstatsxce -e DB_PASS=hlstatsxce -p 80:80 startersclan/hlstatsx-community-edition:1.11.0-web
```

`daemon` image:

```sh
# Use --help for usage
docker run --rm -it -p 27500:27500/udp startersclan/hlstatsx-community-edition:1.10.0-daemon --db-host=db:3306 --db-name=hlstatsxce --db-username=hlstatsxce --db-password=hlstatsxce #--help
docker run --rm -it -p 27500:27500/udp startersclan/hlstatsx-community-edition:1.11.0-daemon --db-host=db:3306 --db-name=hlstatsxce --db-username=hlstatsxce --db-password=hlstatsxce #--help
```

### Docker Compose
Expand Down Expand Up @@ -91,7 +93,7 @@ docker-compose restart daemon

# 3. Finally, add a Counter-Strike 1.6 server. click Games > and unhide 'cstrike' game.
# Then, click Game Settings > Counter-Strike (cstrike) > Add Server.
# IP: 192.168.1.100
# IP: 10.5.0.100
# Port: 27015
# Name: My Counter-Strike 1.6 server
# Rcon Password: password
Expand Down Expand Up @@ -148,8 +150,8 @@ docker-compose down

# Cleanup
docker-compose down
docker volume rm hlstatsx-community-edition-dns-volume
docker volume rm hlstatsx-community-edition-db-volume
docker volume rm hlstatsx-community-edition_dns-volume
docker volume rm hlstatsx-community-edition_db-volume
```

## Release
Expand Down
102 changes: 66 additions & 36 deletions docker-compose.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,58 +9,83 @@ services:
ports:
- 27015:27015/udp
networks:
- default
default:
ipv4_address: 10.5.0.100 # Static IP
stdin_open: true
tty: true
stop_signal: SIGKILL
depends_on:
- source-udp-forwarder
entrypoint:
- /bin/bash
command:
- -c
- |
set -eu
exec hlds_linux -console -noipx -secure -game cstrike +map de_dust2 +maxplayers 32 +sv_lan 0 +ip 0.0.0.0 +port 27015 +rcon_password password +log on +logaddress_add "$$( cat /dns/source-udp-forwarder )" 26999
exec hlds_linux -console -noipx -secure -game cstrike +map de_dust2 +maxplayers 32 +sv_lan 0 +ip 0.0.0.0 +port 27015 +rcon_password password +log on +logaddress_add 10.5.0.50 27500
# Uncomment to test CS2
# 1. Counter-Strike 2 gameserver sends HTTP logs to source-udp-forwarder
# See: https://github.com/startersclan/docker-sourceservers
# cs2:
# image: sourceservers/cs2:latest
# volumes:
# - dns-volume:/dns:ro
# ports:
# - 27016:27016/tcp
# - 27016:27016/udp
# networks:
# default:
# ipv4_address: 10.5.0.101 # Static IP
# stdin_open: true
# tty: true
# stop_signal: SIGKILL
# depends_on:
# - source-udp-forwarder-cs2
# entrypoint:
# - /bin/bash
# command:
# - -c
# - |
# set -eu
# exec game/bin/linuxsteamrt64/cs2 -dedicated -port 27016 +game_type 0 +game_mode 1 +mapgroup mg_active +map de_dust2 +rcon_password password +log on +logaddress_add_http "http://source-udp-forwarder-cs2:26999"

# Uncomment to test CS2
# 2. source-udp-forwarder proxy forwards gameserver logs to the daemon
# See: https://github.com/startersclan/source-udp-forwarder
source-udp-forwarder:
image: startersclan/source-udp-forwarder:latest
environment:
- UDP_LISTEN_ADDR=:26999
- UDP_FORWARD_ADDR=daemon:27500
- FORWARD_PROXY_KEY=somedaemonsecret # The daemon's proxy_key secret
- FORWARD_GAMESERVER_IP=192.168.1.100 # The gameserver's IP as registered in the HLStatsX:CE database
- FORWARD_GAMESERVER_PORT=27015 # The gameserver's IP as registered in the HLStatsX:CE database
- LOG_LEVEL=INFO
- LOG_FORMAT=txt
volumes:
- dns-volume:/dns
networks:
- default
depends_on:
- daemon
entrypoint:
- /bin/sh
command:
- -c
- |
set -eu
echo "Outputting my IP address"
ip addr show eth0 | grep 'inet ' | awk '{print $$2}' | cut -d '/' -f1 | tee /dns/source-udp-forwarder
exec /source-udp-forwarder
# source-udp-forwarder-cs2:
# image: startersclan/source-udp-forwarder:latest
# environment:
# - LISTEN_ADDR=:26999
# - UDP_FORWARD_ADDR=daemon:27500
# - FORWARD_PROXY_KEY=somedaemonsecret # The daemon's proxy_key secret
# - FORWARD_GAMESERVER_IP=10.5.0.101 # The gameserver's IP as registered in the HLStatsX:CE database
# - FORWARD_GAMESERVER_PORT=27016 # The gameserver's IP as registered in the HLStatsX:CE database
# - LOG_LEVEL=INFO
# - LOG_FORMAT=txt
# volumes:
# - dns-volume:/dns
# networks:
# - default
# depends_on:
# - daemon
# entrypoint:
# - /bin/sh
# command:
# - -c
# - |
# set -eu
# echo "Outputting my IP address"
# ip addr show eth0 | grep 'inet ' | awk '{print $$2}' | cut -d '/' -f1 | tee /dns/source-udp-forwarder-cs2
# exec /source-udp-forwarder

# 3. HLStatsX:CE perl daemon accepts the gameserver logs. Gameserver Logs are parsed and stats are recorded
# The daemon's proxy_key secret can only be setup in the HLStatsX:CE Web Admin Panel Settings under 'Proxy Settings' section
daemon:
image: startersclan/hlstatsx-community-edition:1.10.0-daemon
image: startersclan/hlstatsx-community-edition:1.11.0-daemon
ports:
- 27500:27500/udp # For external servers to send logs to the daemon
networks:
- default
default:
ipv4_address: 10.5.0.50 # Static IP
depends_on:
- db
command:
Expand All @@ -77,7 +102,7 @@ services:

# Cron - awards
awards:
image: startersclan/hlstatsx-community-edition:1.10.0-daemon
image: startersclan/hlstatsx-community-edition:1.11.0-daemon
stop_signal: SIGKILL
entrypoint:
- /bin/sh
Expand Down Expand Up @@ -124,7 +149,7 @@ services:
# Available at http://localhost:8081, or https://web.example.com
# Admin Panel username: admin, password: 123456
web:
image: startersclan/hlstatsx-community-edition:1.10.0-web
image: startersclan/hlstatsx-community-edition:1.11.0-web
labels:
- "traefik.enable=true"
- "traefik.docker.network=hlstatsx-community-edition_traefik-network"
Expand Down Expand Up @@ -158,7 +183,7 @@ services:

# Cron - Heatmaps
heatmaps:
image: startersclan/hlstatsx-community-edition:1.10.0-web
image: startersclan/hlstatsx-community-edition:1.11.0-web
volumes:
- games-volume:/web/hlstatsimg/games # Stateful games volume, which also contains heatmaps
environment:
Expand Down Expand Up @@ -267,6 +292,11 @@ services:

networks:
default:
driver: bridge
ipam:
config:
- subnet: 10.5.0.0/16
gateway: 10.5.0.1
traefik-public-network:
traefik-network:
internal: true
Expand Down
96 changes: 63 additions & 33 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,73 @@ services:
ports:
- 27015:27015/udp
networks:
- default
default:
ipv4_address: 10.5.0.100 # Static IP
stdin_open: true
tty: true
stop_signal: SIGKILL
depends_on:
- source-udp-forwarder
entrypoint:
- /bin/bash
command:
- -c
- |
set -eu
exec hlds_linux -console -noipx -secure -game cstrike +map de_dust2 +maxplayers 32 +sv_lan 0 +ip 0.0.0.0 +port 27015 +rcon_password password +log on +logaddress_add "$$( cat /dns/source-udp-forwarder )" 26999
exec hlds_linux -console -noipx -secure -game cstrike +map de_dust2 +maxplayers 32 +sv_lan 0 +ip 0.0.0.0 +port 27015 +rcon_password password +log on +logaddress_add 10.5.0.50 27500
# Uncomment to test CS2
# 1. Counter-Strike 2 gameserver sends HTTP logs to source-udp-forwarder
# See: https://github.com/startersclan/docker-sourceservers
# cs2:
# image: sourceservers/cs2:latest
# volumes:
# - dns-volume:/dns:ro
# ports:
# - 27016:27016/tcp
# - 27016:27016/udp
# networks:
# default:
# ipv4_address: 10.5.0.101 # Static IP
# stdin_open: true
# tty: true
# stop_signal: SIGKILL
# depends_on:
# - source-udp-forwarder-cs2
# entrypoint:
# - /bin/bash
# command:
# - -c
# - |
# set -eu
# exec game/bin/linuxsteamrt64/cs2 -dedicated -port 27016 +game_type 0 +game_mode 1 +mapgroup mg_active +map de_dust2 +rcon_password password +log on +logaddress_add_http "http://source-udp-forwarder-cs2:26999"

# Uncomment to test CS2
# 2. source-udp-forwarder proxy forwards gameserver logs to the daemon
# See: https://github.com/startersclan/source-udp-forwarder
source-udp-forwarder:
image: startersclan/source-udp-forwarder:latest
environment:
- UDP_LISTEN_ADDR=:26999
- UDP_FORWARD_ADDR=daemon:27500
- FORWARD_PROXY_KEY=somedaemonsecret # The daemon's proxy_key secret
- FORWARD_GAMESERVER_IP=192.168.1.100 # The gameserver's IP as registered in the HLStatsX:CE database
- FORWARD_GAMESERVER_PORT=27015 # The gameserver's IP as registered in the HLStatsX:CE database
- LOG_LEVEL=INFO
- LOG_FORMAT=txt
volumes:
- dns-volume:/dns
networks:
- default
depends_on:
- daemon
entrypoint:
- /bin/sh
command:
- -c
- |
set -eu
echo "Outputting my IP address"
ip addr show eth0 | grep 'inet ' | awk '{print $$2}' | cut -d '/' -f1 | tee /dns/source-udp-forwarder
exec /source-udp-forwarder
# source-udp-forwarder-cs2:
# image: startersclan/source-udp-forwarder:latest
# environment:
# - LISTEN_ADDR=:26999
# - UDP_FORWARD_ADDR=daemon:27500
# - FORWARD_PROXY_KEY=somedaemonsecret # The daemon's proxy_key secret
# - FORWARD_GAMESERVER_IP=10.5.0.101 # The gameserver's IP as registered in the HLStatsX:CE database
# - FORWARD_GAMESERVER_PORT=27016 # The gameserver's IP as registered in the HLStatsX:CE database
# - LOG_LEVEL=INFO
# - LOG_FORMAT=txt
# volumes:
# - dns-volume:/dns
# networks:
# - default
# depends_on:
# - daemon
# entrypoint:
# - /bin/sh
# command:
# - -c
# - |
# set -eu
# echo "Outputting my IP address"
# ip addr show eth0 | grep 'inet ' | awk '{print $$2}' | cut -d '/' -f1 | tee /dns/source-udp-forwarder-cs2
# exec /source-udp-forwarder

# 3. HLStatsX:CE perl daemon accepts the gameserver logs. Gameserver Logs are parsed and stats are recorded
# The daemon's proxy_key secret can only be setup in the HLStatsX:CE Web Admin Panel Settings under 'Proxy Settings' section
Expand All @@ -63,7 +87,8 @@ services:
ports:
- 27500:27500/udp # For external servers to send logs to the daemon
networks:
- default
default:
ipv4_address: 10.5.0.50 # Static IP
depends_on:
- db
command:
Expand Down Expand Up @@ -122,7 +147,7 @@ services:
- MYSQL_DATABASE=hlstatsxce
volumes:
- db-volume:/var/lib/mysql
- ./src/sql/install.sql:/docker-entrypoint-initdb.d/install.sql:ro # This seeds the DB only on the first time
- ./src/sql/install.sql:/docker-entrypoint-initdb.d/01-install.sql:ro # This seeds the DB only on the first time
networks:
- default

Expand Down Expand Up @@ -241,6 +266,11 @@ services:
networks:
default:
driver: bridge
ipam:
config:
- subnet: 10.5.0.0/16
gateway: 10.5.0.1

volumes:
dns-volume:
Expand Down
5 changes: 5 additions & 0 deletions src/scripts/HLstats_EventHandlers.plib
Original file line number Diff line number Diff line change
Expand Up @@ -2856,6 +2856,11 @@ sub doEvent_ChangeMap
{
my ($type, $newmap) = @_;

if ($newmap) {
# CS2 does not log 'Started map' event, but 'Loading map' event before it should have populated $newmap already
$g_servers{$s_addr}->set("map", $newmap);
}

$g_servers{$s_addr}->set("map", $newmap);
$g_servers{$s_addr}->clear_winner();

Expand Down
2 changes: 2 additions & 0 deletions src/scripts/HLstats_GameConstants.plib
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use constant {
NUCLEARDAWN => 23,
DDD => 24,
CSGO => 25,
CS2 => 26,
};

%gamecode_to_game = (
Expand Down Expand Up @@ -55,4 +56,5 @@ use constant {
'nucleardawn' => NUCLEARDAWN(),
'dinodday' => DDD(),
'csgo' => CSGO(),
'cs2' => CS2(),
);
Loading

0 comments on commit 16289aa

Please sign in to comment.