diff --git a/gameview.py b/gameview.py index 329dc30..c58716c 100644 --- a/gameview.py +++ b/gameview.py @@ -1288,7 +1288,7 @@ class gui(QtGui.QWidget): self.realizationbtn.setToolTip('Show the next message with a realization effect') self.realizationsnd = audio.loadhandle(False, AOpath + 'sounds/general/sfx-realization.wav', 0, 0, 0) self.shakebtn = buttons.AOToggleButton(self, 265+42 + 164, 192 + 304, "screenshake") # AO 2.8 - self.shakebtn.clicked.connect(self.icchat_focus) + self.shakebtn.clicked.connect(self.onShakeButton) self.shakebtn.setToolTip('Show the next message with a shaking effect') self.customobject = buttons.CustomObjection(self, 250 + 516 - 30, 312 + 40) @@ -1352,6 +1352,7 @@ class gui(QtGui.QWidget): self.areas = [] self.areas_len = 0 + self.no_arup = False self.muteselected = -1 self.unmuteselected = -1 self.muted = [] @@ -1454,6 +1455,10 @@ class gui(QtGui.QWidget): self.effectdropdown.setCurrentIndex(0) self.icchat_focus() + def onShakeButton(self): + self.sfxbutton.setChecked(False) + self.icchat_focus() + def onOOCLoginBtn(self): if not self.oocnameinput.text(): self.oocnameinput.setText("unnamed") @@ -3402,6 +3407,100 @@ class gui(QtGui.QWidget): if self.musicslider.value() == 0: audio.pausehandle(self.music) + def allMusic(self): + for song, fname in self.musiclist.items(): + songitem = QtGui.QListWidgetItem() + songitem.setText(song) + if exists(unicode(AOpath + 'sounds/music/' + fname.replace("","&").lower())): + songitem.setBackgroundColor(QtGui.QColor(128, 255, 128)) + #else: + #songitem.setBackgroundColor(QtGui.QColor(255, 128, 128)) + self.musicitems.addItem(songitem) + + def allEvidence(self, evi): + self.evidence = evi + if self.evidencedropdown.count() > 0: + self.evidencedropdown.clear() + for evi in self.evidence: + while len(evi) < 3: # new AO 2.9 bug where they never correctly escaped evidence name/desc/image on FantaProtocol + evi += [""] + evi[0] = decode_ao_str(evi[0].decode('utf-8')) + evi[1] = decode_ao_str(evi[1].decode('utf-8')) + evi[2] = decode_ao_str(evi[2].decode('utf-8')) + self.evidencedropdown.addItem(evi[0].strip()) + + if not self.evidence: + self.evidencedropdown.setCurrentIndex(0) + self.evidencedesc.setText('.') + else: + self.evidencedropdown.setCurrentIndex(self.selectedevi) + + def updatePlayerList(self, pid, op, utype, data=""): + pid = str(pid) + if op == 0: # Add or remove player + if utype == 0: # Add a player + self.playerList.addItem("[%s]" % pid) + if not pid in self.playerlist: + self.playerlist[pid] = ["", "", "", ""] + if utype == 1: # Remove a player + item = self.playerList.findItems("[%s]" % pid, QtCore.Qt.MatchStartsWith) + if item: + self.playerList.takeItem(self.playerList.row(item[0])) + if pid in self.playerlist: + del self.playerlist[pid] + else: # Update a player + if pid in self.playerlist: + self.playerlist[pid][utype] = data + + item = self.playerList.findItems("[%s]" % pid, QtCore.Qt.MatchStartsWith) + if item: + name = self.playerlist[pid][0] + char = self.playerlist[pid][1] + charname = self.playerlist[pid][2] + text = "[%s]" % pid + if char: + text += " %s" % char + if charname: + text += " (%s)" % charname + if name: + text += " %s" % name + item[0].setText(text) + + def start_pause_timers(self, command, timer_id, timer_ms): + if command == 0: + if not self.onscreen_timer.isActive(): + self.onscreen_timer.start(self.timer_tick) + self.onscreen_timer_times[timer_id] = timer_ms + self.onscreen_timer_paused[timer_id] = False + self.update_timers() + print "[client] Timer %d was started for %d ms" % (timer_id, timer_ms) + elif command == 1: + self.onscreen_timer_paused[timer_id] = True + elif command == 2: + self.onscreen_timer_labels[timer_id].show() + elif command == 3: + self.onscreen_timer_labels[timer_id].hide() + + def update_timers(self): + for timer_id, label in enumerate(self.onscreen_timer_labels): + time_ms = self.onscreen_timer_times[timer_id] + if not time_ms or self.onscreen_timer_paused[timer_id]: + continue + + secs = time_ms / 1000 + mins = secs / 60 + hours = mins / 60 + label.setText("%02d:%02d:%02d" % (hours, mins % 60, secs % 60)) + + self.onscreen_timer_times[timer_id] -= self.timer_tick + if self.onscreen_timer_times[timer_id] <= 0: + label.hide() + self.onscreen_timer_times[timer_id] = 0 + self.onscreen_timer_paused[timer_id] = True + + if self.onscreen_timer_times == [0, 0, 0, 0, 0]: + self.onscreen_timer.stop() + def startGame(self, tcp, playerlist, charlist, musiclist, background, evidence, areas, features=[], oocjoin=[], hplist=[], webAO_bucket=""): self.willDisconnect = False self.mychar = -1 @@ -3508,12 +3607,14 @@ class gui(QtGui.QWidget): for msg in oocjoin: self.ooclog.append(msg) - - self.allMusic() - - for area in areas[0]: - areaitem = QtGui.QListWidgetItem() - self.areaitems.addItem(areaitem) + + if self.areas_len: + for i in range(self.areas_len): + areaitem = QtGui.QListWidgetItem() + self.areaitems.addItem(areaitem) + self.allMusic() + else: + self.no_arup = True for pid in playerlist: self.updatePlayerList(pid, 0, 0) @@ -3542,101 +3643,271 @@ class gui(QtGui.QWidget): self.tcpthread.start() self.icchatinput.setFocus() + +class TCP_Thread(QtCore.QThread): + connectionError = QtCore.pyqtSignal(str, str, str) + MS_Chat = QtCore.pyqtSignal(list) + newChar = QtCore.pyqtSignal(str) + newBackground = QtCore.pyqtSignal(str, bool) + IC_Log = QtCore.pyqtSignal(str) + OOC_Log = QtCore.pyqtSignal(str) + charSlots = QtCore.pyqtSignal() + showCharSelect = QtCore.pyqtSignal() + allEvidence = QtCore.pyqtSignal(list) + rainbowColor = QtCore.pyqtSignal(str) + updatePlayerList = QtCore.pyqtSignal(str, int, int, str) + timerUpdate = QtCore.pyqtSignal(int, int, int) + + send_attempts = 0 + max_attempts = 5 + + def __init__(self, parent): + super(TCP_Thread, self).__init__(parent) + self.parent = parent - def allMusic(self): - for song, fname in self.musiclist.items(): - songitem = QtGui.QListWidgetItem() - songitem.setText(song) - if exists(unicode(AOpath + 'sounds/music/' + fname.replace("","&").lower())): - songitem.setBackgroundColor(QtGui.QColor(128, 255, 128)) - #else: - #songitem.setBackgroundColor(QtGui.QColor(255, 128, 128)) - self.musicitems.addItem(songitem) + def run(self): + pingtimer = 150 + rainbow = 0 + sendtick = 0 + tempdata = "" + color = QtGui.QColor() + color.setHsv(rainbow, 255, 255) + #color.setHsv(0, 255, 255) + while True: + if self.parent.disconnectnow: + self.parent.disconnectCommon() + self.quit() + return + pingtimer -= 1 - def allEvidence(self, evi): - self.evidence = evi - if self.evidencedropdown.count() > 0: - self.evidencedropdown.clear() - for evi in self.evidence: - while len(evi) < 3: # new AO 2.9 bug where they never correctly escaped evidence name/desc/image on FantaProtocol - evi += [""] - evi[0] = decode_ao_str(evi[0].decode('utf-8')) - evi[1] = decode_ao_str(evi[1].decode('utf-8')) - evi[2] = decode_ao_str(evi[2].decode('utf-8')) - self.evidencedropdown.addItem(evi[0].strip()) - - if not self.evidence: - self.evidencedropdown.setCurrentIndex(0) - self.evidencedesc.setText('.') - else: - self.evidencedropdown.setCurrentIndex(self.selectedevi) + if pingtimer == 0: + pingbefore = time.time() + self.parent.tcp.send('CH#%') + pingtimer = 150 - def updatePlayerList(self, pid, op, utype, data=""): - pid = str(pid) - if op == 0: # Add or remove player - if utype == 0: # Add a player - self.playerList.addItem("[%s]" % pid) - if not pid in self.playerlist: - self.playerlist[pid] = ["", "", "", ""] - if utype == 1: # Remove a player - item = self.playerList.findItems("[%s]" % pid, QtCore.Qt.MatchStartsWith) - if item: - self.playerList.takeItem(self.playerList.row(item[0])) - if pid in self.playerlist: - del self.playerlist[pid] - else: # Update a player - if pid in self.playerlist: - self.playerlist[pid][utype] = data + if self.parent.m_chatmessage[TEXT_COLOR] == str(C_RAINBOW): + color.setHsv(rainbow, 255, 255) + rainbow += 5 + if rainbow > 255: + rainbow = 0 + #self.parent.text.setStyleSheet('color: rgb(' + str(color.red()) + ', ' + str(color.green()) + ', ' + str(color.blue()) + ')') + self.rainbowColor.emit('background-color: rgba(0, 0, 0, 0); color: rgb(' + str(color.red()) + ', ' + str(color.green()) + ', ' + str(color.blue()) + ')') - item = self.playerList.findItems("[%s]" % pid, QtCore.Qt.MatchStartsWith) - if item: - name = self.playerlist[pid][0] - char = self.playerlist[pid][1] - charname = self.playerlist[pid][2] - text = "[%s]" % pid - if char: - text += " %s" % char - if charname: - text += " (%s)" % charname - if name: - text += " %s" % name - item[0].setText(text) - - def start_pause_timers(self, command, timer_id, timer_ms): - if command == 0: - if not self.onscreen_timer.isActive(): - self.onscreen_timer.start(self.timer_tick) - self.onscreen_timer_times[timer_id] = timer_ms - self.onscreen_timer_paused[timer_id] = False - self.update_timers() - print "[client] Timer %d was started for %d ms" % (timer_id, timer_ms) - elif command == 1: - self.onscreen_timer_paused[timer_id] = True - elif command == 2: - self.onscreen_timer_labels[timer_id].show() - elif command == 3: - self.onscreen_timer_labels[timer_id].hide() - - def update_timers(self): - for timer_id, label in enumerate(self.onscreen_timer_labels): - time_ms = self.onscreen_timer_times[timer_id] - if not time_ms or self.onscreen_timer_paused[timer_id]: + if sendtick: + sendtick -= 1 + if self.parent.msgqueue and not sendtick: + self.parent.tcp.send(self.parent.msgqueue[0]) + sendtick = 4 + + error, total = self.parent.tcp.recv() + if error == -2: + # if the message can't be sent, discard it + if sendtick == 4: + self.send_attempts += 1 + if self.send_attempts >= self.max_attempts: + self.send_attempts = 0 + #print "[warning] message discarded" + del self.parent.msgqueue[0] + self.parent.msgqueueList.takeItem(0) + continue + elif error == -1: + self.parent.emit(QtCore.SIGNAL('showMessage(QString, QString, QString)'), 'critical', 'Connection lost', "%s connection to server lost." % ("WebSocket" if self.parent.tcp.isWS else "TCP")) + self.parent.willDisconnect = True + self.quit() + return + elif error == -3: + self.parent.emit(QtCore.SIGNAL('showMessage(QString, QString, QString)'), 'critical', 'Connection lost', "There was a critical connection failure. Please check your internet connection.\n\nDetails: %s." % total) + self.parent.willDisconnect = True + self.quit() + return + else: + self.send_attempts = 0 + + handle_packets(self, total) + +def handle_packets(caller, total): + for network in total: + header = network[0] + if header == 'MS': + if len(network) < 15: + print '[warning]', 'malformed/incomplete MS#chat (IC chat) network message was received' continue - secs = time_ms / 1000 - mins = secs / 60 - hours = mins / 60 - label.setText("%02d:%02d:%02d" % (hours, mins % 60, secs % 60)) + network[CHATMSG] = decode_ao_str(network[CHATMSG].decode('utf-8')) + caller.MS_Chat.emit(network) - self.onscreen_timer_times[timer_id] -= self.timer_tick - if self.onscreen_timer_times[timer_id] <= 0: - label.hide() - self.onscreen_timer_times[timer_id] = 0 - self.onscreen_timer_paused[timer_id] = True - - if self.onscreen_timer_times == [0, 0, 0, 0, 0]: - self.onscreen_timer.stop() + elif header == 'MC': + music = decode_ao_str(network[1]) + charid = int(network[2]) + t = time.localtime() + if charid != -1: + try: + name = caller.parent.charlist[charid][0] + except: + name = 'char id %d' % charid + + if len(network) > 3 and network[3]: + name += " ("+network[3].decode("utf-8")+")" + caller.IC_Log.emit('[%d:%.2d] %s changed the music to %s' % (t[3], t[4], name, music)) + else: + caller.IC_Log.emit('[%d:%.2d] The music was changed to %s' % (t[3], t[4], music)) + caller.parent.playMusic(music) + elif header == 'BN': + caller.newBackground.emit(network[1].lower(), True) + + elif header == 'CT': + name = decode_ao_str(network[1].decode('utf-8')) + chatmsg = decode_ao_str(network[2].decode('utf-8').replace("\n", "
")) + caller.OOC_Log.emit("%s: %s" % (name, chatmsg)) + + elif header == 'PV': + caller.parent.mychar = int(network[3]) + caller.parent.charselect.hide() + caller.newChar.emit(caller.parent.charlist[caller.parent.mychar][0]) + + elif header == 'LE': + del network[0] + caller.allEvidence.emit([evi.split('&') for evi in network]) + + elif header == 'ZZ': + if caller.parent.modcall: + audio.freehandle(caller.parent.modcall) + caller.parent.modcall = audio.loadhandle(0, "mod_call.wav", 0, 0, 0) + audio.sethandleattr(caller.parent.modcall, BASS_ATTRIB_VOL, caller.parent.soundslider.value() / 100.0) + audio.playhandle(caller.parent.modcall, False) + + if len(network) > 1: + caller.OOC_Log.emit('[MOD CALL] ' + network[1].replace("\n", "
") + '
') + else: + caller.OOC_Log.emit('[MOD CALL] But there was no extra information. (old server?)') + elif header == 'CharsCheck': + del network[0] + for i in range(len(network)): + caller.parent.charlist[i][1] = int(network[i]) + + caller.charSlots.emit() + + elif header == 'RT': + testimony = network[1] + wtcefile = AOpath+"sounds/general/sfx-testimony2" + if caller.parent.wtcesfx: + audio.freehandle(caller.parent.wtcesfx) + + if testimony == 'judgeruling': + variant = int(network[2]) + if variant == 0: + wtcefile = AOpath+"sounds/general/sfx-notguilty" + elif variant == 1: + wtcefile = AOpath+"sounds/general/sfx-guilty" + else: + variant = 0 + caller.parent.wtcesfx = audio.loadhandle(False, wtcefile+".opus" if exists(wtcefile+".opus") else wtcefile+".wav", 0, 0, 0) + audio.sethandleattr(caller.parent.wtcesfx, BASS_ATTRIB_VOL, caller.parent.soundslider.value() / 100.0) + audio.playhandle(caller.parent.wtcesfx, True) + caller.parent.WTCEsignal.emit(testimony, variant) + + elif header == 'HP': + kind = int(network[1]) + health = int(network[2]) + caller.parent.healthbars.emit(kind, health) + + elif header == 'KK': + reason = network[1] + caller.parent.emit(QtCore.SIGNAL('showMessage(QString, QString, QString)'), 'critical', 'Connection lost', 'You were kicked from the server. (%s)' % reason) + + elif header == 'KB': + reason = network[1] + caller.parent.emit(QtCore.SIGNAL('showMessage(QString, QString, QString)'), 'critical', 'Connection lost', 'You have been banned from the server. (%s)' % reason) + + elif header == 'BB': # message popup (AO 2.9) + message = network[1] + caller.parent.emit(QtCore.SIGNAL('showMessage(QString, QString, QString)'), 'information', 'Message from server', message) + + elif header == 'AUTH': # login status (AO 2.9) + status = int(network[1]) + statusStrings = ["You have logged out", "Wrong password", "Logged in"] + if status == 1: + caller.parent.login = True + caller.parent.playerKick.setDisabled(False) + caller.parent.playerBan.setDisabled(False) + caller.parent.ooclogin.setText("Lo&g out") + elif status == -1: + caller.parent.login = False + caller.parent.playerKick.setDisabled(True) + caller.parent.playerBan.setDisabled(True) + caller.parent.ooclogin.setText("Lo&gin") + caller.OOC_Log.emit("%s" % (statusStrings[status+1])) + + elif header == "CHECK": #ping + pingafter = time.time() + caller.parent.gotPing.emit(int((pingafter - pingbefore)*1000)) + + elif header == 'DONE': + caller.showCharSelect.emit() + + elif header == 'PR': + del network[0] + caller.updatePlayerList.emit(network[0], 0, int(network[1]), "") + + elif header == 'PU': + del network[0] + caller.updatePlayerList.emit(network[0], 1, int(network[1]), network[2].decode('utf-8')) + + elif header == 'ARUP': + del network[0] + kind = int(network[0]) + caller.parent.areas[kind] = [network[i] for i in range(1, len(network))] + + # This is much harder than doing it during the handshake because of the way the music list is implemented + if caller.parent.no_arup: + caller.parent.no_arup = False + caller.parent.areas_len = len(caller.parent.areas[kind]) + print '[client]', 'The server has %d areas' % caller.parent.areas_len + + if caller.parent.areas_len: + for i in range(caller.parent.areas_len): + area_key, area_val = caller.parent.musiclist.items()[0] + caller.parent.areas[4].append(area_val) + + areaitem = QtGui.QListWidgetItem() + caller.parent.areaitems.addItem(areaitem) + + for j in range(len(network)): + if j != kind: + caller.parent.areas[j].append("") + + # Remove the area from the music list + caller.parent.musiclist.popitem(False) + + caller.parent.allMusic() + + for i in range(caller.parent.areas_len): + area_players = caller.parent.areas[0][i] + area_status = caller.parent.areas[1][i].title() + area_cm = caller.parent.areas[2][i].decode('utf-8') + area_locked = caller.parent.areas[3][i].title() + area_name = caller.parent.areas[4][i].decode('utf-8') + if area_status == "Casing": + caller.parent.areaitems.item(i).setText("%s\n%s | %s\n%s users | %s" % (area_name, area_status, area_cm, area_players, area_locked)) + else: + caller.parent.areaitems.item(i).setText("%s\n%s\n%s users | %s" % (area_name, area_status, area_players, area_locked)) + + if area_locked == "Locked": + caller.parent.areaitems.item(i).setIcon(QtGui.QIcon(AO2XPpath + "icons/" + "lock.png")) + else: + caller.parent.areaitems.item(i).setIcon(QtGui.QIcon(AO2XPpath + "icons/" + "house.png")) + + elif header == 'TI': + del network[0] + timer_id = int(network[0]) + command = int(network[1]) + time_ms = 0 + if len(network) == 3: + time_ms = int(network[2]) + + caller.timerUpdate.emit(command, timer_id, time_ms) + class PresentButton(QtGui.QLabel): def __init__(self, gamegui, parent): @@ -3858,243 +4129,3 @@ class NextEmoteButton(QtGui.QLabel): def mousePressEvent(self, event): self.gamewindow.current_emote_page += 1 self.gamewindow.set_emote_page() - -class TCP_Thread(QtCore.QThread): - connectionError = QtCore.pyqtSignal(str, str, str) - MS_Chat = QtCore.pyqtSignal(list) - newChar = QtCore.pyqtSignal(str) - newBackground = QtCore.pyqtSignal(str, bool) - IC_Log = QtCore.pyqtSignal(str) - OOC_Log = QtCore.pyqtSignal(str) - charSlots = QtCore.pyqtSignal() - showCharSelect = QtCore.pyqtSignal() - allEvidence = QtCore.pyqtSignal(list) - rainbowColor = QtCore.pyqtSignal(str) - updatePlayerList = QtCore.pyqtSignal(str, int, int, str) - timerUpdate = QtCore.pyqtSignal(int, int, int) - - send_attempts = 0 - max_attempts = 5 - - def __init__(self, parent): - super(TCP_Thread, self).__init__(parent) - self.parent = parent - - def run(self): - pingtimer = 150 - rainbow = 0 - sendtick = 0 - tempdata = "" - color = QtGui.QColor() - color.setHsv(rainbow, 255, 255) - #color.setHsv(0, 255, 255) - while True: - if self.parent.disconnectnow: - self.parent.disconnectCommon() - self.quit() - return - pingtimer -= 1 - if pingtimer == 0: - pingbefore = time.time() - self.parent.tcp.send('CH#%') - pingtimer = 150 - - if self.parent.m_chatmessage[TEXT_COLOR] == str(C_RAINBOW): - color.setHsv(rainbow, 255, 255) - rainbow += 5 - if rainbow > 255: - rainbow = 0 - #self.parent.text.setStyleSheet('color: rgb(' + str(color.red()) + ', ' + str(color.green()) + ', ' + str(color.blue()) + ')') - self.rainbowColor.emit('background-color: rgba(0, 0, 0, 0); color: rgb(' + str(color.red()) + ', ' + str(color.green()) + ', ' + str(color.blue()) + ')') - - if sendtick: - sendtick -= 1 - if self.parent.msgqueue and not sendtick: - self.parent.tcp.send(self.parent.msgqueue[0]) - sendtick = 4 - - error, total = self.parent.tcp.recv() - if error == -2: - # if the message can't be sent, discard it - if sendtick == 4: - self.send_attempts += 1 - if self.send_attempts >= self.max_attempts: - self.send_attempts = 0 - #print "[warning] message discarded" - del self.parent.msgqueue[0] - self.parent.msgqueueList.takeItem(0) - continue - elif error == -1: - self.parent.emit(QtCore.SIGNAL('showMessage(QString, QString, QString)'), 'critical', 'Connection lost', "%s connection to server lost." % ("WebSocket" if self.parent.tcp.isWS else "TCP")) - self.parent.willDisconnect = True - self.quit() - return - elif error == -3: - self.parent.emit(QtCore.SIGNAL('showMessage(QString, QString, QString)'), 'critical', 'Connection lost', "There was a critical connection failure. Please check your internet connection.\n\nDetails: %s." % total) - self.parent.willDisconnect = True - self.quit() - return - else: - self.send_attempts = 0 - - for network in total: - header = network[0] - #del network[-1] - if header == 'MS': - if len(network) < 15: - print '[warning]', 'malformed/incomplete MS#chat (IC chat) network message was received' - continue - - network[CHATMSG] = decode_ao_str(network[CHATMSG].decode('utf-8')) - self.MS_Chat.emit(network) - - elif header == 'MC': - music = decode_ao_str(network[1]) - charid = int(network[2]) - t = time.localtime() - if charid != -1: - try: - name = self.parent.charlist[charid][0] - except: - name = 'char id %d' % charid - - if len(network) > 3 and network[3]: - name += " ("+network[3].decode("utf-8")+")" - self.IC_Log.emit('[%d:%.2d] %s changed the music to %s' % (t[3], t[4], name, music)) - else: - self.IC_Log.emit('[%d:%.2d] The music was changed to %s' % (t[3], t[4], music)) - self.parent.playMusic(music) - - elif header == 'BN': - self.newBackground.emit(network[1].lower(), True) - - elif header == 'CT': - name = decode_ao_str(network[1].decode('utf-8')) - chatmsg = decode_ao_str(network[2].decode('utf-8').replace("\n", "
")) - self.OOC_Log.emit("%s: %s" % (name, chatmsg)) - - elif header == 'PV': - self.parent.mychar = int(network[3]) - self.parent.charselect.hide() - self.newChar.emit(self.parent.charlist[self.parent.mychar][0]) - - elif header == 'LE': - del network[0] - self.allEvidence.emit([evi.split('&') for evi in network]) - - elif header == 'ZZ': - if self.parent.modcall: - audio.freehandle(self.parent.modcall) - self.parent.modcall = audio.loadhandle(0, "mod_call.wav", 0, 0, 0) - audio.sethandleattr(self.parent.modcall, BASS_ATTRIB_VOL, self.parent.soundslider.value() / 100.0) - audio.playhandle(self.parent.modcall, False) - - if len(network) > 1: - self.OOC_Log.emit('[MOD CALL] ' + network[1].replace("\n", "
") + '
') - else: - self.OOC_Log.emit('[MOD CALL] But there was no extra information. (old server?)') - elif header == 'CharsCheck': - del network[0] - for i in range(len(network)): - self.parent.charlist[i][1] = int(network[i]) - - self.charSlots.emit() - - elif header == 'RT': - testimony = network[1] - wtcefile = AOpath+"sounds/general/sfx-testimony2" - if self.parent.wtcesfx: - audio.freehandle(self.parent.wtcesfx) - - if testimony == 'judgeruling': - variant = int(network[2]) - if variant == 0: - wtcefile = AOpath+"sounds/general/sfx-notguilty" - elif variant == 1: - wtcefile = AOpath+"sounds/general/sfx-guilty" - else: - variant = 0 - self.parent.wtcesfx = audio.loadhandle(False, wtcefile+".opus" if exists(wtcefile+".opus") else wtcefile+".wav", 0, 0, 0) - audio.sethandleattr(self.parent.wtcesfx, BASS_ATTRIB_VOL, self.parent.soundslider.value() / 100.0) - audio.playhandle(self.parent.wtcesfx, True) - self.parent.WTCEsignal.emit(testimony, variant) - - elif header == 'HP': - type = int(network[1]) - health = int(network[2]) - self.parent.healthbars.emit(type, health) - - elif header == 'KK': - reason = network[1] - self.parent.emit(QtCore.SIGNAL('showMessage(QString, QString, QString)'), 'critical', 'Connection lost', 'You were kicked from the server. (%s)' % reason) - - elif header == 'KB': - reason = network[1] - self.parent.emit(QtCore.SIGNAL('showMessage(QString, QString, QString)'), 'critical', 'Connection lost', 'You have been banned from the server. (%s)' % reason) - - elif header == 'BB': # message popup (AO 2.9) - message = network[1] - self.parent.emit(QtCore.SIGNAL('showMessage(QString, QString, QString)'), 'information', 'Message from server', message) - - elif header == 'AUTH': # login status (AO 2.9) - status = int(network[1]) - statusStrings = ["You have logged out", "Wrong password", "Logged in"] - if status == 1: - self.parent.login = True - self.parent.playerKick.setDisabled(False) - self.parent.playerBan.setDisabled(False) - self.parent.ooclogin.setText("Lo&g out") - elif status == -1: - self.parent.login = False - self.parent.playerKick.setDisabled(True) - self.parent.playerBan.setDisabled(True) - self.parent.ooclogin.setText("Lo&gin") - self.OOC_Log.emit("%s" % (statusStrings[status+1])) - - elif header == "CHECK": #ping - pingafter = time.time() - self.parent.gotPing.emit(int((pingafter - pingbefore)*1000)) - - elif header == 'DONE': - self.showCharSelect.emit() - - elif header == 'PR': - del network[0] - self.updatePlayerList.emit(network[0], 0, int(network[1]), "") - - elif header == 'PU': - del network[0] - self.updatePlayerList.emit(network[0], 1, int(network[1]), network[2].decode('utf-8')) - - elif header == 'ARUP': - del network[0] - type = int(network[0]) - self.parent.areas[type] = [network[i] for i in range(1, len(network))] - for i in range(self.parent.areas_len): - try: - area_players = self.parent.areas[0][i] - area_status = self.parent.areas[1][i].title() - area_cm = self.parent.areas[2][i].decode('utf-8') - area_locked = self.parent.areas[3][i].title() - area_name = self.parent.areas[4][i].decode('utf-8') - if area_status == "Casing": - self.parent.areaitems.item(i).setText("%s\n%s | %s\n%s users | %s" % (area_name, area_status, area_cm, area_players, area_locked)) - else: - self.parent.areaitems.item(i).setText("%s\n%s\n%s users | %s" % (area_name, area_status, area_players, area_locked)) - - if area_locked == "Locked": - self.parent.areaitems.item(i).setIcon(QtGui.QIcon(AO2XPpath + "icons/" + "lock.png")) - else: - self.parent.areaitems.item(i).setIcon(QtGui.QIcon(AO2XPpath + "icons/" + "house.png")) - except: - pass - - elif header == 'TI': - del network[0] - timer_id = int(network[0]) - command = int(network[1]) - time_ms = 0 - if len(network) == 3: - time_ms = int(network[2]) - - self.timerUpdate.emit(command, timer_id, time_ms) \ No newline at end of file diff --git a/mainmenu.py b/mainmenu.py index 4b14733..5e441f9 100644 --- a/mainmenu.py +++ b/mainmenu.py @@ -572,16 +572,23 @@ class AOServerInfo(QtCore.QThread): elif header == 'HP': if self.disconnect: continue - type = int(network[1]) + kind = int(network[1]) health = int(network[2]) - hplist.append([type, health]) - - elif header == "ARUP": #AO2 2.6 new feature: area update + hplist.append([kind, health]) + + #AO2 2.6 new feature: area update. Not all servers send this during the handshake! + elif header == "ARUP": del network[0] - type = int(network[0]) - areas[type] = [network[i] for i in range(1, len(network))] - areas_len = len(areas[type]) + kind = int(network[0]) + areas[kind] = [network[i] for i in range(1, len(network))] + areas_len = len(areas[kind]) print '[client]', 'The server has %d areas' % areas_len + + for i in areas_len: + for j in range(len(network)): + if j != kind: + caller.parent.areas[j].append("") + if musiclist: for i in range(areas_len): areas[4].append(musiclist[0])