Exemplo n.º 1
0
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 = []
Exemplo n.º 2
0
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)),
    ]
Exemplo n.º 3
0
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())]
Exemplo n.º 4
0
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())]
Exemplo n.º 5
0
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())]
Exemplo n.º 6
0
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
Exemplo n.º 7
0
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'}
Exemplo n.º 8
0
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()),
    ]
Exemplo n.º 9
0
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 = []
Exemplo n.º 10
0
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())]))]
Exemplo n.º 11
0
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)),
    ]
Exemplo n.º 12
0
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())]
Exemplo n.º 13
0
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())]
Exemplo n.º 14
0
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 = []
Exemplo n.º 15
0
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())]
Exemplo n.º 16
0
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())]
Exemplo n.º 17
0
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())]
Exemplo n.º 19
0
class UpdateUserPosition(amp.Command):
    arguments = [(b'user', amp.Unicode()), (b'x', amp.Float()),
                 (b'y', amp.Float())]
    response = [(b'result', amp.Boolean())]
Exemplo n.º 20
0
"""
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)
}
Exemplo n.º 21
0
class SetUptime(amp.Command):
    arguments = [
        ('start_time', amp.Float()),
    ]
    response = []
    errors = {Exception: 'EXCEPTION'}
Exemplo n.º 22
0
class SetExclaim(amp.Command):
    arguments = [(b'value', amp.Float())]
    response = []
Exemplo n.º 23
0
class Divide(amp.Command):
    arguments = [('numerator', amp.Integer()), ('denominator', amp.Integer())]
    response = [('result', amp.Float())]
    errors = {ZeroDivisionError: 'ZERO_DIVISION'}
Exemplo n.º 24
0
class SetCapitalize(amp.Command):
    arguments = [(b'value', amp.Float())]
    response = []
Exemplo n.º 25
0
 def test_float(self):
     self._test_encode([(1.5, amp.Float())])
Exemplo n.º 26
0
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 = []
Exemplo n.º 27
0
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 = []
Exemplo n.º 28
0
class Divide(amp.Command):
    arguments = [(b"numerator", amp.Integer()),
                 (b"denominator", amp.Integer())]
    response = [(b"result", amp.Float())]
    errors = {ZeroDivisionError: b"ZERO_DIVISION"}
Exemplo n.º 29
0
class Handshake(amp.Command):
    arguments = [('NodeId', amp.Unicode()), ('ListeningPort', amp.Integer()), ('ProtocolVersion', amp.Float())]
    response = [('NodeId', amp.Unicode()), ('ListeningPort', amp.Integer()), ('ProtocolVersion', amp.Float())]