add option to downlaod all patch file, and quit client after 20 loop

This commit is contained in:
AleaJactaEst 2019-05-19 15:29:43 +02:00
parent 37b2a6b85c
commit 7fce47e67c

View file

@ -1385,14 +1385,14 @@ class ClientNetworkConnection:
msg = BitStream() msg = BitStream()
self.buildSystemHeader(msg) self.buildSystemHeader(msg)
msg.pushUint8(8) # SYSTEM_LOGIN_CODE msg.pushUint8(8) # SYSTEM_LOGIN_CODE
msg.pushSint32(_QuitId) # _QuitId msg.pushSint32(self._QuitId) # _QuitId
self._sock.sendto(msg.bytes(), self.frontend) self._sock.sendto(msg.bytes(), self.frontend)
self._ConnectionState = TConnectionState.Quit self._ConnectionState = TConnectionState.Quit
def EmulateFirst(self): def EmulateFirst(self):
self.sendSystemLogin() self.sendSystemLogin()
while True: for _ in range(1, 20): # while True:
data, addr = self._sock.recvfrom(1024) # buffer size is 1024 bytes data, addr = self._sock.recvfrom(1024) # buffer size is 1024 bytes
print( "received message:", data) print( "received message:", data)
self.sendSystemQuit() self.sendSystemQuit()
@ -1406,12 +1406,15 @@ class ClientKhanat:
clientApp="Lirria", clientApp="Lirria",
LanguageCode="fr", LanguageCode="fr",
url="/login/r2_login.php", url="/login/r2_login.php",
suffix = None): suffix = None,
download_patch = False):
self.log = logging.getLogger('myLogger') self.log = logging.getLogger('myLogger')
if suffix is None: if suffix is None:
suffix = str(random.randrange(1, 9999)) suffix = str(random.randrange(1, 9999))
self.log.debug("suffix : %s" % suffix) self.log.debug("suffix : %s" % suffix)
self.download_patch = download_patch
self.khanaturl = khanaturl self.khanaturl = khanaturl
self.login = login + suffix self.login = login + suffix
self.password = password self.password = password
@ -1594,6 +1597,7 @@ class ClientKhanat:
return dstName return dstName
def downloadAllPatch(self): def downloadAllPatch(self):
# TODO - check where client search file to download
for file in self.khanat_idx.CBNPFile: for file in self.khanat_idx.CBNPFile:
tmp = self.getServerFile("%05d/%s.lzma" % (int(self.r2serverversion), file.FileName), False, "") tmp = self.getServerFile("%05d/%s.lzma" % (int(self.r2serverversion), file.FileName), False, "")
with lzma.open(tmp) as fin: with lzma.open(tmp) as fin:
@ -1615,7 +1619,8 @@ class ClientKhanat:
self.khanat_idx.show() self.khanat_idx.show()
# Todo analyze patch and download if necessary or update if incremental - see category # Todo analyze patch and download if necessary or update if incremental - see category
# Download all file in patch - login_patch.cpp:2578 # void CPatchThread::processFile (CPatchManager::SFileToPatch &rFTP) # Download all file in patch - login_patch.cpp:2578 # void CPatchThread::processFile (CPatchManager::SFileToPatch &rFTP)
#self.downloadAllPatch() if self.download_patch:
self.downloadAllPatch()
self.clientNetworkConnection.EmulateFirst() self.clientNetworkConnection.EmulateFirst()
@ -1628,6 +1633,7 @@ def main():
parser.add_argument("--khanaturl", help="khanat URL to auhtenticate", default='localhost') parser.add_argument("--khanaturl", help="khanat URL to auhtenticate", default='localhost')
parser.add_argument("--suffix", help="define suffix") parser.add_argument("--suffix", help="define suffix")
parser.add_argument("-d", "--debug", help="show debug message", action='store_true') parser.add_argument("-d", "--debug", help="show debug message", action='store_true')
parser.add_argument("-p", "--download-patch", help="show debug message", action='store_true')
args = parser.parse_args() args = parser.parse_args()
if args.debug: if args.debug:
@ -1636,7 +1642,7 @@ def main():
level = logging.getLevelName('INFO') level = logging.getLevelName('INFO')
log.setLevel(level) log.setLevel(level)
client = ClientKhanat(args.khanaturl, suffix=args.suffix) client = ClientKhanat(args.khanaturl, suffix=args.suffix, download_patch=args.download_patch)
client.Emulate() client.Emulate()
log.info("End") log.info("End")