prot

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2026 License: AGPL-3.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

View Source
const NONE_INT = -1

Shows that an integer field in a request or response is empty

View Source
const NONE_STRING = "##"

Shows that a string field in a request or response is empty

View Source
const PROTOCOL_VER_LATEST = "3"
View Source
const SERVER_USER_ID = 0

Reserved user ID that will be tied to requests and responses to denote them as server messages

View Source
const UserRequestRegister = "REGISTER"

UserRequestRegister registers a username on a new connection. The server assigns the numeric ID; clients must not generate their own IDs.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatMetadata added in v0.3.0

type ChatMetadata struct {
	// Number of messages there are in a block
	BlockSize int `json:"block_size"`
	// UserID of who created the chat
	Creator int `json:"creator"`
	// A description of what the chat is about
	Description string `json:"description"`
	// ID of the chat
	ID int `json:"id"`
	// Is the chat public?
	IsPublic bool `json:"public"`
	// ID of the last block in the chat. Should be set to -1 and not 0 when creating a chat to prevent and off by 1 error
	LastBlockID int `json:"last_block"`

	LastMessageID int `json:"last_message"`
	// UserIDs of everyone who has access to the chat. This is empty if the chat is public
	Members []int `json:"members"`
	// The name of the chat
	Name string `json:"name"`
	// Total number of blocks in the chat. This should not be updated while the chat is loaded and instead should be calculated from the field `LastBlockID` when saving metadata
	NumberOfBlocks int `json:"blocks"`
	// Total number of messages in the chat. This should not be updated while the chat is loaded and instead should be calculated from the field `LastMessageID` when saving metadata
	NumberOfMessages int `json:"messages"`
}

Information about a chat

type ChatMetadataRequest added in v0.3.0

type ChatMetadataRequest struct {
	// ID of the chat involved
	ChatID int
	// New chat metadata, only initialized for REQ_ADD and REQ_EDIT
	NewMetadata ChatMetadata
	// What the request is (e.g., creating new chat, getting metadata, etc.)
	Type RequestWhat
}

type ChatMetadataResponse added in v0.3.0

type ChatMetadataResponse struct {
	// ID of the chat involved
	ChatID int
	// Chat metadata the client may have requested
	Metadata ChatMetadata
	// Action that this response fulfilled
	Type RequestWhat
}

type ChatRaw

type ChatRaw struct {
	// Protocol version
	Version string `json:"version"`
	// Array of all messages in chat
	Messages []MessageRaw `json:"messages"`
}

Collection of raw messages, used for saving and loading messages, not for communication between the client and server

type ChatRequest

type ChatRequest struct {
	// ID of the chat involved
	ChatID int `json:"chat_id"`
	// Content to be assigned to the given message for editing and adding messages, is empty for `REQ_DEL` and `REQ_GET`
	MessageContent string `json:"content"`
	// ID of the message involved, is -1 for `REQ_ADD`
	MessageID int `json:"message_id"`
	// IDs of the messages the message sent in this chat request is replying to, is non nil only for REQ_ADD and REQ_EDIT
	RepliedIDs []int `json:"replied_ids"`
	// What the request is (e.g., message deletion, editing)
	Type RequestWhat `json:"chat_request_type"`
	// User ID of who sent the request
	UserID int `json:"user_id"`
}

A request to change something about or get information from a chat (e.g., add a message, delete a message, load and receive a message)

type ChatResponse

type ChatResponse struct {
	// ID of the chat involved
	ChatID int `json:"chat_id"`
	// An error that prevented the request from being fulfilled. Is empty if no error occurred
	Error string `json:"error"`
	// ID of the message involved
	MessageID int `json:"message_id"`
	// Messages that the client may have requested
	Messages []MessageRaw `json:"messages"`
	// Public user profiles needed to render message senders
	Users []User `json:"users"`
	// Action that this response fulfilled
	Type RequestWhat `json:"chat_response_type"`
}

A response to a chat request after the request is fulfuilled

type MessageRaw

type MessageRaw struct {
	// What the message says
	Content string `json:"content"`
	// Unique message identifier (assigned incrementally, is -1 when a message is received from a client until the server assigns it an ID)
	ID int `json:"id"`
	// IDs of the message(s) this message is replying to
	RepliedIDs []int `json:"replied_ids"`
	// Time at which the message was sent (unix format)
	Time int64 `json:"time"`
	// User ID of who sent the message
	UserID int `json:"user_id"`
}

Message data sent to and received from the server

type RequestWhat

type RequestWhat string

What action is being requested. What these do differ depending on the RequestWhere

const REQ_ADD RequestWhat = "ADD"

Adds new data provided by the client

REQ_CHAT - Adds a message to the chat
REQ_CHATMETADATA - Creates a new chat
REQ_USER - Registers a new user
const REQ_DEL RequestWhat = "DEL"

Deletes existing data

REQ_CHAT - Deletes the a message
REQ_CHATMETADATA - Deletes a chat
REQ_USER - Deletes a user
const REQ_EDIT RequestWhat = "EDIT"

Edits existing data

REQ_CHAT - Edits a message
REQ_CHATMETADATA - Edits a chat's metadata
REQ_USER - Edits user information
const REQ_GET RequestWhat = "GET"

Sends existing data to the client that requested it

REQ_CHAT - Sends a chat block to the client
REQ_CHATMETADATA - Sends a chat's metadata to the client
REQ_USER - Sends user information to the client

type RequestWhere

type RequestWhere string

What data is the request asking for the action to be done upon

const REQ_CHAT RequestWhere = "CHAT"

Request for chat

const REQ_CHATMETADATA RequestWhere = "CHATMETADATA"

Request for chat metadata

const REQ_USER RequestWhere = "USER"

Request for user

type User added in v0.3.0

type User struct {
	ID       int    `json:"id"`
	Username string `json:"username"`
}

User is the public profile data required to render message senders.

type UserRequest added in v0.3.0

type UserRequest struct {
	RequestType string `json:"request_type"`
	Username    string `json:"username"`
}

UserRequest is sent before chat traffic to establish a connection identity.

type UserResponse added in v0.3.0

type UserResponse struct {
	Error string `json:"error"`
	User  User   `json:"user"`
}

UserResponse is returned for a UserRequest. Error is empty on success.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL