lloesche / valheim-server-docker

Valheim dedicated gameserver with automatic update, World backup, BepInEx and ValheimPlus mod support
https://hub.docker.com/r/lloesche/valheim-server
Apache License 2.0
1.94k stars 272 forks source link

Spawned player example does not work properly #455

Open elonmir opened 2 years ago

elonmir commented 2 years ago

ENV File:

VALHEIM_LOG_FILTER_CONTAINS_Spawned=Got character ZDOID from
ON_VALHEIM_LOG_FILTER_CONTAINS_Spawned={ read l; l=${l//*ZDOID from /}; l=${l// :*/}; msg="[Helheim] Player $l spawned into the world"; curl -sfSL -X POST -H "Content-Type: application/json" -d "{\"username\":\"Valheim Server\",\"content\":\"$msg\"}" "$DISCORD_WEBHOOK"; }

Logs:

valheim_1 | Feb 21 12:16:36 /supervisord: valheim-server 02/21/2022 12:16:36: Got character ZDOID from Elonmir : -982226279:1

Current behaviour in discord:

image

Expected behaviour in discord:

[Helheim] Player Elonmir spawned into the world

schildbach commented 1 year ago

I've got the same issue. It started a while ago, maybe around start of this year. I tried both CONTAINS and REGEXP versions:

VALHEIM_LOG_FILTER_CONTAINS_Spawned=Got character ZDOID from
ON_VALHEIM_LOG_FILTER_CONTAINS_Spawned=read l; l=${l//*ZDOID from /}; l=${l// :*/}; curl -sfS -XPUT -d "{\"msgtype\":\"m.notice\",\"body\":\"$l spawned\"}" "$MATRIX_BOT_SERVER/_matrix/client/r0/rooms/$MATRIX_BOT_ROOM_ID/send/m.room.message/$(date +%s-%N)?access_token=$MATRIX_BOT_ACCESS_TOKEN"
VALHEIM_LOG_FILTER_REGEXP_Spawned=\bGot character ZDOID from \b\w*\b : [^0]\d*:[^0]\b
ON_VALHEIM_LOG_FILTER_REGEXP_Spawned=read l; l=${l//*ZDOID from /}; MESSAGE_CHARACTER=${l// :*/}; curl -sfS -XPUT -d "{\"msgtype\":\"m.notice\",\"body\":\"${MESSAGE_CHARACTER} spawned\"}" "$MATRIX_BOT_SERVER/_matrix/client/r0/rooms/$MATRIX_BOT_ROOM_ID/send/m.room.message/$(date +%s-%N)?access_token=$MATRIX_BOT_ACCESS_TOKEN"

and the messages I get are always missing the player name, similar to the screenshot above.

Symphy24 commented 1 year ago

I'm having a similar issue. When i use the exact same lines in my .env file i can't compile the docker-compose.yml file. I have tried all the variations of this code I could find on this github page. I get the following errors:

WARN[0000] The "l" variable is not set. Defaulting to a blank string. 
WARN[0000] The "msg" variable is not set. Defaulting to a blank string. 
Invalid template: "{ read l; l=${l//*ZDOID from /}; l=${l// :*/}; msg=\"[Helheim] Player $l spawned into the world\"; curl -sfSL -X POST -H \"Content-Type: application/json\" -d \"{\\\"username\\\":\\\"Valheim Server\\\",\\\"content\\\":\\\"$msg\\\"}\" \"$DISCORD_WEBHOOK\"; }"

My compose file:

version: '3.7'
services:

# Valheim Server
  valheim:
    image: lloesche/valheim-server
    container_name: valheim-server
    cap_add:
      - sys_nice
    volumes:
      - /root/Valheim-server/config:/config
      - /root/Valheim-server/data:/opt/valheim
    ports:
      - 2456-2457:2456-2457/udp
      - 9001:9001/tcp
    network_mode: host
    env_file:
      - /root/Valheim-server/valheim.env
    restart: always
    stop_grace_period: 2m

Does this have anything to do with the version 3.7 of my compose file?

NubemInvidia commented 1 year ago

@Symphy24 >

I am also running into this issue, did you figure it out?

caseodilla commented 1 year ago

Same problem here, too. I feel like I've tried every suggested fix, but it always returns a blank string for $l.

I'm using docker-compose and setting the environment variables in an env_file.

VALHEIM_LOG_FILTER_CONTAINS_ConnectedSteam=Got connection SteamID ON_VALHEIM_LOG_FILTER_CONTAINS_ConnectedSteam=read l; l=${l//*SteamID /}; msg="$l logged on"; curl...

I've tried ...ConnectedSteam='{read l... to the same result.

Edit: After more troubleshooting, I've determined that $l does pass in the full string properly, e.g. 01/24/2023 02:08:33: Got connection SteamID 7656..., but it's after the step of l=${l//*SteamID /}; where the string becomes empty.

Kirbo commented 1 year ago

I got it working with a workaround/hack such as this:

VALHEIM_LOG_FILTER_CONTAINS_Spawned=Got character ZDOID from
ON_VALHEIM_LOG_FILTER_CONTAINS_Spawned={ cat > /tmp/character_login && curl -sfSL -X POST -H "Content-Type: application/json" -d "{\"username\":\"Valheim\",\"content\":\"Player $(cat /tmp/character_login | sed -e 's/.* ZDOID from \(.*\) : .*/\1/') spawned into the world\"}" "$DISCORD_WEBHOOK"; }

image

mc12d commented 1 year ago

@Kirbo Thanks for sharing! Saved me from learning sed/awk again..