1
This commit is contained in:
parent
b4fbb9d751
commit
8154244110
@ -21,10 +21,10 @@ def main():
|
||||
help = "account info")
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
ws_url = args if args else 'ws://192.168.100.21:7101/websocket'
|
||||
ws_url = args if args else 'ws://192.168.100.21:7501/websocket'
|
||||
accounts = options.accounts.split(',')
|
||||
accounts = []
|
||||
for i in range(500):
|
||||
for i in range(5):
|
||||
accounts.append('test' + str(i))
|
||||
for account in accounts:
|
||||
ioloop.IOLoop.current().spawn_callback(createVirtualClient, account, ws_url)
|
||||
|
31
server/tools/robot/virtualclient/simulate.py
Normal file
31
server/tools/robot/virtualclient/simulate.py
Normal file
@ -0,0 +1,31 @@
|
||||
import time
|
||||
import datetime
|
||||
|
||||
import cs_proto_pb2
|
||||
import cs_msgid_pb2
|
||||
|
||||
class Simulate(object):
|
||||
|
||||
def __init__(self, joined_msg, mapinfo_msg):
|
||||
|
||||
self._joined_msg = joined_msg
|
||||
self._mapinfo_msg = mapinfo_msg
|
||||
self._curr_player = None
|
||||
self._frames = []
|
||||
self._curr_frameno = 0
|
||||
self._objHash = []
|
||||
|
||||
def addFrame(self, frame):
|
||||
self._frames.append(frame)
|
||||
|
||||
def update(self):
|
||||
i = 0
|
||||
while i < len(self._frames):
|
||||
self._updateFrame(self._frames[i])
|
||||
i += 1
|
||||
self._frames = []
|
||||
|
||||
def _updateFrame(self, frame):
|
||||
self._curr_frameno = frame.frameno
|
||||
for obj in frame.full_objects:
|
||||
self._objHash[obj['union_obj_' + obj.object_type]] = obj
|
@ -9,6 +9,7 @@ from tornado import websocket
|
||||
|
||||
import cs_proto_pb2
|
||||
import cs_msgid_pb2
|
||||
import simulate
|
||||
|
||||
def getSMMsgEnum(sm_msgid):
|
||||
sm_e = cs_msgid_pb2._SMMESSAGEID_E
|
||||
@ -25,16 +26,20 @@ def getSMMsg(sm_msgid):
|
||||
class VirtualClient(object):
|
||||
|
||||
def __init__(self, ws_url, account):
|
||||
self._joined_msg = None
|
||||
self._mapinfo_msg = None
|
||||
self._simulate = None
|
||||
self.ws_url = ws_url
|
||||
self.account = account
|
||||
print(self.ws_url)
|
||||
|
||||
@gen.coroutine
|
||||
def co_connect(self):
|
||||
print("connect, account:%s" % self.account)
|
||||
print("connect begin, account:%s" % self.account)
|
||||
conn = yield websocket.websocket_connect(self.ws_url)
|
||||
assert conn
|
||||
ioloop.IOLoop.current().spawn_callback(self.co_receiveMessage, conn)
|
||||
ioloop.IOLoop.current().spawn_callback(self.co_updateSimulate)
|
||||
self.sendLogin(conn)
|
||||
|
||||
def sendMsg(self, conn, msg):
|
||||
@ -67,7 +72,7 @@ class VirtualClient(object):
|
||||
msg = cs_proto_pb2.CMJoin()
|
||||
msg.server_id = 2
|
||||
msg.account_id = self.account
|
||||
msg.baseskin = 14001
|
||||
#msg.baseskin = 14001
|
||||
self.sendMsg(conn, msg)
|
||||
|
||||
def parsePacket(self, conn, recv_buf):
|
||||
@ -90,6 +95,13 @@ class VirtualClient(object):
|
||||
#print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f'))
|
||||
msg = getSMMsg(msgid)
|
||||
ret = msg.ParseFromString(msgbody)
|
||||
if msgid == cs_msgid_pb2._SMJoinedNotify:
|
||||
self._joined_msg = msg
|
||||
if msgid == cs_msgid_pb2._SMMapInfo:
|
||||
self._mapinfo_msg = msg
|
||||
self._simulate = simulate.Simulate(self._joined_msg, self._mapinfo_msg)
|
||||
if msgid == cs_msgid_pb2._SMUpdate:
|
||||
self._simulate.addFrame(msg)
|
||||
#print(len(msgbody))
|
||||
#print(time.time(), time.strftime('[%H:%M:%S]'), msg.DESCRIPTOR.name + '{')
|
||||
#print(str(msg), end='')
|
||||
@ -109,6 +121,16 @@ class VirtualClient(object):
|
||||
recv_buf += data
|
||||
self.parsePacket(conn, recv_buf)
|
||||
|
||||
@gen.coroutine
|
||||
def co_updateSimulate(self):
|
||||
try:
|
||||
while True:
|
||||
if self._simulate:
|
||||
self._simulate.update()
|
||||
yield None
|
||||
except Exception as e:
|
||||
print('co_updateSimulate', e)
|
||||
|
||||
@gen.coroutine
|
||||
def run(self):
|
||||
ioloop.IOLoop.current().spawn_callback(self.co_connect)
|
||||
|
Loading…
x
Reference in New Issue
Block a user