imrpove tcp handling
This commit is contained in:
parent
0d4ff0ff9d
commit
5da47f070a
13
AOsocket.py
13
AOsocket.py
@ -6,6 +6,8 @@ import ssl
|
||||
|
||||
from constants import *
|
||||
|
||||
printPackets = False
|
||||
|
||||
class AOtcpSocket(object):
|
||||
def __init__(self):
|
||||
self.sock = socket.socket()
|
||||
@ -47,10 +49,13 @@ class AOtcpSocket(object):
|
||||
for i in range(len(totals)):
|
||||
totals[i] = totals[i].split("#")
|
||||
del totals[i][-1]
|
||||
|
||||
if printPackets:
|
||||
print "[packet] Got:", totals
|
||||
return 0, totals
|
||||
|
||||
def send(self, data):
|
||||
if printPackets:
|
||||
print "[packet] Sent:", data
|
||||
return self.sock.send(data)
|
||||
|
||||
def close(self):
|
||||
@ -62,7 +67,7 @@ class AOwebSocket(object):
|
||||
self.isWS = True
|
||||
self.isSecure = False
|
||||
self.header = {
|
||||
"User-Agent": "AO2XP %s, Python %s, %s %s %s" % (GAME_VERSION, platform.python_version(), platform.system(), platform.release(), platform.machine())
|
||||
"User-Agent": "AO2XP %s" % GAME_VERSION
|
||||
}
|
||||
|
||||
def connect(self, ip, port, secure_port):
|
||||
@ -100,9 +105,13 @@ class AOwebSocket(object):
|
||||
totals[i] = totals[i].split("#")
|
||||
del totals[i][-1]
|
||||
|
||||
if printPackets:
|
||||
print "[packet] Got:", totals
|
||||
return 0, totals
|
||||
|
||||
def send(self, data):
|
||||
if printPackets:
|
||||
print "[packet] Sent:", data
|
||||
return self.sock.send(unicode(data))
|
||||
|
||||
def close(self):
|
||||
|
||||
41
gameview.py
41
gameview.py
@ -1,4 +1,4 @@
|
||||
import thread, time, os, urllib, random, re , platform, subprocess
|
||||
import thread, time, os, urllib, random, re, platform, subprocess
|
||||
import charselect, ini, AOsocket, images, packets, demo, buttons
|
||||
|
||||
from os.path import exists, basename
|
||||
@ -330,19 +330,12 @@ class AOCharMovie(QtGui.QLabel):
|
||||
)
|
||||
|
||||
placeholderPath = AO2XPpath + "themes/default/oldplaceholder.gif"
|
||||
|
||||
imgPath = ""
|
||||
downloadCharacters = ini.read_ini_bool("AO2XP.ini", "General", "download characters")
|
||||
|
||||
if apngPath:
|
||||
imgPath = apngPath
|
||||
self.usePillow = 1
|
||||
else:
|
||||
if downloadCharacters:
|
||||
url = "base/characters/" + pChar.lower() + "/" + emotePrefix + pEmote.lower() + ".apng"
|
||||
url = url.replace(" ", "%20")
|
||||
thread.start_new_thread(downloadThread, (url, apngPath))
|
||||
|
||||
pngPath = testPath(
|
||||
AOpath + "characters/" + pChar + "/" + emotePrefix + pEmote + ".png",
|
||||
AOpath + "characters/" + pChar + "/" + emotePrefix + "/" + pEmote + ".png",
|
||||
@ -357,11 +350,6 @@ class AOCharMovie(QtGui.QLabel):
|
||||
imgPath = pngPath
|
||||
self.usePillow = 0
|
||||
else:
|
||||
if downloadCharacters:
|
||||
url = "base/characters/" + pChar.lower() + "/" + emotePrefix + pEmote.lower() + ".png"
|
||||
url = url.replace(" ", "%20")
|
||||
thread.start_new_thread(downloadThread, (url, pngPath))
|
||||
|
||||
webpPath = testPath(
|
||||
AOpath + "characters/" + pChar + "/" + emotePrefix + pEmote + ".webp",
|
||||
AOpath + "characters/" + pChar + "/" + emotePrefix + "/" + pEmote + ".webp",
|
||||
@ -376,11 +364,6 @@ class AOCharMovie(QtGui.QLabel):
|
||||
imgPath = webpPath
|
||||
self.usePillow = 2
|
||||
else:
|
||||
if downloadCharacters:
|
||||
url = "base/characters/" + pChar.lower() + "/"+pEmote.lower() + ".webp"
|
||||
url = url.replace(" ", "%20")
|
||||
thread.start_new_thread(downloadThread, (url, webpPath))
|
||||
|
||||
gifPath = testPath(
|
||||
AOpath + "characters/" + pChar + "/" + emotePrefix + pEmote + ".gif",
|
||||
AOpath + "characters/" + pChar + "/" + emotePrefix + "/" + pEmote + ".gif",
|
||||
@ -395,10 +378,11 @@ class AOCharMovie(QtGui.QLabel):
|
||||
imgPath = gifPath
|
||||
self.usePillow = 0
|
||||
else:
|
||||
if downloadCharacters:
|
||||
url = "base/characters/" + pChar.lower() + "/" + emotePrefix + pEmote.lower() + ".gif"
|
||||
url = url.replace(" ", "%20")
|
||||
thread.start_new_thread(downloadThread, (url, gifPath))
|
||||
if ini.read_ini_bool("AO2XP.ini", "General", "download characters"):
|
||||
pass
|
||||
# url = "base/characters/" + pChar.lower() + "/" + emotePrefix + pEmote.lower() + ".gif"
|
||||
# url = url.replace(" ", "%20")
|
||||
# thread.start_new_thread(downloadThread, (url, gifPath))
|
||||
|
||||
if exists(placeholderPath):
|
||||
imgPath = placeholderPath
|
||||
@ -1083,6 +1067,7 @@ class GUI(QtGui.QWidget):
|
||||
chatmsg = ''
|
||||
charid = -1
|
||||
login = False
|
||||
alignChars = False
|
||||
privateMusicSelected = False
|
||||
privateInventorySelected = False
|
||||
scaling = [SCALING_AUTO, SCALING_AUTO]
|
||||
@ -1825,7 +1810,6 @@ class GUI(QtGui.QWidget):
|
||||
with open(courtroomDesign) as f:
|
||||
for keys in f.read().split("\n"):
|
||||
if not keys or "=" not in keys or keys[0] == ";": continue
|
||||
|
||||
key, value = keys.split("=")
|
||||
design[key.strip()] = value.split(',')
|
||||
|
||||
@ -1919,6 +1903,8 @@ class GUI(QtGui.QWidget):
|
||||
if "found_song_color" in design:
|
||||
self.foundSongItemColor = QtGui.QColor(*[int(x) for x in design["found_song_color"]])
|
||||
|
||||
|
||||
|
||||
self.cbSlide.setVisible("slide_enable" in design)
|
||||
self.cbBench.setVisible("ao2xp_desk" in design)
|
||||
self.OOCLogin.setVisible("ao2xp_login" in design)
|
||||
@ -1955,6 +1941,9 @@ class GUI(QtGui.QWidget):
|
||||
|
||||
self.viewportRatio = self.viewport.width() / float(self.viewport.height())
|
||||
|
||||
# If the viewport is wide, align def/pro sprites properly
|
||||
self.alignChars = (self.viewportRatio > 1.5)
|
||||
|
||||
self.court.resize(self.viewport.size())
|
||||
self.bench.resize(self.viewport.size())
|
||||
self.whiteFlashLabel.resize(self.viewport.size())
|
||||
@ -3809,7 +3798,8 @@ class GUI(QtGui.QWidget):
|
||||
|
||||
if not self.animIsEmpty:
|
||||
self.char.move(self.viewport.width() * hor_offset / 100, self.viewport.height() * vert_offset / 100)
|
||||
self.char.setAlignPos(side)
|
||||
if self.alignChars:
|
||||
self.char.setAlignPos(side)
|
||||
|
||||
# check if paired
|
||||
if not self.mChatMessage[OTHER_CHARID] and not self.animIsEmpty:
|
||||
@ -3823,7 +3813,8 @@ class GUI(QtGui.QWidget):
|
||||
|
||||
if got_otherCharId > -1: # user is paired
|
||||
self.sideChar.show()
|
||||
self.sideChar.setAlignPos(side)
|
||||
if self.alignChars:
|
||||
self.sideChar.setAlignPos(side)
|
||||
|
||||
boxPairOrder = self.mChatMessage[OTHER_CHARID].split("^")
|
||||
if "effects" in self.features and len(boxPairOrder) > 1:
|
||||
|
||||
37
mainmenu.py
37
mainmenu.py
@ -411,6 +411,7 @@ class AOServerInfo(QtCore.QThread):
|
||||
self.useWS = False
|
||||
self.connected = False
|
||||
self.disconnect = False
|
||||
self.musicHack = False
|
||||
|
||||
def setIP(self, name, ip, port, ws_port=0, wss_port=0):
|
||||
self.ip = ip
|
||||
@ -455,8 +456,7 @@ class AOServerInfo(QtCore.QThread):
|
||||
musicList = []
|
||||
pingtimer = 150
|
||||
readytick = -1
|
||||
|
||||
got_arup = False
|
||||
gotARUP = False
|
||||
|
||||
while True:
|
||||
if self.disconnect:
|
||||
@ -498,7 +498,8 @@ class AOServerInfo(QtCore.QThread):
|
||||
maxplayers = int(network[2])
|
||||
self.canConnect.emit()
|
||||
self.setOnlinePlayers.emit('%d/%d players online' % (players, maxplayers))
|
||||
self.tcp.send("ASS#%") # get webAO bucket
|
||||
if self.tcp.isWS:
|
||||
self.tcp.send("ASS#%") # get webAO bucket
|
||||
got_stuff = True
|
||||
|
||||
elif header == "decryptor":
|
||||
@ -507,7 +508,7 @@ class AOServerInfo(QtCore.QThread):
|
||||
|
||||
elif header == "ASS": # ha ha ha...
|
||||
self.webAO_bucket = network[1]
|
||||
print self.webAO_bucket
|
||||
print "[debug] URL:", self.webAO_bucket
|
||||
|
||||
elif header == "ID":
|
||||
self.tcp.send("ID#AO2XP#%s#%%" % "2.11.0") # need to send this to tsuserver3 servers in order to get feature list (FL)
|
||||
@ -605,19 +606,19 @@ class AOServerInfo(QtCore.QThread):
|
||||
|
||||
del network[0]
|
||||
areas[kind] = [network[i] for i in range(len(network))]
|
||||
areas_len = len(areas[kind])
|
||||
areasLen = len(areas[kind])
|
||||
|
||||
for i in range(areas_len):
|
||||
for i in range(areasLen):
|
||||
for j in range(4):
|
||||
if j != kind and not len(areas[j]):
|
||||
areas[j] = ["" for i in range(len(network))]
|
||||
|
||||
if not got_arup:
|
||||
print '[client]', 'The server has %d areas' % areas_len
|
||||
got_arup = True
|
||||
if not gotARUP:
|
||||
print '[client]', 'The server has %d areas' % areasLen
|
||||
gotARUP = True
|
||||
|
||||
if musicList and not len(areas[4]):
|
||||
for i in range(areas_len):
|
||||
if musicList and not self.musicHack and not len(areas[4]):
|
||||
for i in range(areasLen):
|
||||
areas[4].append(musicList[0])
|
||||
del musicList[0]
|
||||
|
||||
@ -642,3 +643,17 @@ class AOServerInfo(QtCore.QThread):
|
||||
if not pid in playerList:
|
||||
playerList[pid] = []
|
||||
playerList[pid].append(network[2].decode('utf-8'))
|
||||
|
||||
# Evil hack to support some servers that don't send music list as SC packet
|
||||
else:
|
||||
if self.disconnect:
|
||||
continue
|
||||
if "mp3" not in network[0] and "opus" not in network[0]:
|
||||
continue
|
||||
|
||||
self.musicHack = True
|
||||
musicList = [music for music in network]
|
||||
self.setConnectProgress.emit('Finishing...')
|
||||
self.tcp.send('RD#%')
|
||||
print '[client]', 'Received songs (%d)' % len(musicList)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user