Esempio n. 1
0
def matched(request, index_path):
    all_info = []
    matchInfo = []
    all_flush = []
    if request.method == 'GET':
        if 'search' in request.GET:
            all_info = SearchMatch(request.GET['search'])
        else:
            try:
                if 'p' in request.GET:
                    int_get = int(request.GET['p'])
                    if int_get < 0:
                        return HttpResponse('F**K YOU HACKER')
                    maxNumber = getNowCount()
                    needFlush = 0
                    if maxNumber > 10:
                        needFlush = (maxNumber // 10) + 1
                        temp = 0
                        while True:
                            if temp == needFlush:
                                break
                            all_flush.append(temp)
                            temp += 1
                    all_info = getALLinfos(int_get * 10, int_get * 10 + 10)
            except:
                all_info = getALLinfos(0, 10)
        for index in range(len(all_info)):
            matchInfo.append({
                'matchid':
                all_info[index][GlobalVar.sql_matched_matchid],
                'red_team_player':
                api_process.process_playerlist_decode(
                    all_info[index][GlobalVar.sql_matched_red_team_player]),
                'blue_team_player':
                api_process.process_playerlist_decode(
                    all_info[index][GlobalVar.sql_matched_blue_team_player]),
                'red_team_score':
                all_info[index][GlobalVar.sql_matched_red_team_score],
                'blue_team_score':
                all_info[index][GlobalVar.sql_matched_blue_team_score],
                'cheater':
                all_info[index][GlobalVar.sql_matched_cheater],
                'serverid':
                all_info[index][GlobalVar.sql_matched_serverid],
                'demoid':
                all_info[index][GlobalVar.sql_matched_demoid],
                'time':
                all_info[index][GlobalVar.sql_matched_time],
                'map':
                all_info[index][GlobalVar.sql_matched_map],
            })
    return render(request, index_path + "/match-list.html", {
        'match': matchInfo,
        'flush': all_flush
    })
Esempio n. 2
0
def api_get(request):
    result = {
        'msgType': 'get_player',
        'rank': 0,
        'info': {},
        'ico': '',
        'matchid': [],
        'banned': 0,
        'success': 0
    }
    if request.GET:
        if 'name' in request.GET:
            player_name = web_socket.htmlescape(request.GET['name'])
            check = GlobalVar.runSQL(
                'SELECT * FROM userdata WHERE `username` = %s LIMIT 1', player_name)
            if not check:
                return api_process.get_json(result)
            data_encode = check[0][GlobalVar.sql_userdata_data]
            data_decode = api_process.process_playerlist_decode(data_encode)
            result['info'] = data_decode
            result['banned'] = check[0][GlobalVar.sql_userdata_banned]
            result['success'] = 1
            result['rank'] = check[0][GlobalVar.sql_userdata_rank]
            result['ico'] = check[0][GlobalVar.sql_userdata_PlayerInfo]
            result['matchid'] = data_decode['matched']
            return api_process.get_json(result)
    return api_process.get_json(result)
Esempio n. 3
0
def api_setmusic(request):
    result = {
        'msgType': 'set_music',
        'success': 0
    }
    if request.GET:
        if 'key' in request.GET and 'musicid' in request.GET:
            sec_key = request.GET['key']
            musicid = request.GET['musicid']
            if not web_socket.is_number(musicid):
                return api_process.get_json(result)
            check = api_process.process_getdata_by_key(sec_key)
            if not check:
                return api_process.get_json(result)
            if check[0][GlobalVar.sql_userdata_banned] == 1:
                return api_process.get_json(result)
            result['success'] = 1
            data_encode = check[0][GlobalVar.sql_userdata_data]
            data_decode = api_process.process_playerlist_decode(data_encode)
            data_decode['music'] = musicid
            data_encode = api_process.process_playerlist_encode(
                data_decode).decode(encoding='GBK')
            GlobalVar.runSQL(
                'update userdata set `data` = %s where `Key` = %s limit 1', (data_encode, sec_key))
    return api_process.get_json(result)
Esempio n. 4
0
def main(request, index_path):
    all_info = []
    roomInfo = []
    all_flush = []
    if request.method == 'GET':
        if 'delroom' in request.GET:
            roomid = request.GET['delroom']
            check = GlobalVar.runSQL(
                'SELECT * FROM roomlist WHERE `RoomID` = %s', roomid)
            if check:
                if not check[0][GlobalVar.sql_roomlist_ingame]:
                    result = {'msgType': 'kick', 'name': '', 'roomid': roomid}
                    GlobalVar.runSQL(
                        "DELETE FROM roomlist WHERE `RoomID` = %s LIMIT 1",
                        roomid)
                    json_encode = api_process.process_playerlist_encode(
                        result).decode(encoding='GBK')
                    redis_connect = GlobalVar.get_value('g_redis_server')
                    redis_connect.publish('room', json_encode)
        try:
            if 'p' in request.GET:
                int_get = int(request.GET['p'])
                if int_get < 0:
                    return HttpResponse('F**K YOU HACKER')
                maxNumber = getNowCount()
                needFlush = 0
                if maxNumber > 10:
                    needFlush = (maxNumber // 10) + 1
                    temp = 0
                    while True:
                        if temp == needFlush:
                            break
                        all_flush.append(temp)
                        temp += 1
                all_info = getALLinfos(int_get * 10, 20)
        except:
            all_info = getALLinfos(0, 10)

    for index in range(len(all_info)):
        player_list_encode = all_info[index][GlobalVar.sql_roomlist_PlayerList]
        player_list_decode = api_process.process_playerlist_decode(
            player_list_encode)
        players_name = list(player_list_decode.keys())
        config = all_info[index][GlobalVar.sql_roomlist_config]
        config_decode = api_process.process_playerlist_decode(config)
        public = '隐身'
        btn_class = "layui-btn layui-btn-normal layui-btn-mini"
        if all_info[index][GlobalVar.sql_roomlist_public]:
            public = '公开'
            btn_class = "layui-btn layui-btn-warm layui-btn-mini"
        search = '空闲'
        btn_search_class = "layui-btn layui-btn-normal layui-btn-mini"
        if all_info[index][GlobalVar.sql_roomlist_StartSearch]:
            search = '搜索中'
            btn_search_class = "layui-btn layui-btn-warm layui-btn-mini"
        ingame = '空闲'
        btn_ingame_class = "layui-btn layui-btn-normal layui-btn-mini"
        if all_info[index][GlobalVar.sql_roomlist_ingame]:
            ingame = '游戏中'
            btn_ingame_class = "layui-btn layui-btn-warm layui-btn-mini"
        roomInfo.append({
            'roomid':
            all_info[index][GlobalVar.sql_roomlist_RoomID],
            'players':
            players_name,
            'in_search':
            all_info[index][GlobalVar.sql_roomlist_StartSearch],
            'rank':
            all_info[index][GlobalVar.sql_roomlist_Rank],
            'title':
            config_decode['title'],
            'text':
            config_decode['text'],
            'ico':
            config_decode['ico'],
            'ingame':
            ingame,
            'public':
            public,
            'search':
            search,
            'btn_class':
            btn_class,
            'btn_search_class':
            btn_search_class,
            'btn_ingame_class':
            btn_ingame_class
        })
    # 剩下的交给前端
    return render(request, index_path + "/room_manage.html", {
        'rooms': roomInfo,
        'flush': all_flush
    })
Esempio n. 5
0
def update_image(request):
    result = {
        'msgType': 'update_image',
        'image': '',
        'uFuck': 0,
        'success': 0
    }
    if request.method == 'POST':
        image_file = request.FILES.get('file', None)
        sec_key = request.POST['key']
        method = request.POST['method']
        check = api_process.process_getdata_by_key(sec_key)
        if not check:
            return api_process.get_json(result)
        if check[0][GlobalVar.sql_userdata_banned] == 1:
            return api_process.get_json(result)
        if method == 'room_ico' and check[0][GlobalVar.sql_userdata_roomid] == '0':
            return api_process.get_json(result)
        if image_file:
            if image_file.size > 2 * 1024 * 1024:
                result['uFuck'] = 1
                return api_process.get_json(result)
            if not check_file_name(image_file):
                result['uFuck'] = 2
                return api_process.get_json(result)
            if file_extension(image_file.name) == '.gif':
                extension = '.gif'
            else:
                extension = '.jpg'
            byte = image_file.read()
            if extension != '.gif':
                if not security.check_iamge(byte):
                    result['success'] = 0
                    result['uFuck'] = 3
                    return api_process.get_json(result)
            save_name = get_md5(byte) + extension
            result['image'] = save_name
            save_dir = os.path.join(os.path.dirname(os.path.dirname(
                os.path.dirname(os.path.realpath(__file__)))), 'static')
            save_dir = os.path.join(save_dir, 'images')
            if method == 'player_avater':
                save_dir = os.path.join(save_dir, 'players')
            elif method == 'room_ico':
                save_dir = os.path.join(save_dir, 'room')
            save_name = os.path.join(save_dir, save_name)
            result['success'] = 1
            if method == 'player_avater':
                GlobalVar.runSQL(
                    'UPDATE userdata SET `PlayerInfo` = %s WHERE `key` = %s LIMIT 1', (result['image'], sec_key))
            elif method == 'room_ico':
                roomid = check[0][GlobalVar.sql_userdata_roomid]
                roomlist = GlobalVar.runSQL(
                    'SELECT * FROM roomlist WHERE `RoomID` = %s limit 1', roomid)
                if not roomid:
                    return api_process.get_json(result)
                room_config_decode = api_process.process_playerlist_decode(
                    roomlist[0][GlobalVar.sql_roomlist_config])
                room_config_decode['ico'] = result['image']
                room_config_encode = api_process.process_playerlist_encode(
                    room_config_decode).decode(encoding='GBK')
                GlobalVar.runSQL(
                    'UPDATE roomlist SET `config` = %s WHERE `RoomID` = %s LIMIT 1', (room_config_encode, roomid))
                GlobalVar.runSQL(
                    'UPDATE userdata SET `roomconfig` = %s WHERE `Key` = %s LIMIT 1', (room_config_encode, sec_key))
            with open(save_name, 'wb') as file:
                file.write(byte)
            return api_process.get_json(result)
    return api_process.get_json(result)
Esempio n. 6
0
def main(request, index_path):
    all_info = []
    userInfo = []
    all_flush = []
    if request.method == 'GET':
        if 'ban' in request.GET:
            setPlayerBan(request.GET['ban'])
        if 'unban' in request.GET:
            setPlayerBan(request.GET['unban'], 0)
        if 'search' in request.GET:
            all_info = searchPlayer(request.GET['search'])
        if 'username' in request.GET:
            all_info = getPlayerinfo(request.GET['username'])
        else:
            try:
                if 'p' in request.GET:
                    int_get = int(request.GET['p'])
                    if int_get < 0:
                        return HttpResponse('F**K YOU HACKER')
                    maxNumber = getNowCount()
                    needFlush = 0
                    if maxNumber > 10:
                        needFlush = (maxNumber // 10) + 1
                        temp = 0
                        left = int_get - 8
                        right = int_get + 8
                        while True:
                            temp += 1
                            if temp == needFlush:
                                break
                            if temp < left or temp > right:
                                continue
                            all_flush.append(temp)

                    all_info = getALLinfos(int_get * 10, 20)
            except:
                all_info = getALLinfos(0, 10)

    for index in range(len(all_info)):
        config_decode = api_process.process_playerlist_decode(
            all_info[index][GlobalVar.sql_userdata_roomconfig])
        status = all_info[index][GlobalVar.sql_userdata_banned]
        banned = '封禁'
        btn_class = 'layui-btn layui-btn-danger layui-btn-mini'
        if not status:
            banned = '正常'
            btn_class = 'layui-btn layui-btn-normal layui-btn-mini'
        userInfo.append({
            'id':
            all_info[index][GlobalVar.sql_userdata_id],
            'name':
            all_info[index][GlobalVar.sql_userdata_username],
            'email':
            all_info[index][GlobalVar.sql_userdata_email],
            'steamID':
            all_info[index][GlobalVar.sql_userdata_SteamID],
            'title':
            config_decode['title'],
            'text':
            config_decode['text'],
            'ico':
            config_decode['ico'],
            'rank':
            all_info[index][GlobalVar.sql_userdata_rank],
            'status':
            banned,
            'btn_class':
            btn_class
        })
    # 剩下的交给前端
    return render(request, index_path + "/member-list.html", {
        'users': userInfo,
        'flush': all_flush
    })