1
This commit is contained in:
parent
b4fbb9d751
commit
8154244110
@ -21,10 +21,10 @@ def main():
|
|||||||
help = "account info")
|
help = "account info")
|
||||||
(options, args) = parser.parse_args()
|
(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 = options.accounts.split(',')
|
||||||
accounts = []
|
accounts = []
|
||||||
for i in range(500):
|
for i in range(5):
|
||||||
accounts.append('test' + str(i))
|
accounts.append('test' + str(i))
|
||||||
for account in accounts:
|
for account in accounts:
|
||||||
ioloop.IOLoop.current().spawn_callback(createVirtualClient, account, ws_url)
|
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_proto_pb2
|
||||||
import cs_msgid_pb2
|
import cs_msgid_pb2
|
||||||
|
import simulate
|
||||||
|
|
||||||
def getSMMsgEnum(sm_msgid):
|
def getSMMsgEnum(sm_msgid):
|
||||||
sm_e = cs_msgid_pb2._SMMESSAGEID_E
|
sm_e = cs_msgid_pb2._SMMESSAGEID_E
|
||||||
@ -25,16 +26,20 @@ def getSMMsg(sm_msgid):
|
|||||||
class VirtualClient(object):
|
class VirtualClient(object):
|
||||||
|
|
||||||
def __init__(self, ws_url, account):
|
def __init__(self, ws_url, account):
|
||||||
|
self._joined_msg = None
|
||||||
|
self._mapinfo_msg = None
|
||||||
|
self._simulate = None
|
||||||
self.ws_url = ws_url
|
self.ws_url = ws_url
|
||||||
self.account = account
|
self.account = account
|
||||||
print(self.ws_url)
|
print(self.ws_url)
|
||||||
|
|
||||||
@gen.coroutine
|
@gen.coroutine
|
||||||
def co_connect(self):
|
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)
|
conn = yield websocket.websocket_connect(self.ws_url)
|
||||||
assert conn
|
assert conn
|
||||||
ioloop.IOLoop.current().spawn_callback(self.co_receiveMessage, conn)
|
ioloop.IOLoop.current().spawn_callback(self.co_receiveMessage, conn)
|
||||||
|
ioloop.IOLoop.current().spawn_callback(self.co_updateSimulate)
|
||||||
self.sendLogin(conn)
|
self.sendLogin(conn)
|
||||||
|
|
||||||
def sendMsg(self, conn, msg):
|
def sendMsg(self, conn, msg):
|
||||||
@ -67,7 +72,7 @@ class VirtualClient(object):
|
|||||||
msg = cs_proto_pb2.CMJoin()
|
msg = cs_proto_pb2.CMJoin()
|
||||||
msg.server_id = 2
|
msg.server_id = 2
|
||||||
msg.account_id = self.account
|
msg.account_id = self.account
|
||||||
msg.baseskin = 14001
|
#msg.baseskin = 14001
|
||||||
self.sendMsg(conn, msg)
|
self.sendMsg(conn, msg)
|
||||||
|
|
||||||
def parsePacket(self, conn, recv_buf):
|
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'))
|
#print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f'))
|
||||||
msg = getSMMsg(msgid)
|
msg = getSMMsg(msgid)
|
||||||
ret = msg.ParseFromString(msgbody)
|
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(len(msgbody))
|
||||||
#print(time.time(), time.strftime('[%H:%M:%S]'), msg.DESCRIPTOR.name + '{')
|
#print(time.time(), time.strftime('[%H:%M:%S]'), msg.DESCRIPTOR.name + '{')
|
||||||
#print(str(msg), end='')
|
#print(str(msg), end='')
|
||||||
@ -109,6 +121,16 @@ class VirtualClient(object):
|
|||||||
recv_buf += data
|
recv_buf += data
|
||||||
self.parsePacket(conn, recv_buf)
|
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
|
@gen.coroutine
|
||||||
def run(self):
|
def run(self):
|
||||||
ioloop.IOLoop.current().spawn_callback(self.co_connect)
|
ioloop.IOLoop.current().spawn_callback(self.co_connect)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user