server

package
v0.0.0-...-9e256ac Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: AGPL-3.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JSON = json

Export temporarily

Functions

func AppendLog

func AppendLog(filename string, fields []interface{}) (err error)

func DebugExit

func DebugExit()

Logs and saves the panic info, exits

func TopPlayers

func TopPlayers(players world.PlayerSet, count int) []world.PlayerData

TopPlayers Top count players with highest score of a world.PlayerSet.

Types

type AddToTeam

type AddToTeam struct {
	TeamID   world.TeamID   `json:"teamID"`
	PlayerID world.PlayerID `json:"playerID"`
}

AddToTeam allows Owners to add members that are requesting and outsiders to request to join.

func (AddToTeam) Process

func (data AddToTeam) Process(h *Hub, _ Client, player *Player)

type Aim

type Aim struct {
	Target world.Vec2f `json:"target"`
}

Aim sets your ship's aim target (for turrets, aircraft, etc.)

func (Aim) Process

func (data Aim) Process(h *Hub, _ Client, player *Player)

type BotClient

type BotClient struct {
	ClientData
	// contains filtered or unexported fields
}

func (*BotClient) Bot

func (bot *BotClient) Bot() bool

func (*BotClient) Close

func (bot *BotClient) Close()

func (*BotClient) Data

func (bot *BotClient) Data() *ClientData

func (*BotClient) Destroy

func (bot *BotClient) Destroy()

func (*BotClient) Init

func (bot *BotClient) Init()

func (*BotClient) Send

func (bot *BotClient) Send(out Outbound)

type Chat

type Chat struct {
	world.PlayerData
	Message string `json:"message"`
}

Chat is a chat message.

type ChatHistory

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

func (*ChatHistory) Update

func (hist *ChatHistory) Update(message string, allowSpam bool) (string, bool)

type Client

type Client interface {
	// Init is called once called by hub goroutine when the client is registered.
	// client.Data().Hub will be set by the time this is called
	Init()

	// Close is called by (only) the hub goroutine when the client is unregistered.
	Close()

	// Send is how the server sends a message to the client.
	Send(out Outbound)

	// Destroy marks the client for destruction. It must call hub.Unregister() only once (no matter how many
	// times it is called; use a sync.Once if necessary). It may be called anywhere.
	Destroy()

	// Is this a bot or real player?
	Bot() bool

	// Data allows the Client to be added to a double-linked list.
	Data() *ClientData
}

Client is an actor on the Hub.

type ClientData

type ClientData struct {
	Player   Player
	Hub      *Hub
	Previous Client
	Next     Client
}

ClientData is the data all clients must have.

type ClientList

type ClientList struct {
	First Client
	Last  Client
	Len   int
}

ClientList is a doubly-linked list of Clients. It can be iterated like this: for client := list.First; client != nil; client = client.Data().Next {} Or to remove all iterated items like this: for client := list.First; client != nil; client = list.Remove(client) {}

func (*ClientList) Add

func (list *ClientList) Add(client Client)

Add adds a Client to the list.

func (*ClientList) Remove

func (list *ClientList) Remove(client Client) (next Client)

Remove removes a Client from the list. Returns the next element of the list.

type Cloud

type Cloud interface {
	fmt.Stringer
	UpdateServer(players int) error
	IncrementPlayerStatistic()
	IncrementNewPlayerStatistic()
	IncrementPlaysStatistic()
	FlushStatistics() error
	UpdateLeaderboard(playerScores map[string]int) error
	UploadTerrainSnapshot(data []byte) error // takes an encoded PNG
	UpdatePeriod() time.Duration
}

A nil cloud is valid to use with any methods (acts as a no-op) This just means server is in offline mode

type Contact

type Contact struct {
	world.Guidance
	world.IDPlayerData
	world.Transform
	ArmamentConsumption []world.Ticks    `json:"armamentConsumption,omitempty"`
	TurretAngles        []world.Angle    `json:"turretAngles,omitempty"`
	Friendly            bool             `json:"friendly,omitempty"`
	TeamFull            bool             `json:"teamFull,omitempty"`
	EntityType          world.EntityType `json:"type,omitempty"`
	Altitude            float32          `json:"altitude,omitempty"`
	Damage              float32          `json:"damage,omitempty"`
	Uncertainty         float32          `json:"uncertainty"`
}

Contact is a view of a world.Entity from an observer. Guidance is not always set, but still marshaled as zeros. TODO: Marshal fake data that represents observable angular velocity without revealing the exact target direction

type CreateTeam

type CreateTeam struct {
	Name string `json:"name"`
}

CreateTeam creates a new team

func (CreateTeam) Process

func (data CreateTeam) Process(h *Hub, _ Client, player *Player)

type Fire

type Fire struct {
	world.Guidance
	PositionTarget world.Vec2f `json:"positionTarget"`
	Index          int         `json:"index"` // Armament index
}

