コード例 #1
0
ファイル: view_users.py プロジェクト: shimdh/mrd_server
def setCash():
    result = dict(
        type=ProtocolTypes.SetCash,
        result=ResultCodes.Success)

    # writeDirtyLog('setCash: ' + request.form['data'])

    if request.form['data']:
        got_data = json.loads(request.form['data'])
        from_keys = [
            'session_id',
            'cash'
        ]
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                got_user.cash = got_data['cash'] or 0
                db_session.add(got_user)

                result['result'] = commitData()
            else:
                result['result'] = ResultCodes.NoData
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #2
0
ファイル: view_inventories.py プロジェクト: shimdh/mrd_server
def getInventories():
    result = {'type': ProtocolTypes.GetInventories}

    if request.method == 'POST' and request.form['data']:
        got_data = json.loads(request.form['data'])

        from_keys = ['session_id']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                if (not got_user.inventories) or (got_user.inventories == ''):
                    result['result'] = ResultCodes.NoData
                else:
                    got_inventories = json.loads(got_user.inventories)
                    if got_inventories:
                        if len(got_inventories) == 0:
                            result['result'] = ResultCodes.NoData
                        else:
                            result['inventories'] = got_user.inventories
                    else:
                        result['result'] = ResultCodes.NoData
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #3
0
ファイル: view_stats.py プロジェクト: shimdh/mrd_server
def getStats():
    result = {'type': ProtocolTypes.GetStats}

    if request.method == 'POST' and request.form['data']:
        got_data = json.loads(request.form['data'])
        from_keys = ['session_id']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                find_stat = Stat.query.filter_by(user_id=got_user.id).first()
                if find_stat:
                    send_stat = dict(
                        exp=find_stat.exp,
                        level=find_stat.level,
                        hp=find_stat.hp,
                        weapon_level=find_stat.weapon_level,
                        weapon_exp=find_stat.weapon_exp,
                        visited_zone_no=find_stat.visited_zone_no,
                    )

                    result['stats'] = json.dumps(send_stat)
                else:
                    result['result'] = ResultCodes.NoData
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #4
0
ファイル: view_slots.py プロジェクト: shimdh/mrd_server
def setSlots():
    result = dict(
        type=ProtocolTypes.SetSlots,
        result=ResultCodes.Success
    )
    if request.method == 'POST' and request.form['data']:
        got_data = json.loads(request.form['data'])
        from_keys = ['session_id', 'slots']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                got_user.slots = json.dumps(got_data['slots'])
                db_session.add(got_user)

                result['result'] = commitData()
                try:
                    db_session.commit()
                except exc.SQLAlchemyError:
                    result['result'] = ResultCodes.DBInputError
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #5
0
ファイル: view_diaries.py プロジェクト: shimdh/mrd_server
def addDiary():
    result = dict(
        type=ProtocolTypes.AddDiary,
        result=ResultCodes.Success
    )

    # writeDirtyLog(request.form['data'])

    if request.form['data']:
        got_data = json.loads(request.form['data'])
        from_keys = [
            'session_id', 
            # 'diary_index'
        ]
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                find_diary = Diary.query.filter_by(
                    user_id=got_user.id, diary_index=got_data['diary_index']).first()
                if find_diary:
                    result['result'] = ResultCodes.DataExist
                else:
                    made_diary = Diary(got_user.id, got_data['diary_index'])
                    db_session.add(made_diary)
                    result['result'] = commitData()
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #6
0
ファイル: view_diaries.py プロジェクト: shimdh/mrd_server
def getDiaries():
    result = dict(
        type=ProtocolTypes.GetDiaries,
        result=ResultCodes.Success)

    # writeDirtyLog(request.form['data'])

    if request.form['data']:
        got_data = json.loads(request.form['data'])
        from_keys = ['session_id']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                find_diaries = Diary.query.filter_by(user_id=got_user.id).all()
                if find_diaries:
                    send_list = list()
                    for find_diary in find_diaries:
                        send_list.append(find_diary.diary_index)

                    result['diaries'] = json.dumps(send_list)
                else:
                    result['result'] = ResultCodes.NoData
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #7
0
ファイル: view_saved.py プロジェクト: shimdh/mrd_server
def setButtonState():
    result = dict(
        type=ProtocolTypes.SetButtonState,
        result=ResultCodes.Success)

    if request.form['data']:
        got_data = json.loads(request.form['data'])
        from_keys = ['session_id', 'button']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                find_button = Button.query.filter_by(
                    user_id=got_user.id).first()
                if find_button:
                    find_button.state = got_data['button']
                    db_session.add(find_button)
                else:
                    made_button = Button(got_user.id, got_data['button'])
                    db_session.add(made_button)

                result['result'] = commitData()
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #8
0
ファイル: view_costumes.py プロジェクト: shimdh/mrd_server
def setOwnCostumebases():
    result = {'type': ProtocolTypes.SetOwnCostumeBases}

    if request.form['data']:
        got_data = json.loads(request.form['data'])
        from_keys = ['session_id', 'own_costumebases']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                if got_data['own_costumebases'] == '':
                    result['result'] = ResultCodes.InputParamError
                else:
                    for got_costumebase_index in got_data['own_costumebases']:
                        find_costumebase = OwnCostumebase.query.filter_by(
                            user_id=got_user.id, costumebase_index=got_costumebase_index).first()
                        if not find_costumebase:
                            temp_costumebase = OwnCostumebase(got_user.id, got_costumebase_index)
                            db_session.add(temp_costumebase)
                    result['result'] = commitData()
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #9
0
ファイル: view_costumes.py プロジェクト: shimdh/mrd_server
def getOwnCostumebases():
    result = {'type': ProtocolTypes.GetOwnCostumeBases}

    if request.form['data']:
        got_data = json.loads(request.form['data'])
        from_keys = ['session_id']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                find_own_costumebases = OwnCostumebase.query.filter_by(user_id=got_user.id).all()
                if find_own_costumebases:
                    found_own_costumebase_list = list()
                    for find_own_costumebase in find_own_costumebases:
                        temp_costumebase_dict = dict(
                            costumebase_index = find_own_costumebase.costumebase_index,
                            lastdate_from_gotcash = find_own_costumebase.lastdate_from_gotcash.strftime(
                                "%Y,%m,%d"))
                        # temp_costumebase_dict['costumebase_index'] = find_own_costumebase.costumebase_index
                        # temp_costumebase_dict['lastdate_from_gotcash'] = find_own_costumebase.lastdate_from_gotcash.strftime(
                        #     "%Y,%m,%d")
                        found_own_costumebase_list.append(temp_costumebase_dict)
                    result['own_costumebases'] = json.dumps(found_own_costumebase_list)
                else:
                    result['result'] = ResultCodes.NoData
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #10
0
ファイル: view_costumes.py プロジェクト: shimdh/mrd_server
def setWornCostume():
    result = dict(
        type=ProtocolTypes.SetWornCostume,
        result=ResultCodes.Success)

    if request.form['data']:
        got_data = json.loads(request.form['data'])
        from_keys = ['session_id', 'costumes']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                find_worn_costume = WornCostume.query.filter_by(user_id=got_user.id).first()
                if find_worn_costume:
                    find_worn_costume.costumes = json.dumps(got_data['costumes'])
                    db_session.add(find_worn_costume)
                else:
                    made_worn_costume = WornCostume(user_id=got_user.id, costumes=json.dumps(got_data['costumes']))
                    db_session.add(made_worn_costume)

                result['result'] = commitData()
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError


    return str(json.dumps(result))
