import "github.com/jdonkervliet/opencraft-go/cmd/opencraft-go"
var blocks string
func main
func main()
type GameData
GameData represents the types of objects that be present in the game such as blocks and items. These can be specified in yaml format to make them easy to change.
type GameData struct {
Blocks []struct {
Name string `yaml:"name"`
Color string `yaml:"color"`
} `yaml:"blocks"`
Items []struct {
Name string `yaml:"name"`
} `yaml:"items"`
}
import "github.com/jdonkervliet/opencraft-go/server"
- type Game
- func NewGame() *Game
- func (g *Game) HandleMessages()
- func (g *Game) IsRunning() bool
- func (g *Game) Start() error
- func (g *Game) Stop()
- func (g *Game) Update()
- func (g *Game) handleIWantChangeBlock(msg *protos.IWantChangeBlock, conn net.Conn)
- func (g *Game) handleIWantColumn(msg *protos.IWantColumn, conn net.Conn)
- func (g *Game) handleIWantMovePlayer(msg *protos.IWantMovePlayer, conn net.Conn)
- func (g *Game) handleIWantPlayer(msg *protos.IWantPlayer, conn net.Conn)
- func (g *Game) handleMessage(msg *IncomingMessage)
- type IncomingMessage
- type ServerPlayer
type Game
Game is the root struct of a single game instance.
type Game struct {
World model.World
Players map[uint32]*ServerPlayer
TickDuration time.Duration
running bool
msgBuf chan *IncomingMessage
s net.Listener
}
func NewGame
func NewGame() *Game
The default constructor for the Game struct.
func (*Game) HandleMessages
func (g *Game) HandleMessages()
Handles incoming messages from clients. This method first checks the length of the message queue and then processes exactly that number of messages. As such, the method is guaranteed to terminate, even when the incoming message rate exceeds the message processing rate.
func (*Game) IsRunning
func (g *Game) IsRunning() bool
Returns true iff the game is running and has not been instructed to stop.
func (*Game) Start
func (g *Game) Start() error
Starts the game server. Specifically, starts listening on a socket for incoming client messages and enqueues them. This function does not start simulating the game world and does not process incoming messages, that needs to be done seperately by the caller of this function by calling Game.Update().
func (*Game) Stop
func (g *Game) Stop()
Stops the game. The game stops sending and receiving messages.
func (*Game) Update
func (g *Game) Update()
Updates the game by one step.
func (*Game) handleIWantChangeBlock
func (g *Game) handleIWantChangeBlock(msg *protos.IWantChangeBlock, conn net.Conn)
Handles the IWantChangeBlock message from the client. Tries to set the block at the specified location to the specified type. It does not send a reply.
func (*Game) handleIWantColumn
func (g *Game) handleIWantColumn(msg *protos.IWantColumn, conn net.Conn)
Handles the IWantColumn message from the client. Currently, the game does not keep track of the world and simply generates a column with a flat 1-block thick layer of non-air blocks in a ColumnData message. TODO the game should generate and keep track of the world.
func (*Game) handleIWantMovePlayer
func (g *Game) handleIWantMovePlayer(msg *protos.IWantMovePlayer, conn net.Conn)
Handles the IWantMovePlayer message from the client. This moves a player avatar to a new position in the world. Currently, the game performs no checks whatsoever if this move is valid. It simply accepts the new position. It does not send a reply.
func (*Game) handleIWantPlayer
func (g *Game) handleIWantPlayer(msg *protos.IWantPlayer, conn net.Conn)
Handles the IWantPlayer message sent by a client. This message is sent when a client initially connects to the server and wants to log in. The client can request to log in with a specific player ID by sending a value > 0. If the received player ID is 0, the game automatically assigns a player ID. Clients logged in with the same player ID control the same player/avatar. On a successful login, the server replies to the client with a YouArePlayer message telling the client their player ID and avatar location.
func (*Game) handleMessage
func (g *Game) handleMessage(msg *IncomingMessage)
Handles a single incoming message from a client and sends a reply if necessary.
type IncomingMessage
IncomingMessage is a struct used to wrap messages that come in from clients. In includes the client connection (to enable sending a reply) and the original protobuf message.
type IncomingMessage struct {
Connection net.Conn
Data *protos.ToServer
}
type ServerPlayer
ServerPlayer represents a player on the server. It contains the data associated with the player's avatar and a slice of connections. We allow a slice of connections, instead of a single connection, to enable a player to log simultaneously via multiple connections to facilitate easy handover when a player switches connection, for example when switching between a regular client to a thin client.
type ServerPlayer struct {
model.Player
controllers []net.Conn
}
func newServerPlayer
func newServerPlayer() *ServerPlayer
The default constructor for the ServerPlayer struct.
Generated by gomarkdoc