Fire fires an armament

func (Fire) Process

func (data Fire) Process(h *Hub, _ Client, player *Player)

type Hub

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

Hub maintains the set of active clients and broadcasts messages to the clients.

func NewHub

func NewHub(options HubOptions) *Hub

c can be nil

func (*Hub) Cloud

func (h *Hub) Cloud()

func (*Hub) Debug

func (h *Hub) Debug()

Debug prints debugging info to console and tmp files.

func (*Hub) Despawn

func (h *Hub) Despawn()

Despawn removes pending players. The purpose is to make removing k players O(n + k) instead of O(n * k) by removing multiple at once.

func (*Hub) GetTerrain

func (h *Hub) GetTerrain() *terrain.Terrain

func (*Hub) Leaderboard

func (h *Hub) Leaderboard()

Leaderboard sends Leaderboard message to each Client. Its run in parallel because it doesn't write to World

func (*Hub) Physics

func (h *Hub) Physics(ticks world.Ticks)

func (*Hub) ReceiveSigned

func (h *Hub) ReceiveSigned(in SignedInbound, important bool)

May not use important=true when called on hub goroutine

func (*Hub) Register

func (h *Hub) Register(client Client)

func (*Hub) Run

func (h *Hub) Run()

func (*Hub) ServeIndex

func (h *Hub) ServeIndex(w http.ResponseWriter, r *http.Request)

func (*Hub) ServeSocket

func (h *Hub) ServeSocket(w http.ResponseWriter, r *http.Request)

func (*Hub) SnapshotTerrain

func (h *Hub) SnapshotTerrain()

Saves a snapshot of the terrain to a tmp directory

func (*Hub) Spawn

func (h *Hub) Spawn()

Spawn spawns non-boat/weapon entities such as collectibles and obstacles.

func (*Hub) Unregister

func (h *Hub) Unregister(client Client)

func (*Hub) Update

func (h *Hub) Update()

Update sends an Update message to each Client. It's run in parallel because it doesn't write to World

type HubOptions

type HubOptions struct {
	Cloud            Cloud
	MinClients       int
	MaxBotSpawnLevel uint8
	Auth             string
}

Hub maintains the set of active clients and broadcasts messages to the clients.

type IDContact

type IDContact struct {
	Contact
	world.EntityID
}

IDContact is a Contact paired with a world.EntityID for efficiency.

type Inbound

type Inbound interface {
	Process(hub *Hub, client Client, player *Player)
}

type InvalidInbound

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

InvalidInbound means invalid message type from client (possibly out of date). NOTE: Do not register, otherwise client could send type "invalidInbound"

func (InvalidInbound) Process

func (data InvalidInbound) Process(_ *Hub, _ Client, _ *Player)

type Leaderboard

type Leaderboard struct {
	Leaderboard []world.PlayerData `json:"leaderboard"`
}

Leaderboard is the top 10 players with the most score.

func (Leaderboard) Pool

func (leaderboard Leaderboard) Pool()

type Manual

type Manual struct {
	world.Guidance
	Active                bool           `json:"active"`
	AngularVelocityTarget *world.Angle   `json:"angVelTarget"` // angular velocity must be calculated on the server to avoid oscillations
	AltitudeTarget        *float32       `json:"altitudeTarget"`
	AimTarget             world.Vec2f    `json:"aimTarget"`
	EntityID              world.EntityID `json:"entityID"` // Ignored for now, and completely optional. This may be used in the future to allow you to drive your weapons manually.
}

Manual controls your ship's Guidance and optionally sets a TurretTarget. TODO embed AimTurrets

func (Manual) Process

func (data Manual) Process(h *Hub, c Client, player *Player)

type Message

type Message struct {
	Data interface{}
}

func (Message) MarshalJSON

func (message Message) MarshalJSON() ([]byte, error)

Overridden by jsoniter

func (*Message) UnmarshalJSON

func (message *Message) UnmarshalJSON([]byte) error

Overridden by jsoniter

type Offline

type Offline struct{}

func (Offline) FlushStatistics

func (offline Offline) FlushStatistics() error

func (Offline) IncrementNewPlayerStatistic

func (offline Offline) IncrementNewPlayerStatistic()

func (Offline) IncrementPlayerStatistic

func (offline Offline) IncrementPlayerStatistic()

func (Offline) IncrementPlaysStatistic

func (offline Offline) IncrementPlaysStatistic()

func (Offline) String

func (offline Offline) String() string

func (Offline) UpdateLeaderboard

func (offline Offline) UpdateLeaderboard(playerScores map[string]int) error

func (Offline) UpdatePeriod

func (offline Offline) UpdatePeriod() time.Duration

func (Offline) UpdateServer

func (offline Offline) UpdateServer(players int) error

func (Offline) UploadTerrainSnapshot

func (offline Offline) UploadTerrainSnapshot(data []byte) error

type Outbound

