database

package
v0.0.0-...-1a052b4 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2015 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SET  = "$set"
	PUSH = "$push"
	PULL = "$pull"
)

MongDB operations

Variables

This section is empty.

Functions

func DeleteObject

func DeleteObject(obj datastore.Identifiable) error

func DirectionToString

func DirectionToString(dir Direction) string

func Find

func Find(t datastore.ObjectType, key string, value interface{}) []bson.ObjectId

func FindAll

func FindAll(t datastore.ObjectType) []bson.ObjectId

func Init

func Init(session Session, dbName string)

func ItemNames

func ItemNames(items []*Item) []string

func RetrieveObjects

func RetrieveObjects(t datastore.ObjectType, objects interface{}) error

func UserNames

func UserNames(users []*User) []string

Types

type Area

type Area struct {
	DbObject `bson:",inline"`

	Name   string
	ZoneId bson.ObjectId
}

func NewArea

func NewArea(name string, zone bson.ObjectId) *Area

func (*Area) GetName

func (self *Area) GetName() string

func (*Area) GetType

func (self *Area) GetType() datastore.ObjectType

func (*Area) GetZoneId

func (self *Area) GetZoneId() bson.ObjectId

func (*Area) SetName

func (self *Area) SetName(name string)

type Areas

type Areas []*Area

type Character

type Character struct {
	DbObject `bson:",inline"`
	RoomId   bson.ObjectId `bson:",omitempty"`

	Name      string
	Cash      int
	Inventory []bson.ObjectId
	Health    int
	HitPoints int
	// contains filtered or unexported fields
}

func (*Character) AddCash

func (self *Character) AddCash(amount int)

func (*Character) AddItem

func (self *Character) AddItem(item *Item)

func (*Character) GetCash

func (self *Character) GetCash() int

func (*Character) GetHealth

func (self *Character) GetHealth() int

func (*Character) GetHitPoints

func (self *Character) GetHitPoints() int

func (*Character) GetItemIds

func (self *Character) GetItemIds() []bson.ObjectId

func (*Character) GetName

func (self *Character) GetName() string

func (*Character) GetRoomId

func (self *Character) GetRoomId() bson.ObjectId

func (*Character) GetType

func (self *Character) GetType() datastore.ObjectType

func (*Character) HasItem

func (self *Character) HasItem(item *Item) bool

func (*Character) Heal

func (self *Character) Heal(hitpoints int)

func (*Character) Hit

func (self *Character) Hit(hitpoints int)

func (*Character) RemoveItem

func (self *Character) RemoveItem(item *Item)

func (*Character) SetCash

func (self *Character) SetCash(cash int)

func (*Character) SetHealth

func (self *Character) SetHealth(health int)

func (*Character) SetHitPoints

func (self *Character) SetHitPoints(hitpoints int)

func (*Character) SetName

func (self *Character) SetName(name string)

func (*Character) SetObjectType

func (self *Character) SetObjectType(t datastore.ObjectType)

Used when loading existing characters from the DB

func (*Character) SetRoomId

func (self *Character) SetRoomId(id bson.ObjectId)

type CharacterList

type CharacterList []*Character

func (CharacterList) Names

func (self CharacterList) Names() []string

type Collection

type Collection interface {
	Find(interface{}) Query
	RemoveId(interface{}) error
	Remove(interface{}) error
	DropCollection() error
	UpdateId(interface{}, interface{}) error
	UpsertId(interface{}, interface{}) error
}

type Coordinate

type Coordinate struct {
	X int
	Y int
	Z int
}

func (*Coordinate) Next

func (self *Coordinate) Next(direction Direction) Coordinate

type Database

type Database interface {
	C(string) Collection
}

type DbObject

type DbObject struct {
	Id bson.ObjectId `bson:"_id"`
	// contains filtered or unexported fields
}

func (*DbObject) Destroy

func (self *DbObject) Destroy()

func (*DbObject) GetId

func (self *DbObject) GetId() bson.ObjectId

func (*DbObject) IsDestroyed

func (self *DbObject) IsDestroyed() bool

func (*DbObject) ReadLock

func (self *DbObject) ReadLock()

func (*DbObject) ReadUnlock

func (self *DbObject) ReadUnlock()

func (*DbObject) WriteLock

func (self *DbObject) WriteLock()

func (*DbObject) WriteUnlock

func (self *DbObject) WriteUnlock()

type Direction

type Direction int
const (
	DirectionNorth     Direction = iota
	DirectionNorthEast Direction = iota
	DirectionEast      Direction = iota
	DirectionSouthEast Direction = iota
	DirectionSouth     Direction = iota
	DirectionSouthWest Direction = iota
	DirectionWest      Direction = iota
	DirectionNorthWest Direction = iota
	DirectionUp        Direction = iota
	DirectionDown      Direction = iota
	DirectionNone      Direction = iota
)

