packet

package
v0.0.0-...-e8a13b5 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package packet is for TCP and UDP packets used in eX0 networking protocol.

Index

Constants

View Source
const MAX_TCP_SIZE = 1448
View Source
const MAX_UDP_SIZE = 1448
View Source
const TCPHeaderSize = 3

TCPHeaderSize is the size in bytes of the TCP packet header.

View Source
const UDPHeaderSize = 1

UDPHeaderSize is the size in bytes of the UDP packet header.

Variables

This section is empty.

Functions

This section is empty.

Types

type BroadcastTextMessage

type BroadcastTextMessage struct {
	TCPHeader

	PlayerID uint8
	Message  []byte
}

func (*BroadcastTextMessage) MarshalBinary

func (p *BroadcastTextMessage) MarshalBinary() ([]byte, error)

func (*BroadcastTextMessage) UnmarshalBinary

func (p *BroadcastTextMessage) UnmarshalBinary(b []byte) error

type ClientCommand

type ClientCommand struct {
	UDPHeader

	CommandSequenceNumber uint8 // Latest command sequence number (i.e., last one in the slice).
	CommandSeriesNumber   uint8
	MovesCount            uint8  // len(Moves) - 1.
	Moves                 []Move // Oldest first, newest last.
}

func (*ClientCommand) MarshalBinary

func (p *ClientCommand) MarshalBinary() ([]byte, error)

func (*ClientCommand) UnmarshalBinary

func (p *ClientCommand) UnmarshalBinary(b []byte) error

type CurrentPlayersInfo

type CurrentPlayersInfo struct {
	TCPHeader

	Players []PlayerInfo
}

func (*CurrentPlayersInfo) MarshalBinary

func (p *CurrentPlayersInfo) MarshalBinary() ([]byte, error)

func (*CurrentPlayersInfo) UnmarshalBinary

func (p *CurrentPlayersInfo) UnmarshalBinary(b []byte, totalPlayerCount uint8) error

type EnterGamePermission

type EnterGamePermission struct {
	TCPHeader
}

func (*EnterGamePermission) MarshalBinary

func (p *EnterGamePermission) MarshalBinary() ([]byte, error)

func (*EnterGamePermission) UnmarshalBinary

func (p *EnterGamePermission) UnmarshalBinary(b []byte) error

type EnteredGameNotification

type EnteredGameNotification struct {
	TCPHeader
}

func (*EnteredGameNotification) MarshalBinary

func (p *EnteredGameNotification) MarshalBinary() ([]byte, error)

func (*EnteredGameNotification) UnmarshalBinary

func (p *EnteredGameNotification) UnmarshalBinary(b []byte) error

type Handshake

type Handshake struct {
	UDPHeader

	Signature uint64
}

func (*Handshake) MarshalBinary

func (p *Handshake) MarshalBinary() ([]byte, error)

func (*Handshake) UnmarshalBinary

func (p *Handshake) UnmarshalBinary(b []byte) error

type JoinServerAccept

type JoinServerAccept struct {
	TCPHeader

	YourPlayerID     uint8
	TotalPlayerCount uint8
}

func (*JoinServerAccept) MarshalBinary

func (p *JoinServerAccept) MarshalBinary() ([]byte, error)

func (*JoinServerAccept) UnmarshalBinary

func (p *JoinServerAccept) UnmarshalBinary(b []byte) error

type JoinServerRefuse

type JoinServerRefuse struct {
	TCPHeader

	RefuseReason uint8
}

func (*JoinServerRefuse) MarshalBinary

func (p *JoinServerRefuse) MarshalBinary() ([]byte, error)

func (*JoinServerRefuse) UnmarshalBinary

func (p *JoinServerRefuse) UnmarshalBinary(b []byte) error

type JoinServerRequest

type JoinServerRequest struct {
	TCPHeader

	Version    uint16
	Passphrase [16]byte
	Signature  uint64
}

func (*JoinServerRequest) MarshalBinary

func (p *JoinServerRequest) MarshalBinary() ([]byte, error)

func (*JoinServerRequest) UnmarshalBinary

func (p *JoinServerRequest) UnmarshalBinary(b []byte) error

type JoinTeamRequest

type JoinTeamRequest struct {
	TCPHeader

	PlayerNumber *uint8 // If > 1 players per connection, player index within the connection.
	Team         Team
}

func (*JoinTeamRequest) MarshalBinary

func (p *JoinTeamRequest) MarshalBinary() ([]byte, error)

func (*JoinTeamRequest) UnmarshalBinary

