本文整理汇总了Python中cuwo.script.ScriptManager类的典型用法代码示例。如果您正苦于以下问题:Python ScriptManager类的具体用法?Python ScriptManager怎么用?Python ScriptManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ScriptManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connectionMade
def connectionMade(self):
if self.connection_state != 0:
self.disconnect('Unexpected data')
return
self.connection_state = 1
server = self.server
if len(server.connections) >= server.config.base.max_players:
# For being able to allow joining by external scritps although server is full
ret = self.scripts.call('on_join_full_server').result
if ret is not True:
self.send_packet(server_full_packet)
self.disconnect()
self.connection_state = -1
print '[INFO] %s tried to join full server' % self.address.host
return
self.packet_handlers = {
ClientVersion.packet_id: self.on_version_packet,
EntityUpdate.packet_id: self.on_entity_packet,
ClientChatMessage.packet_id: self.on_chat_packet,
InteractPacket.packet_id: self.on_interact_packet,
HitPacket.packet_id: self.on_hit_packet,
ShootPacket.packet_id: self.on_shoot_packet
}
self.packet_handler = PacketHandler(CS_PACKETS, self.on_packet)
server.connections.add(self)
self.rights = AttributeSet()
self.scripts = ScriptManager()
server.scripts.call('on_new_connection', connection=self)
示例2: __init__
def __init__(self, config):
self.config = config
base = config.base
# game-related
self.update_packet = ServerUpdate()
self.update_packet.reset()
self.connections = set()
self.players = MultikeyDict()
self.chunk_items = collections.defaultdict(list)
self.entities = {}
self.entity_ids = IDPool(1)
self.update_loop = LoopingCall(self.update)
self.update_loop.start(1.0 / constants.UPDATE_FPS, False)
# server-related
self.git_rev = base.get('git_rev', None)
self.passwords = {}
for k, v in base.passwords.iteritems():
self.passwords[k.lower()] = v
self.scripts = ScriptManager()
for script in base.scripts:
self.load_script(script)
# time
self.extra_elapsed_time = 0.0
self.start_time = reactor.seconds()
self.set_clock('12:00')
示例3: connection_made
def connection_made(self, transport):
self.transport = transport
self.address = transport.get_extra_info('peername')
accept = self.server.scripts.call('on_connection_attempt',
address=self.address).result
# hardban
if accept is False:
self.transport.abort()
self.disconnected = True
return
# enable TCP_NODELAY
sock = transport.get_extra_info('socket')
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, True)
# ban with message
if accept is not None:
join_packet.entity_id = 1
self.send_packet(join_packet)
def disconnect():
chat_packet.entity_id = 0
chat_packet.value = accept
self.send_packet(chat_packet)
self.transport.close()
# need to add a small delay, since the client will otherwise
# ignore our chat message
self.loop.call_later(0.1, disconnect)
self.disconnected = True
self.transport.pause_reading()
return
server = self.server
if len(server.connections) >= server.config.base.max_players:
self.send_packet(server_full_packet)
self.disconnect()
return
self.packet_handlers = {
packets.ClientVersion.packet_id: self.on_version_packet,
packets.EntityUpdate.packet_id: self.on_entity_packet,
packets.ClientChatMessage.packet_id: self.on_chat_packet,
packets.InteractPacket.packet_id: self.on_interact_packet,
packets.HitPacket.packet_id: self.on_hit_packet,
packets.ShootPacket.packet_id: self.on_shoot_packet
}
self.packet_handler = packets.PacketHandler(packets.CS_PACKETS,
self.on_packet)
server.connections.add(self)
self.rights = AttributeSet()
self.scripts = ScriptManager()
server.scripts.call('on_new_connection', connection=self)
示例4: connectionMade
def connectionMade(self):
self.transport.setTcpNoDelay(True)
server = self.server
self.client_packet_handler = PacketHandler(CS_PACKETS,
self.on_client_packet)
self.server_packet_handler = PacketHandler(SC_PACKETS,
self.on_server_packet)
server.connections.add(self)
self.rights = AttributeSet()
self.scripts = ScriptManager()
server.scripts.call('on_new_connection', connection=self)
point = TCP4ClientEndpoint(reactor, self.server.config.base.mitm_ip, self.server.config.base.mitm_port)
d = point.connect(RelayFactory(self))
d.addCallback(self.got_relay_client)
示例5: __init__
def __init__(self, config):
self.config = config
base = config.base
# GAME RELATED
self.update_packet = ServerUpdate()
self.update_packet.reset()
self.connections = set()
self.players = MultikeyDict()
self.entities = {}
self.entity_ids = IDPool(1)
# DATABASE
self.db_con = database.get_connection()
database.create_structure(self.db_con)
# Initialize default world
self.world = World(self)
self.update_loop = LoopingCall(self.update)
self.update_loop.start(1.0 / constants.UPDATE_FPS, False)
# SERVER RELATED
self.git_rev = base.get('git_rev', None)
self.ranks = {}
for k, v in base.ranks.iteritems():
self.ranks[k.lower()] = v
self.scripts = ScriptManager()
for script in base.scripts:
self.load_script(script)
# INGAME TIME
self.extra_elapsed_time = 0.0
self.start_time = reactor.seconds()
self.set_clock('12:00')
# START LISTENING
self.listen_tcp(base.port, self)
示例6: __init__
def __init__(self, loop, config):
self.loop = loop
self.config = config
base = config.base
# game-related
self.update_packet = packets.ServerUpdate()
self.update_packet.reset()
self.connections = set()
self.players = MultikeyDict()
self.chunks = {}
self.updated_chunks = set()
self.update_loop = LoopingCall(self.update)
self.update_loop.start(1.0 / base.update_fps, now=False)
# world
self.world = World(self, self.loop, base.seed, base.use_tgen,
base.use_entities)
# server-related
self.git_rev = base.get('git_rev', None)
self.passwords = {}
for k, v in base.passwords.items():
self.passwords[k.lower()] = v
self.scripts = ScriptManager()
for script in base.scripts:
self.load_script(script)
# time
self.extra_elapsed_time = 0.0
self.start_time = loop.time()
self.set_clock('12:00')
# start listening
asyncio.Task(self.create_server(self.build_protocol,
port=base.port))
示例7: connectionMade
def connectionMade(self):
server = self.server
if len(server.connections) >= server.config.base.max_players:
self.send_packet(server_full_packet)
self.disconnect()
return
self.packet_handlers = {
ClientVersion.packet_id: self.on_version_packet,
EntityUpdate.packet_id: self.on_entity_packet,
ClientChatMessage.packet_id: self.on_chat_packet,
InteractPacket.packet_id: self.on_interact_packet,
HitPacket.packet_id: self.on_hit_packet,
ShootPacket.packet_id: self.on_shoot_packet
}
self.packet_handler = PacketHandler(CS_PACKETS, self.on_packet)
server.connections.add(self)
self.rights = AttributeSet()
self.scripts = ScriptManager()
server.scripts.call('on_new_connection', connection=self)
示例8: __init__
def __init__(self, config):
self.config = config
base = config.base
# game-related
self.update_packet = ServerUpdate()
self.update_packet.reset()
self.connections = set()
self.players = MultikeyDict()
self.entities = {}
# DATABASE
self.db_con = database.get_connection()
database.create_structure(self.db_con)
self.update_loop = LoopingCall(self.update)
self.update_loop.start(1.0 / base.update_fps, False)
# server-related
self.git_rev = base.get('git_rev', None)
self.ranks = {}
for k, v in base.ranks.iteritems():
self.ranks[k.lower()] = v
self.scripts = ScriptManager()
for script in base.scripts:
self.load_script(script)
# time
self.start_time = reactor.seconds()
self.next_secondly_check = self.start_time+1
# start listening
self.listen_tcp(base.port, self)
示例9: CubeWorldConnection
class CubeWorldConnection(asyncio.Protocol):
"""
Protocol used for players
"""
has_joined = False
entity_id = None
entity = None
disconnected = False
scripts = None
chunk = None
mounted_entity = None
def __init__(self, server):
self.server = server
self.world = server.world
self.loop = server.loop
def connection_made(self, transport):
self.transport = transport
self.address = transport.get_extra_info('peername')
accept = self.server.scripts.call('on_connection_attempt',
address=self.address).result
# hardban
if accept is False:
self.transport.abort()
self.disconnected = True
return
# enable TCP_NODELAY
sock = transport.get_extra_info('socket')
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, True)
# ban with message
if accept is not None:
join_packet.entity_id = 1
self.send_packet(join_packet)
def disconnect():
self.disconnected = False
chat_packet.entity_id = 0
chat_packet.value = accept
self.send_packet(chat_packet)
self.disconnected = True
self.transport.close()
# need to add a small delay, since the client will otherwise
# ignore our chat message
self.loop.call_later(0.1, disconnect)
self.disconnected = True
self.transport.pause_reading()
return
server = self.server
if len(server.connections) >= server.config.base.max_players:
self.send_packet(server_full_packet)
self.disconnect()
return
self.packet_handlers = {
packets.ClientVersion.packet_id: self.on_version_packet,
packets.EntityUpdate.packet_id: self.on_entity_packet,
packets.ClientChatMessage.packet_id: self.on_chat_packet,
packets.InteractPacket.packet_id: self.on_interact_packet,
packets.HitPacket.packet_id: self.on_hit_packet,
packets.ShootPacket.packet_id: self.on_shoot_packet,
packets.PassivePacket.packet_id: self.on_passive_packet,
packets.ChunkDiscovered.packet_id: self.on_discover_packet
}
self.packet_handler = packets.PacketHandler(packets.CS_PACKETS,
self.on_packet)
server.connections.add(self)
self.rights = AttributeSet()
self.scripts = ScriptManager()
server.scripts.call('on_new_connection', connection=self)
def data_received(self, data):
if self.is_closing():
return
self.packet_handler.feed(data)
def is_closing(self):
return self.disconnected or self.transport.is_closing()
def disconnect(self, reason=None):
if self.is_closing():
return
self.transport.close()
self.connection_lost(reason)
def connection_lost(self, reason):
if self.disconnected:
return
self.disconnected = True
self.server.connections.discard(self)
if self.has_joined:
#.........这里部分代码省略.........
示例10: CubeWorldConnection
class CubeWorldConnection(Protocol):
"""
Protocol used for players
"""
has_joined = False
entity_id = None
entity_data = None
disconnected = False
scripts = None
def __init__(self, server, addr):
self.address = addr
self.server = server
# connection methods
def connectionMade(self):
server = self.server
if len(server.connections) >= server.config.base.max_players:
self.send_packet(server_full_packet)
self.disconnect()
return
self.packet_handlers = {
ClientVersion.packet_id: self.on_version_packet,
EntityUpdate.packet_id: self.on_entity_packet,
ClientChatMessage.packet_id: self.on_chat_packet,
InteractPacket.packet_id: self.on_interact_packet,
HitPacket.packet_id: self.on_hit_packet,
ShootPacket.packet_id: self.on_shoot_packet
}
self.packet_handler = PacketHandler(CS_PACKETS, self.on_packet)
server.connections.add(self)
self.rights = AttributeSet()
self.scripts = ScriptManager()
server.scripts.call('on_new_connection', connection=self)
def dataReceived(self, data):
self.packet_handler.feed(data)
def disconnect(self, reason=None):
self.transport.loseConnection()
self.connectionLost(reason)
def connectionLost(self, reason):
if self.disconnected:
return
self.disconnected = True
self.server.connections.discard(self)
if self.has_joined:
del self.server.players[self]
print 'Player %s left' % self.name
if self.entity_data is not None:
del self.server.entities[self.entity_id]
if self.entity_id is not None:
self.server.entity_ids.put_back(self.entity_id)
if self.scripts is not None:
self.scripts.unload()
# packet methods
def send_packet(self, packet):
self.transport.write(write_packet(packet))
def on_packet(self, packet):
if self.disconnected:
return
if packet is None:
print 'Invalid packet received'
self.disconnect()
raise StopIteration()
handler = self.packet_handlers.get(packet.packet_id, None)
if handler is None:
# print 'Unhandled client packet: %s' % packet.packet_id
return
handler(packet)
def on_version_packet(self, packet):
if packet.version != constants.CLIENT_VERSION:
mismatch_packet.version = constants.CLIENT_VERSION
self.send_packet(mismatch_packet)
self.disconnect()
return
server = self.server
self.entity_id = server.entity_ids.pop()
join_packet.entity_id = self.entity_id
self.send_packet(join_packet)
seed_packet.seed = server.config.base.seed
self.send_packet(seed_packet)
def on_entity_packet(self, packet):
if self.entity_data is None:
self.entity_data = create_entity_data()
self.server.entities[self.entity_id] = self.entity_data
mask = packet.update_entity(self.entity_data)
self.entity_data.mask |= mask
#.........这里部分代码省略.........
示例11: CubeWorldServer
class CubeWorldServer(Factory):
items_changed = False
exit_code = None
def __init__(self, config):
self.config = config
base = config.base
# game-related
self.update_packet = ServerUpdate()
self.update_packet.reset()
self.connections = set()
self.players = MultikeyDict()
self.chunk_items = collections.defaultdict(list)
self.entities = {}
self.entity_ids = IDPool(1)
self.update_loop = LoopingCall(self.update)
self.update_loop.start(1.0 / base.update_fps, False)
# server-related
self.git_rev = base.get('git_rev', None)
self.passwords = {}
for k, v in base.passwords.iteritems():
self.passwords[k.lower()] = v
self.scripts = ScriptManager()
for script in base.scripts:
self.load_script(script)
# time
self.extra_elapsed_time = 0.0
self.start_time = reactor.seconds()
self.set_clock('12:00')
# start listening
self.listen_tcp(base.port, self)
def buildProtocol(self, addr):
# return None here to refuse the connection.
# will use this later to hardban e.g. DoS
ret = self.scripts.call('on_connection_attempt', address=addr).result
if ret is False:
return None
elif ret is not None:
return BanProtocol(ret)
return CubeWorldConnection(self, addr)
def remove_item(self, chunk, index):
items = self.chunk_items[chunk]
ret = items.pop(index)
self.items_changed = True
return ret.item_data
def drop_item(self, item_data, pos):
item = ChunkItemData()
item.drop_time = 750
# XXX provide sane values for these
item.scale = 0.1
item.rotation = 185.0
item.something3 = item.something5 = item.something6 = 0
item.pos = pos
item.item_data = item_data
self.chunk_items[get_chunk(pos)].append(item)
self.items_changed = True
def update(self):
self.scripts.call('update')
# entity updates
for entity_id, entity in self.entities.iteritems():
entity_packet.set_entity(entity, entity_id, entity.mask)
entity.mask = 0
self.broadcast_packet(entity_packet)
self.broadcast_packet(update_finished_packet)
# other updates
update_packet = self.update_packet
if self.items_changed:
for chunk, items in self.chunk_items.iteritems():
item_list = ChunkItems()
item_list.chunk_x, item_list.chunk_y = chunk
item_list.items = items
update_packet.chunk_items.append(item_list)
self.broadcast_packet(update_packet)
update_packet.reset()
# reset drop times
if self.items_changed:
for items in self.chunk_items.values():
for item in items:
item.drop_time = 0
self.items_changed = False
# time update
time_packet.time = self.get_time()
time_packet.day = self.get_day()
#.........这里部分代码省略.........
示例12: CubeWorldServer
class CubeWorldServer(Factory):
items_changed = False
exit_code = None
world = None
def __init__(self, config):
self.config = config
base = config.base
# game-related
self.update_packet = ServerUpdate()
self.update_packet.reset()
self.connections = set()
self.players = MultikeyDict()
self.entities = {}
# DATABASE
self.db_con = database.get_connection()
database.create_structure(self.db_con)
self.update_loop = LoopingCall(self.update)
self.update_loop.start(1.0 / base.update_fps, False)
# server-related
self.git_rev = base.get('git_rev', None)
self.ranks = {}
for k, v in base.ranks.iteritems():
self.ranks[k.lower()] = v
self.scripts = ScriptManager()
for script in base.scripts:
self.load_script(script)
# time
self.start_time = reactor.seconds()
self.next_secondly_check = self.start_time+1
# start listening
self.listen_tcp(base.port, self)
def buildProtocol(self, addr):
# return None here to refuse the connection.
# will use this later to hardban e.g. DoS
ret = self.scripts.call('on_connection_attempt', address=addr).result
if ret is False:
print '[WARNING] Connection attempt for %s blocked by script!' % addr.host
return None
elif ret is not None:
return BanProtocol(ret)
if database.is_banned_ip(self.db_con, addr.host):
print '[INFO] Banned client %s tried to join.' % addr.host
return BanProtocol('You are banned on this server.')
return CubeWorldConnection(self, addr)
def update(self):
self.scripts.call('update')
# entity updates
for entity_id, entity in self.entities.iteritems():
entity.mask = 0
def send_chat(self, value):
packet = ServerChatMessage()
packet.entity_id = 0
packet.value = value
self.broadcast_packet(packet)
def broadcast_packet(self, packet):
data = write_packet(packet)
for player in self.players.values():
player.transport.write(data)
# line/string formatting options based on config
def format(self, value):
format_dict = {'server_name': self.config.base.server_name}
return value % format_dict
def format_lines(self, value):
lines = []
for line in value:
lines.append(self.format(line))
return lines
# script methods
def load_script(self, name):
try:
return self.scripts[name]
except KeyError:
pass
try:
mod = __import__('scripts.%s' % name, globals(), locals(), [name])
except ImportError, e:
traceback.print_exc(e)
return None
script = mod.get_class()(self)
#.........这里部分代码省略.........
示例13: __init__
class CubeWorldServer:
exit_code = None
world = None
old_time = None
skip_index = 0
def __init__(self, loop, config):
self.loop = loop
self.config = config
base = config.base
# game-related
self.update_packet = packets.ServerUpdate()
self.update_packet.reset()
self.connections = set()
self.players = MultikeyDict()
self.updated_chunks = set()
use_same_loop = base.update_fps == base.network_fps
if use_same_loop:
def update_callback():
self.update()
self.send_update()
else:
update_callback = self.update
self.update_loop = LoopingCall(update_callback)
self.update_loop.start(1.0 / base.update_fps, now=False)
if use_same_loop:
self.send_loop = self.update_loop
else:
self.send_loop = LoopingCall(self.send_update)
self.send_loop.start(1.0 / base.network_fps, now=False)
self.mission_loop = LoopingCall(self.update_missions)
self.mission_loop.start(base.mission_update_rate, now=False)
# world
self.world = World(self, self.loop, base.seed,
use_tgen=base.use_tgen,
use_entities=base.use_entities,
chunk_retire_time=base.chunk_retire_time,
debug=base.world_debug_info)
if base.world_debug_file is not None:
debug_fp = open(base.world_debug_file, 'wb')
self.world.set_debug(debug_fp)
# server-related
self.git_rev = base.get('git_rev', None)
self.passwords = {}
for k, v in base.passwords.items():
self.passwords[k.lower()] = v
self.scripts = ScriptManager()
for script in base.scripts:
self.load_script(script)
# time
self.extra_elapsed_time = 0.0
self.start_time = loop.time()
self.set_clock('12:00')
# start listening
self.loop.set_exception_handler(self.exception_handler)
self.loop.create_task(self.create_server(self.build_protocol,
port=base.port,
family=socket.AF_INET))
def exception_handler(self, loop, context):
exception = context.get('exception')
if isinstance(exception, TimeoutError):
pass
else:
loop.default_exception_handler(context)
def build_protocol(self):
return CubeWorldConnection(self)
def drop_item(self, item_data, pos):
item = packets.ChunkItemData()
item.drop_time = 750
# XXX provide sane values for these
item.scale = 0.1
item.rotation = 185.0
item.something3 = item.something5 = item.something6 = 0
item.pos = pos
item.item_data = item_data
self.world.get_chunk(get_chunk(pos)).add_item(item)
def add_packet_list(self, items, l, size):
for item in iterate_packet_list(l):
items.append(item.data.copy())
def handle_tgen_packets(self, in_queue):
if in_queue is None:
return
#.........这里部分代码省略.........
示例14: CubeWorldServer
class CubeWorldServer(Factory):
items_changed = False
exit_code = 0
last_secondly_check = None
updates_since_last_second = 0
updates_per_second = 0
current_change_index = 0
world = None
def __init__(self, config):
self.config = config
base = config.base
# GAME RELATED
self.update_packet = ServerUpdate()
self.update_packet.reset()
self.connections = set()
self.players = MultikeyDict()
self.entities = {}
self.entity_ids = IDPool(1)
# DATABASE
self.db_con = database.get_connection()
database.create_structure(self.db_con)
# Initialize default world
self.world = World(self)
self.update_loop = LoopingCall(self.update)
self.update_loop.start(1.0 / constants.UPDATE_FPS, False)
# SERVER RELATED
self.git_rev = base.get('git_rev', None)
self.ranks = {}
for k, v in base.ranks.iteritems():
self.ranks[k.lower()] = v
self.scripts = ScriptManager()
for script in base.scripts:
self.load_script(script)
# INGAME TIME
self.extra_elapsed_time = 0.0
self.start_time = reactor.seconds()
self.set_clock('12:00')
# START LISTENING
self.listen_tcp(base.port, self)
def buildProtocol(self, addr):
con_remain = self.config.base.max_connections_per_ip
for connection in self.connections:
if connection.address.host == addr.host:
con_remain -= 1
if con_remain <= 0:
if con_remain == 0:
print '[WARNING] Too many connections from %s, closing...' % addr.host
connection.disconnect()
if con_remain <= 0:
return
self.db_con = database.get_connection()
if database.is_banned_ip(self.db_con, addr.host):
print '[INFO] Banned client %s tried to join.' % addr.host
return 'You are banned from this server.'
if self.scripts.call('on_connection_attempt', address=addr).result is False:
print '[WARNING] Connection attempt for %s blocked by script!' % addr.host
return False
return CubeWorldConnection(self, addr)
def remove_item(self, chunk_x, chunk_y, index):
print '[DEBUG] Removing item #%s from chunk %s,%s' % (index, chunk_x, chunk_y)
chunk = self.world.get_chunk_unscaled(chunk_x, chunk_y)
ret = chunk.item_list.pop(index)
self.items_changed = True
return ret.item_data
def drop_item(self, item_data, pos):
print '[DEBUG] Dropping item at %s,%s' % (pos.x, pos.y)
chunk = self.world.get_chunk_scaled(pos.x, pos.y)
if len(chunk.item_list) > constants.MAX_ITEMS_PER_CHUNK:
print '[WARNING] To many items at Chunk(%s,%s)!' % (math.floor(pos.x / constants.CHUNK_SCALE), math.floor(pos.y / constants.CHUNK_SCALE))
return False
item = ChunkItemData()
item.drop_time = 750
item.scale = 0.1
item.rotation = 185.0
item.something3 = item.something5 = item.something6 = 0
item.pos = pos
item.item_data = item_data
chunk.item_list.append(item)
self.items_changed = True
def update(self):
self.scripts.call('update')
uxtime = reactor.seconds()
if self.last_secondly_check:
#.........这里部分代码省略.........
示例15: CubeWorldConnection
class CubeWorldConnection(Protocol):
"""
Protocol used for players
"""
relay_client = None
relay_packets = None
has_joined = False
entity_id = None
entity_data = None
login_id = None
rank = None
disconnected = False
scripts = None
chunk = None
old_pos = None
old_health = None
old_level = None
old_xp = None
def __init__(self, server, addr):
self.address = addr
self.server = server
self.relay_packets = []
# connection methods
def got_relay_client(self, p):
self.relay_client = p
for data in self.relay_packets:
self.relay_client.transport.write(data)
self.relay_packets = None
print 'Relaying Client Packets.'
def connectionMade(self):
self.transport.setTcpNoDelay(True)
server = self.server
self.client_packet_handler = PacketHandler(CS_PACKETS,
self.on_client_packet)
self.server_packet_handler = PacketHandler(SC_PACKETS,
self.on_server_packet)
server.connections.add(self)
self.rights = AttributeSet()
self.scripts = ScriptManager()
server.scripts.call('on_new_connection', connection=self)
point = TCP4ClientEndpoint(reactor, self.server.config.base.mitm_ip, self.server.config.base.mitm_port)
d = point.connect(RelayFactory(self))
d.addCallback(self.got_relay_client)
def serverDataReceived(self, data):
self.server_packet_handler.feed(data)
def dataReceived(self, data):
self.client_packet_handler.feed(data)
def disconnect(self, reason=None):
self.transport.loseConnection()
self.connectionLost(reason)
def connectionLost(self, reason):
if self.relay_client is not None:
self.relay_client.transport.loseConnection()
if self.disconnected:
return
self.disconnected = True
if self.login_id is not None:
database.update_online_seconds(self.server.db_con, self.login_id)
self.server.connections.discard(self)
if self.has_joined:
del self.server.players[self]
print '[INFO] Player %s #%s left the game.' % (self.name, self.entity_id)
self.server.send_chat('<<< %s #%s left the game' % (self.name, self.entity_id))
if self.entity_data is not None:
del self.server.entities[self.entity_id]
if self.scripts is not None:
self.scripts.unload()
# packet methods
def send_packet(self, packet):
self.transport.write(write_packet(packet))
def relay_packet(self, packet):
if self.relay_client is None:
self.relay_packets.append(write_packet(packet))
else:
self.relay_client.transport.write(write_packet(packet))
def on_server_packet(self, packet):
if packet.packet_id == EntityUpdate.packet_id:
if packet.entity_id == self.entity_id:
self.on_entity_packet(packet)
elif packet.packet_id == JoinPacket.packet_id:
#.........这里部分代码省略.........