I knew a threaded bancho server was going to be a bad idea...
This commit is contained in:
parent
050c1d5fe8
commit
e63a85e4a4
|
@ -15,9 +15,9 @@ def handle(userToken, packetData):
|
|||
matchID = userToken.matchID
|
||||
if matchID not in glob.matches.matches:
|
||||
return
|
||||
match = glob.matches.matches[matchID]
|
||||
|
||||
# Set slot or match mods according to modType
|
||||
with glob.matches.matches[matchID] as match:
|
||||
if match.matchModMode == matchModModes.FREE_MOD:
|
||||
# Freemod
|
||||
# Host can set global DT/HT
|
||||
|
|
|
@ -10,9 +10,7 @@ def handle(userToken, packetData):
|
|||
if matchID not in glob.matches.matches:
|
||||
return
|
||||
|
||||
# Get our match
|
||||
match = glob.matches.matches[matchID]
|
||||
|
||||
with glob.matches.matches[matchID] as match:
|
||||
# Host check
|
||||
if userToken.userID != match.hostUserID:
|
||||
return
|
||||
|
|
|
@ -21,10 +21,8 @@ def handle(userToken, packetData):
|
|||
if matchID not in glob.matches.matches:
|
||||
return
|
||||
|
||||
# Get match object
|
||||
match = glob.matches.matches[matchID]
|
||||
|
||||
# Host check
|
||||
with glob.matches.matches[matchID] as match:
|
||||
if userToken.userID != match.hostUserID:
|
||||
return
|
||||
|
||||
|
|
|
@ -8,8 +8,6 @@ def handle(userToken, packetData):
|
|||
# Read packet data
|
||||
packetData = clientPackets.changeSlot(packetData)
|
||||
|
||||
# Get match
|
||||
match = glob.matches.matches[userToken.matchID]
|
||||
|
||||
with glob.matches.matches[userToken.matchID] as match:
|
||||
# Change slot
|
||||
match.userChangeSlot(userID, packetData["slotID"])
|
||||
|
|
|
@ -20,9 +20,7 @@ def handle(userToken, packetData):
|
|||
if matchID not in glob.matches.matches:
|
||||
raise exceptions.matchCreateError()
|
||||
|
||||
# Get match object
|
||||
match = glob.matches.matches[matchID]
|
||||
|
||||
with glob.matches.matches[matchID] as match:
|
||||
# Join that match
|
||||
userToken.joinMatch(matchID)
|
||||
|
||||
|
|
|
@ -17,14 +17,12 @@ def handle(userToken, packetData):
|
|||
if matchID not in glob.matches.matches:
|
||||
return
|
||||
|
||||
# Match exists, get object
|
||||
match = glob.matches.matches[matchID]
|
||||
|
||||
# Hash password if needed
|
||||
#if password != "":
|
||||
# if password != "":
|
||||
# password = generalUtils.stringMd5(password)
|
||||
|
||||
# Check password
|
||||
with glob.matches.matches[matchID] as match:
|
||||
if match.matchPassword != "" and match.matchPassword != password:
|
||||
raise exceptions.matchWrongPasswordException()
|
||||
|
||||
|
|
|
@ -15,8 +15,6 @@ def handle(userToken, _, has):
|
|||
if matchID not in glob.matches.matches:
|
||||
return
|
||||
|
||||
# The match exists, get object
|
||||
match = glob.matches.matches[matchID]
|
||||
|
||||
# Set has beatmap/no beatmap
|
||||
with glob.matches.matches[matchID] as match:
|
||||
match.userHasBeatmap(userID, has)
|
||||
|
|
|
@ -15,8 +15,6 @@ def handle(userToken, _):
|
|||
if matchID not in glob.matches.matches:
|
||||
return
|
||||
|
||||
# Get match object
|
||||
match = glob.matches.matches[matchID]
|
||||
|
||||
# Change team
|
||||
with glob.matches.matches[matchID] as match:
|
||||
match.changeTeam(userID)
|
||||
|
|
|
@ -15,8 +15,6 @@ def handle(userToken, _):
|
|||
if matchID not in glob.matches.matches:
|
||||
return
|
||||
|
||||
# The match exists, get object
|
||||
match = glob.matches.matches[matchID]
|
||||
|
||||
# Set our match complete
|
||||
with glob.matches.matches[matchID] as match:
|
||||
match.playerCompleted(userID)
|
||||
|
|
|
@ -15,8 +15,6 @@ def handle(userToken, _):
|
|||
if matchID not in glob.matches.matches:
|
||||
return
|
||||
|
||||
# Match exists, get object
|
||||
match = glob.matches.matches[matchID]
|
||||
|
||||
# Fail user
|
||||
with glob.matches.matches[matchID] as match:
|
||||
match.playerFailed(userID)
|
||||
|
|
|
@ -16,15 +16,13 @@ def handle(userToken, packetData):
|
|||
if matchID not in glob.matches.matches:
|
||||
return
|
||||
|
||||
# The match exists, get object
|
||||
match = glob.matches.matches[matchID]
|
||||
|
||||
# Change slot id in packetData
|
||||
slotID = match.getUserSlotID(userID)
|
||||
|
||||
# Parse the data
|
||||
data = clientPackets.matchFrames(packetData)
|
||||
|
||||
with glob.matches.matches[matchID] as match:
|
||||
# Change slot id in packetData
|
||||
slotID = match.getUserSlotID(userID)
|
||||
|
||||
# Update the score
|
||||
match.updateScore(slotID, data["totalScore"])
|
||||
match.updateHP(slotID, data["currentHp"])
|
||||
|
|
|
@ -17,8 +17,6 @@ def handle(userToken, packetData):
|
|||
if matchID not in glob.matches.matches:
|
||||
return
|
||||
|
||||
# Get match object
|
||||
match = glob.matches.matches[matchID]
|
||||
|
||||
# Send invite
|
||||
with glob.matches.matches[matchID] as match:
|
||||
match.invite(userID, packetData["userID"])
|
||||
|
|
|
@ -12,8 +12,8 @@ def handle(userToken, packetData):
|
|||
matchID = userToken.matchID
|
||||
if matchID not in glob.matches.matches:
|
||||
return
|
||||
match = glob.matches.matches[matchID]
|
||||
|
||||
with glob.matches.matches[matchID] as match:
|
||||
# Host check
|
||||
if userID != match.hostUserID:
|
||||
return
|
||||
|
|
|
@ -15,8 +15,6 @@ def handle(userToken, _):
|
|||
if matchID not in glob.matches.matches:
|
||||
return
|
||||
|
||||
# The match exists, get object
|
||||
match = glob.matches.matches[matchID]
|
||||
|
||||
# Set our load status
|
||||
with glob.matches.matches[matchID] as match:
|
||||
match.playerLoaded(userID)
|
||||
|
|
|
@ -8,8 +8,8 @@ def handle(userToken, _):
|
|||
matchID = userToken.matchID
|
||||
if matchID not in glob.matches.matches:
|
||||
return
|
||||
match = glob.matches.matches[matchID]
|
||||
|
||||
with glob.matches.matches[matchID] as match:
|
||||
# Get our slotID and change ready status
|
||||
slotID = match.getUserSlotID(userID)
|
||||
if slotID is not None:
|
||||
|
|
|
@ -15,8 +15,6 @@ def handle(userToken, _):
|
|||
if matchID not in glob.matches.matches:
|
||||
return
|
||||
|
||||
# The match exists, get object
|
||||
match = glob.matches.matches[matchID]
|
||||
|
||||
# Skip
|
||||
with glob.matches.matches[matchID] as match:
|
||||
match.playerSkip(userID)
|
||||
|
|
|
@ -13,9 +13,7 @@ def handle(userToken, _):
|
|||
if matchID not in glob.matches.matches:
|
||||
return
|
||||
|
||||
# The match exists, get object
|
||||
match = glob.matches.matches[matchID]
|
||||
|
||||
with glob.matches.matches[matchID] as match:
|
||||
# Host check
|
||||
if userToken.userID != match.hostUserID:
|
||||
return
|
||||
|
|
|
@ -16,10 +16,8 @@ def handle(userToken, packetData):
|
|||
if matchID not in glob.matches.matches:
|
||||
return
|
||||
|
||||
# Match exists, get object
|
||||
match = glob.matches.matches[matchID]
|
||||
|
||||
# Host check
|
||||
with glob.matches.matches[matchID] as match:
|
||||
if userToken.userID != match.hostUserID:
|
||||
return
|
||||
|
||||
|
|
|
@ -6,4 +6,5 @@ def handle(userToken, packetData):
|
|||
matchID = packetData["matchID"]
|
||||
if matchID not in glob.matches.matches or not userToken.tournament:
|
||||
return
|
||||
userToken.enqueue(glob.matches.matches[matchID].matchDataCache)
|
||||
with glob.matches.matches[matchID] as m:
|
||||
userToken.enqueue(m.matchDataCache)
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue
Block a user