func (p *JoinTeamRequest) UnmarshalBinary(b []byte) error

type LoadLevel

type LoadLevel struct {
	TCPHeader

	LevelFilename []byte
}

func (*LoadLevel) MarshalBinary

func (p *LoadLevel) MarshalBinary() ([]byte, error)

func (*LoadLevel) UnmarshalBinary

func (p *LoadLevel) UnmarshalBinary(b []byte) error

type LocalPlayerInfo

type LocalPlayerInfo struct {
	TCPHeader

	NameLength  uint8
	Name        []byte
	CommandRate uint8
	UpdateRate  uint8
}

func (*LocalPlayerInfo) MarshalBinary

func (p *LocalPlayerInfo) MarshalBinary() ([]byte, error)

func (*LocalPlayerInfo) UnmarshalBinary

func (p *LocalPlayerInfo) UnmarshalBinary(b []byte) error

type Move

type Move struct {
	MoveDirection int8
	Stealth       uint8
	Z             float32
}

type Ping

type Ping struct {
	UDPHeader

	PingData      uint32
	LastLatencies []uint16
}

func (*Ping) MarshalBinary

func (p *Ping) MarshalBinary() ([]byte, error)

func (*Ping) UnmarshalBinary

func (p *Ping) UnmarshalBinary(b []byte, totalPlayerCount uint8) error

type PlayerInfo

type PlayerInfo struct {
	NameLength uint8
	Name       []byte // If NameLength > 0.
	Team       Team   // If NameLength > 0.
	State      *State // If NameLength > 0 && Team != 2.
}

type PlayerJoinedServer

type PlayerJoinedServer struct {
	TCPHeader

	PlayerID   uint8
	NameLength uint8
	Name       []byte
}

func (*PlayerJoinedServer) MarshalBinary

func (p *PlayerJoinedServer) MarshalBinary() ([]byte, error)

func (*PlayerJoinedServer) UnmarshalBinary

func (p *PlayerJoinedServer) UnmarshalBinary(b []byte) error

type PlayerJoinedTeam

type PlayerJoinedTeam struct {
	TCPHeader

	PlayerID uint8
	Team     Team
	State    *State // If Team != 2.
}

func (*PlayerJoinedTeam) MarshalBinary

func (p *PlayerJoinedTeam) MarshalBinary() ([]byte, error)

func (*PlayerJoinedTeam) UnmarshalBinary

func (p *PlayerJoinedTeam) UnmarshalBinary(b []byte) error

type PlayerLeftServer

type PlayerLeftServer struct {
	TCPHeader

	PlayerID uint8
}

func (*PlayerLeftServer) MarshalBinary

func (p *PlayerLeftServer) MarshalBinary() ([]byte, error)

func (*PlayerLeftServer) UnmarshalBinary

func (p *PlayerLeftServer) UnmarshalBinary(b []byte) error

type PlayerUpdate

type PlayerUpdate struct {
	ActivePlayer uint8
	State        *State // If ActivePlayer == true.
}

type PlayerWasHit

type PlayerWasHit struct {
	TCPHeader

	PlayerID    uint8
	HealthGiven float32
}

func (*PlayerWasHit) MarshalBinary

func (p *PlayerWasHit) MarshalBinary() ([]byte, error)

func (*PlayerWasHit) UnmarshalBinary

func (p *PlayerWasHit) UnmarshalBinary(b []byte) error

type Pong

type Pong struct {
	UDPHeader

	PingData uint32
}

func (*Pong) MarshalBinary

func (p *Pong) MarshalBinary() ([]byte, error)

func (*Pong) UnmarshalBinary

func (p *Pong) UnmarshalBinary(b []byte) error

type Pung

type Pung struct {
	UDPHeader

	PingData uint32
	Time     float64
}

func (*Pung) MarshalBinary

func (p *Pung) MarshalBinary() ([]byte, error)

func (*Pung) UnmarshalBinary

func (p *Pung) UnmarshalBinary(b []byte) error

type SendTextMessage

type SendTextMessage struct {
	TCPHeader

	Message []byte
}

func (*SendTextMessage) MarshalBinary

func (p *SendTextMessage) MarshalBinary() ([]byte, error)

func (*SendTextMessage) UnmarshalBinary

func (p *SendTextMessage) UnmarshalBinary(b []byte) error

type ServerUpdate

type ServerUpdate struct {
	UDPHeader

	CurrentUpdateSequenceNumber uint8
	PlayerUpdates               []PlayerUpdate
}

func (*ServerUpdate) MarshalBinary