func StringToDirection

func StringToDirection(str string) Direction

func (Direction) Opposite

func (self Direction) Opposite() Direction

type Item

type Item struct {
	DbObject `bson:",inline"`

	Name string
}

func NewItem

func NewItem(name string) *Item

func (*Item) GetName

func (self *Item) GetName() string

func (*Item) GetType

func (self *Item) GetType() datastore.ObjectType

type Iterator

type Iterator interface {
	All(interface{}) error
}

type MongoCollection

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

func (MongoCollection) DropCollection

func (mc MongoCollection) DropCollection() error

func (MongoCollection) Find

func (mc MongoCollection) Find(selector interface{}) Query

func (MongoCollection) Remove

func (mc MongoCollection) Remove(selector interface{}) error

func (MongoCollection) RemoveId

func (mc MongoCollection) RemoveId(id interface{}) error

func (MongoCollection) UpdateId

func (mc MongoCollection) UpdateId(id interface{}, change interface{}) error

func (MongoCollection) UpsertId

func (mc MongoCollection) UpsertId(id interface{}, change interface{}) error

type MongoDatabase

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

func (MongoDatabase) C

func (md MongoDatabase) C(collectionName string) Collection

type MongoIterator

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

func (MongoIterator) All

func (mi MongoIterator) All(result interface{}) error

type MongoQuery

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

func (MongoQuery) Count

func (mq MongoQuery) Count() (int, error)

func (MongoQuery) Iter

func (mq MongoQuery) Iter() Iterator

func (MongoQuery) One

func (mq MongoQuery) One(result interface{}) error

type MongoSession

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

func NewMongoSession

func NewMongoSession(session *mgo.Session) *MongoSession

func (MongoSession) DB

func (ms MongoSession) DB(dbName string) Database

type NonPlayerChar

type NonPlayerChar struct {
	Character `bson:",inline"`

	Roaming      bool
	Conversation string
}

func NewNonPlayerChar

func NewNonPlayerChar(name string, roomId bson.ObjectId) *NonPlayerChar

func (*NonPlayerChar) GetConversation

func (self *NonPlayerChar) GetConversation() string

func (*NonPlayerChar) GetRoaming

func (self *NonPlayerChar) GetRoaming() bool

func (*NonPlayerChar) PrettyConversation

func (self *NonPlayerChar) PrettyConversation() string

func (*NonPlayerChar) SetConversation

func (self *NonPlayerChar) SetConversation(conversation string)

func (*NonPlayerChar) SetRoaming

func (self *NonPlayerChar) SetRoaming(roaming bool)

type NonPlayerCharList

type NonPlayerCharList []*NonPlayerChar

func (NonPlayerCharList) Characters

func (self NonPlayerCharList) Characters() CharacterList

type PlayerChar

type PlayerChar struct {
	Character `bson:",inline"`

	UserId bson.ObjectId
	// contains filtered or unexported fields
}

func NewPlayerChar

func NewPlayerChar(name string, userId bson.ObjectId, roomId bson.ObjectId) *PlayerChar

func (*PlayerChar) GetUserId

func (self *PlayerChar) GetUserId() bson.ObjectId

func (*PlayerChar) IsOnline

func (self *PlayerChar) IsOnline() bool

func (*PlayerChar) SetOnline

func (self *PlayerChar) SetOnline(online bool)

func (*PlayerChar) SetUserId

func (self *PlayerChar) SetUserId(id bson.ObjectId)

type PlayerCharList

type PlayerCharList []*PlayerChar

func (PlayerCharList) Characters

func (self PlayerCharList) Characters() CharacterList

type Query

type Query interface {
	Count() (int, error)
	One(interface{}) error
	Iter() Iterator
}

type Room

type Room struct {
	DbObject `bson:",inline"`

	ZoneId        bson.ObjectId
	AreaId        bson.ObjectId `bson:",omitempty"`
	Title         string
	Description   string
	Items         []bson.ObjectId
	Location      Coordinate
	ExitNorth     bool
	ExitNorthEast bool
	ExitEast      bool
	ExitSouthEast bool
	ExitSouth     bool
	ExitSouthWest bool
	ExitWest      bool
	ExitNorthWest bool
	ExitUp        bool
	ExitDown      bool

	Properties map[string]string
}

func NewRoom

func NewRoom(zoneId bson.ObjectId, location Coordinate) *Room

func (*Room) AddItem

func (self *Room) AddItem(item *Item)

func (*Room) GetAreaId

