samp

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: Apache-2.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	RPCClientJoin          uint8 = 25
	RPCDeath               uint8 = 53
	RPCRequestClass        uint8 = 128
	RPCRequestSpawn        uint8 = 129
	RPCConnectionRejected  uint8 = 130
	RPCSpawn               uint8 = 52
	RPCWorldPlayerAdd      uint8 = 32
	RPCSetSpawnInfo        uint8 = 68
	RPCSetPlayerPos        uint8 = 12
	RPCSetPlayerPosFindZ   uint8 = 13
	RPCSetPlayerHealth     uint8 = 14
	RPCSetPlayerSkin       uint8 = 153
	RPCSetPlayerTeam       uint8 = 69
	RPCSetFacingAngle      uint8 = 19
	RPCSetPlayerArmour     uint8 = 66
	RPCPutPlayerInVehicle  uint8 = 70
	RPCRemoveFromVehicle   uint8 = 71
	RPCSetPlayerColor      uint8 = 72
	RPCSetPlayerDrunkLevel uint8 = 35
	RPCClickPlayer         uint8 = 23
	RPCEnterVehicle        uint8 = 26
	RPCDialogResponse      uint8 = 62
	RPCClickTextDraw       uint8 = 83
	RPCChat                uint8 = 101
	RPCServerCommand       uint8 = 50
	RPCExitVehicle         uint8 = 154
	RPCUpdateScores        uint8 = 155
	RPCServerJoin          uint8 = 137
	RPCServerQuit          uint8 = 138
	RPCInitGame            uint8 = 139
	RPCClientMessage       uint8 = 93
	RPCClientCheck         uint8 = 103
	RPCDialogBox           uint8 = 61
	RPCShowTextDraw        uint8 = 134
	RPCHideTextDraw        uint8 = 135
	RPCSetTextDrawString   uint8 = 105
	RPCCreateObject        uint8 = 44
	RPCDestroyObject       uint8 = 47
	RPCWorldVehicleAdd     uint8 = 164
	RPCWorldVehicleRemove  uint8 = 165
	RPCVehicleDeath        uint8 = 136
	RPCSetVehicleHealth    uint8 = 147
)
View Source
const InvalidSAMPPlayerID uint16 = ^uint16(0)

InvalidSAMPPlayerID is the wire representation of an unknown killer.

View Source
const UnknownDeathReason uint8 = ^uint8(0)

UnknownDeathReason is the public-event sentinel for a death whose weapon cannot be recovered from the authoritative update. Weapon ID 0 means "fist" in SA-MP and must not be reused for an unknown cause.

Variables

View Source
var (
	ErrNicknameTooLong        = errors.New("samp: nickname is too long")
	ErrConnectionRejected     = errors.New("samp: connection rejected")
	ErrBadVersion             = errors.New("samp: incorrect client version")
	ErrBadNickname            = errors.New("samp: unacceptable nickname")
	ErrBadMod                 = errors.New("samp: bad client mod version")
	ErrBadPlayerID            = errors.New("samp: unable to allocate a player slot")
	ErrMessageTooLong         = errors.New("samp: message is too long")
	ErrMalformedPacket        = errors.New("samp: malformed packet")
	ErrClientNotConnected     = errors.New("samp: client is not connected")
	ErrClientNotSpawned       = errors.New("samp: client is not spawned")
	ErrSpawnNotReady          = errors.New("samp: spawn information is not ready")
	ErrSpawnCooldown          = errors.New("samp: respawn cooldown is active")
	ErrVehicleEntryInProgress = errors.New("samp: another vehicle entry is already in progress")
	ErrVehicleEntryCanceled   = errors.New("samp: vehicle entry was canceled before completion")
	ErrVehicleEntryOutOfRange = errors.New("samp: vehicle is not streamed or is outside the normal entry range")
)
View Source
var (
	ErrMotionSpeed      = errors.New("samp: motion speed must be positive")
	ErrMotionTarget     = errors.New("samp: motion target is not finite")
	ErrMotionNotDriver  = errors.New("samp: drive task requires the driver seat")
	ErrMotionNotSpawned = errors.New("samp: client is not spawned")
)

