Skip to content

Commit

Permalink
feat: Support alpine client :^)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amund211 committed Jan 6, 2025
1 parent e63ae3e commit 0c29bbc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/prism/overlay/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"INFO]: [LC] ", # Lunar client
"[Render thread/INFO]: ", # Fabric 1.20
"[Client thread/INFO]: [LC] ", # New lunar
"[Client thread/INFO] [Alpine Client/]: ", # Alpine
)

# Vanilla and forge
Expand All @@ -60,6 +61,12 @@
"[Astolfo HTTP Bridge]: [CHAT] ",
)

# This client likes to include a bunch of random characters in it's prefix
ALPINE_CHAT_PREFIX_REGEX = re.compile(
r"\[Client thread\/INFO\] \[alpine ?client.*\]: \[CHAT\] ",
flags=re.IGNORECASE,
)


def strip_until(line: str, *, until: str) -> str:
"""
Expand Down Expand Up @@ -131,6 +138,13 @@ def parse_logline(logline: str) -> Event | None:
if chat_prefix is not None:
return parse_chat_message(strip_until(logline, until=chat_prefix))

# Special case for alpine
if "alpine" in logline.lower() and (
alpine_match := ALPINE_CHAT_PREFIX_REGEX.search(logline)
):
# "[Client thread/INFO] [alpineclient.xxxxx/]: [CHAT] Player1 ...
return parse_chat_message(strip_until(logline, until=alpine_match.group()))

# Horrible special case
NETTY_CLIENT_FRAGMENT = "[Netty Client IO #"
NETTY_CHAT_FRAGMENT = "/INFO]: [CHAT] "
Expand Down Expand Up @@ -161,6 +175,23 @@ def parse_client_info(info: str) -> ClientEvent | None:
username = strip_until(info, until=SETTING_USER_PREFIX)
return InitializeAsEvent(username)

ALPINE_SETTING_USER_PREFIX = "Setting account (name="
if info.startswith(ALPINE_SETTING_USER_PREFIX):
logger.debug("Processing alpine setting user message")
username_and_suffix = strip_until(info, until=ALPINE_SETTING_USER_PREFIX)

comma_index = username_and_suffix.find(",")
if comma_index == -1:
logger.debug("No comma found in alpine setting user message")
return None

username = username_and_suffix[:comma_index]
if not valid_username(username):
logger.debug(f"Invalid username in alpine setting user message {username}")
return None

return InitializeAsEvent(username)

return None


Expand Down
16 changes: 16 additions & 0 deletions tests/prism/overlay/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ def test_remove_deduplication_suffix(message: str, result: str) -> None:
"[15:03:53] [Client thread/INFO]: [CHAT] Can't find a player by the name of '!somewierdcommand'", # Unknown command
"[15:03:53] [Client thread/INFO]: [CHAT] Can't find a player by the name of '!", # Empty/malformed
"[15:03:53] [Client thread/INFO]: [CHAT] Can't find a player by the name of '!a=b=c'", # Too many arguments to setnick
# Malformed alpine set user
"[17:19:24] [Client thread/INFO] [Alpine Client/]: Setting account (name=Player1)",
"[17:19:24] [Client thread/INFO] [Alpine Client/]: Setting account (name=?, uuid=337482fe-8a15-47f6-bea5-a84918a86393)",
# Attempts to inject final kill messages
"[00:03:18] [Client thread/INFO]: [CHAT] §9Party §8> §b[MVP§3+§b] Player1§f: Player2 was spooked off the map by Player3. FINAL KILL!",
"[20:44:24] [Client thread/INFO]: [CHAT] §4[651✫] §b[MVP§3+§b] Player1§f: Player2 was spooked off the map by Player3. FINAL KILL!",
Expand Down Expand Up @@ -446,6 +449,11 @@ def test_remove_deduplication_suffix(message: str, result: str) -> None:
"[18:52:20] [Client thread/INFO]: Setting user: Player1",
InitializeAsEvent("Player1"),
),
(
# Initialize as on alpine client
"[17:19:24] [Client thread/INFO] [Alpine Client/]: Setting account (name=Player1, uuid=337482fe-8a15-47f6-bea5-a84918a86393)",
InitializeAsEvent("Player1"),
),
(
"[Info: 2021-11-29 22:30:40.455294561: GameCallbacks.cpp(162)] Game/net.minecraft.client.gui.GuiNewChat (Client thread) Info [CHAT] ONLINE: Player1, Player2, Player3, Player5, Player6, Player7, Player8, Player9",
LobbyListEvent(
Expand Down Expand Up @@ -774,6 +782,14 @@ def test_remove_deduplication_suffix(message: str, result: str) -> None:
raw_message="Player1 was Player2's final #1,234. FINAL KILL!",
),
),
(
# Final kill on alpine client
"[17:26:11] [Client thread/INFO] [alpineclient.lIlllIllIIllIIIIIIIIIlllIIIIIIlIllIlIIIl/]: [CHAT] Player1 was buzzed to death by Player2. FINAL KILL!",
BedwarsFinalKillEvent(
dead_player="Player1",
raw_message="Player1 was buzzed to death by Player2. FINAL KILL!",
),
),
(
"[00:26:36] [Client thread/INFO]: [CHAT] Player1 disconnected.",
BedwarsDisconnectEvent(username="Player1"),
Expand Down

0 comments on commit 0c29bbc

Please sign in to comment.