Commit 01bccbea authored by Alvin Natawiguna's avatar Alvin Natawiguna
Browse files

Added cache clearing mechanism on server start

parent cdf5e150
......@@ -866,7 +866,7 @@ class SendItemAcceptOfferCommand(Command):
command.execute()
result = command.getStatus()
if result['status'] == "ok":
if result['status'] == Command.RESULT_OK:
# create a duplicate in the offer
self.game.duplicateAcceptedOffer(demandedItem,
game.item.Item(offer['offer']['id'], offer['offer']['count']),
......@@ -1124,4 +1124,12 @@ def findOffers(ip, port, item):
if result['status'] == Command.RESULT_FAIL:
raise IOError("Cannot fetch item offers from ({}, {}): {}".format(ip, port, result['description']))
else:
raise IOError("Cannot fetch item offers from ({}, {}): Unknown error".format(ip, port))
\ No newline at end of file
raise IOError("Cannot fetch item offers from ({}, {}): Unknown error".format(ip, port))
def clearCache():
with pymongo.MongoClient() as client:
db = client.get_database(game.game_class.Game.DB_NAME)
assert db.authenticate(game.game_class.Game.DB_USERNAME, game.game_class.Game.DB_PASSWORD)
db.activeServers.remove({})
db.cachedOffers.remove({})
\ No newline at end of file
......@@ -199,6 +199,8 @@ def scheduleBatchFindOffer(scheduler, externalAddr):
if __name__ == '__main__':
HOST, PORT = '0.0.0.0', int(sys.argv[1])
command.clearCache()
extip = getExternalIp()
command.ServerStatusCommand.IGNORED_IP.append(extip)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment