示例#1
0
 def create_player(params):
     lock.acquire()
     try:
         Player.Player(params[1], True, params[2])
         send(params[0], "DON")
         lock.release()
     except FileExistsError:
         lock.release()
         Server.send_error(params[0], 4)
示例#2
0
 def delete_player(params):
     lock.acquire()
     try:
         a = Player.Player(params[1], False)
         a.delete_player()
         send(params[0], 'DON')
         lock.release()
     except FileNotFoundError:
         lock.release()
         Server.send_error(params[0], 5)
示例#3
0
 def remove_unit(params):
     lock.acquire()
     try:
         a = Player.Player(params[1], False)
         a.remove_unit_form_db(int(params[2]))
         send(params[0], 'DON')
         lock.release()
     except FileNotFoundError:
         lock.release()
         Server.send_error(params[0], 2)
示例#4
0
 def attack(params):
     lock.acquire()
     p1 = Player.Player(params[1], False)
     p2 = Player.Player(params[3], False)
     ranged = bool(int(params[5]))
     flank = bool(int(params[6]))
     charge = bool(int(params[7]))
     front = bool(int(params[8]))
     advantage = float(params[9])
     try:
         d, c = p1.attack(int(params[2]), p2, int(params[4]), ranged, flank,
                          charge, front, advantage)
         send(params[0], f"GDC~{d}~{c}")
         lock.release()
     except IndexError:
         lock.release()
         Server.send_error(params[0], 3)
     except ValueError:
         lock.release()
         Server.send_error(params[0], 12)
示例#5
0
 def is_dead_or_ran(params):
     lock.acquire()
     try:
         a = Player.Player(params[1], False)
         res = a.is_dead_or_ran(params[2])
         send(params[0], f"GTF~{int(res)}")
         lock.release()
     except FileNotFoundError:
         lock.release()
         Server.send_error(params[0], 5)
     except IndexError:
         lock.release()
         Server.send_error(params[0], 3)
示例#6
0
 def add_unit(params):
     lock.acquire()
     try:
         a = Player.Player(params[1], False)
         a.add_unit_by_name(params[2])
         send(params[0], 'DON')
         lock.release()
     except FileNotFoundError as e:
         lock.release()
         if "unit" in str(e):
             Server.send_error(params[0], 2)
         else:
             Server.send_error(params[0], 5)
示例#7
0
    def send_all_units(params):
        lock.acquire()
        try:
            a = Player.Player(params[1], False)
            all_units = a.get_unit(-1)
            lock.release()
        except FileNotFoundError:
            Server.send_error(params[0], 5)
            lock.release()
            return

        send(params[0], f"GAU~{len(all_units)}")
        for unt in all_units:
            msg = "GUT~" + '~'.join([str(val) for val in unt.as_tuple()])
            send(params[0], msg)
示例#8
0
 def send_unit(params):
     lock.acquire()
     if params[2].isdigit():
         try:
             unt = Player.Player(params[1],
                                 False).get_unit(int(params[2])).as_tuple()
         except IndexError:
             Server.send_error(params[0], 3)
             lock.release()
             return
     else:
         try:
             unt = Unit.Unit.unit_by_name(params[2]).as_tuple()
         except FileNotFoundError:
             Server.send_error(params[0], 2)
             lock.release()
             return
     msg = "GUT~" + '~'.join([str(val) for val in unt])
     send(params[0], msg)
     lock.release()