示例#1
0
 def on_update_time(self, params_data):
     paramsMap = supp.getParamsValMap(params_data)
     print('Recieved message: ' + str(params_data) + ' ' + paramsMap['request_id'])
     self.sio.emit('verify_message', "request_id={}".format(paramsMap['request_id']))
     #####
     if self.on_update_time_call is not None:
         self.on_update_time_call(paramsMap)
示例#2
0
def on_verify_message(data):
    # print("Message recieved: " + str(data) + "from client " + str(clients[request.sid]))

    paramsDict = supp.getParamsValMap(data)
    if request.sid in clients and clients[request.sid] is not None:
        query = "call chess.verify_message({0}, {1})".format(paramsDict['request_id'], clients[request.sid])
        execute_no_res_async(query)
示例#3
0
    def on_win_pack(self, data):
        paramsMap = supp.getParamsValMap(data)

        print('Recieved message: ' + str(paramsMap))

        self.sio.emit('verify_message', "request_id={}".format(paramsMap['request_id']))

        if self.on_win_pack_call is not None:
            self.on_win_pack_call(paramsMap)
示例#4
0
def on_confirm_auth(data):
    print("Message recieved: " + str(data))

    paramsDict = supp.getParamsValMap(data)

    query = "select chess.confirm_auth('{0}', '{1}')".format(paramsDict['email'],
                                                           paramsDict['auth_code'])
    res = int(execute_one_res_async(query)[0])
    if res == 0:
        # send error message
        socketio.emit('error', 'message=wrong auth code or email', room=request.sid)
示例#5
0
def on_update_pack(data):
    print("Message recieved: " + str(data))
    params_dict = supp.getParamsValMap(data)
    if request.sid in clients and clients[request.sid] is not None:
        try:
            query = "call chess.update_pack({0}, '{1}')" \
                    "".format(clients[request.sid], params_dict['pack_name'])
            print('query is ' + query)
            execute_no_res_async(query)
        except:
            print("Error while update pack")
示例#6
0
def on_find_pair(data):
    print("Message recieved: " + str(data))
    paramsDict = supp.getParamsValMap(data)
    if request.sid in clients and clients[request.sid] is not None:
        query = "call chess.find_pair({0}, {1}, {2}, {3}," \
                " p_game_time := TIME '00:{4}:00')".format(clients[request.sid],
                                                           int(paramsDict['low_rate']),
                                                           int(paramsDict['hight_rate']),
                                                           int(paramsDict['move_time']),
                                                           str(paramsDict['game_time']).rjust(2, '0'))
        execute_no_res_async(query)
示例#7
0
def on_auth(data):
    print("Message recieved: " + str(data))
    paramsDict = supp.getParamsValMap(data)
    print("Parsed params: " + str(paramsDict))

    if not validate_email(paramsDict['email']):
        return

    query = "select chess.registrate('{0}', '{1}', '{2}')".format(paramsDict['login'],
                                                                  paramsDict['password'],
                                                                  paramsDict['email'])

    res = execute_one_res_async(query)[0]
    if res == "":
        # send error message
        socketio.emit('error', 'message=Wrong registration params', room=request.sid)
示例#8
0
def on_login(data):
    print("Message recieved: " + str(data))

    paramsDict = supp.getParamsValMap(data)

    query = "select chess.login('{0}', '{1}')".format(paramsDict['login'], paramsDict['password'])
    # set user_id for session
    print("login SID is " + str(request.sid))
    user_id = int(execute_one_res_async(query)[0])
    if user_id < 0:
        print('Invalid user!')
        # send error message
        socketio.emit('error', 'message=Unknown login or password', room=request.sid)
        return
    clients[request.sid] = user_id
    user_client_map[user_id] = request.sid
    print("login ID is " + str(clients[request.sid]))
示例#9
0
def on_update_board(data):
    print("Message recieved: " + str(data))
    paramsDict = supp.getParamsValMap(data)

    # get board from database
    if clients[request.sid] is not None:
        query = "select * from chess.get_current_game_board_state({0})".format(clients[request.sid])
    else:
        return
    try:
        rec = execute_one_res_async(query)
        print("Game state is " + str(rec))
        board = rec[0]
        side = int(rec[1])
    except:
        print("Game doesn't exists")
        return
    # print("server_board is " + str(rec))
    # convert to game_controller
    print("Board is " + str(board))
    print("Side is " + str(side))
    if board is not None:
        cur_game_controller = game_controller.GameController(None, str(board))
    else:
        cur_game_controller = game_controller.GameController(Board())

    move = vec.Move(vec.Vector2d(int(paramsDict['p1']), int(paramsDict['p2'])),
                    vec.Vector2d(int(paramsDict['p3']), int(paramsDict['p4'])))

    res = cur_game_controller.check_move(move, Side(side))

    if res == game_controller.MoveResult.INCORRECT:
        print("Wrong move send")
        return

    is_playing = 1
    game_result = None
    pawn_swaped_figure = paramsDict['swapped_figure']

    print('Swaped figure is ' + str(pawn_swaped_figure))

    cur_game_controller.update(move, Side(side))

    if pawn_swaped_figure is not None:
        cur_game_controller.swap_pawn(move.point_to, pawn_swaped_figure)
        res = cur_game_controller.check_board_res(Side(side))

    if res == game_controller.MoveResult.STALEMATE:
        is_playing = 0
    elif res == game_controller.MoveResult.MATE:
        is_playing = 0
        game_result = 0 if Side(side) is Side.WHITE else 1

    if game_result is None:
        execute_no_res_async("call chess.update_game_state({0}, '{1}', "
                             "{2}::bit, NULL)".format(clients[request.sid],
                                                      cur_game_controller.serialize_to_str(),
                                                      is_playing))
    else:
        execute_no_res_async("call chess.update_game_state({0}, '{1}', "
                             "{2}::bit, {3}::bit)".format(clients[request.sid],
                                                          cur_game_controller.serialize_to_str(),
                                                          is_playing,
                                                          game_result))
示例#10
0
def on_find_pair_list(data):
    paramsDict = supp.getParamsValMap(data)
    print("Message recieved: " + str(data))
    if request.sid in clients and clients[request.sid] is not None:
        query = "call chess.start_game_by_pairing_id({0}, {1})".format(clients[request.sid], paramsDict['pairing_id'])
        execute_no_res_async(query)
示例#11
0
 def on_avail_packs(self, data):
     paramsMap = supp.getParamsValMap(data)
     self.sio.emit('verify_message', "request_id={}".format(paramsMap['request_id']))
     if self.on_avail_packs_call is not None:
         self.on_avail_packs_call(paramsMap['packs'])
示例#12
0
 def on_error(self, data):
     paramsMap = supp.getParamsValMap(data)
     print('Recieved message: ' + str(paramsMap))
     if self.on_error_call is not None:
         self.on_error_call(paramsMap)