Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.8.1
1.8.2
30 changes: 29 additions & 1 deletion src/torchlight/PlayerManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from torchlight.AudioManager import AudioManager
from torchlight.Constants import Clients
from torchlight.Player import Player
from torchlight.Sourcemod import SourcemodConfig
from torchlight.Sourcemod import SourcemodAdmin, SourcemodConfig
from torchlight.Torchlight import Torchlight


Expand Down Expand Up @@ -176,3 +176,31 @@ def FindName(self, name: str) -> Player | None:
if player and player.name == name:
return player
return None

@staticmethod
def create_console_player() -> Player:
player = Player(
0,
0,
"[CONSOLE]",
"127.0.0.1",
"CONSOLE",
)
player.admin = SourcemodAdmin(
name="CONSOLE",
unique_id=player.unique_id,
level=100,
flag_bits=0,
groups=[],
)
player.storage = dict(
{
"Audio": {
"Uses": 0,
"LastUse": 0.0,
"LastUseLength": 0.0,
"TimeUsed": 0.0,
}
}
)
return player
2 changes: 1 addition & 1 deletion src/torchlight/SourceModAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async def _MakeCall(self, function: str, *args: Any, **kwargs: Any) -> dict[str,
if isinstance(res_raw, dict):
res = res_raw

if res["error"]:
if "error" in res and res["error"]:
raise Exception("{}({})\n{}".format(function, args, res["error"]))

return res
29 changes: 3 additions & 26 deletions src/torchlight/SourceRCONClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from typing import Any

from torchlight.CommandHandler import CommandHandler
from torchlight.Player import Player
from torchlight.Sourcemod import SourcemodAdmin
from torchlight.PlayerManager import PlayerManager


class SourceRCONClient:
Expand Down Expand Up @@ -73,29 +72,7 @@ def ParsePacket(self, data_raw: bytes) -> None:
if data:
data = data.strip('"')
self.logger.info(sys._getframe().f_code.co_name + f' Exec: "{data}"')
player = Player(
0,
0,
"[CONSOLE]",
"127.0.0.1",
"CONSOLE",
)
player.admin = SourcemodAdmin(
name="CONSOLE",
unique_id=player.unique_id,
level=100,
flag_bits=0,
groups=[],
)
player.storage = dict(
{
"Audio": {
"Uses": 0,
"LastUse": 0.0,
"LastUseLength": 0.0,
"TimeUsed": 0.0,
}
}
)

player = PlayerManager.create_console_player()
asyncio.Task(self.command_handler.HandleCommand(data, player))
# self.p_send(p_id, 0, self._server.torchlight.GetLine())
3 changes: 3 additions & 0 deletions src/torchlight/Torchlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def SayChat(self, message: str, player: Player | None = None) -> None:

# @profile
def SayPrivate(self, player: Player, message: str) -> None:
if player.index == 0:
return

message = f"{{darkblue}}[Torchlight]: {{default}}{message}"
if len(message) > 976:
message = message[:973] + "..."
Expand Down
19 changes: 19 additions & 0 deletions src/torchlight/cli.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
import asyncio
import logging
import signal
import sys
from types import FrameType

import click

from torchlight.Config import Config
from torchlight.PlayerManager import PlayerManager
from torchlight.SourceRCONServer import SourceRCONServer
from torchlight.TorchlightHandler import TorchlightHandler

logger = logging.getLogger(__name__)


torchlight_handler: TorchlightHandler | None = None


def graceful_shutdown(signal: int, frame: FrameType | None) -> None:
if torchlight_handler and torchlight_handler.audio_manager:
logger.info("Stopping all audio sounds")
player = PlayerManager.create_console_player()
torchlight_handler.audio_manager.Stop(player, "")
sys.exit(0)


@click.command()
@click.option("--config-folder", default="config", help="Configuration folder path.")
@click.version_option()
Expand All @@ -23,8 +38,12 @@ def cli(config_folder: str) -> None:
datefmt=config["Logging"]["datefmt"],
)

signal.signal(signal.SIGINT, graceful_shutdown)
signal.signal(signal.SIGTERM, graceful_shutdown)

event_loop = asyncio.get_event_loop()

global torchlight_handler
torchlight_handler = TorchlightHandler(event_loop, config)

# Handles new connections on 0.0.0.0:27015
Expand Down