network

package
v0.0.0-...-0eba227 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2018 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IDMAP map[int]bool

IDMAP is a map of current in use IDs... this is overkill for this game, but it's here

Functions

func CreateNewID

func CreateNewID() int

CreateNewID returns a unique ID for a new player

func HandleMessages

func HandleMessages(p *Player, s *GameServer)

func Read

func Read(c *net.TCPConn, buffer []byte) bool

func Write

func Write(p *Player) bool

Types

type Command

type Command struct {
	Row, Col       int
	Name           string
	Message        string
	Rooms          []int
	CommType       CommandType
	ShipPlacements []*PlaceShipType
}

type CommandType

type CommandType int
const (
	CommandConnected CommandType = iota
	CommandAttack
	CommandDisconnected
	CommandSetTheBoard
	CommandHello
	CommandFull
	CommandHealthCheck
	CommandJoinRoom
	CommandListRooms
	CommandLeaveRoom
	CommandRoomFull
	CommandYouStart
)

type GameServer

type GameServer struct {
	Players []*Player
	// contains filtered or unexported fields
}

GameServer is our main netorking entity

func CreateGameServer

func CreateGameServer(port string) *GameServer

CreateGameServer returns a pointer to a GameServer struct

func (*GameServer) CheckPlayers

func (s *GameServer) CheckPlayers(t time.Time)

func (*GameServer) CreatePlayer

func (s *GameServer) CreatePlayer(conn *net.TCPConn) bool

CreatePlayer adds the player to the slice of players

func (*GameServer) Run

func (s *GameServer) Run()

Run the GameServer

func (*GameServer) ShutDown

func (s *GameServer) ShutDown()

type PlaceShipType

type PlaceShipType struct {
	Row, Col   int
	Vertical   bool
	ShipLength int
	ShipType   string
}

type Player

type Player struct {
	ID int
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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