cible

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2022 License: MIT Imports: 18 Imported by: 0

README

cible - a multi user game

In cible, players connect to a server and embark on adventures as different characters. It's a terminal based multi user dungeon(MUD) game, where you control your character with the keyboard.

Quick start

$ go install github.com/gregoryv/cible/cmd/cible@latest
$ cible -h
Usage: cible [OPTIONS]

Options
    -b, --bind : ":8089"
    -d, --debug
    -s, --server
    -h, --help

To play a local game start a server first

$ cible -s

then in another terminal run the client

$ USER=majorPain cible

Download

Binaries are available at https://www.7de.se/dl

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTextFormat = &TextFormat{
	cols: 72,
}

Functions

func Boxed added in v0.4.0

func Boxed(p []byte, width int) []byte

func Center added in v0.4.0

func Center(p interface{}) []byte

func CenterIn added in v0.4.0

func CenterIn(p []byte, width int) []byte

func Decode

func Decode(v interface{}, m *Message) error

func Indent added in v0.4.0

func Indent(p interface{}) []byte

Types

type Area

type Area struct {
	Ident
	Title
	Tiles
}

func Spaceport added in v0.4.0

func Spaceport() *Area

func (*Area) AddTile added in v0.4.0

func (a *Area) AddTile(tiles ...*Tile)

func (*Area) Tile

func (a *Area) Tile(id Ident) (*Tile, error)

type Areas

type Areas []*Area

func (Areas) Area

func (me Areas) Area(id Ident) (*Area, error)

type Bot

type Bot struct{}

type BufIO

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

func NewBufIO

func NewBufIO() *BufIO

func (*BufIO) Read

func (me *BufIO) Read(p []byte) (int, error)

func (*BufIO) Write

func (me *BufIO) Write(p []byte) (int, error)

type Character

type Character struct {
	Ident
	Name
	Position
	IsBot
	*Inventory
	// contains filtered or unexported fields
}

func (*Character) Transmit

func (me *Character) Transmit(m Message) error

func (*Character) TransmitOthers

func (me *Character) TransmitOthers(g *Game, m Message) error

type Characters

type Characters interface {
	Character(Ident) (*Character, error)
	Add(*Character)
	Remove(Ident)
	Len() int
	At(Position) []*Character
}

type CharactersMap

type CharactersMap struct {
	Index map[Ident]*Character
	// contains filtered or unexported fields
}

func NewCharactersMap

func NewCharactersMap() *CharactersMap

func (*CharactersMap) Add

func (me *CharactersMap) Add(c *Character)

func (*CharactersMap) At

func (me *CharactersMap) At(p Position) []*Character

func (*CharactersMap) Character

func (me *CharactersMap) Character(id Ident) (*Character, error)

func (*CharactersMap) Len

func (me *CharactersMap) Len() int

func (*CharactersMap) Remove

func (me *CharactersMap) Remove(id Ident)

type Client

type Client struct {
	logger.Logger
	Host string

	net.Conn

	Out chan Message
	In  chan Message
}

func NewClient

func NewClient() *Client

func (*Client) Connect

func (me *Client) Connect(ctx context.Context) error

type Decoder

type Decoder interface {
	Decode(v any) error
}

type Direction

type Direction int
const (
	N Direction = iota
	NE
	E
	SE
	S
	SW
	W
	NW
)

func (Direction) String

func (i Direction) String() string

type Encoder

type Encoder interface {
	Encode(v any) error
}

type Event

type Event interface{}

func NewEvent added in v0.2.0

func NewEvent(name string) (Event, bool)

NewEvent returns a new instance of the named event. Returns false if the event has not been registered.

type EventApproach added in v0.4.0

type EventApproach struct {
	Name
}

when character enters a tile

type EventDisconnect added in v0.3.0

type EventDisconnect struct {
	// set by server
	Ident
}

type EventGoAway added in v0.4.0

