Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@expose
def Ping(self):
if self.pong_count % 100 == 0:
delta = datetime.now() - self.old_time
self.old_time = datetime.now()
print "Pong: ping " + str(self.pong_count) + " from " + str(self.ref.channel) + \
str(delta.seconds) + "." + str(delta.microseconds // 1000)
self.ref.channel.notify("Pong", channel=self.ref)
self.pong_count += 1
@expose
def get_docstring(self, message):
""" This method has no content but a docstring. """
@expose
def multiply(self, *args):
"""Multiplies the argument list."""
res = reduce(lambda x,y: x*y, args)
print "Calculated", res
self.ref.reply(res)
@expose
def is_server_connected(self):
if isinstance(self.server_actor, RemoteActorReference):
self.ref.reply(self.server_actor.is_connected())
else:
self.ref.reply(self.server_actor.is_alive)
@expose
def say_hello(self, main_actor, team_name, host=None, port=None):
""" Opens a connection to the remote main_actor,
and sends it a "hello" message with the given team_name.
"""
self.server_actor = get_server_actor(main_actor, host, port)
if not self.server_actor:
self.ref.reply("failed")
return
try:
if self.server_actor.query("hello", [team_name, self.ref.uuid]).get(2) == "ok":
_logger.info("Connection accepted")
self.ref.reply("ok")
except Queue.Empty:
self.ref.reply("actor no reply")
@expose
def minigame(self):
"""Demos a small game."""
if len(self.players) != 2:
self.ref.reply("Need two players.")
return
reqs = []
for player in self.players:
reqs.append( player.query("random_int", []) )
res = 0
for answer in reqs:
res += answer.get()
if res % 2 != 0:
@expose
def delayed_start_game(self):
""" Waits a bit before really starting the game. """
time.sleep(0.3)
self.ref.notify("start_game")
@expose
def initialize_game(self, layout, number_bots, game_time):
""" Initialises a new game.
"""
self.game_master = GameMaster(layout, number_bots, game_time)
self.check_for_start()
@expose
def Start(self):
print "Ping: Starting"
self.pong.notify("Ping", channel=self.ref)
self.pings_left -= 1
@expose
def set_initial(self, universe):
""" Called by the server. This method tells us the initial universe.
"""
self.ref.reply(self.team._set_initial(universe))