本文整理汇总了Python中utility_functions.build_packet函数的典型用法代码示例。如果您正苦于以下问题:Python build_packet函数的具体用法?Python build_packet怎么用?Python build_packet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了build_packet函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: warp_player_to_player
def warp_player_to_player(self, from_string, to_string):
self.logger.debug("Warp player-to-player command called by %s: %s to %s", self.protocol.player.name,
from_string, to_string)
from_player = self.player_manager.get_logged_in_by_name(from_string)
to_player = self.player_manager.get_logged_in_by_name(to_string)
if from_player is not None:
if to_player is not None:
from_protocol = self.factory.protocols[from_player.protocol]
if from_player is not to_player:
self.logger.debug("target: %s", to_player.uuid)
warp_packet = build_packet(Packets.PLAYER_WARP,
player_warp_write(t="WARP_TO",
world_id=to_player.uuid))
else:
warp_packet = build_packet(Packets.PLAYER_WARP,
player_warp_write(t="WARP_TO_OWN_SHIP",
world_id=None))
from_protocol.client_protocol.transport.write(warp_packet)
if from_string != to_string:
self.protocol.send_chat_message("Warped ^yellow;%s^green; to ^yellow;%s^green;." % (from_string, to_string))
else:
self.protocol.send_chat_message("Warped to ^yellow;%s^green;." % to_string)
else:
self.protocol.send_chat_message("No player by the name ^yellow;%s^green; found." % to_string)
self.protocol.send_chat_message(self.warp.__doc__)
return
else:
self.protocol.send_chat_message("No player by the name ^yellow;%s^green; found." % from_string)
self.protocol.send_chat_message(self.warp.__doc__)
示例2: warp_player_to_player
def warp_player_to_player(self, from_string, to_string):
self.logger.debug("Warp player-to-player command called by %s: %s to %s", self.protocol.player.name,
from_string, to_string)
from_player = self.player_manager.get_logged_in_by_name(from_string)
to_player = self.player_manager.get_logged_in_by_name(to_string)
print from_player
print to_player
if from_player is not None:
if to_player is not None:
from_protocol = self.factory.protocols[from_player.protocol]
if from_player is not to_player:
warp_packet = build_packet(Packets.WARP_COMMAND,
warp_command_write(t="WARP_OTHER_SHIP",
player=to_player.name.encode('utf-8')))
print warp_packet
else:
warp_packet = build_packet(Packets.WARP_COMMAND,
warp_command_write(t='WARP_UP'))
from_protocol.client_protocol.transport.write(warp_packet)
else:
self.protocol.send_chat_message("No player by the name %s found." % to_string)
self.protocol.send_chat_message(self.warp.__doc__)
return
else:
self.protocol.send_chat_message("No player by the name %s found." % from_string)
self.protocol.send_chat_message(self.warp.__doc__)
示例3: warp_player_to_player
def warp_player_to_player(self, from_string, to_string):
from_player = self.player_manager.get_logged_in_by_name(from_string)
to_player = self.player_manager.get_logged_in_by_name(to_string)
if from_player is not None:
if to_player is not None:
from_protocol = self.factory.protocols[from_player.protocol]
if from_player is not to_player:
warp_packet = build_packet(Packets.WARP_COMMAND,
warp_command_write(t="WARP_OTHER_SHIP",
player=to_player.name.encode('utf-8')))
else:
warp_packet = build_packet(Packets.WARP_COMMAND,
warp_command_write(t='WARP_UP'))
from_protocol.client_protocol.transport.write(warp_packet)
if from_string != to_string:
self.protocol.send_chat_message("Warped ^yellow;%s^green; to ^yellow;%s^green;." % (from_string, to_string))
else:
self.protocol.send_chat_message("Warped to ^yellow;%s^green;." % to_string)
else:
self.protocol.send_chat_message("No player by the name ^yellow;%s^green; found." % to_string)
self.protocol.send_chat_message(self.warp.__doc__)
return
else:
self.protocol.send_chat_message("No player by the name ^yellow;%s^green; found." % from_string)
self.protocol.send_chat_message(self.warp.__doc__)
示例4: warp
def warp(self, name):
"""Warps you to a planet. Syntax: /warp [warp name]"""
name = " ".join(name).strip().strip("\t")
if len(name) == 0:
warps = []
for warp in self.planet_warps:
if warps != "":
warps.append(warp[1])
warpnames = " ".join(warps)
self.protocol.send_chat_message("List of planet warps:\n " + warpnames)
return
for warp in self.planet_warps:
if warp[1] == name:
sector, x, y, z, planet, satellite = warp[0].split(":")
x, y, z, planet, satellite = map(int, (x, y, z, planet, satellite))
warp_packet = build_packet(
Packets.WARP_COMMAND,
warp_command_write(t="MOVE_SHIP", sector=sector, x=x, y=y, z=z, planet=planet, satellite=satellite),
)
self.protocol.client_protocol.transport.write(warp_packet)
warp_packet = build_packet(Packets.WARP_COMMAND, warp_command_write(t="WARP_DOWN"))
self.protocol.client_protocol.transport.write(warp_packet)
self.protocol.send_chat_message("Warped.")
return
self.protocol.send_chat_message("No warp with that name!")
示例5: home
def home(self, arg):
"""Warps you to your home planet.\nSyntax: /home"""
player = self.player_manager.get_logged_in_by_name(self.protocol.player.name)
from_protocol = self.factory.protocols[player.protocol]
warp_packet = build_packet(Packets.WARP_COMMAND, warp_command_write(t='WARP_HOME'))
from_protocol.client_protocol.transport.write(warp_packet)
self.protocol.send_chat_message("^yellow;%s^green; warped to their home planet." % self.protocol.player.name)
示例6: beam_to_planet
def beam_to_planet(self, where):
warp_packet = build_packet(Packets.WARP_COMMAND, warp_command_write(t="WARP_DOWN"))
self.protocol.client_protocol.transport.write(warp_packet)
self.protocol.send_chat_message("Beamed down to ^yellow;%s^green; and your ship will arrive soon." % where)
self.factory.broadcast_planet(
"%s^green; beamed down to the planet" % self.protocol.player.colored_name(self.config.colors),
planet=self.protocol.player.planet)
示例7: warp_self_to_player
def warp_self_to_player(self, name):
self.logger.debug("Warp command called by %s to %s", self.protocol.player.name, name)
name = " ".join(name)
target_player = self.player_manager.get_logged_in_by_name(name)
if target_player is not None:
if target_player is not self.protocol.player:
warp_packet = build_packet(Packets.WARP_COMMAND,
warp_command_write(t="WARP_OTHER_SHIP",
player=target_player.name.encode('utf-8')))
else:
warp_packet = build_packet(Packets.WARP_COMMAND,
warp_command_write(t='WARP_UP'))
self.protocol.client_protocol.transport.write(warp_packet)
else:
self.protocol.send_chat_message("No player by the name %s found." % name)
self.protocol.send_chat_message(self.warp.__doc__)
示例8: connectionLost
def connectionLost(self, reason=connectionDone):
"""
Called as a pseudo-destructor when the connection is lost.
:param reason: The reason for the disconnection.
:return: None
"""
try:
if self.client_protocol is not None:
x = build_packet(packets.Packets.CLIENT_DISCONNECT_REQUEST,
packets.client_disconnect_request().build(Container(data=0)))
if self.player is not None and self.player.logged_in:
self.client_disconnect_request(x)
self.client_protocol.transport.write(x)
self.client_protocol.transport.abortConnection()
except:
logger.error("Couldn't disconnect protocol.")
finally:
try:
self.factory.protocols.pop(self.id)
except:
logger.info("Protocol was not in factory list. This should not happen.")
logger.info("protocol id: %s" % self.id)
finally:
logger.info("Lost connection from IP: %s", self.transport.getPeer().host)
self.transport.abortConnection()
示例9: on_chat_received
def on_chat_received(self, data):
now = datetime.now()
try:
p = chat_received().parse(data.data)
if p.name == 'server':
return
# Running a regex substitution on every chat message isn't exactly great but it'll have to do for now.
sender = self.player_manager.get_by_name(
str(
re.sub('(\\^\\w+;|\\^#\\w+;|\\W)|(\\s\\s+)', '', p.name)
)
)
if self.config.chattimestamps:
p.name = '{}> <{}'.format(
now.strftime('%H:%M'),
sender.colored_name(self.config.colors)
)
else:
p.name = sender.colored_name(self.config.colors)
self.protocol.transport.write(
build_packet(Packets.CHAT_RECEIVED, chat_received().build(p))
)
except AttributeError as e:
self.logger.warning(
'Received AttributeError in colored_name. %s', str(e)
)
self.protocol.transport.write(data.original_data)
return False
示例10: warp_player_to_outpost
def warp_player_to_outpost(self, player_string):
self.logger.debug(
'Warp player-to-outpost command called by %s: '
'sending %s to the outpost',
self.protocol.player.name, player_string
)
player_to_send = self.player_manager.get_logged_in_by_name(
player_string
)
if player_to_send is not None:
player_protocol = self.factory.protocols[player_to_send.protocol]
warp_packet = build_packet(
Packets.PLAYER_WARP,
player_warp_toworld_write(
world_type=WarpWorldType.UNIQUE_WORLD,
destination='outpost'
)
)
player_protocol.client_protocol.transport.write(warp_packet)
self.protocol.send_chat_message(
'Warped ^yellow;{}^green; to the outpost.'.format(
player_string
)
)
else:
self.protocol.send_chat_message(
'No player by the name ^yellow;{}^green; found.'.format(
player_string
)
)
self.protocol.send_chat_message(self.warp.__doc__)
示例11: disconnect
def disconnect(self):
x = build_packet(
packets.Packets.CLIENT_DISCONNECT_REQUEST,
packets.client_disconnect_request().build(Container(data=0))
)
self.transport.write(x)
self.transport.abortConnection()
示例12: poi
def poi(self, name):
"""Moves you and your ship to a Planet of Interest (PoI). Syntax: /poi [name] *omit [name] for list of PoI's"""
name = " ".join(name).strip().strip("\t")
if len(name) == 0:
warps = []
for warp in self.planet_warps:
if warps != "":
warps.append(warp[1])
warpnames = "^green;, ^yellow;".join(warps)
self.protocol.send_chat_message("List of PoI's: ^yellow;" + warpnames)
return
on_ship = self.protocol.player.on_ship
if not on_ship:
self.protocol.send_chat_message("You need to be on a ship!")
return
for warp in self.planet_warps:
if warp[1] == name:
sector, x, y, z, planet, satellite = warp[0].split(":")
x, y, z, planet, satellite = map(int, (x, y, z, planet, satellite))
warp_packet = build_packet(
Packets.WARP_COMMAND,
warp_command_write(t="MOVE_SHIP", sector=sector, x=x, y=y, z=z, planet=planet, satellite=satellite),
)
self.protocol.client_protocol.transport.write(warp_packet)
# warp_packet = build_packet(Packets.WARP_COMMAND,
# warp_command_write(t="WARP_DOWN"))
# self.protocol.client_protocol.transport.write(warp_packet)
# self.protocol.send_chat_message("Beamed down to ^yellow;%s^green; and your ship will arrive soon." % name)
self.protocol.send_chat_message("Warp drive engaged! Warping to ^yellow;%s^green;." % name)
return
self.protocol.send_chat_message("There is no PoI with that name!")
示例13: poi
def poi(self, name):
"""Warps your ship to a Planet of Interest (PoI).\nSyntax: /poi [name] *omit name for a list of PoI's"""
name = " ".join(name).strip().strip("\t")
if len(name) == 0:
warps = []
for warp in self.pois:
if warps != "":
warps.append(warp[1])
warpnames = "^green;, ^yellow;".join(warps)
if warpnames == "": warpnames = "^gray;(none)^green;"
self.protocol.send_chat_message(self.poi.__doc__)
self.protocol.send_chat_message("List of PoI's: ^yellow;" + warpnames)
return
on_ship = self.protocol.player.on_ship
if not on_ship:
self.protocol.send_chat_message("You need to be on a ship!")
return
for warp in self.pois:
if warp[1] == name:
x, y, z, planet, satellite = warp[0].split(":")
x, y, z, planet, satellite = map(int, (x, y, z, planet, satellite))
warp_packet = build_packet(Packets.FLY_SHIP,
fly_ship_write(x=x,
y=y,
z=z,
planet=planet,
satellite=satellite))
self.protocol.client_protocol.transport.write(warp_packet)
self.protocol.send_chat_message("Warp drive engaged! Warping to ^yellow;%s^green;." % name)
return
self.protocol.send_chat_message("There is no PoI named ^yellow;%s^green;." % name)
示例14: send_chat_message
def send_chat_message(self, text, channel=0, world='', name=''):
"""
Convenience function to send chat messages to the client. Note that this
does *not* send messages to the server at large; broadcast should be
used for messages to all clients, or manually constructed chat messages
otherwise.
:param text: Message text, may contain multiple lines.
:param channel: The chat channel/context. 0 is global, 1 is planet.
:param world: World
:param name: The name to display before the message. Blank leaves no
brackets, otherwise it will be displayed as `<name>`.
:return: None
"""
logger.debug("Sent chat message with text: %s", text)
if '\n' in text:
lines = text.split('\n')
for line in lines:
self.send_chat_message(line)
return
chat_data = packets.chat_received().build(Container(chat_channel=channel,
world=world,
client_id=0,
name=name,
message=text))
chat_packet = build_packet(packets.Packets.CHAT_RECEIVED,
chat_data)
self.transport.write(chat_packet)
示例15: teleport_to_own_ship
def teleport_to_own_ship(self, data):
"""
Teleports a player to their own ship. If no source player is provided,
we assume you mean yourself.
Syntax: /teleport home [source player]
"""
usage = 'Syntax: /teleport home [source player]'
if not data:
source = self.protocol.player.name
else:
source, rest = extract_name(data)
if not self._validate_player(source):
self.protocol.send_chat_message(usage)
return
source = source.lower()
source_player = self.player_manager.get_logged_in_by_name(source)
if source_player is None:
self.logger.debug('Error: Player %s is not logged in.', source)
self.protocol.send_chat_message(
'Error: Player {} is not logged in.'.format(source)
)
return
source_protocol = self.factory.protocols[source_player.protocol]
teleport_packet = build_packet(
Packets.PLAYER_WARP, player_warp_toalias_write(alias=2)
)
source_protocol.client_protocol.transport.write(teleport_packet)