type EventGoAway struct {
	Name
}

type EventInventoryUpdate added in v0.5.0

type EventInventoryUpdate struct {
	*Inventory
}

type EventJoin

type EventJoin struct {
	// set by game
	Ident
	Name
}

type EventJoinGame added in v0.5.0

type EventJoinGame struct {
	Player
	// set by game
	*Character

	Title // of the area
	// contains filtered or unexported fields
}

type EventLeave

type EventLeave struct {
	// set by server
	Ident

	// set by game
	Name
}

type EventLook added in v0.2.0

type EventLook struct {
	// set by server
	Ident // character who is looking

	Tile

	Loose Items
}

type EventMove added in v0.3.0

type EventMove struct {
	Direction

	// set by server
	Ident

	// set by game
	Position
	Title // of the area
	*Tile
	Body []byte
}

Your character EventMove in the game

func (*EventMove) String added in v0.3.0

func (me *EventMove) String() string

type EventPickup added in v0.5.0

type EventPickup struct {
	Ident
	Item
}

type EventSay

type EventSay struct {
	Text string

	// set by server, character who is speaking
	Ident

	// set by game
	Name
}

type EventStopGame

type EventStopGame struct{}

type Game

type Game struct {
	World
	Characters

	MaxTasks     int
	LogAllEvents bool

	logger.Logger
	// contains filtered or unexported fields
}

func NewGame

func NewGame() *Game

func (*Game) AffectGame added in v0.2.0

func (g *Game) AffectGame(e interface{}) error

func (*Game) Character

func (g *Game) Character(id Ident) (*Character, error)

Character returns a character in the game by id.

func (*Game) Do

func (g *Game) Do(e Event) error

Do enques the task and waits for it to complete

func (*Game) Enqueue

func (g *Game) Enqueue(t *Task)

func (*Game) Place

func (g *Game) Place(p Position) (a *Area, t *Tile, err error)

Place returns the position as area and tile.

func (*Game) Run

func (g *Game) Run(ctx context.Context) error

type GobProtocol

type GobProtocol struct{}

Protocol used over the wire

func (*GobProtocol) NewDecoder

func (me *GobProtocol) NewDecoder(r io.Reader) Decoder

func (*GobProtocol) NewEncoder

func (me *GobProtocol) NewEncoder(w io.Writer) Encoder

type IO

type IO io.ReadWriter

type Ident

type Ident string

func (*Ident) SetIdent added in v0.2.0

func (me *Ident) SetIdent(v string)

type Inventory added in v0.5.0

type Inventory struct {
	Items
}

func NewInventory added in v0.5.0

func NewInventory() *Inventory

func (*Inventory) AddItem added in v0.5.0

func (me *Inventory) AddItem(v Item)

type IsBot

type IsBot bool

type Item added in v0.5.0

type Item struct {
	Name
	Count uint
}

type Items added in v0.5.0

type Items []Item

type Long

type Long string

type Message

type Message struct {
	Id        string
	EventName string
	Body      []byte
}

Message is for transferring events between client and server using encoding/gob

func NewMessage

func NewMessage[T any](v *T) Message

func (*Message) CheckError

func (m *Message) CheckError() error

func (*Message) Size

func (m *Message) Size() int

func (*Message) String

func (m *Message) String() string

type Name

type Name string

func (*Name) SetName added in v0.3.0

func (me *Name) SetName(v string)
type Nav [8]Ident
func (n Nav) String() string

type Player

type Player struct {
	Name
}

type Position

type Position struct {
	Area Ident
	Tile Ident
}

func (*Position) Equal

func (p *Position) Equal(v Position) bool

type Protocol

type Protocol interface {
	NewEncoder(w io.Writer) Encoder
	NewDecoder(r io.Reader) Decoder
}

type RWCache

type RWCache struct {
	io.ReadWriter
	LastRead  []byte
	LastWrite []byte
}

