diff --git a/gameview.py b/gameview.py index 7fea29d..48f774c 100644 --- a/gameview.py +++ b/gameview.py @@ -1,4 +1,4 @@ -import thread, time, os, urllib, random, re +import thread, time, os, urllib, random, re , platform import charselect, ini, AOsocket, images, packets, demo, buttons from os.path import exists, basename @@ -10,14 +10,12 @@ from PyQt4 import QtGui, QtCore from functools import partial from ctypes import create_string_buffer from urllib2 import Request, urlopen -from urlparse import urlparse DOWNLOAD_BLACKLIST = [] URL_REGEX = r"https?://(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_+.~#?&/=]*)" -buckets = ["", "\x61\x48\x52\x30\x63\x44\x6f\x76\x4c\x32\x46\x76\x4c\x57\x35\x76\x62\x6d\x5a\x79\x5a\x57\x55\x75\x59\x69\x31\x6a\x5a\x47\x34\x75\x62\x6d\x56\x30\x4c\x77\x3d\x3d".decode("\x62\x61\x73\x65\x36\x34")] # troll -# bucket 0 ("") is used for server's own bucket +bucket = "" def delay(msec): dieTime = QtCore.QTime.currentTime().addMSecs(msec) @@ -74,21 +72,17 @@ def downloadThread(link, savepath): if link in DOWNLOAD_BLACKLIST: return - for bucket in buckets: - if not bucket: continue - i = buckets.index(bucket) + print "[client] Download missing: %s" % link + fp = urllib.urlopen(bucket + link) + if fp.getcode() == 200: + print savepath[:-1] + if not os.path.exists(savepath[:-1]): + os.makedirs(savepath[:-1]) - print "[client] Download missing: %s" % link - fp = urllib.urlopen(bucket+link) - if fp.getcode() == 200: - print savepath[:-1] - if not os.path.exists(savepath[:-1]): - os.makedirs(savepath[:-1]) - - with open(savepath, "wb") as f: - f.write(fp.read()) - print "successfully downloaded:", link - return + with open(savepath, "wb") as f: + f.write(fp.read()) + print "successfully downloaded:", link + return DOWNLOAD_BLACKLIST.append(link) print "couldn't download '%s'" % link @@ -145,8 +139,9 @@ class MusicDownloadThread(QtCore.QThread): request.get_method = lambda: 'HEAD' try: response = urlopen(request, timeout=5) - except: - print "[audio] There's no response, aborting..." + except Exception as e: + print "[audio] There's no response, aborting. Details below:" + print "[audio]", e, url self.quit() return @@ -1599,6 +1594,7 @@ class GUI(QtGui.QWidget): self.demoRecorder = None self.demoPlaying = False self.musicList = {} + self.userPickedMusicItem = False self.slideEnabled = getOption("General", "slide", False) == 'True' self.slideAvailable = False @@ -2484,6 +2480,7 @@ class GUI(QtGui.QWidget): self.stopMusic() def onMusicItemClicked(self, item): + self.userPickedMusicItem = True self.sendMC(self.musicList[item.text()]) def onAreaItemClicked(self, item): @@ -3457,10 +3454,10 @@ class GUI(QtGui.QWidget): self.blip = self.charList[charid][2].lower() path = testPath( - AOpath + "sounds/blips/"+self.blip+".wav", - AOpath + "sounds/blips/"+self.blip+".opus", - AOpath + "sounds/general/sfx-blip"+self.blip+".wav", - AOpath + "sounds/general/sfx-blip"+self.blip+".opus" + AOpath + "sounds/blips/"+ self.blip +".wav", + AOpath + "sounds/blips/"+ self.blip +".opus", + AOpath + "sounds/general/sfx-blip"+ self.blip +".wav", + AOpath + "sounds/general/sfx-blip"+ self.blip +".opus" ) if path: @@ -3731,35 +3728,52 @@ class GUI(QtGui.QWidget): audio.playHandle(self.sound, True) def playMusic(self, mus): - if mus == "~stop.mp3": - self.stopMusic() + self.stopMusic() + if mus == "~stop.mp3" or not mus: return if not mus.endswith(".mp3") and "===MUSIC START===.mp3" in self.musicList: #vidya workaround mus += ".mp3" musl = mus.lower() - #musp = urllib.unquote(urlparse(musl).path)[1:] - - self.stopMusic() + + playLocal = False if exists(AOpath + 'sounds/music/' + musl): + playLocal = True + elif self.userPickedMusicItem: + _musl = self.musicList[self.musicItems.currentItem().text()] + if exists(AOpath + 'sounds/music/' + _musl): + if isinstance(_musl, unicode): + if platform.system() == "Windows": + musl = _musl.encode('mbcs') + else: + musl = _musl.encode('utf-8') + else: + musl = _musl + playLocal = True + + self.userPickedMusicItem = False + + if playLocal: self.music = audio.loadHandle(False, AOpath + 'sounds/music/' + musl, 0, 0, BASS_SAMPLE_LOOP) - audio.setHandleAttr(self.music, BASS_ATTRIB_VOL, self.sliMusicVolume.value() / 100.0) - audio.playHandle(self.music, True) - if self.sliMusicVolume.value() == 0: - audio.pauseHandle(self.music) + if self.music: + audio.setHandleAttr(self.music, BASS_ATTRIB_VOL, self.sliMusicVolume.value() / 100.0) + audio.playHandle(self.music, True) + if self.sliMusicVolume.value() == 0: + audio.pauseHandle(self.music) + else: + error = audio.getBassError() + print "[audio] Couldn't play local track! Error", error elif ini.read_ini_bool("AO2XP.ini", "General", "download music", True): - if mus.lower().startswith("http"): - #self.music = audio.loadURLHandle(mus, 0, BASS_STREAM_BLOCK | BASS_SAMPLE_LOOP) + if musl.startswith("http"): self.music = audio.loadURLHandle(mus, 0, BASS_SAMPLE_LOOP) print "[audio] Trying to play", mus else: - for bucket in buckets: - if not bucket: continue - print "[audio] Music stream:", bucket+'base/sounds/music/' + mus - self.music = audio.loadURLHandle(bucket+'base/sounds/music/' + musl, 0, BASS_STREAM_BLOCK | BASS_SAMPLE_LOOP) - if self.music: break + global bucket + mus = musl = bucket + 'base/sounds/music/' + musl.replace(" ", "%20") + print "[audio] Music stream:", bucket + 'base/sounds/music/' + mus + self.music = audio.loadURLHandle(musl, 0, BASS_SAMPLE_LOOP) if self.music: audio.setHandleAttr(self.music, BASS_ATTRIB_VOL, self.sliMusicVolume.value() / 100.0) @@ -3962,11 +3976,14 @@ class GUI(QtGui.QWidget): # We want only song names without paths or extensions in the music list for song in musicList: - self.musicList[QtCore.QString(os.path.splitext(basename(song))[0].decode('utf-8').replace("","&"))] = song.decode('utf-8') + _basename = os.path.splitext(basename(song)) + self.musicList[QtCore.QString(_basename[0].decode('utf-8').replace("","&"))] = song.decode('utf-8') if "base/" in webAO_bucket: webAO_bucket = webAO_bucket.replace("base/", "") - buckets[0] = webAO_bucket + global bucket + bucket = webAO_bucket + self.charSelect.setCharList(charList) autopick = getOption("General", "auto pick").decode('utf-8').lower() coincidence = -1 @@ -4174,17 +4191,17 @@ class GUI(QtGui.QWidget): def updateAreaList(self): try: for i in range(self.areasLen): - area_players = self.areas[0][i] - area_status = self.areas[1][i].title() - area_cm = self.areas[2][i].decode('utf-8') - area_locked = self.areas[3][i].title() - area_name = self.areas[4][i].decode('utf-8') - if area_status == "Casing": - self.areaItems.item(i).setText("%s\n%s | %s\n%s users | %s" % (area_name, area_status, area_cm, area_players, area_locked)) + areaPlayers = self.areas[0][i] + areaStatus = self.areas[1][i].title() + areaCM = self.areas[2][i].decode('utf-8') + areaLocked = self.areas[3][i].title() + areaName = self.areas[4][i].decode('utf-8') + if areaStatus == "Casing": + self.areaItems.item(i).setText("%s\n%s | %s\n%s users | %s" % (areaName, areaStatus, areaCM, areaPlayers, areaLocked)) else: - self.areaItems.item(i).setText("%s\n%s\n%s users | %s" % (area_name, area_status, area_players, area_locked)) + self.areaItems.item(i).setText("%s\n%s\n%s users | %s" % (areaName, areaStatus, areaPlayers, areaLocked)) - if area_locked == "Locked": + if areaLocked == "Locked": self.areaItems.item(i).setIcon(QtGui.QIcon(AO2XPpath + "icons/" + "lock.png")) else: self.areaItems.item(i).setIcon(QtGui.QIcon(AO2XPpath + "icons/" + "house.png"))