type Outbound interface {
	// Pool returns the contents of Outbound to their sync.Pool
	Pool()
}

type Pay

type Pay struct {
	Position world.Vec2f `json:"position"`
}

Drop gold coins to transfer score (within limits)

func (Pay) Process

func (data Pay) Process(h *Hub, _ Client, player *Player)

type Player

type Player struct {
	world.Player
	ChatHistory ChatHistory
	FPS         float32

	// Optimizations
	TerrainArea world.AABB
}

Player is an extension of world.Player with extra data

type RemoveFromTeam

type RemoveFromTeam struct {
	PlayerID world.PlayerID `json:"playerID"`
}

RemoveFromTeam either kicks someone from your team if you are Owner or leaves your team.

func (RemoveFromTeam) Process

func (data RemoveFromTeam) Process(h *Hub, _ Client, player *Player)

type SendChat

type SendChat struct {
	Message string `json:"message"`
	Team    bool   `json:"team"`
}

SendChat sends a chat message to global chat.

func (SendChat) Process

func (data SendChat) Process(h *Hub, client Client, player *Player)

type SignedInbound

type SignedInbound struct {
	Client Client
	Inbound
}

type SocketClient

type SocketClient struct {
	ClientData
	// contains filtered or unexported fields
}

SocketClient is a middleman between the websocket connection and the hub.

func NewSocketClient

func NewSocketClient(conn *websocket.Conn, ipStr string) *SocketClient

Create a SocketClient from a connection

func (*SocketClient) Bot

func (client *SocketClient) Bot() bool

func (*SocketClient) Close

func (client *SocketClient) Close()

func (*SocketClient) Data

func (client *SocketClient) Data() *ClientData

func (*SocketClient) Destroy

func (client *SocketClient) Destroy()

func (*SocketClient) Init

func (client *SocketClient) Init()

func (*SocketClient) Send

func (client *SocketClient) Send(message Outbound)

type Spawn

type Spawn struct {
	Name string           `json:"name"`
	Type world.EntityType `json:"type"`
	Auth string           `json:"auth"`   // Auth unlocks certain names and removes some checks
	Code world.TeamCode   `json:"invite"` // Code automatically adds the Player to the team with that code
	New  bool             `json:"new"`    // Whether first time playing
}

Spawn spawns your ship.

func (Spawn) Process

func (data Spawn) Process(h *Hub, client Client, player *Player)

type Spoke

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

func NewSpoke

func NewSpoke(options SpokeOptions) *Spoke

func (*Spoke) GetTerrain

func (s *Spoke) GetTerrain() terrain.Terrain

func (*Spoke) ReceiveSigned

func (s *Spoke) ReceiveSigned(in SignedInbound)

func (*Spoke) Register

func (s *Spoke) Register(client Client) (err error)

func (*Spoke) Unregister

func (s *Spoke) Unregister(client Client)

type SpokeOptions

type SpokeOptions struct {
	URL url.URL
}

type Target

type Target struct {
	*Contact
	// contains filtered or unexported fields
}

Target is a contact that is closest or furthest

func (*Target) Closest

func (t *Target) Closest(contact *Contact, distanceSquared float32)

func (*Target) Found

func (t *Target) Found() bool

type Team

type Team struct {
	world.Team
	Chats []Chat
}

Team is an extension of world.Team with extra data

type Trace

type Trace struct {
	FPS float32 `json:"fps"`
}

Trace sends debug info.

func (Trace) Process

func (trace Trace) Process(_ *Hub, _ Client, p *Player)

type Update

type Update struct {
	Chats        []Chat               `json:"chats,omitempty"`
	Contacts     []IDContact          `json:"contacts,omitempty"`
	TeamChats    []Chat               `json:"teamChats,omitempty"`
	TeamCode     world.TeamCode       `json:"teamInvite,omitempty"`
	TeamMembers  []world.IDPlayerData `json:"teamMembers,omitempty"`
	TeamRequests []world.IDPlayerData `json:"teamJoinRequests,omitempty"`
	DeathReason  world.DeathReason    `json:"deathReason,omitempty"`
	Terrain      *terrain2.Data       `json:"terrain,omitempty"`

	// Put smaller fields here for packing
	PlayerID    world.PlayerID `json:"playerID,omitempty"`
	EntityID    world.EntityID `json:"entityID,omitempty"`
	WorldRadius float32        `json:"worldRadius,omitempty"`
}

Update is a view of Contacts, TeamMembers, and Terrain. It is dependant special marshaller on Update.Contacts to marshal as a map.

func NewUpdate

func NewUpdate() *Update

func (*Update) Pool

func (update *Update) Pool()

Pool Uses pointers for reuse in pool

type Upgrade

type Upgrade struct {
	Type world.EntityType `json:"type"`
}

Upgrade upgrades your ship.

func (Upgrade) Process

func (data Upgrade) Process(h *Hub, _ Client, player *Player)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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