func NewRWCache

func NewRWCache(rw io.ReadWriter) *RWCache

func (*RWCache) Read

func (me *RWCache) Read(p []byte) (int, error)

func (*RWCache) Write

func (me *RWCache) Write(p []byte) (int, error)

type Server

type Server struct {
	logger.Logger
	Bind            string
	MaxConnections  int // not really max allowed players, more like DOS throttling
	MaxAcceptErrors int

	net.Listener
	// contains filtered or unexported fields
}

func NewServer

func NewServer() *Server

func (*Server) Run

func (me *Server) Run(ctx context.Context, g *Game) error

type Short

type Short string

type StdIO

type StdIO struct {
	io.Reader // input
	io.Writer // output
}

func NewStdIO

func NewStdIO() *StdIO

type Task

type Task struct {
	Event
	// contains filtered or unexported fields
}

func NewTask

func NewTask(e Event) *Task

func (*Task) Done

func (me *Task) Done() error

Done blocks until event is handled, can be called multiple times.

func (*Task) String added in v0.3.0

func (me *Task) String() string

type TextFormat added in v0.4.0

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

func (*TextFormat) Center added in v0.4.0

func (f *TextFormat) Center(p []byte) []byte

func (*TextFormat) Indent added in v0.4.0

func (f *TextFormat) Indent(p []byte) []byte

func (*TextFormat) Prefix added in v0.4.0

func (f *TextFormat) Prefix(p []byte) []byte

type Tile

type Tile struct {
	Ident
	Short
	Long
	Nav
}
func (me *Tile) Link(to ...interface{})

func (*Tile) String

func (t *Tile) String() string

type Tiles

type Tiles []*Tile

type Title

type Title string

type Transceiver

type Transceiver struct {
	Encoder
	Decoder
}

func NewTransceiver

func NewTransceiver(rw io.ReadWriter, proto Protocol) *Transceiver

func (*Transceiver) Receive

func (me *Transceiver) Receive(v any) error

func (*Transceiver) Transmit

func (me *Transceiver) Transmit(v any) error

type Transmitter

type Transmitter interface {
	Transmit(any) error
}

type UI

type UI struct {
	logger.Logger
	// cache last input/output to simplify tests
	IO *RWCache

	*Character
	Location string // used in prompt
	// contains filtered or unexported fields
}

func NewUI

func NewUI() *UI

func (*UI) CID

func (me *UI) CID() Ident

func (*UI) CharacterName added in v0.4.0

func (me *UI) CharacterName() Name

func (*UI) Do

func (u *UI) Do(v string)

func (*UI) DoWait

func (u *UI) DoWait(v, duration string)

func (*UI) HandleEvent added in v0.2.0

func (u *UI) HandleEvent(e interface{})

func (*UI) OtherPlayer

func (me *UI) OtherPlayer(name Name, text string)

for notifications

func (*UI) OtherPlayerSays

func (me *UI) OtherPlayerSays(name Name, text string)

only for speach

func (*UI) Print added in v0.4.0

func (me *UI) Print(v ...interface{}) (int, error)

func (*UI) Printf added in v0.5.0

func (me *UI) Printf(format string, v ...interface{}) (int, error)

func (*UI) Println added in v0.2.0

func (me *UI) Println(v ...interface{}) (int, error)

func (*UI) Run

func (u *UI) Run(ctx context.Context) error

func (*UI) ShowIntro

func (u *UI) ShowIntro()

func (*UI) Use

func (me *UI) Use(c *Client)

func (*UI) Write

func (me *UI) Write(p []byte) (int, error)

func (*UI) WritePrompt

func (u *UI) WritePrompt()

type World

type World struct {
	Areas
}

func Earth

func Earth() World

Directories

Path Synopsis
cmd
cible
Command cibtel provides telnet access to a cible game
Command cibtel provides telnet access to a cible game

Jump to

Keyboard shortcuts

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