コード例 #11
0
ファイル: view_puzzles.py プロジェクト: shimdh/mrd_server
def getOpenedPuzzlePieces():
    result = dict(
        type=ProtocolTypes.GetPuzzlePieces,
        result=ResultCodes.Success)

    if request.form['data']:
        got_data = json.loads(request.form['data'])
        from_keys = ['session_id']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                find_puzzle_pieces = OpenedPuzzlePiece.query.filter_by(user_id=got_user.id).all()
                if find_puzzle_pieces:
                    send_list = list()
                    for find_puzzle_piece in find_puzzle_pieces:
                        tmp_piece = dict(
                            puzzle_index=find_puzzle_piece.puzzle_index,
                            condition=find_puzzle_piece.condition)
                        send_list.append(tmp_piece)

                    result['puzzle_pieces'] = json.dumps(send_list)
                else:
                    result['result'] = ResultCodes.NoData
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #12
0
ファイル: view_puzzles.py プロジェクト: shimdh/mrd_server
def addOpenedPuzzle():
    result = dict(
        type=ProtocolTypes.AddPuzzle,
        result=ResultCodes.Success
        )

    # writeDirtyLog(request.form['data'])

    if request.form['data']:
        got_data = json.loads(request.form['data'])
        from_keys = [
            'session_id',
            # 'puzzle_index', 'opened'
        ]
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                find_puzzle = OpenedPuzzle.query.filter_by(
                    user_id=got_user.id, puzzle_index=got_data['puzzle_index']).first()
                if find_puzzle:
                    find_puzzle.opened = got_data['opened']
                    db_session.add(find_puzzle)
                else:
                    made_puzzle = OpenedPuzzle(
                        got_user.id, got_data['puzzle_index'], got_data['opened'])
                    db_session.add(made_puzzle)

                result['result'] = commitData()
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #13
0
ファイル: view_stats.py プロジェクト: shimdh/mrd_server
def setStats():
    result = {'type': ProtocolTypes.SetStats}

    if request.method == 'POST' and request.form['data']:
        got_data = json.loads(request.form['data'])
        from_keys = ['session_id', 'stats']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                got_stat = got_data['stats']
                find_stat = Stat.query.filter_by(user_id=got_user.id).first()
                if find_stat:
                    # find_stat.__dict__.update(dict(
                    #     exp=got_stat['exp'],
                    #     level=got_stat['level'],
                    #     hp=got_stat['hp'],
                    #     weapon_level=got_stat['weapon_level'],
                    #     weapon_exp=got_stat['weapon_exp'],
                    #     visited_zone_no=got_stat['visited_zone_no'],
                    #     updated_date=datetime.datetime.now()))
                    find_stat.exp = got_stat['exp']
                    find_stat.level = got_stat['level']
                    find_stat.hp = got_stat['hp']
                    find_stat.weapon_level = got_stat['weapon_level']
                    find_stat.weapon_exp = got_stat['weapon_exp']
                    find_stat.visited_zone_no = got_stat['visited_zone_no']
                    find_stat.updated_date = datetime.datetime.now()

                    db_session.add(find_stat)
                else:
                    made_stat = Stat(got_user.id)
                    # made_stat.__dict__.update(dict(
                    #     exp=got_stat['exp'],
                    #     level=got_stat['level'],
                    #     hp=got_stat['hp'],
                    #     weapon_level=got_stat['weapon_level'],
                    #     weapon_exp=got_stat['weapon_exp'],
                    #     visited_zone_no=got_stat['visited_zone_no'],
                    #     updated_date=datetime.datetime.now()))
                    made_stat.exp = got_stat['exp']
                    made_stat.level = got_stat['level']
                    made_stat.hp = got_stat['hp']
                    made_stat.weapon_level = got_stat['weapon_level']
                    made_stat.weapon_exp = got_stat['weapon_exp']
                    made_stat.visited_zone_no = got_stat['visited_zone_no']
                    made_stat.updated_date = datetime.datetime.now()

                    db_session.add(made_stat)

                try:
                    db_session.commit()
                except exc.SQLAlchemyError:
                    result['result'] = ResultCodes.DBInputError
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #14
0
ファイル: view_friends.py プロジェクト: shimdh/mrd_server
def requestFriend():
    result = dict(
        type=ProtocolTypes.RequestFriend,
        result=ResultCodes.Success)

    if request.form['data']:
        got_data = json.loads(request.form['data'])

        from_keys = ['session_id', 'request_friend']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                find_friend = Friend.query.filter_by(user_id=got_user.id, friend_id=got_data['request_friend']).first()
                if not find_friend:
                    friend_data = Friend(got_user.id, got_data['request_friend'])
                    db_session.add(friend_data)
                    write_mail = Mail(got_user.id, got_data['request_friend'], u"친구 신청")
                    write_mail.request_friend = True
                    db_session.add(write_mail)
                    result['result'] = commitData()
                else:
                    result['result'] = ResultCodes.DataExist
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #15
0
ファイル: view_mails.py プロジェクト: shimdh/mrd_server
def openMail():
    result = dict(
        type=ProtocolTypes.OpenMail,
        result=ResultCodes.Success
    )

    if request.form['data']:
        got_data = json.loads(request.form['data'])
        from_keys = ['session_id', 'mail_index']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                got_mail = Mail.query.filter_by(id=got_data['mail_index'], to_user_id=got_user.id).first()
                if got_mail:
                    got_mail.opened = True
                    db_session.add(got_mail)
                    result['result'] = commitData()
                else:
                    result['result'] = ResultCodes.NoData
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #16
0
ファイル: view_mails.py プロジェクト: shimdh/mrd_server
def deleteMails():
    result = dict(
        type=ProtocolTypes.DeleteMails,
        result=ResultCodes.Success
    )
    if request.form['data']:
        got_data = json.loads(request.form['data'])
        from_keys = ['session_id', 'mail_indexes']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                if len(got_data['mail_indexes']) > 0:
                    got_mails = Mail.query.filter(
                        Mail.id.in_(got_data['mail_indexes'])).all()
                    if got_mails:
                        for got_mail in got_mails:
                            db_session.delete(got_mail)
                        result['result'] = commitData()
                else:
                    result['result'] = ResultCodes.InputParamError
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #17
0
ファイル: view_saved.py プロジェクト: shimdh/mrd_server
def getSavedStory():
    result = dict(
        type=ProtocolTypes.GetSavedStory,
        result=ResultCodes.Success)

    if request.form['data']:
        got_data = json.loads(request.form['data'])
        from_keys = ['session_id']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                find_story = SavedStory.query.filter_by(
                    user_id=got_user.id).first()
                if find_story:
                    tmp_result = dict(
                        zone_index=find_story.zone_index,
                        episode_no=find_story.episode_no,
                        wave_no=find_story.wave_no,
                        position=find_story.position,
                        rotation=find_story.rotation)
                    result.update(tmp_result)
                else:
                    result['result'] = ResultCodes.NoData
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #18
0
ファイル: view_mails.py プロジェクト: shimdh/mrd_server
def readMail():
    result = dict(
        type=ProtocolTypes.ReadMail,
        result=ResultCodes.Success)

    if request.form['data']:
        got_data = json.loads(request.form['data'])
        from_keys = ['session_id', 'mail_index']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                got_mail = Mail.query.filter_by(
                    id=got_data['mail_index']).first()
                if got_mail:
                    if not got_mail.from_user_id in lst_from_system_mails:
                        from_user_char = Character.query.filter_by(user_id=got_mail.from_user_id).first()
                        if from_user_char:
                            result['mail_index'] = got_mail.id
                            result['from_name'] = from_user_char.name
                            result['from_user_id'] = got_mail.from_user_id
                            result['sent_date'] = got_mail.registered_date.strftime(
                                "%Y,%m,%d,%H,%M")
                            result['title'] = from_user_char.name + u"로부터 메일"
                            result['content'] = got_mail.content
                            if not got_mail.items or got_mail.items == '':
                                result['items'] = ''
                            else:
                                result['items'] = got_mail.items
                        else:
                            result['result'] = ResultCodes.InputParamError
                    else:
                        if got_mail.from_user_id == lst_from_system_mails[0]:
                            temp_mail_system_name = u"시스템"
                            temp_mail_title = u"시스템으로부터의 메일"
                        if got_mail.from_user_id == lst_from_system_mails[1]:
                            temp_mail_system_name = u"해적선"
                            temp_mail_title = u"해적선으로부터의 메일"
                        result['mail_index'] = got_mail.id
                        result['from_name'] = temp_mail_system_name
                        result['from_user_id'] = got_mail.from_user_id
                        result['sent_date'] = got_mail.registered_date.strftime(
                            "%Y,%m,%d,%H,%M")
                        result['title'] = temp_mail_title
                        result['content'] = got_mail.content
                        if not got_mail.items or got_mail.items == '':
                            result['items'] = ''
                        else:
                            result['items'] = got_mail.items

                else:
                    result['result'] = ResultCodes.NoData
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #19
0
ファイル: view_friends.py プロジェクト: shimdh/mrd_server
def receiveFriendShipPoint():
    result = dict(
        type=ProtocolTypes.ReceiveFriendShipPoint,
        result=ResultCodes.Success
    )

    if request.form['data']:
        got_data = json.loads(request.form['data'])

        from_keys = ['session_id', 'friend_id']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                find_me = Friend.query.filter_by(
                    user_id=got_user.id, friend_id=got_data['friend_id']).first()
                if find_me:
                    if not find_me.friendship_sent_date:
                        result['result'] = ResultCodes.InputParamError
                    else:
                        if not find_me.friendship_received_date:
                            find_me.friendship_received_date = datetime.datetime.now()

                            db_session.add(find_me)

                            friendship_point = Config.query.filter_by(str_key='receiving_friendship_point').first()
                            if friendship_point:
                                got_user.friendship_point += int(friendship_point.str_value)
                                db_session.add(got_user)
                                result['added_friendship_point'] = int(friendship_point.str_value)
                            result['result'] = commitData()
                        else:
                            if find_me.friendship_sent_date == datetime.date.today():
                                if not find_me.friendship_received_date or (
                                    find_me.friendship_received_date != datetime.date.today()):
                                    find_me.friendship_received_date = datetime.date.today()

                                    db_session.add(find_me)

                                    friendship_point = Config.query.filter_by(str_key='receiving_friendship_point').first()
                                    if friendship_point:
                                        got_user.friendship_point += int(friendship_point.str_value)
                                        db_session.add(got_user)
                                        result['added_friendship_point'] = int(friendship_point.str_value)
                                    result['result'] = commitData()
                                else:
                                    result['result'] = ResultCodes.InputParamError
                            else:
                                result['result'] = ResultCodes.InputParamError
                else:
                    result['result'] = ResultCodes.NoData
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #20
0
ファイル: view_saved.py プロジェクト: shimdh/mrd_server
def setSavedCurrentZone():
    result = dict(
        type=ProtocolTypes.SetSavedCurrentZone,
        result=ResultCodes.Success)

    def useFoundData(got_user_id, zone_index, episode, position, rotation):
        find_current_zone = SavedCurrentZone.query.filter_by(
            user_id=got_user_id).first()
        
        if find_current_zone:
            find_current_zone.zone_index = zone_index
            find_current_zone.episode = json.dumps(episode)
            find_current_zone.position = json.dumps(position)
            find_current_zone.rotation = json.dumps(rotation)
            find_current_zone.updated_date = datetime.datetime.now()

            return find_current_zone

        else:
            made_current_zone = SavedCurrentZone(got_user_id, zone_index)
            made_current_zone.episode = json.dumps(episode)
            made_current_zone.position = json.dumps(position)
            made_current_zone.rotation = json.dumps(rotation)
            made_current_zone.updated_date = datetime.datetime.now()

            return made_current_zone

    if request.form['data']:
        got_data = json.loads(request.form['data'])
        from_keys = [
            'session_id', 'zone_index', 'episode',
            'position', 'rotation']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                db_session.add(
                    useFoundData(
                        got_user.id, 
                        got_data['zone_index'],
                        got_data['episode'],
                        got_data['position'],
                        got_data['rotation']))

                result['result'] = commitData()
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #21
0
ファイル: view_saved.py プロジェクト: shimdh/mrd_server
def setSavedStory():
    result = dict(
        type=ProtocolTypes.SetSavedStory,
        result=ResultCodes.Success)

    if request.form['data']:
        got_data = json.loads(request.form['data'])
        from_keys = [
            'session_id', 
            'zone_index',
            # 'episode_no',
            # 'wave_no',
            # 'position',
            # 'rotation',
        ]
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                find_story = SavedStory.query.filter_by(
                    user_id=got_user.id).first()
                if find_story:
                    find_story.zone_index = got_data['zone_index']
                    find_story.episode_no = got_data['episode_no']
                    find_story.wave_no = got_data['wave_no']
                    find_story.position = json.dumps(got_data['position'])
                    find_story.rotation = json.dumps(got_data['rotation'])
                    find_story.updated_date = datetime.datetime.now()

                    db_session.add(find_story)
                else:
                    made_story = SavedStory(
                        got_user.id, 
                        got_data['zone_index'], 
                        got_data['episode_no'], 
                        got_data['wave_no'])
                    made_story.position = json.dumps(got_data['position'])
                    made_story.rotation = json.dumps(got_data['rotation'])

                    db_session.add(made_story)

                result['result'] = commitData()
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #22
0
ファイル: view_friends.py プロジェクト: shimdh/mrd_server
def getFriendCharacterInfo():
    result = dict(
        type=ProtocolTypes.GetFriendCharacterInfo,
        result=ResultCodes.Success)

    if request.form['data']:
        got_data = json.loads(request.form['data'])

        from_keys = ['session_id', 'friend_id']
        if checkContainKeys(from_keys, got_data):
            if (got_data['friend_id'] is None) or (got_data['friend_id'] == ''):
                result['result'] = ResultCodes.InputParamError
            else:
                result['result'], got_user = checkSessionId(got_data['session_id'])

                if got_user:
                    find_friend_character = Character.query.filter_by(id=got_data['friend_id']).first()
                    if find_friend_character:
                        send_friend_info = dict(
                            user_id=got_data['friend_id'],
                            name=find_friend_character.name,
                            level=find_friend_character.level,
                            body_type=find_friend_character.body_type,
                            cloak_type=find_friend_character.cloak_type,
                            color_r=find_friend_character.color_r,
                            color_g=find_friend_character.color_g,
                            color_b=find_friend_character.color_b,
                            exp=find_friend_character.exp,
                            face_type=find_friend_character.face_type,
                            hp=find_friend_character.hp,
                            gender=find_friend_character.gender,
                            hair_type=find_friend_character.hair_type,
                            weapon_exp=find_friend_character.weapon_exp,
                            weapon_level=find_friend_character.weapon_level,
                            weapon_type=find_friend_character.weapon_type,
                        )

                        result['friend_info'] = json.dumps(send_friend_info)
                    else:
                        result['result'] = ResultCodes.NoData
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #23
0
ファイル: view_friends.py プロジェクト: shimdh/mrd_server
def acceptFriend():
    #writeDirtyLog('acceptFriend: ' + request.form['data'])
    result = dict(
        type=ProtocolTypes.AcceptFriend,
        result=ResultCodes.Success)

    if request.method == 'POST' and request.form['data']:
        got_data = json.loads(request.form['data'])

        from_keys = ['session_id', 'accept_friend']
        if checkContainKeys(from_keys, got_data):
            if (got_data['accept_friend'] is None) or (got_data['accept_friend'] == ''):
                result['result'] = ResultCodes.InputParamError
            else:
                result['result'], got_user = checkSessionId(got_data['session_id'])

                if got_user:
                    find_friend = Friend.query.filter_by(
                        user_id=got_data['accept_friend'], friend_id=got_user.id, requested=True, accepted=False).first()
                    if find_friend:
                        find_friend.accepted = True
                        db_session.add(find_friend)
                        my_friend = Friend.query.filter_by(
                            user_id=got_user.id, friend_id=got_data['accept_friend']).first()
                        if my_friend:
                            my_friend.request = True
                            my_friend.accepted = True
                            db_session.add(my_friend)
                        else:
                            regist_friend = Friend(got_user.id, got_data['accept_friend'])
                            regist_friend.request = True
                            regist_friend.accepted = True
                            db_session.add(regist_friend)
                        result['result'] = commitData()
                    else:
                        result['result'] = ResultCodes.NoData
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #24
0
ファイル: view_slots.py プロジェクト: shimdh/mrd_server
def getSlots():
    result = {'type': ProtocolTypes.GetSlots}

    if request.method == 'POST' and request.form['data']:
        got_data = json.loads(request.form['data'])
        from_keys = ['session_id']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                if (got_user.slots is None) or (got_user.slots == ''):
                    result['result'] = ResultCodes.NoData
                else:
                    result['slots'] = got_user.slots
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #25
0
ファイル: view_friends.py プロジェクト: shimdh/mrd_server
def addFriend():
    result = dict(
        type=ProtocolTypes.AddFriend,
        result=ResultCodes.Success)

    if request.form['data']:
        got_data = json.loads(request.form['data'])

        from_keys = ['session_id', 'name']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                pass
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #26
0
ファイル: view_costumes.py プロジェクト: shimdh/mrd_server
def gotCashFromCostumeBases():
    result = dict(
        type=ProtocolTypes.GotCashFromCostumeBases,
        result=ResultCodes.Success)

    # writeDirtyLog('gotCashFromCostumeBases: ' + request.form['data'])

    if request.form['data']:
        got_data = json.loads(request.form['data'])
        from_keys = ['session_id',
            'costumebases']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                ok_bases = list()
                for costume_base in got_data['costumebases']:
                    find_own_costumebase = OwnCostumebase.query.filter_by(
                        user_id=got_user.id, costumebase_index=costume_base['index']).first()
                    if find_own_costumebase:
                        find_own_costumebase.lastdate_from_gotcash = datetime.datetime.now()
                        db_session.add(find_own_costumebase)

                        got_user.cash += costume_base['cash']
                        db_session.add(got_user)

                        result['result'] = commitData()

                        if result['result'] == ResultCodes.Success:
                            ok_bases.append(find_own_costumebase.costumebase_index)
                    else:
                        result['result'] = ResultCodes.NoData

                if len(ok_bases) > 0:
                    result['costumebase_indexes'] = ok_bases
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #27
0
ファイル: view_friends.py プロジェクト: shimdh/mrd_server
def getFriendShipPointInfo():
    result = dict(
        type=ProtocolTypes.GetFriendShipPointInfo,
        result=ResultCodes.Success
    )

    if request.form['data']:
        got_data = json.loads(request.form['data'])

        from_keys = ['session_id']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                result['friendship_point'] = got_user.friendship_point
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #28
0
ファイル: view_characters.py プロジェクト: shimdh/mrd_server
def createCharacter():
    result = dict(
        type=ProtocolTypes.CreateCharacter,
        result=ResultCodes.Success)

    if request.form['data']:
        got_data = json.loads(request.form['data'])

        from_keys = ['session_id', 'character']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])
            if got_user:
                got_character = Character.query.filter_by(user_id=got_user.id).first()
                if got_character:
                    result['result'] = ResultCodes.DataExist
                else:
                    got_character = got_data['character']
                    got_user.name = got_character['name']
                    db_session.add(got_user)

                    user_character = Character(got_user.id, got_character['name'])
                    user_character.body_type = got_character['body_type']
                    user_character.cloak_type = got_character['cloak_type']
                    user_character.color_r = got_character['color_r']
                    user_character.color_g = got_character['color_g']
                    user_character.color_b = got_character['color_b']
                    user_character.face_type = got_character['face_type']
                    user_character.gender = got_character['gender']
                    user_character.hair_type = got_character['hair_type']
                    user_character.weapon_type = got_character['weapon_type']
                    
                    db_session.add(user_character)

                    result['result'] = commitData()
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #29
0
ファイル: view_friends.py プロジェクト: shimdh/mrd_server
def getWaitingFriends():
    result = dict(
        type=ProtocolTypes.GetWaitingFriends,
        result=ResultCodes.Success)

    if request.form['data']:
        got_data = json.loads(request.form['data'])

        from_keys = ['session_id']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                find_friends = Friend.query.filter_by(
                    friend_id=got_user.id, requested=True, accepted=False).all()
                if find_friends:
                    friends_data = list()
                    for find_friend in find_friends:
                        friend_data = User.query.filter_by(id=find_friend.user_id).first()
                        if friend_data:
                            tmp_friend = dict(
                                id=find_friend.user_id,
                                name=friend_data.name,
                                nickname=friend_data.nickname,
                                last_login=friend_data.login_date.strftime("%Y,%m,%d")
                            )
                            friends_data.append(tmp_friend)

                        if len(friends_data) == 0:
                            result['result'] = ResultCodes.NoData
                        else:
                            result['waiting_friends'] = json.dumps(friends_data)
                else:
                    result['result'] = ResultCodes.NoData
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
コード例 #30
0
ファイル: view_users.py プロジェクト: shimdh/mrd_server
def getCash():
    result = dict(
        type=ProtocolTypes.GetCash,
        result=ResultCodes.Success)

    if request.form['data']:
        got_data = json.loads(request.form['data'])
        from_keys = [
            'session_id']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                result['cash'] = got_user.cash
            else:
                result['result'] = ResultCodes.NoData
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))