func (self *Room) GetAreaId() bson.ObjectId

func (*Room) GetDescription

func (self *Room) GetDescription() string

func (*Room) GetExits

func (self *Room) GetExits() []Direction

func (*Room) GetItemIds

func (self *Room) GetItemIds() []bson.ObjectId

func (*Room) GetLocation

func (self *Room) GetLocation() Coordinate

func (*Room) GetProperties

func (self *Room) GetProperties() map[string]string

func (*Room) GetProperty

func (self *Room) GetProperty(name string) string

func (*Room) GetTitle

func (self *Room) GetTitle() string

func (*Room) GetType

func (self *Room) GetType() datastore.ObjectType

func (*Room) GetZoneId

func (self *Room) GetZoneId() bson.ObjectId

func (*Room) HasExit

func (self *Room) HasExit(dir Direction) bool

func (*Room) HasItem

func (self *Room) HasItem(item *Item) bool

func (*Room) NextLocation

func (self *Room) NextLocation(direction Direction) Coordinate

func (*Room) RemoveItem

func (self *Room) RemoveItem(item *Item)

func (*Room) RemoveProperty

func (self *Room) RemoveProperty(key string)

func (*Room) SetAreaId

func (self *Room) SetAreaId(areaId bson.ObjectId)

func (*Room) SetDescription

func (self *Room) SetDescription(description string)

func (*Room) SetExitEnabled

func (self *Room) SetExitEnabled(dir Direction, enabled bool)

func (*Room) SetLocation

func (self *Room) SetLocation(location Coordinate)

func (*Room) SetProperty

func (self *Room) SetProperty(name, value string)

func (*Room) SetTitle

func (self *Room) SetTitle(title string)

func (*Room) SetZoneId

func (self *Room) SetZoneId(zoneId bson.ObjectId)

func (*Room) ToString

func (self *Room) ToString(players []*PlayerChar, npcs []*NonPlayerChar, items []*Item, area *Area) string

type Rooms

type Rooms []*Room

type Session

type Session interface {
	DB(string) Database
}

type Time

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

func GetTime

func GetTime() Time

Returns the time of day

type User

type User struct {
	DbObject `bson:",inline"`

	Name      string
	ColorMode utils.ColorMode
	Password  []byte
	// contains filtered or unexported fields
}

func NewUser

func NewUser(name string, password string) *User

func (*User) GetColorMode

func (self *User) GetColorMode() utils.ColorMode

func (*User) GetConnection

func (self *User) GetConnection() net.Conn

func (*User) GetInput

func (self *User) GetInput(text string) string

func (*User) GetName

func (self *User) GetName() string

func (*User) GetPassword

func (self *User) GetPassword() []byte

GetPassword returns the SHA1 of the user's password

func (*User) GetType

func (self *User) GetType() datastore.ObjectType

func (*User) Online

func (self *User) Online() bool

func (*User) SetColorMode

func (self *User) SetColorMode(cm utils.ColorMode)

func (*User) SetConnection

func (self *User) SetConnection(conn net.Conn)

func (*User) SetOnline

func (self *User) SetOnline(online bool)

func (*User) SetPassword

func (self *User) SetPassword(password string)

SetPassword SHA1 hashes the password before saving it to the database

func (*User) SetTerminalType

func (self *User) SetTerminalType(tt string)

func (*User) SetWindowSize

func (self *User) SetWindowSize(width int, height int)

func (*User) TerminalType

func (self *User) TerminalType() string

func (*User) VerifyPassword

func (self *User) VerifyPassword(password string) bool

func (*User) WindowSize

func (self *User) WindowSize() (width int, height int)

func (*User) Write

func (self *User) Write(text string) (int, error)

func (*User) WriteLine

func (self *User) WriteLine(line string) (int, error)

type Users

type Users []*User

func (Users) Contains

func (self Users) Contains(u *User) bool

func (Users) Len

func (self Users) Len() int

func (Users) Less

func (self Users) Less(i, j int) bool

func (Users) Swap

func (self Users) Swap(i, j int)

type World

type World struct {
	DbObject `bson:",inline"`
}

func GetWorld

func GetWorld() *World

Returns the World object. There should only ever be one of these

type Zone

type Zone struct {
	DbObject `bson:",inline"`

	Name string
}

func NewZone

func NewZone(name string) *Zone

func (*Zone) GetName

func (self *Zone) GetName() string

func (*Zone) GetType

func (self *Zone) GetType() datastore.ObjectType

func (*Zone) SetName

func (self *Zone) SetName(name string)

type Zones

type Zones []*Zone

func (Zones) Contains

func (self Zones) Contains(z *Zone) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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