I knew a threaded bancho server was going to be a bad idea...
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import copy
|
||||
import json
|
||||
import threading
|
||||
from common.log import logUtils as log
|
||||
from constants import dataTypes
|
||||
from constants import matchModModes
|
||||
@@ -60,6 +61,7 @@ class match:
|
||||
self.isTourney = isTourney
|
||||
self.isLocked = False # if True, users can't change slots/teams. Used in tourney matches
|
||||
self.isStarting = False
|
||||
self._lock = threading.Lock()
|
||||
|
||||
# Create all slots and reset them
|
||||
self.slots = []
|
||||
@@ -83,55 +85,55 @@ class match:
|
||||
"""
|
||||
# General match info
|
||||
# TODO: Test without safe copy, the error might have been caused by outdated python bytecode cache
|
||||
safeMatch = copy.deepcopy(self)
|
||||
# safeMatch = copy.deepcopy(self)
|
||||
struct = [
|
||||
[safeMatch.matchID, dataTypes.UINT16],
|
||||
[int(safeMatch.inProgress), dataTypes.BYTE],
|
||||
[self.matchID, dataTypes.UINT16],
|
||||
[int(self.inProgress), dataTypes.BYTE],
|
||||
[0, dataTypes.BYTE],
|
||||
[safeMatch.mods, dataTypes.UINT32],
|
||||
[safeMatch.matchName, dataTypes.STRING]
|
||||
[self.mods, dataTypes.UINT32],
|
||||
[self.matchName, dataTypes.STRING]
|
||||
]
|
||||
if censored and safeMatch.matchPassword:
|
||||
if censored and self.matchPassword:
|
||||
struct.append(["redacted", dataTypes.STRING])
|
||||
else:
|
||||
struct.append([safeMatch.matchPassword, dataTypes.STRING])
|
||||
struct.append([self.matchPassword, dataTypes.STRING])
|
||||
|
||||
struct.extend([
|
||||
[safeMatch.beatmapName, dataTypes.STRING],
|
||||
[safeMatch.beatmapID, dataTypes.UINT32],
|
||||
[safeMatch.beatmapMD5, dataTypes.STRING]
|
||||
[self.beatmapName, dataTypes.STRING],
|
||||
[self.beatmapID, dataTypes.UINT32],
|
||||
[self.beatmapMD5, dataTypes.STRING]
|
||||
])
|
||||
|
||||
# Slots status IDs, always 16 elements
|
||||
for i in range(0,16):
|
||||
struct.append([safeMatch.slots[i].status, dataTypes.BYTE])
|
||||
struct.append([self.slots[i].status, dataTypes.BYTE])
|
||||
|
||||
# Slot teams, always 16 elements
|
||||
for i in range(0,16):
|
||||
struct.append([safeMatch.slots[i].team, dataTypes.BYTE])
|
||||
struct.append([self.slots[i].team, dataTypes.BYTE])
|
||||
|
||||
# Slot user ID. Write only if slot is occupied
|
||||
for i in range(0,16):
|
||||
if safeMatch.slots[i].user is not None and safeMatch.slots[i].user in glob.tokens.tokens:
|
||||
struct.append([glob.tokens.tokens[safeMatch.slots[i].user].userID, dataTypes.UINT32])
|
||||
if self.slots[i].user is not None and self.slots[i].user in glob.tokens.tokens:
|
||||
struct.append([glob.tokens.tokens[self.slots[i].user].userID, dataTypes.UINT32])
|
||||
|
||||
# Other match data
|
||||
struct.extend([
|
||||
[safeMatch.hostUserID, dataTypes.SINT32],
|
||||
[safeMatch.gameMode, dataTypes.BYTE],
|
||||
[safeMatch.matchScoringType, dataTypes.BYTE],
|
||||
[safeMatch.matchTeamType, dataTypes.BYTE],
|
||||
[safeMatch.matchModMode, dataTypes.BYTE],
|
||||
[self.hostUserID, dataTypes.SINT32],
|
||||
[self.gameMode, dataTypes.BYTE],
|
||||
[self.matchScoringType, dataTypes.BYTE],
|
||||
[self.matchTeamType, dataTypes.BYTE],
|
||||
[self.matchModMode, dataTypes.BYTE],
|
||||
])
|
||||
|
||||
# Slot mods if free mod is enabled
|
||||
if safeMatch.matchModMode == matchModModes.FREE_MOD:
|
||||
if self.matchModMode == matchModModes.FREE_MOD:
|
||||
for i in range(0,16):
|
||||
struct.append([safeMatch.slots[i].mods, dataTypes.UINT32])
|
||||
struct.append([self.slots[i].mods, dataTypes.UINT32])
|
||||
|
||||
# Seed idk
|
||||
# TODO: Implement this, it should be used for mania "random" mod
|
||||
struct.append([safeMatch.seed, dataTypes.UINT32])
|
||||
struct.append([self.seed, dataTypes.UINT32])
|
||||
|
||||
return struct
|
||||
|
||||
@@ -854,3 +856,11 @@ class match:
|
||||
message = "The match is now empty."
|
||||
|
||||
chat.sendMessage("FokaBot", chanName, message)
|
||||
|
||||
def __enter__(self):
|
||||
# 🌚🌚🌚🌚🌚
|
||||
self._lock.acquire()
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self._lock.release()
|
||||
|
Reference in New Issue
Block a user