You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This project also comes with a package that allows developers to write server plugins.
Warning
WIP. Subject to change.
import{command,IClient,on,Plugin,ServerEvent,}from'jsr:@p2sr/ghosting';exportclassExamplePluginextendsPlugin{name='Example Plugin';version='1.0.0';authors=['NeKz'];license='MIT';
@command('ping','Ping the server!')asynconPing(){awaitthis.respond('pong!');}
@command('dm <player> <message...>','DM a player!')asynconDirectMessage(client: IClient,message: string,){awaitthis.respondToClient(client,message);}
@on(ServerEvent.ClientMessage)asynconClientMessage(message: string){// Use own command handlerconst[command, ..._rest]=message.split(' ');switch(command){case'/ping': {awaitthis.respond('pong');break;}case'/dm': {// ...break;}}}}
Protocol
Endianness
SourceAutoRecord uses SFML which encodes integer types like u16, u32, u64 in big-endian (BE).
Packets
This is the encoded representation of sf::Packet from SFML. Every TCP packet includes a field for the total
length of the data.
Field
Type
Description
length
u32
TCP only! Length of data field.
data
Header + Packet
Packet of type Connect, Ping etc.
Header
The header value (u8) defines the type of the packet. Since UDP is optional for clients the implementation is only
required for HEART_BEAT, COUNTDOWN and UPDATE packets.
sequenceDiagram
participant Server
Note left of Server: ghost.portal2.sr
participant Client
Note right of Client: SourceAutoRecord
participant Clients
Client->>Server: connection_packet
Server->>Client: confirm_connection_packet
Server->>Clients: connect_packet (broadcast)
sequenceDiagram
participant Server
Note left of Server: ghost.portal2.sr
participant Client
Note right of Client: SourceAutoRecord
participant Clients
Client->>Server: disconnect_packet
Server->>Clients: disconnect_packet (broadcast)
sequenceDiagram
participant Server
Note left of Server: ghost.portal2.sr
participant Client
Note right of Client: SourceAutoRecord
Client->>Server: ping_packet
Server->>Client: ping_echo_packet
sequenceDiagram
participant Server
Note left of Server: ghost.portal2.sr
participant Client
Note right of Client: SourceAutoRecord
participant Clients
Client->>Server: map_change_packet
Server->>Clients: map_change_packet
sequenceDiagram
participant Server
Note left of Server: ghost.portal2.sr
participant Client
Note right of Client: SourceAutoRecord
participant Clients
Client->>Server: message_packet
Server->>Clients: message_packet (broadcast)
Loading
Server Message
sequenceDiagram
participant Server
Note left of Server: ghost.portal2.sr
Note right of Clients: SourceAutoRecord
participant Clients
Server->>Clients: message_packet (broadcast)
sequenceDiagram
participant Server
Note left of Server: ghost.portal2.sr
participant Client
Note right of Client: SourceAutoRecord
Server->>Clients: countdown_packet (broadcast)
Client->>Server: confirm_countdown_packet
Server->>Client: confirm_countdown_packet (id = 0)
sequenceDiagram
participant Server
Note left of Server: ghost.portal2.sr
participant Client
Note right of Client: SourceAutoRecord
participant Clients
Client->>Server: speedrun_finish_packet
Server->>Clients: speedrun_finish_packet (broadcast)
sequenceDiagram
participant Server
Note left of Server: ghost.portal2.sr
participant Client
Note right of Client: SourceAutoRecord
participant Clients
Client->>Server: model_change_packet
Server->>Clients: model_change_packet (broadcast)
sequenceDiagram
participant Server
Note left of Server: ghost.portal2.sr
participant Client
Note right of Client: SourceAutoRecord
participant Clients
Client->>Server: color_change_packet
Server->>Clients: color_change_packet (broadcast)