class PacketBulletNew(amp.Command): requiresAnswer = False arguments = [(b'id', amp.Integer()), (b'color_r', amp.Integer()), (b'color_g', amp.Integer()), (b'color_b', amp.Integer()), (b'position_x', amp.Float()), (b'position_y', amp.Float()), (b'velocity_x', amp.Float()), (b'velocity_y', amp.Float())] response = []
class FetchRequestLengthStats(amp.Command): "A command to request request length statistics from a running weasyl backend." arguments = [ ('percentiles', amp.ListOf(amp.Integer())), ('lengths', amp.ListOf(amp.Float())), ] response = [ ('lengths', amp.ListOf(amp.Float(), optional=True)), ('percentiles', amp.ListOf(amp.Float(), optional=True)), ]
class ClientPing(amp.Command): """Client originated ping message for gauging latency. Message attributes: clienttime - timestamp at client when ping generated. Response attributes: clienttime - timestamp at client when ping generated. servertime - timestamp at server when ping response generated. """ arguments = [('clienttime', amp.Float())] response = [('clienttime', amp.Float()), ('servertime', amp.Float())]
class ClientControlEvent(amp.Command): """Client user control event. Message attributes: timestamp - Timestamp of control event. thrust - Forward/reverse thrust force. ccwthrust - Counter-clockwise thrust impulse. shootv - Velocity of a fired bullet. shoote - Energy of a fired bullet. """ arguments = [('timestamp', amp.Float()), ('thrust', amp.Float()), ('ccwthrust', amp.Float()), ('shootv', amp.Float()), ('shoote', amp.Float())]
class ServerPrivateObjectStateEvent(amp.Command): """Server private object state event. Message attributes: objectid - Numeric ID of the object. wlevel - Weapon health level. flevel - Fuel health level. slevel - Shield health level. Response attributes: result - 1 for success. """ arguments = [('objectid', amp.Integer()), ('wlevel', amp.Float()), ('flevel', amp.Float()), ('slevel', amp.Float())] response = [('result', amp.Integer())]
def init_for_twisted_amp(commands): from twisted.protocols import amp type_map = { 'string': amp.String(), 'unicode': amp.String( ), # originally was amp.Unicode() - but I don't think Unicode is necessary for JSON strings 'boolean': amp.Boolean(), 'float': amp.Float(), 'integer': amp.Integer() } def convert_args(argdata): return [(x[0], type_map[x[1]]) for x in argdata] CMD = {} for name, data in commands.iteritems(): CMD[name] = type( name, (amp.Command, ), { 'commandName': name, 'arguments': convert_args(data['arguments']), 'response': convert_args(data['response']), 'errors': convert_args(data.get('errors', ())), 'requiresAnswer': data.get('requiresAnswer', True) }) return CMD
class ReSyncSession(amp.Command): arguments = [('sessId', amp.Integer()), ('ip', amp.String()), ('hostname', amp.String()), ('delim', amp.String()), ('playerId', amp.Integer()), ('time_connected', amp.Integer()), ('last_activity', amp.Float()), ('mxp', amp.Boolean())] response = [] errors = {Exception: 'EXCEPTION'}
class FetchRequestStats(amp.Command): "A command to request request statistics from a running weasyl backend." arguments = [] response = [ ('requestCount', amp.Integer()), ('errorPercentage', amp.Float()), ('mostActiveClients', amp.Integer()), ]
class PacketShipUpdate(amp.Command): requiresAnswer = False arguments = [(b'id', amp.Integer()), (b'position_x', amp.Float()), (b'position_y', amp.Float()), (b'velocity_x', amp.Float()), (b'velocity_y', amp.Float()), (b'rotation', amp.Float()), (b'angvelocity', amp.Float()), (b'health', amp.Float())] response = []
class Count(amp.Command): arguments = [('n', amp.Integer())] response = [('oki', amp.Integer()), ('oks', amp.String()), ('oku', amp.Unicode()), ('okb', amp.Boolean()), ('okf', amp.Float()), ('okd', amp.Decimal()), ('okt', amp.DateTime()), ('okl1', amp.ListOf(amp.Integer())), ('okl2', amp.ListOf(amp.ListOf(amp.String()))), ('okla', amp.AmpList([('a', amp.Integer()), ('b', amp.Unicode())]))]
class FetchRequestBreakdownStats(amp.Command): "A command to request request breakdown statistics from a running weasyl backend." arguments = [ ('percentiles', amp.ListOf(amp.Integer())), ] response = [ ('averageTimeQueued', amp.Float(optional=True)), ('averageTimeInSQL', amp.Float(optional=True)), ('averageTimeInMemcached', amp.Float(optional=True)), ('averageTimeInPython', amp.Float(optional=True)), ('totalTimeQueued', amp.Float(optional=True)), ('totalTimeInSQL', amp.Float(optional=True)), ('totalTimeInMemcached', amp.Float(optional=True)), ('totalTimeInPython', amp.Float(optional=True)), ('queries', amp.ListOf(amp.Float(), optional=True)), ]
class ServerObjectDropEvent(amp.Command): """Server object drop event. An object has died/exploded/quit, etc. Message attributes: objectid - Numeric ID of the object. eventtime - Timestamp of drop. Response attributes: result - 1 for success. """ arguments = [('objectid', amp.Integer()), ('eventtime', amp.Float())] response = [('result', amp.Integer())]
class ServerPlayerStatsEvent(amp.Command): """Server player stats event. Message attributes: playername - Name of player - empty string when done. playtime - Cumulative seconds of play time. killcount - Total number of kills since connected. killedcount - Total number of deaths since connected. Response attributes: result - 1 for success. """ arguments = [('playername', amp.String()), ('playtime', amp.Float()), ('killcount', amp.Integer()), ('killedcount', amp.Integer())] response = [('result', amp.Integer())]
class PacketShip(amp.Command): requiresAnswer = False arguments = [(b'id', amp.Integer()), (b'color_r', amp.Integer()), (b'color_g', amp.Integer()), (b'color_b', amp.Integer()), (b'position_x', amp.Float()), (b'position_y', amp.Float()), (b'velocity_x', amp.Float()), (b'velocity_y', amp.Float()), (b'rotation', amp.Float()), (b'angvelocity', amp.Float()), (b'isme', amp.Boolean())] response = []
class ClientJoinRequest(amp.Command): """Client join/respawn request. Message attributes: shipname - User/player name. radius - Radius of the ship in pixels. wmax - Weapon relative maximum level (0-100). fmax - Fuel relative maximum level (0-100). smax - Shield relative maximum level (0-100). image - Bitmap of the ship icon (pygame format). imagex - Width of image. imagey - Height of image. thrustimg - Bitmap of the ship thrusting image. bulletimg - Bitmap of the ship's bullet image. """ arguments = [('shipname', amp.String()), ('radius', amp.Integer()), ('wmax', amp.Integer()), ('fmax', amp.Integer()), ('smax', amp.Integer()), ('image', amp.String()), ('imagex', amp.Integer()), ('imagey', amp.Integer()), ('thrustimg', amp.String()), ('bulletimg', amp.String())] response = [('shipid', amp.Integer()), ('time', amp.Float()), ('gamewidth', amp.Integer()), ('gameheight', amp.Integer())]
class ServerObjectStateEvent(amp.Command): """Server object state change event. Message attributes: objectid - Numeric ID of object. objecttype - Text representation of object type. objectname - Name of object. eventtime - Timestamp of object event. x - X coordinate of object position. y - Y coordinate of object position. vx - X component of object velocity. vy - Y component of object velocity. a - Axial acceleration of object. r - Rotational position of object in radians (0 points up). rr - Rotational rate of object in radians/second. Response attributes: result - 1 for success. """ arguments = [('objectid', amp.Integer()), ('objecttype', amp.String()), ('objectname', amp.String()), ('eventtime', amp.Float()), ('x', amp.Float()), ('y', amp.Float()), ('vx', amp.Float()), ('vy', amp.Float()), ('a', amp.Float()), ('r', amp.Float()), ('rr', amp.Float())] response = [('result', amp.Integer())]
class SyncWorld(amp.Command): requiresResponse = True arguments = [] response = [("time", amp.Float()), ("objects", WorldObjects())]
class IndoorPiA(amp.Command): arguments = [('TA', amp.Float()), ('PA', amp.Float()), ('HA', amp.Float())] response = [('cksu', amp.Float())]
class UpdateUserPosition(amp.Command): arguments = [(b'user', amp.Unicode()), (b'x', amp.Float()), (b'y', amp.Float())] response = [(b'result', amp.Boolean())]
""" Encodes simple Python data structures into their AMP wire formats. """ from twisted.protocols import amp def toBoxKwargs(inputKwargs): """ Encodes kwargs for an AMP remote call as box arguments, assuming the kwargs are all of the correct type. """ boxKwargs = {} for key, value in inputKwargs.iteritems(): boxKwargs[key] = _ampEncoders[value.__class__](value) return boxKwargs _ampEncoders = { int: amp.Integer().toString, float: amp.Float().toString, unicode: amp.Unicode().toString, list: lambda l: amp.ListOf(_ampEncoders[l[0].__class__].im_self).toString(l) }
class SetUptime(amp.Command): arguments = [ ('start_time', amp.Float()), ] response = [] errors = {Exception: 'EXCEPTION'}
class SetExclaim(amp.Command): arguments = [(b'value', amp.Float())] response = []
class Divide(amp.Command): arguments = [('numerator', amp.Integer()), ('denominator', amp.Integer())] response = [('result', amp.Float())] errors = {ZeroDivisionError: 'ZERO_DIVISION'}
class SetCapitalize(amp.Command): arguments = [(b'value', amp.Float())] response = []
def test_float(self): self._test_encode([(1.5, amp.Float())])
class PacketBulletUpdate(amp.Command): requiresAnswer = False arguments = [(b'id', amp.Integer()), (b'position_x', amp.Float()), (b'position_y', amp.Float()), (b'velocity_x', amp.Float()), (b'velocity_y', amp.Float()), (b'active', amp.Boolean())] response = []
class PacketPlanet(amp.Command): requiresAnswer = False arguments = [(b'id', amp.Integer()), (b'radius', amp.Integer()), (b'position_x', amp.Float()), (b'position_y', amp.Float()), (b'mass', amp.Float()), (b'image', amp.Unicode())] response = []
class Divide(amp.Command): arguments = [(b"numerator", amp.Integer()), (b"denominator", amp.Integer())] response = [(b"result", amp.Float())] errors = {ZeroDivisionError: b"ZERO_DIVISION"}
class Handshake(amp.Command): arguments = [('NodeId', amp.Unicode()), ('ListeningPort', amp.Integer()), ('ProtocolVersion', amp.Float())] response = [('NodeId', amp.Unicode()), ('ListeningPort', amp.Integer()), ('ProtocolVersion', amp.Float())]