def __dologin(self): logout("start login") params = {} params['appId'] = self.gameId params['clientId'] = self.clientId params['deviceId'] = TyCodec.des_encode(self.deviceId) params['snsId'] = TyCodec.des_encode(self.snsId) params['imei'] = TyCodec.des_encode(self.imei) sign = self.__md5_sign(params) params['code'] = sign param_str = '&'.join(k + "=" + params[k] for k in sorted(params.keys())) murl = 'http://%s:%d/open/v3/user/processSnsId?' % ( self.host, self.httpPort) + param_str logout('HTTP Login Request:' + murl) webpage = urlopen(murl) response = webpage.read() logout('HTTP Login Response:' + response) webpage.close() msg = json.loads(response) self.userId = msg['result']['userId'] self.authorCode = msg['result']['authorCode'] self.userEmail = msg['result']['userEmail'] self.authInfo = { 'authcode': self.authorCode, 'account': self.userEmail, 'uid': self.userId } self.authInfo = json.dumps(self.authInfo) self.tcpIp = msg['result']['tcpsrv']['ip'] self.tcpPort = int(msg['result']['tcpsrv']['port']) return True
def __md5_sign(self, param): param_str = '&'.join(k + "=" + param[k] for k in sorted(param.keys())) logout("md5 sign str:" + param_str) des_str = TyCodec.des_encode(param_str) logout("des encode str:" + des_str) digest = md5(des_str).hexdigest() return digest
def ty_decode(self, dststr): ddstr = TyCodec.tycode(self.session_seed + int(dststr[:4], 16), dststr[4:]) ddstr = zlib.decompress(ddstr) return ddstr
def ty_encode(self, srcstr): dlen = len(srcstr) tstr = '%04X' % dlen czstr = TyCodec.tycode(self.session_seed + dlen, srcstr) return tstr + czstr