func (p *ServerUpdate) MarshalBinary() ([]byte, error)

func (*ServerUpdate) UnmarshalBinary

func (p *ServerUpdate) UnmarshalBinary(b []byte, totalPlayerCount uint8) error

type State

type State struct {
	CommandSequenceNumber uint8
	X                     float32
	Y                     float32
	Z                     float32
}

type TCPHeader

type TCPHeader struct {
	Length uint16
	Type   Type
}

func (*TCPHeader) UnmarshalBinary

func (h *TCPHeader) UnmarshalBinary(b []byte) error

type Team

type Team uint8
const (
	Red       Team = 0
	Blue      Team = 1
	Spectator Team = 2
)

func (Team) String

func (t Team) String() string

type TimeRequest

type TimeRequest struct {
	UDPHeader

	SequenceNumber uint8
}

func (*TimeRequest) MarshalBinary

func (p *TimeRequest) MarshalBinary() ([]byte, error)

func (*TimeRequest) UnmarshalBinary

func (p *TimeRequest) UnmarshalBinary(b []byte) error

type TimeResponse

type TimeResponse struct {
	UDPHeader

	SequenceNumber uint8
	Time           float64
}

func (*TimeResponse) MarshalBinary

func (p *TimeResponse) MarshalBinary() ([]byte, error)

func (*TimeResponse) UnmarshalBinary

func (p *TimeResponse) UnmarshalBinary(b []byte) error

type Type

type Type uint8
const (
	// TCP packet types.
	JoinServerRequestType        Type = 1
	JoinServerAcceptType         Type = 2
	JoinServerRefuseType         Type = 3
	UDPConnectionEstablishedType Type = 5
	EnterGamePermissionType      Type = 6
	EnteredGameNotificationType  Type = 7
	SendTextMessageType          Type = 10
	BroadcastTextMessageType     Type = 11
	LoadLevelType                Type = 20
	CurrentPlayersInfoType       Type = 21
	PlayerJoinedServerType       Type = 25
	PlayerLeftServerType         Type = 26
	JoinTeamRequestType          Type = 27
	PlayerJoinedTeamType         Type = 28
	LocalPlayerInfoType          Type = 30
	PlayerWasHitType             Type = 40

	// UDP packet types.
	ClientCommandType Type = 1
	ServerUpdateType  Type = 2
	WeaponCommandType Type = 3
	WeaponActionType  Type = 4
	PingType          Type = 10
	PongType          Type = 11
	PungType          Type = 12
	HandshakeType     Type = 100
	TimeRequestType   Type = 105
	TimeResponseType  Type = 106
)

func (Type) String

func (i Type) String() string

type UDPConnectionEstablished

type UDPConnectionEstablished struct {
	TCPHeader
}

func (*UDPConnectionEstablished) MarshalBinary

func (p *UDPConnectionEstablished) MarshalBinary() ([]byte, error)

func (*UDPConnectionEstablished) UnmarshalBinary

func (p *UDPConnectionEstablished) UnmarshalBinary(b []byte) error

type UDPHeader

type UDPHeader struct {
	Type Type
}

func (*UDPHeader) UnmarshalBinary

func (h *UDPHeader) UnmarshalBinary(b []byte) error

type WeaponAction

type WeaponAction struct {
	UDPHeader

	PlayerID     uint8
	Action       WeaponState
	Time         float64
	Z            float32 // If Action is WeaponSystem::FIRE.
	WeaponNumber uint8   // If Action is WeaponSystem::CHANGE_WEAPON.
}

func (*WeaponAction) MarshalBinary

func (p *WeaponAction) MarshalBinary() ([]byte, error)

func (*WeaponAction) UnmarshalBinary

func (p *WeaponAction) UnmarshalBinary(b []byte) error

type WeaponCommand

type WeaponCommand struct {
	UDPHeader

	Action       WeaponState
	Time         float64
	Z            float32 // If Action is WeaponSystem::FIRE.
	WeaponNumber uint8   // If Action is WeaponSystem::CHANGE_WEAPON.
}

func (*WeaponCommand) MarshalBinary

func (p *WeaponCommand) MarshalBinary() ([]byte, error)

func (*WeaponCommand) UnmarshalBinary

func (p *WeaponCommand) UnmarshalBinary(b []byte) error

type WeaponState

type WeaponState uint8
const (
	Idle         WeaponState = 0
	Fire         WeaponState = 1
	Reload       WeaponState = 2
	ChangeWeapon WeaponState = 3
)

Jump to

Keyboard shortcuts

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