Restart match. Interaction with websockets.

Please post any questions about developing your plugin here. Please use the search function before posting!
Posts: 43
Joined: Mon Oct 02, 2017 7:57 am
Location: Moscow

Restart match. Interaction with websockets.

Postby battleweaver » Mon May 14, 2018 12:44 pm

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://'
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:
if == 'text':
response = json.loads(event.text)
if type(response) is dict \
and response.get('action') == 'restart' \
and response.get('server') == ConVar('hostname').get_string():

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?
User avatar
Project Leader
Posts: 1920
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Restart match. Interaction with websockets.

Postby Ayuto » Mon May 14, 2018 1:57 pm

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.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 6 guests