server

package
Version: v0.0.0-...-a54a77b Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2014 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ID_Welcome    = PacketID(iota)
	ID_EnterGame  = PacketID(iota)
	ID_LoginError = PacketID(iota)

	ID_SpawnPlayer     = PacketID(iota)
	ID_PlayerInfo      = PacketID(iota)
	ID_PlayerTransform = PacketID(iota)
	ID_RemovePlayer    = PacketID(iota)
	ID_PlayerMove      = PacketID(iota)

	ID_Respawn = PacketID(iota)
)

Variables

This section is empty.

Functions

func OnPlayerMove

func OnPlayerMove(c *Client, p Packet)

func OnPlayerRespawn

func OnPlayerRespawn(c *Client, p Packet)

func OnWelcomePacket

func OnWelcomePacket(c *Client, p Packet)

func PlayerEnterGame

func PlayerEnterGame(c *Client)

func StartServer

func StartServer()

func TestGenerator

func TestGenerator()

Types

type Client

type Client struct {
	Socket   *net.TCPConn
	ID       ID
	Name     string
	X, Y     float32
	Rotation float32

	Decoder *gob.Decoder
	Encoder *gob.Encoder

	Disconnected int32
}

func (*Client) HandlePacket

func (c *Client) HandlePacket(p Packet)

func (*Client) OnPanic

func (c *Client) OnPanic()

func (*Client) Run

func (c *Client) Run()

func (*Client) Send

func (c *Client) Send(p Packet)

type EnterGame

type EnterGame struct {
	PlayerID ID
	Name     string
}

func (EnterGame) ID

func (e EnterGame) ID() PacketID

type ID

type ID int32

type IDGenerator

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

func NewIDGenerator

func NewIDGenerator(buffer int, threadSafe bool) *IDGenerator

func (*IDGenerator) NextID

func (gen *IDGenerator) NextID() ID

func (*IDGenerator) PutID

func (gen *IDGenerator) PutID(id ID)

type Job

type Job func()

type LoginError

type LoginError struct {
	Error string
}

func (LoginError) ID

func (e LoginError) ID() PacketID

type Packet

type Packet interface {
	ID() PacketID
}

func NewEnterGame

func NewEnterGame(id ID, name string) Packet

func NewLoginError

func NewLoginError(error string) Packet

func NewPlayerMove

func NewPlayerMove(transfrom PlayerTransform) Packet

func NewPlayerRespawn

func NewPlayerRespawn() Packet

func NewRemovePlayer

func NewRemovePlayer(playerID ID) Packet

func NewSpawnPlayer

func NewSpawnPlayer(playerTransform PlayerTransform, playerInfo PlayerInfo) Packet

func NewWelcome

func NewWelcome(name string) Packet

type PacketID

type PacketID int16

type PlayerInfo

type PlayerInfo struct {
	PlayerID ID
	Name     string
}

func NewPlayerInfo

func NewPlayerInfo(playerID ID, name string) PlayerInfo

func (PlayerInfo) ID

func (s PlayerInfo) ID() PacketID

type PlayerMove

type PlayerMove struct {
	PlayerTransform
}

func (PlayerMove) ID

func (s PlayerMove) ID() PacketID

type PlayerRespawn

type PlayerRespawn struct {
}

func (PlayerRespawn) ID

func (s PlayerRespawn) ID() PacketID

type PlayerTransform

type PlayerTransform struct {
	PlayerID ID
	X, Y     float32
	Rotation float32
}

func NewPlayerTransform

func NewPlayerTransform(playerID ID, X, Y, Rotation float32) PlayerTransform

func (PlayerTransform) ID

func (s PlayerTransform) ID() PacketID

type RemovePlayer

type RemovePlayer struct {
	PlayerID ID
}

func (RemovePlayer) ID

func (s RemovePlayer) ID() PacketID

type Server

type Server struct {
	Socket  *net.TCPListener
	Clients map[ID]*Client
	Jobs    chan Job
	IDGen   *IDGenerator
}
var MainServer *Server

func (*Server) Run

func (s *Server) Run()

type SpawnPlayer

type SpawnPlayer struct {
	PlayerTransform
	PlayerInfo
}

func (SpawnPlayer) ID

func (s SpawnPlayer) ID() PacketID

type Welcome

type Welcome struct {
	Name string
}

func (Welcome) ID

func (w Welcome) ID() PacketID

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL