
PRELIMINARY - - - - - - - - 05/03/2004
Protocol version not yet 2.  
  But 0x02 will be its version for inter-prtocol purposes.

This protocol is only intended to replace current protocol.  Because current protocol
not expanable

SMLAN PROTCOL TCP/8765

Protcol is entirelly packaged in EzSockets Data Packets (use send and receive packet)

This will prevent any out-of-sync errors with future or past versions.

The protocol is impervious to fragmented, or bonded TCP packets.

Basic Representation:

Octet 0123 4 5
     +----+-+---//--+
     |ssss|C|Payload|
     +----+-+---//--+

ssss    - size of packet, handled by ezsockets (if you're using C++)
C       - Command.
Payload - variable size based on command

The payload may contain more data than expected, i.e. new protocol version.


In the following protocol, the term size means the size of the chunk of data.
If the "size" is	"NT" then that means it's a null-terminating string.
			"MSN" most significant 4 bits (byte/16)
			"LSN" least significant 4 bits (byte%16)


Note: Primary player is 0x0, secondary player is 0x1

CLIENT to SERVER protocol:

000:	No Operation
 Desc:		This command will cause server to respond with a no op responce.
 Payload:	None
 Responce:	Server 001
 
001:	No Operation Responce
 Desc:		This command is used to respond to a no operation.
 Payload:	None
 Responce:	None

002:	Hello
 Desc:		This is the first packet from a client to server, stating below 
		information  (NOTE: Names are no longer sent in this packet)
 Payload:	
    Size	Description:
    1		Client protocol version
    NT		Name of build of StepMania
 Responce:	Server 002



003:	Game Start Request
 Desc:		This command is called once after most loading is done, and
		again immediately before the sound starts.
 Payload:	
    Size	Description
    MSN		Primary player difficulty (feet)   (0 for no player)
    LSN		Secondary player difficulty (feet) (0 for no player)
    MSN		Primary player difficulty (0=Beginner, 1=easy, etc.) 
    LSN		Second player difficulty (0=Beginner, 1=easy, etc.)
    MSN		Start Position (0 is pre-sync, 1 is for sync)
    LSN		Reserved
    NT		Song Title
    NT		Song Subtitle
    NT		Song Artist   
    NT		Course Title     (If none exists; make it just a null)
    NT		Song Options (in string-format)
    NT		Primary Player's options (Null if non-existant)
    NT		Secondary Player's Options (Null if non-existant)
    
 Responce: 	Server 003


004:	Game Over Notice
 Desc:		This command is sent when end of game is encounterd
 Payload:	None.
 Responce:	None.

005:	Game Status update
 Desc:		Updates game info for each step
 Payload:
    Size	Description
    MSN		Player #
    LSN		StepID 
		1: Miss
		2: Boo
		3: Good
		4: Great
		5: Perfect
		6: Marvelous
		7: NG
		8: OK

    MSN		Projected Grade (StepMania enum int)
    LSN		Reserved
    4		Net-order long containing score.
    2		Net-order int containing combo.
    2		Net-order int containing health.
    2		Net-order # containing offset
			32767 would be DEAD on the note
			If the user is hitting late, the # will be higher
			It if the user is exactly 0.25 seconds off, the
			number will be different by 500, if 0.5, it will be
			different by 1000.
 Responce:	None.

006: Style Update    (PLEASE NOTE THIS HAS NOTHING TO DO WITH SERVER COMMAND 6)
 Desc:		This is sent when a style is chosen.  
 Size:
    1		# of enabled players (1 means 1, 2 means 2)
    1		Player #   (0 means 1st, 1 means 2nd)
    NT		Player Name for #
   (Additional player's and #'s) (enabled players ONLY)

 Responce:	None

007:	Chat message
 Desc:		The user typed a message for general chat.
 Size:
    NT		Message

008:	Request Start Game and Tell server existance/non existance of song.
 Desc:		The user selected a song on a Net-enabled selection
 Size:
    1		Usage of message
		0: (in responce to server 8) User has specified song
		1: (in responce to server 8) User does NOT have specified song
		2: User requested a start game on given song
    NT		Song Title    (As gotten by GetTranslitMainTitle)
    NT		Song Artist   (As Gotten by GetTranslitArtist)
    NT		Song Subtitle (As gotten by GetTranslitSubTitle)

009: //Reserved

010:	User entered/exited Network Music Selection Screen
 Size:
    1			
		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

011:	User has changed player options
 Size:
    NT		Player 0's options
    NT		Player 1's options


012:	SMOnline Packet.	//SPECIAL CASE!!!
	NOTE: The smonline packet is not defined here.
	The SMLan packet 12 is a wrapper for the SMOnline packet.
	This is so that we can have "protection" of sorts when 
	it comes to the coding of SMOnline, so we don't have to
	use the lower level commands when dealing with SMOnline.
 Size:
    1		SMOnline command	//This used to say 2, but it looks like 1 in all cases
 <VARIABLE>	SMOnline data

SERVER to CLIENT protocol: (begins at 128)

NOTE: Server responces always add 128, thus a server responce for no operation
	is 128, not 000

000(128):No Operation 
 Desc:		This command will cause server to respond with a no op responce.
 Payload:	None
 Responce:	Server 001

001(129):No Operation Responce
 Desc:		This command is used to respond to a no operation.
 Payload:	None
 Responce:	None

002(130):Server Hello Responce
 Desc:		This introduces the server.
 Payload:
    Size	Description
    1		Server protocol version //NOTE: if protocol version is 128+, then this
			server is an SMOnline server
    NT		Server Name
    4		Random key ( at the moment only used for an alternate login method )

003(131):Allow Start
 Desc:		This will cause the client to start the game.
 Payload:	None
 Responce:	None

004(132):Game over stats
 Desc:		this packet is send in responce to the game over packet
		it contains information regarding how well each player did.
 Payload:
    1		# of players sent in this packet (active players)
	The way this works is to send every player's info for a given
	 field.  Like every player's score will be sent first, then every
	 player's grade.
    1		First player's player ID
	<Other player's IDs>
    4		Score
	<Other player's scores>
    1		Grade
	<Other player's Grades>
    1		Difficulty (0=beginner, 1=light, etc.)
	<Other player's difficulties>
    2           miss
	<Other player's misses>
    2		boo		
	<Other player's boos>
    2		good (All players)
    2		great (All players)
    2		perfect (All players)
    2		marvelous (All players)
    2		ok (All players)
    2		max_combo (All players)
    NT		Player's options
	<Other player's options>


005:(133)Scoreboard update
 Desc:		This will update the client's scoreboard.
 Payload:	
    Size
    1		Which section
		0: Names
		1: Combos
		2: Projected Grades
    1		# of players to display

	If Names, then:
    1		Player in first place's ID
    1		Player in second place's ID
    ...
    1		Last player's ID
	If Combos, then:
    2		First player's combo
    2		Second Player's combo
    ...
    2		Last player's combo
	If Project grades
    1		Player 1's grade (in the same format used when reporting projected grades)
    1		Player 2's grade
    ...
    1		Last player's projected grade


006:(134)System Message  (PLEASE NOTE THIS HAS NOTHING TO DO WITH CLIENT COMMAND 6)
 Desc: 		Send system message to user
 Payload:
    Size	Description
    NT		Message

007:(135)Chat Message
 Desc:		Add a chat message to the chat window on some StepMania screens.
 Payload:	
    Size	Description
    NT		Message

008:(136)Tell client to start song/ask if client has song
 Desc:		The user selected a song on a Net-enabled selection
 Size:
    1		Usage of message
		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
    NT		Song Title    (As gotten by GetTranslitMainTitle)
    NT		Song Artist   (As Gotten by GetTranslitArtist)
    NT		Song Subtitle (As gotten by GetTranslitSubTitle)

009:(137)Update user list
 Desc:		This sends all the users currently connected
 Size:
    1		Max # of players
    1		# of players in this packet
    1		Player 0's status
    NT		Player 0's name (if there is no player here... make it a null (""))
    1		Player 1's status
    NT		Player 1's name
    ...
    1		Last player's status
    NT		Last player's name
     Status:  
	0	Inative (no info on this user yet)
	1	Active (you know who it is)
	2	In Selection Screen
	3	In Options
	4 	In Evaluation

010:(138)Force change to Networking select music screen.
 Size:
    NT		Set Specified gametype
    NT		Set Specified style

011:(139)Reserved


012:(140)SMOnline Packet.	//SPECIAL CASE!!!
	NOTE: The smonline packet is not defined here.
	The SMLan packet 12 is a wrapper for the SMOnline packet.
	This is so that we can have "protection" of sorts when 
	it comes to the coding of SMOnline, so we don't have to
	use the lower level commands when dealing with SMOnline.
 Size:
    1		SMOnline command
 <VARIABLE>	SMOnline data














----------------------------------------------------------------
Client SMOnline packets:
000:  Send Login Information
 Size:
    1		Player Number
    1		Encryption text
		0: MD5 hash
		1: MD5 ( MD5 hash + salt ) (salt is plain text, base 10 string )
    NT		Username
    NT		Password

  Note: The client is not permitted to use method (1) for authentication
	if the salt it received from the server is 0



001: User asks to enter room
 Size:
    1		Enter/Exit?
		0: User wishes to exit room
		1: User wishes to enter room 
    NT		Room Name (Used when entering rooms)
    NT		Password (Empty if password not used)

002: Create a new Room
 Size:
    1		Room Type
		0: Normal room (has sub rooms)
		1: Game room (no sub rooms)
    NT		Room Title
    NT		Room Description


Server SMOnline packets:
000:  Login Responce
    1		Approval Status
		0: Approved
		1: Approval Failed
    NT		Login responce (plain text)

001:  Room Update (Changing rooms)
 Size:
    1		Type of update
		0: Change Room Title
		1: Update List of other rooms (or games)

	If Room Title Update:
    NT		Room Title
    NT		Room Description
    1		Type of room:
		0: Chat room
		1: Game room
	
	If Room List Update:
    1		Number of rooms
    NT		Room1 Title
    NT		Room1 Description			
    NT		Room2 Title
    NT		Room2 Description
	...
    NT		RoomN Title
    NT		RoomN Description

    Room Status appended for reverse compatibility
    1		Room1 Status
		0: Normal Room
		1: Passworded Room
		2: Room in game
		3: First stage of song selection has been done
		4: Second stage of song selection has been done
    1		Room2 Status
	...
    1		RoomN Status	
