本文整理汇总了Python中cuwo.script.ScriptManager.unload方法的典型用法代码示例。如果您正苦于以下问题:Python ScriptManager.unload方法的具体用法?Python ScriptManager.unload怎么用?Python ScriptManager.unload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cuwo.script.ScriptManager
的用法示例。
在下文中一共展示了ScriptManager.unload方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from cuwo.script import ScriptManager [as 别名]
# 或者: from cuwo.script.ScriptManager import unload [as 别名]
#.........这里部分代码省略.........
for player in self.players.values():
player.send_data(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, update=False):
try:
return self.scripts[name]
except KeyError:
pass
try:
mod = __import__('scripts.%s' % name, globals(), locals(), [name])
if update:
importlib.reload(mod)
except ImportError as e:
traceback.print_exc()
return None
script = mod.get_class()(self)
print('Loaded script %r' % name)
return script
def unload_script(self, name):
try:
self.scripts[name].unload()
except KeyError:
return False
print('Unloaded script %r' % name)
return True
def call_command(self, user, command, args):
"""
Calls a command from an external interface, e.g. IRC, console
"""
return self.scripts.call('on_command', user=user, command=command,
args=args).result
def get_mode(self):
return self.scripts.call('get_mode').result
# command convenience methods (for /help)
def get_commands(self):
for script in self.scripts.get():
if script.commands is None:
continue
for command in script.commands.values():
yield command
def get_command(self, name):
for script in self.scripts.get():
if script.commands is None:
continue
name = script.aliases.get(name, name)
command = script.commands.get(name, None)
示例2: CubeWorldConnection
# 需要导入模块: from cuwo.script import ScriptManager [as 别名]
# 或者: from cuwo.script.ScriptManager import unload [as 别名]
#.........这里部分代码省略.........
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:
del self.server.players[self]
print('Player %s left' % self.name)
if self.entity is not None:
self.entity.destroy()
if self.entity_id is not None:
# need to handle this here, since the player may not have an
# entity yet
self.world.entity_ids.put_back(self.entity_id)
if self.scripts is not None:
self.scripts.unload()
# packet methods
def send_data(self, data):
if self.is_closing():
return
self.transport.write(data)
def send_packet(self, packet):
if self.is_closing():
return
data = packets.write_packet(packet)
self.transport.write(data)
def on_packet(self, packet):
if self.is_closing():
return
if packet is None:
self.on_invalid_packet('data')
return
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
示例3: CubeWorldConnection
# 需要导入模块: from cuwo.script import ScriptManager [as 别名]
# 或者: from cuwo.script.ScriptManager import unload [as 别名]
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
#.........这里部分代码省略.........
示例4: __init__
# 需要导入模块: from cuwo.script import ScriptManager [as 别名]
# 或者: from cuwo.script.ScriptManager import unload [as 别名]
#.........这里部分代码省略.........
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, update=False):
try:
return self.scripts[name]
except KeyError:
pass
try:
mod = __import__('scripts.%s' % name, globals(), locals(), [name])
if update:
importlib.reload(mod)
except ImportError as e:
traceback.print_exc()
return None
script = mod.get_class()(self)
print('Loaded script %r' % name)
return script
def unload_script(self, name):
try:
self.scripts[name].unload()
except KeyError:
return False
print('Unloaded script %r' % name)
return True
def call_command(self, user, command, args):
"""
Calls a command from an external interface, e.g. IRC, console
"""
return self.scripts.call('on_command', user=user, command=command,
args=args).result
def get_mode(self):
return self.scripts.call('get_mode').result
# command convenience methods (for /help)
def get_commands(self):
for script in self.scripts.get():
if script.commands is None:
continue
for command in script.commands.values():
yield command
def get_command(self, name):
for script in self.scripts.get():
if script.commands is None:
continue
name = script.aliases.get(name, name)
command = script.commands.get(name, None)
示例5: CubeWorldConnection
# 需要导入模块: from cuwo.script import ScriptManager [as 别名]
# 或者: from cuwo.script.ScriptManager import unload [as 别名]
class CubeWorldConnection(Protocol):
"""
Protocol used for players
"""
connection_state = 0
entity_id = None
entity_data = None
login_id = None
change_index = -1
scripts = None
chunk = None
old_name = None
old_pos = None
old_health = None
old_level = None
old_xp = None
# used for anti chat spamming
time_last_chat = 0
chat_messages_burst = 0
# used for detecting dead connections
time_last_packet = 0
time_last_rate = 0
packet_count = 0
packet_rate = 0
# used for basic DoS protection
packet_burst = 0
def __init__(self, server, addr):
self.address = addr
self.server = server
# connection methods
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)
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.connection_state < 0:
return
self.server.connections.discard(self)
if self.connection_state >= 3:
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))
self.connection_state = -1
if self.entity_id is not None:
self.server.world.unregister(self.entity_id)
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.connection_state < 0:
return
if packet is None:
#.........这里部分代码省略.........
示例6: CubeWorldConnection
# 需要导入模块: from cuwo.script import ScriptManager [as 别名]
# 或者: from cuwo.script.ScriptManager import unload [as 别名]
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:
#.........这里部分代码省略.........