Documentation ¶
Index ¶
- Variables
- func AppendLog(filename string, fields []interface{}) (err error)
- func DebugExit()
- func TopPlayers(players world.PlayerSet, count int) []world.PlayerData
- type AddToTeam
- type Aim
- type BotClient
- type Chat
- type ChatHistory
- type Client
- type ClientData
- type ClientList
- type Cloud
- type Contact
- type CreateTeam
- type Fire
- type Hub
- func (h *Hub) Cloud()
- func (h *Hub) Debug()
- func (h *Hub) Despawn()
- func (h *Hub) GetTerrain() *terrain.Terrain
- func (h *Hub) Leaderboard()
- func (h *Hub) Physics(ticks world.Ticks)
- func (h *Hub) ReceiveSigned(in SignedInbound, important bool)
- func (h *Hub) Register(client Client)
- func (h *Hub) Run()
- func (h *Hub) ServeIndex(w http.ResponseWriter, r *http.Request)
- func (h *Hub) ServeSocket(w http.ResponseWriter, r *http.Request)
- func (h *Hub) SnapshotTerrain()
- func (h *Hub) Spawn()
- func (h *Hub) Unregister(client Client)
- func (h *Hub) Update()
- type HubOptions
- type IDContact
- type Inbound
- type InvalidInbound
- type Leaderboard
- type Manual
- type Message
- type Offline
- func (offline Offline) FlushStatistics() error
- func (offline Offline) IncrementNewPlayerStatistic()
- func (offline Offline) IncrementPlayerStatistic()
- func (offline Offline) IncrementPlaysStatistic()
- func (offline Offline) String() string
- func (offline Offline) UpdateLeaderboard(playerScores map[string]int) error
- func (offline Offline) UpdatePeriod() time.Duration
- func (offline Offline) UpdateServer(players int) error
- func (offline Offline) UploadTerrainSnapshot(data []byte) error
- type Outbound
- type Pay
- type Player
- type RemoveFromTeam
- type SendChat
- type SignedInbound
- type SocketClient
- type Spawn
- type Spoke
- type SpokeOptions
- type Target
- type Team
- type Trace
- type Update
- type Upgrade
Constants ¶
This section is empty.
Variables ¶
var JSON = json
Export temporarily
Functions ¶
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.
type BotClient ¶
type BotClient struct { ClientData // contains filtered or unexported fields }
func (*BotClient) Data ¶
func (bot *BotClient) Data() *ClientData
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
}
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 ¶
ClientData is the data all clients must have.
type ClientList ¶
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) 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
type Fire ¶
type Fire struct { world.Guidance PositionTarget world.Vec2f `json:"positionTarget"` Index int `json:"index"` // Armament index }
Fire fires an armament
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub maintains the set of active clients and broadcasts messages to the clients.
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 (*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) ReceiveSigned ¶
func (h *Hub) ReceiveSigned(in SignedInbound, important bool)
May not use important=true when called on hub goroutine
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 ¶
type HubOptions ¶
Hub maintains the set of active clients and broadcasts messages to the clients.
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"
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
type Message ¶
type Message struct {
Data interface{}
}
func (Message) MarshalJSON ¶
Overridden by jsoniter
func (*Message) UnmarshalJSON ¶
Overridden by jsoniter
type Offline ¶
type Offline struct{}
func (Offline) FlushStatistics ¶
func (Offline) IncrementNewPlayerStatistic ¶
func (offline Offline) IncrementNewPlayerStatistic()
func (Offline) IncrementPlayerStatistic ¶
func (offline Offline) IncrementPlayerStatistic()
func (Offline) IncrementPlaysStatistic ¶
func (offline Offline) IncrementPlaysStatistic()
func (Offline) UpdateLeaderboard ¶
func (Offline) UpdatePeriod ¶
func (Offline) UpdateServer ¶
func (Offline) UploadTerrainSnapshot ¶
type Outbound ¶
type Outbound interface {
// Pool returns the contents of Outbound to their sync.Pool
Pool()
}
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 ¶
RemoveFromTeam either kicks someone from your team if you are Owner or leaves your team.
type SignedInbound ¶
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.
type Spoke ¶
type Spoke struct {
// contains filtered or unexported fields
}
func NewSpoke ¶
func NewSpoke(options SpokeOptions) *Spoke
func (*Spoke) GetTerrain ¶
func (*Spoke) ReceiveSigned ¶
func (s *Spoke) ReceiveSigned(in SignedInbound)
func (*Spoke) Unregister ¶
type SpokeOptions ¶
type Target ¶
type Target struct { *Contact // contains filtered or unexported fields }
Target is a contact that is closest or furthest
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.