amoeba

package module
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2021 License: MIT Imports: 24 Imported by: 0

README

amoeba GoDoc Go Report Card MIT license

heroku hosted: amoeba demo game client

  • very simple webapp game client
    • move with WASD
  • server side physics game world
    • bump and smash into others
  • server ai behavior: move

modified version of lonng/nano

- deprecated/archived fork of this repo

amoeba golang client/server example

added support for:

  • pipeline encode/decode
  • pipeline encrypt/decrypt
  • beginning of lifecycles
    • variable tick rate game loop
  • drivers:
  • attach/bind nano to existing web frameworks:
  • token based auth jwt
  • session/per packet auth
  • session uuid
  • golang client ws amoeba-client

amoeba

DOCS FROM NANO

exact nano paradigm | nano -> amoeba

nano image

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCloseClosedGroup   = errors.New("close closed group")
	ErrClosedGroup        = errors.New("group closed")
	ErrMemberNotFound     = errors.New("member not found in the group")
	ErrSessionDuplication = errors.New("session has existed in the current group")
)

Errors that could be occurred during message handling.

View Source
var VERSION = "0.6.0"

VERSION returns current amoeba version

Functions

func ExtendEcho

func ExtendEcho(e *echo.Echo, opts ...Option)

ExtendEcho -- HELPER TO EXTEND AN ECHO WEB SERVER

func Listen

func Listen(addr string, opts ...Option)

Listen listens on the TCP network address addr and then calls Serve with handler to handle requests on incoming connections.

func Shutdown

func Shutdown()

Shutdown send a signal to let 'amoeba' shutdown itself.

func WatchShutdown

func WatchShutdown()

Types

type Group

type Group struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Group represents a session group which used to manage a number of sessions, data send to the group will send to all session in it.

func NewGroup

func NewGroup(n string) *Group

NewGroup returns a new group instance

func NewGroupWithDriver

func NewGroupWithDriver(n string, driverType azdrivers.DriverKeyType, newDriver bool, onUpdate func()) (*Group, error)

NewGroupWithDriver -- returns a new group instance with driver support driverType = mongo | firebase driverString = mongo uri | firebase cfg file path

func (*Group) Add

func (g *Group) Add(session *session.Session) error

Add add session to group

func (*Group) Broadcast

func (g *Group) Broadcast(route string, v interface{}) error

Broadcast push the message(s) to all members

func (*Group) Close

func (g *Group) Close() error

Close destroy group, which will release all resource in the group

func (*Group) Contains

func (g *Group) Contains(uid int64) bool

Contains check whether a UID is contained in current group or not

func (*Group) ContainsUUID

func (g *Group) ContainsUUID(uuid string) bool

Contains check whether a UUID is contained in current group or not

func (*Group) Count

func (g *Group) Count() int

Count get current member amount in the group

func (*Group) GetMember

func (g *Group) GetMember(uid int64) (*session.Session, error)

Member returns specified UID's session

func (*Group) GetName

func (g *Group) GetName() string

func (*Group) GetOnUpdate

func (g *Group) GetOnUpdate() *scheduler.GameLoop

func (*Group) InitDriver

func (g *Group) InitDriver(driverType azdrivers.DriverKeyType, driverString string, isNew bool) error

func (*Group) Leave

func (g *Group) Leave(s *session.Session) error

Leave remove specified UID related session from group

func (*Group) LeaveAll

func (g *Group) LeaveAll() error

LeaveAll clear all sessions in the group

func (*Group) Member

func (g *Group) Member(uid int64) (*session.Session, error)

Member returns specified UID's session

func (*Group) MemberUUID

func (g *Group) MemberUUID(uuid string) (*session.Session, error)

Member returns specified UUID's session

func (*Group) Members

func (g *Group) Members() []int64

Members returns all member's UID in current group

func (*Group) MembersShortUUID

func (g *Group) MembersShortUUID() []string

MembersShortUUID

