Skip to content
This repository has been archived by the owner on Jul 18, 2019. It is now read-only.

Commit

Permalink
Bug fix in startingTimer
Browse files Browse the repository at this point in the history
  • Loading branch information
Igoorx committed Jun 30, 2019
1 parent 98e6d21 commit 4447c9e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
10 changes: 4 additions & 6 deletions match.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4447c9e

Please sign in to comment.