smserver.smutils package

Submodules

smserver.smutils.smattack module

Import the list of available attacks in stepmania

class smserver.smutils.smattack.SMAttack

Bases: enum.Enum

Represent all the attacks available

smserver.smutils.smconn module

class smserver.smutils.smconn.SMThread(server, ip, port)

Bases: threading.Thread

logger = <logging.Logger object>
run()
stop()
class smserver.smutils.smconn.StepmaniaConn(serv, ip, port)

Bases: object

ALLOWED_PACKET = []
ENCODING = 'binary'
close()
logger = <logging.Logger object>
received_data()
run()
send(packet)

smserver.smutils.smpacket module

The `SMpacket module

Provide easy utilisation of the stepmania protocol.

Example:
>>> from smserver.smutils.smpacket import *
>>> # Create a new packet instance
>>> packet = SMPacket.new(SMServerCommand.NSCCM, message="test")
>>> print(packet)
<SMPacketServerNSCCM message="test">
>>> # Binary encode your packet
>>> packet.binary
b'\x00\x00\x00\x06\x87test\x00'
>>> # Decode binary data
>>> packet2 = SMPacket.from_("binary", packet.binary)
>>> print(packet2)
<SMPacketServerNSCCM message="test">
>>> packet = SMPacket.new(SMServerCommand.NSCPing)
>>> # JSON encode your packet
>>> packet.json
'{"_command": 128}'
>>> # Decode JSON data
>>> packet2 = SMPacket.from_("json", packet.json)
>>> print(packet2)
<SMPacketServerNSCPing >
class smserver.smutils.smpacket.ParentCommand

Bases: enum.Enum

classmethod get(value, default=None)
class smserver.smutils.smpacket.SMClientCommand

Bases: smserver.smutils.smpacket.SMCommand

List of client commands available

class smserver.smutils.smpacket.SMCommand

Bases: smserver.smutils.smpacket.ParentCommand

class smserver.smutils.smpacket.SMOClientCommand

Bases: smserver.smutils.smpacket.SMOCommand

List of SMO Client commands available

class smserver.smutils.smpacket.SMOCommand

Bases: smserver.smutils.smpacket.ParentCommand

class smserver.smutils.smpacket.SMOPacketClient(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

class smserver.smutils.smpacket.SMOPacketClientCreateRoom(**kwargs)

Bases: smserver.smutils.smpacket.SMOPacketClient

command = <SMOClientCommand.CREATEROOM: 2>
class smserver.smutils.smpacket.SMOPacketClientEnterRoom(**kwargs)

Bases: smserver.smutils.smpacket.SMOPacketClient

command = <SMOClientCommand.ENTERROOM: 1>
class smserver.smutils.smpacket.SMOPacketClientLogin(**kwargs)

Bases: smserver.smutils.smpacket.SMOPacketClient

command = <SMOClientCommand.LOGIN: 0>
class smserver.smutils.smpacket.SMOPacketClientRoomInfo(**kwargs)

Bases: smserver.smutils.smpacket.SMOPacketClient

command = <SMOClientCommand.ROOMINFO: 3>
class smserver.smutils.smpacket.SMOPacketServer(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

class smserver.smutils.smpacket.SMOPacketServerGeneralInfo(**kwargs)

Bases: smserver.smutils.smpacket.SMOPacketServer

command = <SMOServerCommand.GENERALINFO: 2>
class smserver.smutils.smpacket.SMOPacketServerLogin(**kwargs)

Bases: smserver.smutils.smpacket.SMOPacketServer

command = <SMOServerCommand.LOGIN: 0>
class smserver.smutils.smpacket.SMOPacketServerRoomInfo(**kwargs)

Bases: smserver.smutils.smpacket.SMOPacketServer

command = <SMOServerCommand.ROOMINFO: 3>
class smserver.smutils.smpacket.SMOPacketServerRoomUpdate(**kwargs)

Bases: smserver.smutils.smpacket.SMOPacketServer

command = <SMOServerCommand.ROOMUPDATE: 1>
class smserver.smutils.smpacket.SMOServerCommand

Bases: smserver.smutils.smpacket.SMOCommand

List of SMO Server commands available

class smserver.smutils.smpacket.SMPacket(**kwargs)

Bases: object

Main class for declare/parse packet

binary

Return the full binary encoded packet (size + command + payload)

Example:
>>> from smserver.smutils.smpacket import *
>>> packet = SMPacket.new(SMServerCommand.NSCCM, message="msg")
>>> print(packet.binary)
b'\x00\x00\x00\x05\x87msg\x00'
binarycommand

Return the command in a binary string

Example:
>>> from smserver.smutils.smpacket import *
>>> packet = SMPacket.new(SMServerCommand.NSCCM, message="msg")
>>> print(packet.binarycommand)
b'\x87'
binarysize

Return the size of the packet in a 4 bytes string.

Example:
>>> from smserver.smutils.smpacket import *
>>> packet = SMPacket.new(SMServerCommand.NSCCM, message="msg")
>>> print(packet.binarysize)
b'\x00\x00\x00\x05'
command = None
data

Return the command + payload in a binary string

Example:
>>> from smserver.smutils.smpacket import *
>>> packet = SMPacket.new(SMServerCommand.NSCCM, message="msg")
>>> print(packet.data)
b'\x87msg\x00'
classmethod decode(payload, payload_option)
classmethod decode_json(payload, payload_option)
classmethod encode(values, payload_option)
classmethod from_(encoding, data)

Decode the packet from the specified format (json or binary)

classmethod from_json(payload)

Decode a JSON encoded packet

Example:
>>> from smserver.smutils.smpacket import *
>>> json_data = '{"message": "msg"}'
>>> print(SMPacketServerNSCCM.from_json(json_data))
<SMPacketServerNSCCM message="msg">
classmethod from_payload(payload)

Decode the given binary payload

Example:
>>> from smserver.smutils.smpacket import *
>>> payload_data = b'msg\x00'
>>> print(SMPacketServerNSCCM.from_payload(payload_data))
<SMPacketServerNSCCM message="msg">
get(value, default=None)
classmethod get_class(command)

Get the class which avec the corresponding command

Example:
>>> from smserver.smutils.smpacket import *
>>> print(SMPacket.get_class(SMServerCommand.NSCCM))
<class 'smserver.smutils.smpacket.SMPacketServerNSCCM'>
json

Return the JSON encoded packet

Example:
>>> from smserver.smutils.smpacket import *
>>> packet = SMPacket.new(SMServerCommand.NSCPing)
>>> print(packet.json)
{"_command": 128}
classmethod new(command, **kwargs)

Return an instance with the corresponding command.

If no command is found, return None

Example:
>>> from smserver.smutils.smpacket import *
>>> print(SMPacket.new(SMServerCommand.NSCCM, message="msg"))
<SMPacketServerNSCCM message="msg">
classmethod parse_binary(binary)
classmethod parse_data(data)
classmethod parse_json(data)
payload

Return the paylaod encoded in binary

Example:
>>> from smserver.smutils.smpacket import *
>>> packet = SMPacket.new(SMServerCommand.NSCCM, message="msg")
>>> print(packet.payload)
b'msg\x00'
to_(encoding)

Encode the packet to the specified format (json or binary)

class smserver.smutils.smpacket.SMPacketClientNSCAttack(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Client command 014 (reserved)

command = <SMClientCommand.NSCAttack: 14>
class smserver.smutils.smpacket.SMPacketClientNSCCM(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Client command 007 (Chat Message)

The user typed a message for general chat.

Parameters:message (str) – The message sent by the client.
Example:
>>> from smserver.smutils import smpacket
>>> packet = smpacket.SMPacketClientNSCCM(message="Client message")
>>> print(packet.binary)
b'\x00\x00\x00\x10\x07Client message\x00'
command = <SMClientCommand.NSCCM: 7>
class smserver.smutils.smpacket.SMPacketClientNSCCUUL(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Client command 009 (reserved)

command = <SMClientCommand.NSCCUUL: 9>
class smserver.smutils.smpacket.SMPacketClientNSCFormatted(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Client command 013 (reserved)

command = <SMClientCommand.NSCFormatted: 13>
class smserver.smutils.smpacket.SMPacketClientNSCGON(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Client command 004 (Game Over Notice)

This command is sent when end of game is encounter.

Example:
>>> from smserver.smutils import smpacket
>>> packet = smpacket.SMPacketClientNSCGON()
>>> print(packet.binary)
b'\x00\x00\x00\x01\x04'
command = <SMClientCommand.NSCGON: 4>
class smserver.smutils.smpacket.SMPacketClientNSCGSR(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Client command 003 (Game Start Request)

This command is called once after most loading is done, and again immediately before the sound starts.

The server has to respond with a SMPacketServerNSCGSR, if not the client will freeze.

Parameters:
  • first_player_feet (int) – Primary player feet (0 for no player)
  • second_player_feet (int) – Secondary player feet (0 for no player)
  • first_player_difficulty (int) – Primary player difficulty (0=Beginner, 1=easy, etc.)
  • second_player_difficulty (int) – Secondary player difficulty (0=Beginner, 1=easy, etc.)
  • start_position (int) – (0 is pre-sync, 1 is for sync)
  • reserved (int) – ignored
  • song_title (str) – Title of the song to play
  • song_subtitle (str) – Subtitle of the song to play
  • song_artist (str) – Artist of the song to play
  • course_title (str) – Course Title
  • song_options (str) – Song option in string format
  • first_player_options (str) – Primary player’s option
  • second_player_options (str) – Secondary player’s option
command = <SMClientCommand.NSCGSR: 3>
class smserver.smutils.smpacket.SMPacketClientNSCGSU(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Client command 005 (Game Status update)

Update game info for each step in the game

Parameters:
  • player_id (int) – player # (0 or 1)
  • step_id (int) – (1: hitMine, 2: AvoidMine, ...)
  • grade (int) – Projected Grade (0: AAAA, 1: AAA, ...)
  • reserved (int) – ignored
  • score (int) – Actual score
  • combo (int) – Actual combo
  • health (int) – Actual health
  • offset (int) – Offset from the note (32767=miss)
command = <SMClientCommand.NSCGSU: 5>
class smserver.smutils.smpacket.SMPacketClientNSCHello(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Client command 002. (Hello)

This is the first packet from a client to server.

Parameters:
  • version (int) – Client protocol version
  • name (str) – Name of the stepmania build
Example:
>>> from smserver.smutils import smpacket
>>> packet = smpacket.SMPacketClientNSCHello(
...     name="stepmania",
...     version=128
... )
>>> print(packet.binary)
b'\x00\x00\x00\x0c\x02\x80stepmania\x00'
command = <SMClientCommand.NSCHello: 2>
class smserver.smutils.smpacket.SMPacketClientNSCPing(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Client command 000. (Ping)

This command will cause server to respond with a PingR Command

Example:
>>> from smserver.smutils import smpacket
>>> packet = smpacket.SMPacketClientNSCPing()
>>> print(packet.binary)
b'\x00\x00\x00\x01\x00'
command = <SMClientCommand.NSCPing: 0>
class smserver.smutils.smpacket.SMPacketClientNSCPingR(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Client command 001. (Ping response)

This command is used to respond to Ping Command.

Example:
>>> from smserver.smutils import smpacket
>>> packet = smpacket.SMPacketClientNSCPingR()
>>> print(packet.binary)
b'\x00\x00\x00\x01\x01'
command = <SMClientCommand.NSCPingR: 1>
class smserver.smutils.smpacket.SMPacketClientNSCRSG(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Client command 008 (Request Start Game)

Request Start Game and Tell server existance/non existance of song: The user selected a song on a Net-enabled selection

Parameters:
  • usage (int) – Usage for this message
  • song_title (str) – Song title
  • song_subtitle (str) – Song artist
  • song_artist (str) – Song subtitle
Example:
>>> # Client select the song ('Title', by 'Artist').
>>> from smserver.smutils import smpacket
>>> packet = smpacket.SMPacketClientNSCRSG(
...     usage=2,
...     song_title="Title",
...     song_artist="Artist",
... )
>>> print(packet.binary)
b'\x00\x00\x00\x10\x08\x02Title\x00Artist\x00\x00'
command = <SMClientCommand.NSCRSG: 8>
class smserver.smutils.smpacket.SMPacketClientNSCSU(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Client command 006 (Style Update)

This is sent when a profile is choosed. It also indicates the number of players in the local client. (1 or 2)

Parameters:
  • nb_players (int) – Number of players in the client (1 or 2)
  • player_id (int) – Player ID (0 or 1)
  • player_name (str) – Player name
Example:
>>> from smserver.smutils import smpacket
>>> packet = smpacket.SMPacketClientNSCSU(
...     nb_players=2,
...     player_id=0,
...     player_name="profile1",
... )
>>> print(packet.binary)
b'\x00\x00\x00\x0c\x06\x02\x00profile1\x00'
command = <SMClientCommand.NSCSU: 6>
class smserver.smutils.smpacket.SMPacketClientNSCUOpts(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Client command 011 (User options)

User has changed player’s options

Parameters:
  • player_0 (str) – Player 0 options
  • player_1 (str) – Player 1 options
command = <SMClientCommand.NSCUOpts: 11>
class smserver.smutils.smpacket.SMPacketClientNSSCSMS(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Client command 010 (User status)

Indicate where the user is

Parameters:action (int) – Int enum indicating where the user is

Action available:

  • 0: exited ScreenNetSelectMusic
  • 1: entered ScreenNetSelectMusic
  • 2: Not Sent
  • 3: entered options screen
  • 4: exited the evaluation screen
  • 5: entered evaluation screen
  • 6: exited ScreenNetRoom
  • 7: entered ScreenNetRoom
Example:
>>> from smserver.smutils import smpacket
>>> # Client enter in room selection
>>> packet = smpacket.SMPacketClientNSSCSMS(
...     action=7,
... )
>>> print(packet.binary)
b'\x00\x00\x00\x02\n\x07'
command = <SMClientCommand.NSSCSMS: 10>
class smserver.smutils.smpacket.SMPacketClientNSSMONL(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Client command 012 (SMOnline Packet)

The SMLan packet 12 is a wrapper for the SMOnline packet.

Parameters:packet (SMOPacketClient) – The SMOPacket to include
command = <SMClientCommand.NSSMONL: 12>
class smserver.smutils.smpacket.SMPacketClientXMLPacket(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Client command 15 (XMLPacket)

This packet contains data in XML format.

Parameters:xml (str) – XML string
command = <SMClientCommand.XMLPacket: 15>
class smserver.smutils.smpacket.SMPacketServerNSCAttack(player=0, time=1000, attack=None)

Bases: smserver.smutils.smpacket.SMPacket

Server command 142 (Attack Client)

Parameters:
  • player (int) – Player number (0 or 1)
  • time (int) – Duration of the attack (in ms)
  • attack (str or smserver.smutils.smattack.SMAttack) – Text describing modifiers

List of attack available are in smattack module.

Example:
>>> from smserver.smutils import smpacket, smattack
>>> packet = smpacket.SMPacketServerNSCAttack(
...     player=0, # Send the attack to the player 0
...     time=1000, # The attack will last 1 second
...     attack='drunk', #Send a drunk attack
... )
>>> print(packet.binary)
b'\x00\x00\x00\x0c\x8e\x00\x00\x00\x03\xe8drunk\x00'
>>> packet = smpacket.SMPacketServerNSCAttack(
...     player=0,
...     time=1000,
...     attack=smattack.SMAttack.Drunk, # Use an Enum value
... )
>>> print(packet.binary)
b'\x00\x00\x00\x0c\x8e\x00\x00\x00\x03\xe8drunk\x00'
command = <SMServerCommand.NSCAttack: 142>
class smserver.smutils.smpacket.SMPacketServerNSCCM(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Server command 135 (Chat Message)

Add a chat message to the chat window on some StepMania screens.

Parameters:message (str) – The message to add
Example:
>>> from smserver.smutils import smpacket
>>> packet = smpacket.SMPacketServerNSCSU(message="Client message")
>>> print(packet.binary)
b'\x00\x00\x00\x10\x86Client message\x00'
command = <SMServerCommand.NSCCM: 135>
class smserver.smutils.smpacket.SMPacketServerNSCCUUL(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Server command 137 (Update user list)

This sends all the users currently connected

Parameters:
  • max_players (int) – NB max of players (max 255)
  • nb_players (int) – NB of player’s in this packet
  • players (list) – List containing status and name for each user
command = <SMServerCommand.NSCCUUL: 137>
class smserver.smutils.smpacket.SMPacketServerNSCFormatted(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Server command 141 (Formatted information packet)

Send formatted information regarding the server back to the player.

Parameters:
  • server_name (str) – Server name
  • server_port (int) – Port the server is listening on
  • nb_players (int) – Number of players connected
command = <SMServerCommand.NSCFormatted: 141>
class smserver.smutils.smpacket.SMPacketServerNSCGON(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Server command 132 (Game over stats)

This packet is send in response to the game over packet. It contains information regarding how well each player did.

Parameters:
  • nb_players (int) – NB of players stats in this packet (size of the next list)
  • ids (list) – Player’s ID (calculate from the SMPacketServerNSCUUL)
  • score (list) – Player’s score
  • grade (list) – Player’s grade
  • difficulty (list) – Player’s difficulty
  • flawless (list) – NB of flawless note
  • perfect (list) – NB of perfect note
  • great (list) – NB of great note
  • good (list) – NB of good note
  • bad (list) – NB of bad note
  • miss (list) – NB of miss note
  • held (list) – NB of held note
  • max_combo (list) – Player’s max combo
  • options (list) – Player’s options
command = <SMServerCommand.NSCGON: 132>
class smserver.smutils.smpacket.SMPacketServerNSCGSR(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Server command 131 (Allow Start)

This will cause the client to start the game

Example:
>>> from smserver.smutils import smpacket
>>> packet = smpacket.SMPacketServerNSCGSR()
>>> print(packet.binary)
b'\x00\x00\x00\x01\x83'
command = <SMServerCommand.NSCGSR: 131>
class smserver.smutils.smpacket.SMPacketServerNSCGSU(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Server command 133 (Scoreboard update)

This will update the client’s scoreboard.

Parameters:
  • section (int) – Which section to update (0: names, 1:combos, 2: grades)
  • nb_players (int) – Nb of plyaers in this packet
  • options (list) – Int list contining names, combos or grades
Example:
>>> from smserver.smutils import smpacket
>>> packet = smpacket.SMPacketServerNSCGSU(
...     section=1, # Update the actual combo
...     nb_players=2, # 2 users in this packet
...     options=[12, 5] # List containing the combos
... )
>>> print(packet.binary)
b'\x00\x00\x00\x07\x85\x01\x02\x00\x0c\x00\x05'
command = <SMServerCommand.NSCGSU: 133>
class smserver.smutils.smpacket.SMPacketServerNSCHello(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Server command 130 (Hello)

This command introduces the server. (In response of Client Hello command)

Parameters:
  • version (str) – The server protocol version (always 128)
  • name (str) – Name of the server
  • key (int) – Random key, used for hash password
Example:
>>> from smserver.smutils import smpacket
>>> packet = smpacket.SMPacketServerNSCHello(
...     version=128,
...     name="MyServer",
...     key=999999999
... )
>>> print(packet.binary)
b'\x00\x00\x00\x0f\x82\x80MyServer\x00;\x9a\xc9\xff'
command = <SMServerCommand.NSCHello: 130>
class smserver.smutils.smpacket.SMPacketServerNSCPing(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Server command 128 (Ping)

This command will cause client to respond with a PingR command

Example:
>>> from smserver.smutils import smpacket
>>> packet = smpacket.SMPacketServerNSCPing()
>>> print(packet.binary)
b'\x00\x00\x00\x01\x80'
command = <SMServerCommand.NSCPing: 128>
class smserver.smutils.smpacket.SMPacketServerNSCPingR(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Server command 129 (PingR)

This command is used to respond to a Ping command.

Example:
>>> from smserver.smutils import smpacket
>>> packet = smpacket.SMPacketServerNSCPingR()
>>> print(packet.binary)
b'\x00\x00\x00\x01\x81'
command = <SMServerCommand.NSCPingR: 129>
class smserver.smutils.smpacket.SMPacketServerNSCRSG(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Server command 136 (Request Start Game)

Tell client to start song/ask if client has song

Parameters:
  • usage (int) – Usage of this message
  • song_title (str) – Song title
  • song_artist (str) – Song artist
  • song_subtitle (str) – Song subtitle

Usage available:

  • 0: See if client has song
  • 1: See if client has song, if so, scroll to song
  • 2: See if client has song, if so, scroll to song, and play that song
  • 3: Blindly start song
Example:
>>> from smserver.smutils import smpacket
>>> packet = smpacket.SMPacketServerNSCRSG(
...     usage=0, # Check song presence
...     song_title="title",
...     song_artist="artist",
...     song_subtitle="subtitle",
... )
>>> print(packet.binary)
b'\x00\x00\x00\x18\x88\x00title\x00artist\x00subtitle\x00'
command = <SMServerCommand.NSCRSG: 136>
class smserver.smutils.smpacket.SMPacketServerNSCSU(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Server command 134 (System Message)

Send a system message to user

Parameters:message (str) – The message to send
Example:
>>> from smserver.smutils import smpacket
>>> packet = smpacket.SMPacketServerNSCSU(message="System message")
>>> print(packet.binary)
b'\x00\x00\x00\x10\x86System message\x00'
command = <SMServerCommand.NSCSU: 134>
class smserver.smutils.smpacket.SMPacketServerNSCUOpts(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Server command 139 (reserved)

command = <SMServerCommand.NSCUOpts: 139>
class smserver.smutils.smpacket.SMPacketServerNSSCSMS(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Server command 138

Force change to Networking select music screen.

Parameters:
  • gametype (str) – Set specified gametype
  • style (str) – Set specified style
command = <SMServerCommand.NSSCSMS: 138>
class smserver.smutils.smpacket.SMPacketServerNSSMONL(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Server command 140 (SMOnline Packet)

The SMLan packet 140 is a wrapper for the SMOnline packet.

Parameters:packet (SMOPacketServer) – The SMOPacket to include
command = <SMServerCommand.NSSMONL: 140>
class smserver.smutils.smpacket.SMPacketServerXMLPacket(**kwargs)

Bases: smserver.smutils.smpacket.SMPacket

Server command 143 (XMLPacket)

This packet contains data in XML format.

Parameters:xml (str) – XML string
command = <SMServerCommand.XMLPacket: 143>
class smserver.smutils.smpacket.SMPayloadType

Bases: enum.Enum

List of the available type

class smserver.smutils.smpacket.SMPayloadTypeAbstract

Bases: object

Parent class for declaring new type of data.

DEFAULT = None
static decode(payload, opt=None)

Define here how the data is dedoced.

Take the payload and option and return the data and remaining payload

static encode(data, opt=None)

Define here how the data is encoded.

Take the data and option and return the encoded data

class smserver.smutils.smpacket.SMPayloadTypeINT

Bases: smserver.smutils.smpacket.SMPayloadTypeAbstract

INT data encode in x bytes.

DEFAULT = 0
static decode(payload, size=1)

Decode binary string into integer

Example:
>>> SMPayloadTypeINT.decode(b"remaining_payload", size=1)
(b'remaining_payload', 1)
>>> # Return None if size exceed
>>> SMPayloadTypeINT.decode(b"", size=50)
(b'\x01', None)
static encode(data, size=1)

Encode integer into binary string

Example:
>>> SMPayloadTypeINT.encode(2, size=2)
b'\x00\x02'
>>> SMPayloadTypeINT.encode(123456789, size=4)
b'\x07[\xcd\x15'
>>> # Return the max is size exceed
>>> SMPayloadTypeINT.encode(5165165, size=2)
b'\xff\xff'
class smserver.smutils.smpacket.SMPayloadTypeINTLIST

Bases: smserver.smutils.smpacket.SMPayloadTypeAbstract

List of integer

DEFAULT = []
static decode(payload, opt=None)

Decode binary string into int list

Parameters:
  • data – the string to decode
  • opt – the encoding option: (integer size, size of the array)
Example:
>>> SMPayloadTypeINTLIST.decode(b"", opt=(1, 2))
(b'', [2, 5])
>>> SMPayloadTypeINTLIST.decode(b"remaining_payload", opt=(2, 1))
(b'remaining_payload', [517])
>>> # Return none if size exceed
>>> SMPayloadTypeINTLIST.decode(b'', opt=(1, 5))
(b'\x01', None)
static encode(data, opt=None)

Encode integer list into binary string.

Parameters:
  • data – the list to encode
  • opt – the encoding option: (integer size, size of the array)
Example:
>>> SMPayloadTypeINTLIST.encode([2, 5], opt=(1, 2))
b'\x02\x05'
>>> SMPayloadTypeINTLIST.encode([1], opt=(1, 2)) # zero padding
b'\x01\x00'
>>> # Size exceed
>>> SMPayloadTypeINTLIST.encode([65000, 123456789], opt=(2, 2))
b'\xfd\xe8\xff\xff'
class smserver.smutils.smpacket.SMPayloadTypeLIST

Bases: smserver.smutils.smpacket.SMPayloadTypeAbstract

Generic type for declaring list of other type

DEFAULT = []
static decode(payload, opt=None)
static encode(data, opt=None)
class smserver.smutils.smpacket.SMPayloadTypeMAP

Bases: smserver.smutils.smpacket.SMPayloadTypeAbstract

Generic type for declaring encoding which depends on precedent values.

DEFAULT = {}
static decode(payload, opt=None)
static encode(data, opt=None)
class smserver.smutils.smpacket.SMPayloadTypeNT

Bases: smserver.smutils.smpacket.SMPayloadTypeAbstract

Null terminated string.

DEFAULT = ''
static decode(payload, opt=None)

Decode null terminated string into unicode string

Parameters:
  • data – the null terminated string
  • opt – Do nothing
Example:
>>> SMPayloadTypeNT.decode(b"nt_string\x00remaining_string...")
(b'remaining_string...', 'nt_string')
static encode(data, opt=None)

Encode unicode string into null terminated string.

Parameters:
  • data – the string to encode
  • opt – Do nothing
Example:
>>> SMPayloadTypeNT.encode("unicode_string")
b'unicode_string\x00'
class smserver.smutils.smpacket.SMPayloadTypeNTLIST

Bases: smserver.smutils.smpacket.SMPayloadTypeAbstract

List of null terminated string

DEFAULT = []
static decode(payload, size=None)

Decode byte strings into list of unicode string

Parameters:
  • data – List of unicode string
  • size – size of the list
Example:
>>> SMPayloadTypeNTLIST.decode(b"string1\x00string2\x00remaining\x00_string...", 2)
(b'remaining\x00_string...', ['string1', 'string2'])
>>> SMPayloadTypeNTLIST.decode(b"string1\x00string2\x00remaining_string...") # guess size
(b'remaining_string...', ['string1', 'string2'])
>>> SMPayloadTypeNTLIST.decode(b"string1\x00remaining_string...", 3)
(b'remaining_string...', ['string1', '', ''])
static encode(data, size=None)

Encode list of unicode string into null terminated strings.

Parameters:
  • data – the list to encode
  • size – Size of the list
Example:
>>> SMPayloadTypeNTLIST.encode(["string1", "string2"], 2)
b'string1\x00string2\x00'
>>> # zero padding
>>> SMPayloadTypeNTLIST.encode(["string1", "string2"], 5)
b'string1\x00string2\x00\x00\x00\x00'
>>> # force size
>>> SMPayloadTypeNTLIST.encode(["string1", "string2"], 1)
b'string1\x00'
>>> # guess size
>>> SMPayloadTypeNTLIST.encode(["string1", "string2"])
b'string1\x00string2\x00'
class smserver.smutils.smpacket.SMPayloadTypePacket

Bases: smserver.smutils.smpacket.SMPayloadTypeAbstract

Type for encoding packet in packet

static decode(payload, opt=None)
static encode(data, opt=None)
class smserver.smutils.smpacket.SMServerCommand

Bases: smserver.smutils.smpacket.SMCommand

List of server commands available

smserver.smutils.smpacket.main()

smserver.smutils.smthread module

class smserver.smutils.smthread.PacketHandler(server, conn, packet)

Bases: object

handle()
on_createroom()
on_enterroom()
on_login()
on_nscattack()
on_nsccm()
on_nsccuul()
on_nscformatted()
on_nscgon()
on_nscgsr()
on_nscgsu()
on_nschello()
on_nscping()
on_nscpingr()
on_nscrsg()
on_nscsu()
on_nscuopts()
on_nsscsms()
on_nssmonl()
on_roominfo()
on_xmlpacket()
send(packet)
sendall(packet)
sendroom(room, packet)
class smserver.smutils.smthread.StepmaniaServer(servers)

Bases: object

SERVER_TYPE = {'udp': <class 'smserver.smutils.smconnections.udpsocket.UDPServer'>, 'async': <class 'smserver.smutils.smconnections.asynctcpserver.AsyncSocketServer'>, 'websocket': <class 'smserver.smutils.smconnections.websocket.WebSocketServer'>, 'classic': <class 'smserver.smutils.smconnections.smtcpsocket.SocketServer'>}
add_connection(conn)
connections
find_connection(user_id)

Find the connection where a specific user is

ingame_connections(room_id)

Iterator of all the connections in a given room which have send a NSCGSR packet

is_alive()

Check if all the thread are still alive

on_disconnect(serv)
on_packet(serv, packet)
player_connections(room_id)

Iterator of all the connection’s player (not spectator)

room_connections(room_id)

Iterator of all the connections in a given room

sendall(packet)

Send a packet to all the connections in the server

Parameters:packet (smserver.smutils.smpacket.SMPacket) – The packet to send
sendingame(room_id, packet)

Send a packet to all the connections currently playing in the room

Parameters:
sendplayers(room_id, packet)

Send a packet to all the player’s connections in the room

(not to spectator player)

Parameters:
sendroom(room_id, packet)

Send a packet to all the connections in the room

Parameters:
start()

Module contents