From 4447c9ec538a4b08bae011d13a9cca63d4fd6590 Mon Sep 17 00:00:00 2001 From: Igor Pissolati Date: Sun, 30 Jun 2019 18:04:10 -0300 Subject: [PATCH] Bug fix in startingTimer --- match.py | 10 ++++------ server.py | 6 +++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/match.py b/match.py index f9f7008..5aa8639 100644 --- a/match.py +++ b/match.py @@ -46,7 +46,7 @@ def removePlayer(self, player): if player.voted: self.votes -= 1 - if not self.playing and self.votes >= len(self.players) * self.server.voteRateToStart: + if self.server.enableVoteStart and not self.playing and self.votes >= len(self.players) * self.server.voteRateToStart: self.start() def getPlayer(self, pid): @@ -125,20 +125,18 @@ def onPlayerReady(self, player): if not self.playing: if self.startingTimer is None and len(self.getPlayersData()) >= self.server.playerCap: - self.startingTimer = reactor.callLater(3, self.start) - elif self.votes >= len(self.players) * self.server.voteRateToStart: + self.startingTimer = reactor.callLater(3, self.start, True) + elif self.server.enableVoteStart and self.votes >= len(self.players) * self.server.voteRateToStart: self.start() def voteStart(self): self.votes += 1 - if not self.playing and self.votes >= len(self.players) * self.server.voteRateToStart: + if self.server.enableVoteStart and not self.playing and self.votes >= len(self.players) * self.server.voteRateToStart: self.start() def start(self, forced = False): if self.playing or (not forced and len(self.players) < self.server.playerMin): # We need at-least 10 players to start return - if not self.server.enableVoteStart and len(self.players) < self.server.playerCap: - return self.playing = True try: diff --git a/server.py b/server.py index 94318ac..bb7593c 100644 --- a/server.py +++ b/server.py @@ -269,13 +269,13 @@ def onBinaryMessage(self): return True class MyServerFactory(WebSocketServerFactory): - def __init__(self): + def __init__(self, url): with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "server.cfg"), "r") as f: self.configHash = hashlib.md5(f.read()).hexdigest() self.readConfig(self.configHash) - WebSocketServerFactory.__init__(self, u"ws://127.0.0.1:{0}/royale/ws".format(self.listenPort)) + WebSocketServerFactory.__init__(self, url.format(self.listenPort)) self.players = list() self.matches = list() @@ -362,7 +362,7 @@ def removeMatch(self, match): if __name__ == '__main__': - factory = MyServerFactory() + factory = MyServerFactory(u"ws://127.0.0.1:{0}/royale/ws") # factory.setProtocolOptions(maxConnections=2) reactor.listenTCP(factory.listenPort, factory)