.BANCHO. Implemented packet streams for multiplayer

This commit is contained in:
Nyo
2016-10-04 23:43:02 +02:00
parent afbd8e7e8c
commit 795b6f09be
12 changed files with 187 additions and 287 deletions

View File

@@ -111,7 +111,7 @@ def handle(userToken, packetData):
match.matchModMode = matchModModes.normal
# Send updated settings
match.sendUpdate()
match.sendUpdates()
# Console output
log.info("MPROOM{}: Updated room settings".format(match.matchID))

View File

@@ -2,7 +2,6 @@ from common.log import logUtils as log
from constants import clientPackets
from constants import exceptions
from constants import serverPackets
from events import joinMatchEvent
from objects import glob
@@ -26,7 +25,7 @@ def handle(userToken, packetData):
match = glob.matches.matches[matchID]
# Join that match
joinMatchEvent.joinMatch(userToken, matchID, packetData["matchPassword"])
userToken.joinMatch(matchID)
# Give host to match creator
match.setHost(userID)

View File

@@ -3,38 +3,26 @@ from common.log import logUtils as log
from constants import clientPackets
from constants import exceptions
from constants import serverPackets
from helpers import chatHelper as chat
from objects import glob
def handle(userToken, packetData):
# read packet data
packetData = clientPackets.joinMatch(packetData)
matchID = packetData["matchID"]
password = packetData["password"]
# Get match from ID
joinMatch(userToken, packetData["matchID"], packetData["password"])
def joinMatch(userToken, matchID, password, isPasswordHashed = False):
try:
# Stop spectating
userToken.stopSpectating()
# Leave other matches
if userToken.matchID > -1 and userToken.matchID != matchID:
userToken.partMatch()
# Get usertoken data
userID = userToken.userID
# Make sure the match exists
if matchID not in glob.matches.matches:
raise exceptions.matchNotFoundException
return
# Match exists, get object
match = glob.matches.matches[matchID]
# Hash password if needed
if isPasswordHashed == False and password != "":
if password != "":
password = generalUtils.stringMd5(password)
# Check password
@@ -44,24 +32,7 @@ def joinMatch(userToken, matchID, password, isPasswordHashed = False):
raise exceptions.matchWrongPasswordException
# Password is correct, join match
result = match.userJoin(userID)
# Check if we've joined the match successfully
if not result:
raise exceptions.matchJoinErrorException
# Match joined, set matchID for usertoken
userToken.joinMatch(matchID)
# Send packets
userToken.enqueue(serverPackets.matchJoinSuccess(matchID))
chat.joinChannel(token=userToken, channel="#multi_{}".format(matchID))
except exceptions.matchNotFoundException:
userToken.enqueue(serverPackets.matchJoinFail())
log.warning("{} has tried to join a mp room, but it doesn't exist".format(userToken.username))
except exceptions.matchWrongPasswordException:
userToken.enqueue(serverPackets.matchJoinFail())
log.warning("{} has tried to join a mp room, but he typed the wrong password".format(userToken.username))
except exceptions.matchJoinErrorException:
userToken.enqueue(serverPackets.matchJoinFail())
log.warning("{} has tried to join a mp room, but an error has occured".format(userToken.username))
log.warning("{} has tried to join a mp room, but he typed the wrong password".format(userToken.username))

View File

@@ -21,7 +21,7 @@ def handle(userToken, _=None):
userToken.stopSpectating()
# Part matches
userToken.partMatch()
userToken.leaveMatch()
# Part all joined channels
for i in userToken.joinedChannels:

View File

@@ -24,8 +24,4 @@ def handle(userToken, packetData):
slotID = match.getUserSlotID(userID)
# Enqueue frames to who's playing
for i in range(0,16):
if match.slots[i].userID > -1 and match.slots[i].status == slotStatuses.playing:
token = glob.tokens.getTokenFromUserID(match.slots[i].userID)
if token is not None:
token.enqueue(serverPackets.matchFrames(slotID, packetData))
glob.streams.broadcast(match.playingStreamName, serverPackets.matchFrames(slotID, packetData))

View File

@@ -22,27 +22,4 @@ def handle(userToken, _):
if userToken.userID != match.hostUserID:
return
# Make sure we have enough players
if match.countUsers() < 2 or match.checkTeams() == False:
return
# Change inProgress value
match.inProgress = True
# Set playing to ready players and set load, skip and complete to False
for i in range(0,16):
if (match.slots[i].status & slotStatuses.ready) > 0:
match.slots[i].status = slotStatuses.playing
match.slots[i].loaded = False
match.slots[i].skip = False
match.slots[i].complete = False
# Send match start packet
for i in range(0,16):
if (match.slots[i].status & slotStatuses.playing) > 0 and match.slots[i].userID != -1:
token = glob.tokens.getTokenFromUserID(match.slots[i].userID)
if token is not None:
token.enqueue(serverPackets.matchStart(matchID))
# Send updates
match.sendUpdate()
match.start()

View File

@@ -1,2 +1,2 @@
def handle(userToken, _=None):
userToken.partMatch()
userToken.leaveMatch()