Exemple #1
0
def info(uid, game_obj):
    game = SingletonGame.get_game()
    a = game.get_player(uid)
    if a is not None:
        return [uid], FullAnswer(uid, game).get_ret_object()
    else:
        sp = game.get_spectrator(uid)
        if sp is None:
            return IGNORE()
        return [uid], FullAnswer(None, game).get_ret_object()
Exemple #2
0
def disc(uid: int, game_obj):
    game = SingletonGame.get_game()
    pl = game.get_player(uid)
    game.disconnect_player(uid)
    if pl is None:
        return IGNORE()
    return (
        game.get_spectrators_and_ids(),
        Answer(pl, GC.ACTION_LIST["dc"]).get_ret_object(),
    )
Exemple #3
0
    def run(self, channel, end_loop_channel):  # start handler
        self.data = SyncServiceCommunicator(
            channel, end_loop_channel)  # listening room channel
        self.data.clear_channel()
        parser = WorkerParser()
        while True:
            channel, msg = self.data.pull_from_work_channel(0)

            try:
                act, uid, obj = parser.parse_in(msg)
            except BaseException:
                continue

            if channel == end_loop_channel:
                if act == SERVER_COMMUNICATING_CONSTANTS["PING_COMMAND"]:
                    sto = obj.pop(SERVER_COMMUNICATING_CONSTANTS["W8ANSWERIN"],
                                  None)
                    if sto is None:
                        continue
                    self.send([sto], "im_allive_yo!")
                    self.data.set_expire_chan(sto, 5)
                    continue
                if act == SERVER_COMMUNICATING_CONSTANTS["SERV_STOP"]:
                    sto = obj.pop(SERVER_COMMUNICATING_CONSTANTS["W8ANSWERIN"],
                                  None)
                    if sto is None:
                        continue
                    gd = SingletonGame.get_game()
                    pl_2_disc = gd.get_spectrators_and_ids()
                    for a in pl_2_disc:
                        c, d = WorkerParser.KICK_PLAYER(a)
                        self.send(c, d)
                        self.data.set_expire_chan(str(a), 5)
                    self.data.set_expire_chan(channel, 10)
                    self.data.set_expire_chan(end_loop_channel, 10)
                    self.send([sto], "im_closed_yo!")
                    self.data.set_expire_chan(sto, 20)
                    exit(0)

            if act is None or uid is None:
                continue

            fun = self._functions_to_handle.get(act, None)
            if fun is None:
                continue

            send_to, msg = fun(int(uid), obj)
            self.send(send_to, msg)

            while DelayedSend.is_set():
                self.send(*(DelayedSend.get_data()))
Exemple #4
0
def session(game_obj):
    a = GameData.get_data()
    if not a.player.admin:
        return IGNORE()
    game = SingletonGame.get_game()
    cli = game.stepping_cli()
    if cli is None or cli.player_state != PlayerState.set_thinking_state():
        return (
            [a.player.get_id()],
            ErrorActAnswer("NoActiveCliOrGameNotStarted").get_ret_object(),
        )
    if cli.points < 3:
        return ([a.player.get_id()],
                ErrorActAnswer("NotEnoughPoints").get_ret_object())
    cli.points -= 3
    return a.active_players_spct, Answer(cli).get_ret_object()
Exemple #5
0
def target_data(uid, game_obj):
    game = SingletonGame.get_game()
    pl_fnum = game_obj.get("fnm", None)
    if pl_fnum is None:
        return IGNORE()
    player = game.get_player_fnum(pl_fnum)
    if player is None:
        return IGNORE()
    answ = {}
    if player.target is None:
        answ["err"] = "Пусто"
    else:
        answ["err"] = player.target
    return (
        [uid],
        Answer(None, GC.ACTION_LIST["card_data"], answ,
               lowpack=True).get_ret_object(),
    )
Exemple #6
0
def allow_res(game_obj):
    a = GameData.get_data()
    if not a.player.admin:
        return IGNORE()
    game = SingletonGame.get_game()
    cli = game.stepping_cli()
    if cli is None or cli.player_state != PlayerState.set_thinking_state():
        return (
            [a.player.get_id()],
            ErrorActAnswer("NoActiveCliOrGameNotStarted").get_ret_object(),
        )
    if cli.points < 1:
        return ([a.player.get_id()],
                ErrorActAnswer("NotEnoughPoints").get_ret_object())
    cli.can_take_resource = True
    return (
        [cli.get_id()],
        Answer(cli, GC.ACTION_LIST["can_take_resource"], True,
               True).get_ret_object(),
    )
