Page 1 of 1

Restart match. Interaction with websockets.

Posted: Mon May 14, 2018 12:44 pm
by battleweaver
Hi, guys!
My goal is restarting a match/round with certain parameters automatically. The command is to be given somewhere outside my server.
I tried websocket communication through lomond library.

Syntax: Select all

import json

from filters.players import PlayerIter
from lomond import WebSocket # pip install lomond

from cvars import ConVar
from messages import SayText2
from simple_settings import settings

from .utils import sdm_logger

WEBSOCKET_URL = 'wss://echo.websocket.org'
websocket = WebSocket(WEBSOCKET_URL)


def do_restart():
for player in PlayerIter('human'):
SayText2(f'WOW!!! RESTART MESSAGE CAME!!!').send(player.index)
print('!!!!!!!!! websocket message recieved !!!!!!!')
for event in websocket:
print(event)
if event.name == 'text':
response = json.loads(event.text)
if type(response) is dict \
and response.get('action') == 'restart' \
and response.get('server') == ConVar('hostname').get_string():
do_restart()

Establishing connection works fine. The bad thing is that lomond library coroutine stops any other CS:GO server process. CS:GO server thinks, that an infinite loop occured and reboots itself.
Is there any way to alter communication with websocket or is there any way to recieve such command outside? Thinking of requests library approach, but maybe any other option available?

Re: Restart match. Interaction with websockets.

Posted: Mon May 14, 2018 1:57 pm
by Ayuto
You need to create a new thread for that. Ideally, you use our GameThread class. It's a subclass of threading.Thread with a little addition that prints a warning if your plugin is unloaded while the thread is still running.