Check games every 100 requests
git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@4375 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
bb4c6e56c2
commit
9acf48f307
|
@ -26,7 +26,7 @@ from __future__ import with_statement
|
|||
################################################################################
|
||||
#
|
||||
|
||||
__author__ = "Gerard Krol, Tim Perrei, Freddie Witherden, Gerhard Schaden"
|
||||
__author__ = "Gerard Krol, Tim Perrei, Freddie Witherden, Gerhard Schaden, Dennis Schridde"
|
||||
__version__ = "2.0"
|
||||
__bpydoc__ = """\
|
||||
This script runs a Warzone 2100 2.x masterserver
|
||||
|
@ -52,6 +52,7 @@ import cmd
|
|||
gamePort = 9999 # Gameserver port.
|
||||
lobbyPort = 9998 # Lobby port.
|
||||
gsSize = 112 # Size of GAMESTRUCT in byte.
|
||||
checkInterval = 100 # Interval between requests causing a gamedb check
|
||||
|
||||
logging.basicConfig(level = logging.DEBUG, format = "%(asctime)-15s %(levelname)s %(message)s")
|
||||
|
||||
|
@ -76,7 +77,7 @@ class GameDB:
|
|||
def removeGame(self, g):
|
||||
""" remove a game from the list"""
|
||||
with gamedblock:
|
||||
# if g is not in thel list, ignore the KeyError exception
|
||||
# if g is not in the list, ignore the KeyError exception
|
||||
try:
|
||||
self.list.remove(g)
|
||||
except KeyError:
|
||||
|
@ -95,6 +96,19 @@ class GameDB:
|
|||
""" filter all games of a certain host"""
|
||||
return filter(lambda x: x.host == host, self.getGames())
|
||||
|
||||
def checkGames(self):
|
||||
with gamedblock:
|
||||
gamesCount = len(self.getGames())
|
||||
logging.debug("Checking: %i game(s)" % (gamesCount))
|
||||
for game in self.getGames():
|
||||
if not game.check():
|
||||
logging.debug("Removing unreachable game: %s" % game)
|
||||
# HACK Code duplication with removeGame()
|
||||
try:
|
||||
self.list.remove(g)
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
def listGames(self):
|
||||
with gamedblock:
|
||||
gamesCount = len(self.getGames())
|
||||
|
@ -158,9 +172,17 @@ class Game:
|
|||
################################################################################
|
||||
# Socket Handler.
|
||||
|
||||
requests = 0
|
||||
requestlock = Lock()
|
||||
|
||||
class RequestHandler(SocketServer.ThreadingMixIn, SocketServer.StreamRequestHandler):
|
||||
def handle(self):
|
||||
global gamedb
|
||||
global requests, requestlock, gamedb
|
||||
|
||||
with requestlock:
|
||||
requests += 1
|
||||
if requests >= checkInterval:
|
||||
gamedb.checkGames()
|
||||
|
||||
# client address
|
||||
gameHost = self.client_address[0]
|
||||
|
|
Loading…
Reference in New Issue