Exemple #7
0
def allow_yn(game_obj):
    a = GameData.get_data()
    if not a.player.admin:
        return IGNORE()
    game = SingletonGame.get_game()
    cli = game.stepping_cli()
    if cli is None:
        return (
            [a.player.get_id()],
            ErrorActAnswer("NoActiveCliOrGameNotStarted").get_ret_object(),
        )
    if cli.penalty is not None:
        return [a.player.get_id()
                ], ErrorActAnswer("CliHavePenalty").get_ret_object()
    if cli.player_state != PlayerState.set_thinking_state():
        return [a.player.get_id()
                ], ErrorActAnswer("PlayerStillMoving").get_ret_object()
    cli.player_state = PlayerState.set_yncubic_state()
    return (
        [cli.get_id()],
        Answer(cli, GC.ACTION_LIST["can_throw_yn"], True,
               True).get_ret_object(),
    )
Exemple #8
0
def next_step(game_obj):
    a = GameData.get_data()
    if not a.player.admin:
        return IGNORE()
    game = SingletonGame.get_game()
    if game.game_state == GC.GAME_CONSTANTS["GAME_STATE_W8_CLIENTS"]:
        return [a.player.get_id()
                ], ErrorActAnswer("GameNotStarted").get_ret_object()
    ns = game.next_step()
    if not ns:
        return [a.player.get_id()
                ], ErrorActAnswer("NoPlayers").get_ret_object()

    cli = game.stepping_cli()
    cli.cubic_thrown = False
    cli.yncubic_thrown = False
    cl_data = CliRetPosAnswer(cli)
    for cr in cl_data.get_my_ret_obj():
        DelayedSend.set_send([cli.get_id()], cr)
    for cr in cl_data.get_pub_ret_obj():
        DelayedSend.set_send(a.active_players_spct, cr)
    return a.active_players_spct, Answer(
        cli, GC.ACTION_LIST["step"]).get_ret_object()
Exemple #9
0
def game_start(game_obj):
    a = GameData.get_data()
    if not a.player.admin:
        return IGNORE()
    game = SingletonGame.get_game()
    if game.game_state != GC.GAME_CONSTANTS["GAME_STATE_W8_CLIENTS"]:
        return [a.player.get_id()
                ], ErrorActAnswer("GameStarted").get_ret_object()
    clients = game.get_all_ids()
    game.game_state = GC.GAME_CONSTANTS["GAME_START"]
    game.start_game()
    ns = game.next_step()
    if not ns:
        game.game_state = GC.GAME_CONSTANTS["GAME_STATE_W8_CLIENTS"]
        return [a.player.get_id()
                ], ErrorActAnswer("NoPlayers").get_ret_object()
    cli = game.stepping_cli()

    DelayedSend.set_send(
        a.active_players_spct,
        Answer(
            cli,
            GC.ACTION_LIST["card_data"],
            print_step_set(game, "ИГРА НАЧАЛАСЬ! Порядок ходов:\n"),
            lowpack=True,
        ).get_ret_object(),
    )

    for c in clients:
        r = game.get_player(c)
        r.show_turn = True
        DelayedSend.set_send([r.get_id()],
                             Answer(r, GC.ACTION_LIST["get_info"],
                                    True).get_ret_object())

    return [a.player.get_id()], ErrorActAnswer("GameSTARTED").get_ret_object()
Exemple #10
0
def bun_unban(game_obj):
    a = GameData.get_data()
    if not a.player.admin:
        return IGNORE()
    fnm = game_obj.get("fnm", None)
    if fnm is None:
        return IGNORE()
    game = SingletonGame.get_game()
    cli = game.get_player_fnum(fnm)
    if cli is None:
        return IGNORE()
    if cli.penalty is None:
        cli.penalty = GC.PENALTY_LIST["stop"]
    elif cli.penalty == GC.PENALTY_LIST["win"]:
        return IGNORE()
    else:
        cli.penalty = None
    if cli.penalty is None:
        return (
            game.get_spectrators_and_ids(),
            Answer(cli, GC.ACTION_LIST["rem_pen"]).get_ret_object(),
        )
    else:
        return (game.get_spectrators_and_ids(), Answer(cli).get_ret_object())
Exemple #11
0
def get_card_data(uid, game_obj):
    game = SingletonGame.get_game()
    pl_fnum = game_obj.get("fnm", None)
    if pl_fnum is None:
        return IGNORE()
    player = game.get_player_fnum(pl_fnum)
    if player is None:
        return IGNORE()
    if player.penalty is not None:
        return IGNORE()
    answ = {}
    if player.open_elevel:
        answ["elvl"] = abs(player.cur_position_num)
    if player.rune is not None:
        answ["rune"] = player.rune
    if player.resources is not None:
        answ["res"] = [player.resources]
    if len(answ) == 0:
        answ["err"] = "Пусто"
    return (
        [uid],
        Answer(None, GC.ACTION_LIST["card_data"], answ,
               lowpack=True).get_ret_object(),
    )
Exemple #12
0
from game.gamelogic.gamecl import SingletonGame
from game.worker import App
from game.gamelogic.parcer import BaseParser
import argparse

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("-r", type=int, required=True)
    arg = parser.parse_args()
    t = arg.r
    SingletonGame.create_game(t, 14, 25)
    App.run(BaseParser().create_room_name(t), "e" + BaseParser().create_room_name(t))