func (*Group) MembersUUID

func (g *Group) MembersUUID() []string

MembersUUID --

func (*Group) Multicast

func (g *Group) Multicast(route string, v interface{}, filter SessionFilter) error

Multicast push the message to the filtered clients

func (*Group) SetOnUpdate

func (g *Group) SetOnUpdate(fn func(delta float64), tickRate int64)

type LifeCycles

type LifeCycles struct {
	OnUpdate *scheduler.GameLoop
}

type Option

type Option func(*cluster.Options)

func WithAdvertiseAddr

func WithAdvertiseAddr(addr string, retryInterval ...time.Duration) Option

WithAdvertiseAddr sets the advertise address option, it will be the listen address in master node and an advertise address which cluster member to connect

func WithCheckOriginFunc

func WithCheckOriginFunc(fn func(*http.Request) bool) Option

WithCheckOriginFunc sets the function that check `Origin` in http headers

func WithClientAddr

func WithClientAddr(addr string) Option

WithMemberAddr sets the listen address which is used to establish connection between cluster members. Will select an available port automatically if no member address setting and panic if no available port

func WithComponents

func WithComponents(components *component.Components) Option

WithComponents sets the Components

func WithDebugMode

func WithDebugMode() Option

WithDebugMode let 'amoeba' to run under Debug mode.

func WithDictionary

func WithDictionary(dict map[string]uint16) Option

SetDictionary sets routes map

func WithFirebase

func WithFirebase(path string) Option

func WithGrpcOptions

func WithGrpcOptions(opts ...grpc.DialOption) Option

WithGrpcOptions sets the grpc dial options

func WithHandshakeValidator

func WithHandshakeValidator(fn func([]byte) error) Option

WithHandshakeValidator sets the function that Verify `handshake` data

func WithHeartbeatInterval

func WithHeartbeatInterval(d time.Duration) Option

WithHeartbeatInterval sets Heartbeat time interval

func WithIsWebsocket

func WithIsWebsocket(enableWs bool) Option

WithIsWebsocket indicates whether current node WebSocket is enabled

func WithJWT

func WithJWT(authJWT *auth.JWT) Option

func WithJWTOpts

func WithJWTOpts(signKey, algo string, genTokenFunc auth.JWTFunc) Option

func WithLabel

func WithLabel(label string) Option

WithLabel sets the current node label in cluster

func WithLogger

func WithLogger(l log.Logger) Option

WithLogger overrides the default logger

func WithMaster

func WithMaster() Option

WithMaster sets the option to indicate whether the current node is master node

func WithMongo

func WithMongo(uri string) Option

func WithPipeline

func WithPipeline(pipeline pipeline.Pipeline) Option

func WithSerializer

func WithSerializer(serializer serialize.Serializer) Option

WithSerializer customizes application serializer, which automatically Marshal and UnMarshal handler payload

func WithTSLConfig

func WithTSLConfig(certificate, key string) Option

WithTSLConfig sets the `key` and `certificate` of TSL

func WithTimerPrecision

func WithTimerPrecision(precision time.Duration) Option

SetTimerPrecision sets the ticker precision, and time precision can not less than a Millisecond, and can not change after application running. The default precision is time.Second

func WithWSPath

func WithWSPath(path string) Option

type SessionFilter

type SessionFilter func(*session.Session) bool

SessionFilter represents a filter which was used to filter session when Multicast, the session will receive the message while filter returns true.

Directories

Path Synopsis
benchmark
io
examples
demo/amoeba
https://github.com/revzim/amoeba/examples/chat
https://github.com/revzim/amoeba/examples/chat
demo/chat2
https://github.com/revzim/amoeba/examples/chat2
https://github.com/revzim/amoeba/examples/chat2
internal
env
env represents the environment of the current process, includes work path and config path etc.
env represents the environment of the current process, includes work path and config path etc.
log

Jump to

Keyboard shortcuts

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