Functions

func AuthKey

func AuthKey(challenge string) string

func DecodeServerText

func DecodeServerText(charset, value string) string

Types

type ChatEvent

type ChatEvent struct {
	PlayerID *uint16
	Text     string
	Color    uint32
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func DialClient

func DialClient(ctx context.Context, address, nickname, password, charset string) (*Client, error)

func DialClientWithOptions added in v0.1.3

func DialClientWithOptions(ctx context.Context, address, nickname, password, charset string, options ClientOptions) (*Client, error)

func (*Client) ClickPlayer

func (c *Client) ClickPlayer(ctx context.Context, playerID uint16) error

func (*Client) ClickTextDraw

func (c *Client) ClickTextDraw(ctx context.Context, textDrawID uint16) error

func (*Client) Close

func (c *Client) Close() error

func (*Client) DriveTo added in v0.1.4

func (c *Client) DriveTo(vehicleID uint16, target [3]float32, speed, tolerance float32) (uint64, error)

func (*Client) EnterVehicle

func (c *Client) EnterVehicle(ctx context.Context, vehicleID uint16, passenger bool, requestedMode VehicleEntryMode) error

func (*Client) Events

func (c *Client) Events() <-chan Event

func (*Client) ExitVehicle

func (c *Client) ExitVehicle(ctx context.Context) error

func (*Client) NotifyLocalPlayerDeath added in v0.1.4

func (c *Client) NotifyLocalPlayerDeath(source DeathSource)

NotifyLocalPlayerDeath lets a native backend report a ped death when it can observe the local GTA ped directly. The cause remains explicitly unknown because this compatibility entry point carries no damage metadata.

func (*Client) NotifyLocalPlayerDeathWithCause added in v0.1.4

func (c *Client) NotifyLocalPlayerDeathWithCause(source DeathSource, reason uint8, killerID uint16)

NotifyLocalPlayerDeathWithCause reports a native-confirmed death and its SA-MP weapon/killer metadata. It is intentionally separate from server health handling: RPC_SetPlayerHealth cannot establish either field.

func (*Client) NotifyLocalVehicleDestroyed added in v0.1.4

func (c *Client) NotifyLocalVehicleDestroyed(vehicleID uint16, remoteControlled bool)

NotifyLocalVehicleDestroyed is the integration point for a future native GTA backend. Vehicle removal is not by itself enough to kill the local player, so this only detaches the local occupant. A native backend that has independently confirmed ped death must call NotifyLocalPlayerDeath.

func (*Client) RefreshScores

func (c *Client) RefreshScores(ctx context.Context) error

func (*Client) RequestSpawn added in v0.1.3

func (c *Client) RequestSpawn(ctx context.Context) error

RequestSpawn mirrors the two SA-MP spawn paths. During class selection the client asks the server for spawn authorization with RPC_RequestSpawn. After a confirmed death, PC SA-MP keeps the existing spawn information and sends RPC_Spawn directly; repeating RPC_RequestSpawn would incorrectly reopen the class-selection transaction on servers that enforce the native protocol.

func (*Client) RespondDialog

func (c *Client) RespondDialog(ctx context.Context, id int16, button uint8, item int16, input string) error

func (*Client) RespondDialogBytes

func (c *Client) RespondDialogBytes(ctx context.Context, id int16, button uint8, item int16, input []byte) error

func (*Client) SendChat

func (c *Client) SendChat(ctx context.Context, text string) error

func (*Client) SendCommand

func (c *Client) SendCommand(ctx context.Context, command string) error

func (*Client) SetAFK

func (c *Client) SetAFK(enabled bool)

func (*Client) SetKeys

func (c *Client) SetKeys(ctx context.Context, mask uint32) error

func (*Client) StopMovement added in v0.1.4

func (c *Client) StopMovement()

func (*Client) Teleport

func (c *Client) Teleport(ctx context.Context, x, y, z float32) error

func (*Client) WalkTo added in v0.1.4

func (c *Client) WalkTo(target [3]float32, speed, tolerance float32) (uint64, error)

type ClientOptions added in v0.1.3

type ClientOptions struct {
	EmulatePCClientCheck bool
	RespawnPolicy        RespawnPolicy
	// GPCI is the persisted per-installation client identifier used in the
	// SA-MP join handshake. An empty value generates a fallback identifier for
	// callers that do not have access to the application store.
	GPCI string
}

ClientOptions controls compatibility behavior that is optional in the Android raksamp client. In particular, PC client-check emulation is off by default there and must not be advertised unless explicitly requested.

type DeathCause added in v0.1.4

type DeathCause struct {
	Reason      uint8
	KillerID    uint16
	ReasonKnown bool
}

DeathCause is supplied by a native GTA integration when it can inspect the actual ped damage state. Server health RPCs do not contain this information.

type DeathSource added in v0.1.4

type DeathSource string
const (
	DeathSourceServerHealth DeathSource = "server_health"
	// Vehicle and RC vehicle sources are reserved for an integration that has
	// confirmed ped death; server vehicle RPCs only detach the occupant.
	DeathSourceVehicle   DeathSource = "vehicle"
	DeathSourceRCVehicle DeathSource = "rc_vehicle"
)

type DialogEvent

type DialogEvent struct {
	ID                               int16
	Style                            uint8
	Title, Button1, Button2, Message string
	RawMessage                       []byte
}

type Event

type Event struct {
	Type EventType
	Data any
}

type EventType

type EventType string
const (
	EventJoined          EventType = "joined"
	EventChat            EventType = "chat"
	EventPlayerJoin      EventType = "player.join"
	EventPlayerQuit      EventType = "player.quit"
	EventScores          EventType = "scores"
	EventDialog          EventType = "dialog"
	EventDisconnected    EventType = "disconnected"
	EventProtocolError   EventType = "protocol.error"
	EventTextDrawShow    EventType = "textdraw.show"
	EventTextDrawHide    EventType = "textdraw.hide"
	EventTextDrawText    EventType = "textdraw.text"
	EventObjectAdd       EventType = "object.add"
	EventObjectRemove    EventType = "object.remove"
	EventVehicleAdd      EventType = "vehicle.add"
	EventVehicleRemove   EventType = "vehicle.remove"
	EventPlayerSync      EventType = "player.sync"
	EventPosition        EventType = "position"
	EventAppearance      EventType = "appearance"
	EventVehicleState    EventType = "vehicle.state"
	EventPlayerHealth    EventType = "player.health"
	EventPlayerLifeState EventType = "player.state"
	EventPlayerDeath     EventType = "player.death"
	EventVehicleHealth   EventType = "vehicle.health"
	EventSpawned         EventType = "spawned"
	EventVehicleSync     EventType = "vehicle.sync"
	EventMovement        EventType = "movement"
)

type Info

type Info struct {
	Password                     bool
	Players, MaxPlayers          int
	Hostname, GameMode, Language string
}

func Query

func Query(ctx context.Context, host string, port int) (Info, error)

type MotionEvent added in v0.1.4

type MotionEvent struct {
	TaskID   uint64
	Kind     MotionKind
	State    MotionState
	Position [3]float32
	Target   [3]float32
	Progress float32
	Error    string
}

MotionEvent is deliberately small: it is emitted at task boundaries and at a throttled progress cadence, not once per network sync frame.

type MotionKind added in v0.1.4

type MotionKind string
const (
	MotionWalk  MotionKind = "walk"
	MotionDrive MotionKind = "drive"
)

type MotionState added in v0.1.4

type MotionState string
const (
	MotionStarted   MotionState = "started"
	MotionProgress  MotionState = "progress"
	MotionCompleted MotionState = "completed"
	MotionStopped   MotionState = "stopped"
	MotionFailed    MotionState = "failed"
)

type ObjectEvent

type ObjectEvent struct {
	ID      uint16
	ModelID int32
	X, Y, Z float32
}

type PlayerDeathEvent added in v0.1.4

type PlayerDeathEvent struct {
	Reason      uint8
	KillerID    uint16
	ReasonKnown bool
	Source      DeathSource
}

type PlayerEvent

type PlayerEvent struct {
	ID          uint16
	Name        string
	Score, Ping int32
	X, Y, Z     float32
	Health      float32
	Armour      float32
	Skin        int32
	Team        uint8
	Rotation    float32
	HasPosition bool
	HasSkin     bool
	HasTeam     bool
	HasRotation bool
	Color       uint32
	HasColor    bool
}

type PlayerHealthEvent added in v0.1.4

type PlayerHealthEvent struct {
	Health float32
	Armour float32
}

type PlayerLifeState added in v0.1.4

type PlayerLifeState string

PlayerLifeState is the protocol-visible lifecycle of the local player. Internal transaction phases deliberately remain private: plugins should see stable semantic states, while the client can still distinguish a request being written from a spawn already being committed.

const (
	PlayerLifeStateClassSelection      PlayerLifeState = "class_selection"
	PlayerLifeStateSpawnReady          PlayerLifeState = "spawn_ready"
	PlayerLifeStateSpawnRequestPending PlayerLifeState = "spawn_request_pending"
	PlayerLifeStateSpawned             PlayerLifeState = "spawned"
	PlayerLifeStateDead                PlayerLifeState = "dead"
)

type PlayerLifeStateEvent added in v0.1.4

type PlayerLifeStateEvent struct {
	State PlayerLifeState
}

type RespawnPolicy added in v0.1.4

type RespawnPolicy uint8

RespawnPolicy controls who drives the spawn transaction after class data or death is available. The protocol client remains usable in manual mode, while the application can opt into Android-like automatic spawning.

const (
	RespawnPolicyManual RespawnPolicy = iota
	RespawnPolicyAutomatic
)

type SpawnInfo

type SpawnInfo struct {
	Team     uint8
	Skin     int32
	Position [3]float32
	Rotation float32
}

func (SpawnInfo) PlayerEvent

func (s SpawnInfo) PlayerEvent() PlayerEvent

type SpawnedEvent added in v0.1.4

type SpawnedEvent struct {
	Health float32
	Armour float32
}

type TextDrawEvent

type TextDrawEvent struct {
	ID                                                     uint16
	Text                                                   string
	Style, Flags, Shadow, Outline, Selectable              uint8
	LetterColor, BoxColor, BackgroundColor                 uint32
	X, Y, LetterWidth, LetterHeight, LineWidth, LineHeight float32
	ModelID                                                uint16
}

type VehicleEntryMode added in v0.1.4

type VehicleEntryMode string

VehicleEntryMode controls how the headless client transitions from on-foot to vehicle synchronization. Direct is the historical behavior: the local state changes as soon as RPC_EnterVehicle is sent. Normal preserves the network sequence of a regular client: RPC_EnterVehicle marks the beginning of entry, on-foot sync continues during the entry task, and vehicle sync starts only after the entry phase completes.

const (
	VehicleEntryDirect VehicleEntryMode = "direct"
	VehicleEntryNormal VehicleEntryMode = "normal"
)

func NormalizeVehicleEntryMode added in v0.1.4

func NormalizeVehicleEntryMode(mode VehicleEntryMode) (VehicleEntryMode, error)

NormalizeVehicleEntryMode validates an entry mode and maps the empty value to the backward-compatible direct mode.

type VehicleEvent

type VehicleEvent struct {
	ID              uint16
	ModelID         int32
	X, Y, Z, Health float32
	Angle           float32
}

type VehicleHealthEvent added in v0.1.4

type VehicleHealthEvent struct {
	ID     uint16
	Health float32
}

type VehicleStateEvent

type VehicleStateEvent struct {
	InVehicle bool
	Passenger bool
	VehicleID uint16
	Health    float32
	HasHealth bool
}

Jump to

Keyboard shortcuts

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