处理utf8问题
This commit is contained in:
parent
52dfddbd82
commit
e3f4586442
@ -24,7 +24,7 @@ def main():
|
||||
ws_url = args if args else 'ws://192.168.100.21:7101/websocket'
|
||||
accounts = options.accounts.split(',')
|
||||
accounts = []
|
||||
for i in range(10):
|
||||
for i in range(500):
|
||||
accounts.append('test' + str(i))
|
||||
for account in accounts:
|
||||
ioloop.IOLoop.current().spawn_callback(createVirtualClient, account, ws_url)
|
||||
|
@ -43,14 +43,21 @@ class VirtualClient(object):
|
||||
msgid = eval('cs_msgid_pb2._' + msg.DESCRIPTOR.name)
|
||||
PACK_SIGN = 'KS'
|
||||
enmsg = bytearray(msg.SerializeToString())
|
||||
pktlen_str = chr(len(enmsg) & 0xFF) + chr(len(enmsg) >> 8 & 0xFF)
|
||||
msgid_str = chr(msgid & 0xFF) + chr(msgid >> 8 & 0xFF)
|
||||
seqid_str = chr(seqid & 0xFF) + chr(seqid >> 8 & 0xFF) + \
|
||||
chr(seqid >> 16 & 0xFF) + chr(seqid >> 24 & 0xFF)
|
||||
sign_str = PACK_SIGN
|
||||
reserved_str = chr(0) + chr(0)
|
||||
buff = pktlen_str + msgid_str + seqid_str + sign_str + reserved_str + enmsg.decode('utf-8')
|
||||
conn.write_message(buff.encode('utf-8'), True)
|
||||
head = bytearray(12)
|
||||
head[0] = len(enmsg) & 0xFF
|
||||
head[1] = len(enmsg) >> 8 & 0xFF
|
||||
head[2] = msgid & 0xFF
|
||||
head[3] = msgid >> 8 & 0xFF
|
||||
head[4] = 0
|
||||
head[5] = 0
|
||||
head[6] = 0
|
||||
head[7] = 0
|
||||
head[8] = ord('K')
|
||||
head[9] = ord('S')
|
||||
head[10] = 0
|
||||
head[11] = 0
|
||||
buff = head + enmsg
|
||||
conn.write_message(bytes(buff), True)
|
||||
print(time.time(), time.strftime('[%H:%M:%S]'), msg.DESCRIPTOR.name + '{')
|
||||
print(str(msg), end='')
|
||||
print('}', end='')
|
||||
@ -60,6 +67,7 @@ class VirtualClient(object):
|
||||
msg = cs_proto_pb2.CMJoin()
|
||||
msg.server_id = 2
|
||||
msg.account_id = self.account
|
||||
msg.baseskin = 14001
|
||||
self.sendMsg(conn, msg)
|
||||
|
||||
def parsePacket(self, conn, recv_buf):
|
||||
|
Loading…
x
Reference in New Issue
Block a user