Protocol Spec - 0xZ0F/RECourseCapstone GitHub Wiki

! Spoilers Ahead !

Please do not use this to cheat, this is mainly used so I don't forget the protocol spec as I develop the project.

The general control flow is as follows:

Client -- Hello -> Server
Client <-- SID --- Server
Client --- CMD --> Server
Client <-- ... --> Server
Client -- Exit --> Server

Header

Every packet is prefixed with the header.

DataLen Type Status SID Data
2 Bytes 1 Byte 1 Byte 4 Bytes DataLen Bytes
  • DataLen - Length of the data.
  • Type - Type of packet being sent.
  • Status - Used to denote success or errors.
  • SID - Session ID. Zero if one has not been provided.
  • Data - Data for the type of packet sent.

Hello

Request:

No data.

Response

SID
4 Bytes

Check Balance

Check your balance.

Request

Flag
1 Byte
  • Flag - What format to receive the flag in. For example, pretty may be a string of $100.00 and raw may be a float of 100.00.

Response

Len Data
1 Byte Len Bytes
  • Len - Length of the data.
  • Data - Balance in the format specified by Flag in the request.

Store Inventory

Get list of items for sale and information about them.

Request

No data.

Response

ID NameLen DescLen BuyPrice SellPrice Available Name Desc ...
2 Bytes 1 Byte 2 Bytes 2 Bytes 2 Bytes 4 Bytes NameLen Bytes DescLen Bytes Next Item ...

For the response, an item is defined as the following fields together:

  • ID - Item ID.
  • NameLen - Length of the item's name.
  • DescLen - Length of the item's description.
  • BuyPrice - Cost to buy the item.
  • SellPrice - Cost to sell the item.
  • Available - Number of items in stock.
  • Name - Item's name.
  • Desc - Item's description.

Items are put sequentially one after another up to the length of DataLen in the header.

Search Store Inventory

Search items for sale.

Request

Flag QueryLen Query
1 Byte 2 Bytes QueryLen Bytes
  • Flag - Type of query such as search by name, description, etc.
  • QueryLen - Length of the Query string.
  • Query - Query string.

Response

Same format as Store Inventory.

Client Inventory

Get a list of items the client currently has.

Request

No data.

Response

ID NameLen DescLen Amount Name Desc ...
2 Bytes 1 Byte 2 Bytes 4 Bytes NameLen Bytes DescLen Bytes Next Item ...
  • ID - Item ID.
  • NameLen - Length of the item's name.
  • Name - Item's name.
  • DescLen - Length of the item's description.
  • Desc - Item's description.
  • Amount - Number of this item owned.

Items are put sequentially one after another up to the length of DataLen in the header.

Buy

Buy an item from the store.

Request

ItemID
2 Bytes
  • ItemID - ID of the item to buy.

Response

Status
1 Byte
  • Status - Status of the buy such as success, failure, not in stock, etc.

It's recommended the client retrieves their balance again after a successful buy.

Sell

Sell an item if you have one.

Request

ItemID
2 Bytes
  • ItemID - ID of the item to sell.

Response

Status
1 Byte
  • Status - Status of the sell such as success, failure, etc.

It's recommended the client retrieves their balance again after a successful sell.

⚠️ **GitHub.com Fallback** ⚠️