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 *
|
from constants import *
|
||||||
|
|
||||||
|
printPackets = False
|
||||||
|
|
||||||
class AOtcpSocket(object):
|
class AOtcpSocket(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.sock = socket.socket()
|
self.sock = socket.socket()
|
||||||
@ -47,10 +49,13 @@ class AOtcpSocket(object):
|
|||||||
for i in range(len(totals)):
|
for i in range(len(totals)):
|
||||||
totals[i] = totals[i].split("#")
|
totals[i] = totals[i].split("#")
|
||||||
del totals[i][-1]
|
del totals[i][-1]
|
||||||
|
if printPackets:
|
||||||
|
print "[packet] Got:", totals
|
||||||
return 0, totals
|
return 0, totals
|
||||||
|
|
||||||
def send(self, data):
|
def send(self, data):
|
||||||
|
if printPackets:
|
||||||
|
print "[packet] Sent:", data
|
||||||
return self.sock.send(data)
|
return self.sock.send(data)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
@ -62,7 +67,7 @@ class AOwebSocket(object):
|
|||||||
self.isWS = True
|
self.isWS = True
|
||||||
self.isSecure = False
|
self.isSecure = False
|
||||||
self.header = {
|
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):
|
def connect(self, ip, port, secure_port):
|
||||||
@ -100,9 +105,13 @@ class AOwebSocket(object):
|
|||||||
totals[i] = totals[i].split("#")
|
totals[i] = totals[i].split("#")
|
||||||
del totals[i][-1]
|
del totals[i][-1]
|
||||||
|
|
||||||
|
if printPackets:
|
||||||
|
print "[packet] Got:", totals
|
||||||
return 0, totals
|
return 0, totals
|
||||||
|
|
||||||
def send(self, data):
|
def send(self, data):
|
||||||
|
if printPackets:
|
||||||
|
print "[packet] Sent:", data
|
||||||
return self.sock.send(unicode(data))
|
return self.sock.send(unicode(data))
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
|||||||
35
gameview.py
35
gameview.py
@ -330,19 +330,12 @@ class AOCharMovie(QtGui.QLabel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
placeholderPath = AO2XPpath + "themes/default/oldplaceholder.gif"
|
placeholderPath = AO2XPpath + "themes/default/oldplaceholder.gif"
|
||||||
|
|
||||||
imgPath = ""
|
imgPath = ""
|
||||||
downloadCharacters = ini.read_ini_bool("AO2XP.ini", "General", "download characters")
|
|
||||||
|
|
||||||
if apngPath:
|
if apngPath:
|
||||||
imgPath = apngPath
|
imgPath = apngPath
|
||||||
self.usePillow = 1
|
self.usePillow = 1
|
||||||
else:
|
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(
|
pngPath = testPath(
|
||||||
AOpath + "characters/" + pChar + "/" + emotePrefix + pEmote + ".png",
|
AOpath + "characters/" + pChar + "/" + emotePrefix + pEmote + ".png",
|
||||||
AOpath + "characters/" + pChar + "/" + emotePrefix + "/" + pEmote + ".png",
|
AOpath + "characters/" + pChar + "/" + emotePrefix + "/" + pEmote + ".png",
|
||||||
@ -357,11 +350,6 @@ class AOCharMovie(QtGui.QLabel):
|
|||||||
imgPath = pngPath
|
imgPath = pngPath
|
||||||
self.usePillow = 0
|
self.usePillow = 0
|
||||||
else:
|
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(
|
webpPath = testPath(
|
||||||
AOpath + "characters/" + pChar + "/" + emotePrefix + pEmote + ".webp",
|
AOpath + "characters/" + pChar + "/" + emotePrefix + pEmote + ".webp",
|
||||||
AOpath + "characters/" + pChar + "/" + emotePrefix + "/" + pEmote + ".webp",
|
AOpath + "characters/" + pChar + "/" + emotePrefix + "/" + pEmote + ".webp",
|
||||||
@ -376,11 +364,6 @@ class AOCharMovie(QtGui.QLabel):
|
|||||||
imgPath = webpPath
|
imgPath = webpPath
|
||||||
self.usePillow = 2
|
self.usePillow = 2
|
||||||
else:
|
else:
|
||||||
if downloadCharacters:
|
|
||||||
url = "base/characters/" + pChar.lower() + "/"+pEmote.lower() + ".webp"
|
|
||||||
url = url.replace(" ", "%20")
|
|
||||||
thread.start_new_thread(downloadThread, (url, webpPath))
|
|
||||||
|
|
||||||
gifPath = testPath(
|
gifPath = testPath(
|
||||||
AOpath + "characters/" + pChar + "/" + emotePrefix + pEmote + ".gif",
|
AOpath + "characters/" + pChar + "/" + emotePrefix + pEmote + ".gif",
|
||||||
AOpath + "characters/" + pChar + "/" + emotePrefix + "/" + pEmote + ".gif",
|
AOpath + "characters/" + pChar + "/" + emotePrefix + "/" + pEmote + ".gif",
|
||||||
@ -395,10 +378,11 @@ class AOCharMovie(QtGui.QLabel):
|
|||||||
imgPath = gifPath
|
imgPath = gifPath
|
||||||
self.usePillow = 0
|
self.usePillow = 0
|
||||||
else:
|
else:
|
||||||
if downloadCharacters:
|
if ini.read_ini_bool("AO2XP.ini", "General", "download characters"):
|
||||||
url = "base/characters/" + pChar.lower() + "/" + emotePrefix + pEmote.lower() + ".gif"
|
pass
|
||||||
url = url.replace(" ", "%20")
|
# url = "base/characters/" + pChar.lower() + "/" + emotePrefix + pEmote.lower() + ".gif"
|
||||||
thread.start_new_thread(downloadThread, (url, gifPath))
|
# url = url.replace(" ", "%20")
|
||||||
|
# thread.start_new_thread(downloadThread, (url, gifPath))
|
||||||
|
|
||||||
if exists(placeholderPath):
|
if exists(placeholderPath):
|
||||||
imgPath = placeholderPath
|
imgPath = placeholderPath
|
||||||
@ -1083,6 +1067,7 @@ class GUI(QtGui.QWidget):
|
|||||||
chatmsg = ''
|
chatmsg = ''
|
||||||
charid = -1
|
charid = -1
|
||||||
login = False
|
login = False
|
||||||
|
alignChars = False
|
||||||
privateMusicSelected = False
|
privateMusicSelected = False
|
||||||
privateInventorySelected = False
|
privateInventorySelected = False
|
||||||
scaling = [SCALING_AUTO, SCALING_AUTO]
|
scaling = [SCALING_AUTO, SCALING_AUTO]
|
||||||
@ -1825,7 +1810,6 @@ class GUI(QtGui.QWidget):
|
|||||||
with open(courtroomDesign) as f:
|
with open(courtroomDesign) as f:
|
||||||
for keys in f.read().split("\n"):
|
for keys in f.read().split("\n"):
|
||||||
if not keys or "=" not in keys or keys[0] == ";": continue
|
if not keys or "=" not in keys or keys[0] == ";": continue
|
||||||
|
|
||||||
key, value = keys.split("=")
|
key, value = keys.split("=")
|
||||||
design[key.strip()] = value.split(',')
|
design[key.strip()] = value.split(',')
|
||||||
|
|
||||||
@ -1919,6 +1903,8 @@ class GUI(QtGui.QWidget):
|
|||||||
if "found_song_color" in design:
|
if "found_song_color" in design:
|
||||||
self.foundSongItemColor = QtGui.QColor(*[int(x) for x in design["found_song_color"]])
|
self.foundSongItemColor = QtGui.QColor(*[int(x) for x in design["found_song_color"]])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self.cbSlide.setVisible("slide_enable" in design)
|
self.cbSlide.setVisible("slide_enable" in design)
|
||||||
self.cbBench.setVisible("ao2xp_desk" in design)
|
self.cbBench.setVisible("ao2xp_desk" in design)
|
||||||
self.OOCLogin.setVisible("ao2xp_login" 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())
|
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.court.resize(self.viewport.size())
|
||||||
self.bench.resize(self.viewport.size())
|
self.bench.resize(self.viewport.size())
|
||||||
self.whiteFlashLabel.resize(self.viewport.size())
|
self.whiteFlashLabel.resize(self.viewport.size())
|
||||||
@ -3809,6 +3798,7 @@ class GUI(QtGui.QWidget):
|
|||||||
|
|
||||||
if not self.animIsEmpty:
|
if not self.animIsEmpty:
|
||||||
self.char.move(self.viewport.width() * hor_offset / 100, self.viewport.height() * vert_offset / 100)
|
self.char.move(self.viewport.width() * hor_offset / 100, self.viewport.height() * vert_offset / 100)
|
||||||
|
if self.alignChars:
|
||||||
self.char.setAlignPos(side)
|
self.char.setAlignPos(side)
|
||||||
|
|
||||||
# check if paired
|
# check if paired
|
||||||
@ -3823,6 +3813,7 @@ class GUI(QtGui.QWidget):
|
|||||||
|
|
||||||
if got_otherCharId > -1: # user is paired
|
if got_otherCharId > -1: # user is paired
|
||||||
self.sideChar.show()
|
self.sideChar.show()
|
||||||
|
if self.alignChars:
|
||||||
self.sideChar.setAlignPos(side)
|
self.sideChar.setAlignPos(side)
|
||||||
|
|
||||||
boxPairOrder = self.mChatMessage[OTHER_CHARID].split("^")
|
boxPairOrder = self.mChatMessage[OTHER_CHARID].split("^")
|
||||||
|
|||||||
35
mainmenu.py
35
mainmenu.py
@ -411,6 +411,7 @@ class AOServerInfo(QtCore.QThread):
|
|||||||
self.useWS = False
|
self.useWS = False
|
||||||
self.connected = False
|
self.connected = False
|
||||||
self.disconnect = False
|
self.disconnect = False
|
||||||
|
self.musicHack = False
|
||||||
|
|
||||||
def setIP(self, name, ip, port, ws_port=0, wss_port=0):
|
def setIP(self, name, ip, port, ws_port=0, wss_port=0):
|
||||||
self.ip = ip
|
self.ip = ip
|
||||||
@ -455,8 +456,7 @@ class AOServerInfo(QtCore.QThread):
|
|||||||
musicList = []
|
musicList = []
|
||||||
pingtimer = 150
|
pingtimer = 150
|
||||||
readytick = -1
|
readytick = -1
|
||||||
|
gotARUP = False
|
||||||
got_arup = False
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if self.disconnect:
|
if self.disconnect:
|
||||||
@ -498,6 +498,7 @@ class AOServerInfo(QtCore.QThread):
|
|||||||
maxplayers = int(network[2])
|
maxplayers = int(network[2])
|
||||||
self.canConnect.emit()
|
self.canConnect.emit()
|
||||||
self.setOnlinePlayers.emit('%d/%d players online' % (players, maxplayers))
|
self.setOnlinePlayers.emit('%d/%d players online' % (players, maxplayers))
|
||||||
|
if self.tcp.isWS:
|
||||||
self.tcp.send("ASS#%") # get webAO bucket
|
self.tcp.send("ASS#%") # get webAO bucket
|
||||||
got_stuff = True
|
got_stuff = True
|
||||||
|
|
||||||
@ -507,7 +508,7 @@ class AOServerInfo(QtCore.QThread):
|
|||||||
|
|
||||||
elif header == "ASS": # ha ha ha...
|
elif header == "ASS": # ha ha ha...
|
||||||
self.webAO_bucket = network[1]
|
self.webAO_bucket = network[1]
|
||||||
print self.webAO_bucket
|
print "[debug] URL:", self.webAO_bucket
|
||||||
|
|
||||||
elif header == "ID":
|
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)
|
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]
|
del network[0]
|
||||||
areas[kind] = [network[i] for i in range(len(network))]
|
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):
|
for j in range(4):
|
||||||
if j != kind and not len(areas[j]):
|
if j != kind and not len(areas[j]):
|
||||||
areas[j] = ["" for i in range(len(network))]
|
areas[j] = ["" for i in range(len(network))]
|
||||||
|
|
||||||
if not got_arup:
|
if not gotARUP:
|
||||||
print '[client]', 'The server has %d areas' % areas_len
|
print '[client]', 'The server has %d areas' % areasLen
|
||||||
got_arup = True
|
gotARUP = True
|
||||||
|
|
||||||
if musicList and not len(areas[4]):
|
if musicList and not self.musicHack and not len(areas[4]):
|
||||||
for i in range(areas_len):
|
for i in range(areasLen):
|
||||||
areas[4].append(musicList[0])
|
areas[4].append(musicList[0])
|
||||||
del musicList[0]
|
del musicList[0]
|
||||||
|
|
||||||
@ -642,3 +643,17 @@ class AOServerInfo(QtCore.QThread):
|
|||||||
if not pid in playerList:
|
if not pid in playerList:
|
||||||
playerList[pid] = []
|
playerList[pid] = []
|
||||||
playerList[pid].append(network[2].decode('utf-8'))
|
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