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)
def add_code(request, index_path): result = [] if 'add' in request.GET: add_num = int(request.GET['add']) if add_num > 100: return json.dumps(result) for index in range(add_num): rand_str = generate_random_str(24) result.append(rand_str) GlobalVar.runSQL('INSERT INTO invitecode (`code`) VALUES (%s)', rand_str) return render(request, index_path + "/invitecode-add.html", {'code_array': result})
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)
def add_casual(request, index_path): info = { 'server_id': '服务器ID', 'hostname': '服务器主人名字', 'ip': 'ip地址', 'port': '27015', 'type': '死斗', 'add_server': 1 } if request.method == 'GET': if 'add_casual' in request.GET: server_id = request.GET['id'] hostname = request.GET['hostname'] ip = request.GET['ipaddr'] port = request.GET['port'] type = request.GET['type'] GlobalVar.runSQL( 'INSERT INTO casualservers (`serverid`,`hostname`,`ip`,`port`,`type`) VALUES (%s,%s,%s,%s,%s)', (server_id, hostname, ip, port, type)) return render(request, index_path + "/admin-edit-server-casual.html", info)
def add(request, index_path): info = { 'server_id': '服务器ID', 'server_location': '服务器地理位置', 'server_group': '服务器分组', 'server_ip_port': '127.0.0.1:27015', 'add_server': 1 } if request.method == 'GET': if 'addserver' in request.GET: server_id = request.GET['id'] location = request.GET['location'] group = request.GET['group'] ipaddr = request.GET['ipaddr'] ip = ipaddr.split(':')[0] port = int(ipaddr.split(':')[1]) matching = 0 GlobalVar.runSQL( 'INSERT INTO matchserver (`serverID`,`location`,`group`,`matching`,`ip`,`port`) VALUES (%s,%s,%s,%s,%s,%s)', (server_id, location, group, matching, ip, port)) return render(request, index_path + "/admin-edit-server.html", info)
def getALLinfos(first, last): return GlobalVar.runSQL( "select * from matched ORDER BY `time` ASC limit %s,%s", (first, last))
def SearchMatch_matching(id): return GlobalVar.runSQL( "select * from matching where `serverid` ORDER BY `uptime` ASC like %s", ('%' + id + '%'))
def deleteServerByID(id): GlobalVar.runSQL("DELETE FROM matchserver where `serverID` = %s limit 1", (id))
def getInviteCode(): return GlobalVar.runSQL("SELECT COUNT(*) FROM invitecode")[0][0]
def search(name): return GlobalVar.runSQL("select * from matchserver where serverID like %s", ('%' + name + '%'))
def SearchMatch(id): return GlobalVar.runSQL("select * from invitecode where `code` like %s", ('%' + id + '%'))
def getNowCount(): return GlobalVar.runSQL("select COUNT(*) from invitecode ")[0][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)
def casual(request, index_path): all_info = [] serverInfo = [] all_flush = [] if request.method == 'GET': if 'del' in request.GET: GlobalVar.runSQL('DELETE FROM casualservers WHERE `serverid` = %s', (request.GET['del'])) if 'edit_server' in request.GET and 'id' in request.GET: info = { 'server_id': request.GET['id'], 'hostname': request.GET['hostname'], 'ip': request.GET['ip'], 'port': request.GET['port'], 'type': request.GET['type'], 'add_server': 0 } return render(request, index_path + "/admin-edit-server-casual.html", info) if 'config_casual' in request.GET: server_id = request.GET['id'] hostname = request.GET['hostname'] ip = request.GET['ipaddr'] port = request.GET['port'] type = request.GET['type'] GlobalVar.runSQL( "UPDATE casualservers SET `serverid`=%s,`hostname`=%s,`ip`=%s,`port`=%s,`type`=%s WHERE `serverid` = %s limit 1", (server_id, hostname, ip, port, type, request.GET['config_casual'])) if 'search' in request.GET: all_info = search_casual(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_casual() 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_casual(int_get * 10, 20) except: all_info = getALLinfos_casual(0, 10) for index in range(len(all_info)): serverInfo.append({ 'id': all_info[index][GlobalVar.sql_casualservers_serverid], 'hostname': all_info[index][GlobalVar.sql_casualservers_hostname], 'ip': all_info[index][GlobalVar.sql_casualservers_ip], 'port': all_info[index][GlobalVar.sql_casualservers_port], 'type': all_info[index][GlobalVar.sql_casualservers_type] }) # 剩下的交给前端 return render(request, index_path + "/server_casual.html", { 'servers': serverInfo, 'flush': all_flush })
def getALLinfos(first, last): return GlobalVar.runSQL("select * from matchserver limit %s,%s ", (first, last))
def search_casual(name): return GlobalVar.runSQL( "select * from casualservers where serverid like %s", ('%' + name + '%'))
def SearchMatch(id): return GlobalVar.runSQL( "select * from matched where `matchid` ORDER BY `time` ASC like %s", ('%' + id + '%'))
def changeMatchStusbyID(id, status): GlobalVar.runSQL( "UPDATE matchserver SET `matching` = %s WHERE `serverID` = %s limit 1", (int(status), id))
def getNowCount_matching(): return GlobalVar.runSQL("select COUNT(id) from matching ")[0][0]
def getRegisterUsers(): return GlobalVar.runSQL("SELECT COUNT(id) FROM userdata")[0][0]
def getALLinfos(first, last): return GlobalVar.runSQL("select * from invitecode limit %s,%s", (first, last))
def getMatchs(): return GlobalVar.runSQL("SELECT COUNT(*) FROM matching")[0][0]
def getNowCount(): return GlobalVar.runSQL("select COUNT(*) from roomlist")[0][0]
def getMatchingStatus(id): return GlobalVar.runSQL( "SELECT * FROM matchserver where `serverID` = %s limit 1", (id))[0][GlobalVar.sql_matchserver_matching]
def getServers(): return GlobalVar.runSQL("SELECT COUNT(*) FROM matchserver")[0][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 })
def getBannedPlayer(): return GlobalVar.runSQL("SELECT COUNT(*) FROM userdata WHERE `banned` = 1")[0][0]
def getALLinfos(first, last): return GlobalVar.runSQL("select * from roomlist limit %s,%s ", (first, last))
def getMysqlVersion(): return GlobalVar.runSQL("select version()")[0][0]
def getNowCount_casual(): return GlobalVar.runSQL("select COUNT(*) from casualservers")[0][0]