...

Package field

import "github.com/Diarkis/diarkis/field"
Overview
Index

Overview ▾

Package field ▷

Field - Unified MMO

Allows the users to connect in the same world MMO-style without server separation. Extremely low-latency and scalable. Easy to maintain as it auto-scales.

[IMPORTANT]: There is a known edge case with position value calculation with negative values. If x and/or y are negative, it they will not be considered within the field of vision with positive values.

Configurations

Field configuratiuons are explained below.

{
  "fieldSize": 377970000,
  "fieldOfVisionSize": 100,
  "syncLimitOnDiscard": 50,
  "ttl": 10000
}

▶︎ Configuration Values

fieldSize - Default is 377970000

The surface area size of the entire world to be auto-devided across the server nodes.

fieldOfVisionSize - Default is 100

This is the size of field of vision. The field of vision does not change and remains the same for all clients.

syncLimitOnDiscard - Default is 50

Limit of how many other clients to sync on user discard (disappearance packet).

ttl - Default is 10000

TTL of the client position data in milliseconds.

Index ▾

func AddUserPositionValidation(validator func(*user.User, int64, int64, int64) bool)
func AfterDisappearCmd(callback func(*user.User, func(error)))
func AfterSyncCmd(callback func(*user.User, func(error)))
func AfterSyncInitCmd(callback func(*user.User, func(error)))
func BeforeDisappearCmd(callback func(*user.User, func(error)))
func BeforeSyncCmd(callback func(*user.User, func(error)))
func BeforeSyncInitCmd(callback func(*user.User, func(error)))
func Broadcast(userData *user.User, uList []*UserEntity, ver uint8, cmd uint16, msg []byte, reliable bool)
func Disappear(userData *user.User, syncLimit int)
func ExposeCommands()
func GetGrid() (int64, int64, int64, int64)
func GetServerSyncLimit() int
func GetUserPosition(userData *user.User) (int64, int64, int64)
func IsUserInSight(mySID, otherSID string) bool
func IsWS()
func Reconnect(meshEndPoint string, userData *user.User, callback func(error, string))
func SetCustomFilter(customFilterID uint8, filter func(*user.User, []*UserEntity) []*UserEntity)
func SetOnGridUpdated(callback func(int64, int64, int64, int64))
func Setup(confpath string)
func Sync(userData *user.User, x, y, z int64, syncLimit int, msg []byte) (string, []*UserEntity, []*UserEntity, [][]byte)
func Update(userData *user.User, x int64, y int64, z int64) string
type UserEntity
    func ApplyCustomFilter(customFilterID uint8, userData *user.User, uList []*UserEntity) []*UserEntity
    func FindUsersByPosition(x, y, z int64, howMany int) ([]*UserEntity, []string)

func AddUserPositionValidation

func AddUserPositionValidation(validator func(*user.User, int64, int64, int64) bool)

AddUserPositionValidation registers a validation function to be called on Sync

func AfterDisappearCmd

func AfterDisappearCmd(callback func(*user.User, func(error)))

AfterDisappearCmd registers a command to be executed after field disappear: Must be called before ExposeCommands()

func AfterSyncCmd

func AfterSyncCmd(callback func(*user.User, func(error)))

AfterSyncCmd registers a command to be executed after field sync: Must be called before ExposeCommands()

func AfterSyncInitCmd

func AfterSyncInitCmd(callback func(*user.User, func(error)))

AfterSyncInitCmd registers a command to be executed after field sync: Must be called before ExposeCommands()

func BeforeDisappearCmd

func BeforeDisappearCmd(callback func(*user.User, func(error)))

BeforeDisappearCmd registers a command to be executed before field disappear: Must be called before ExposeCommands()

func BeforeSyncCmd

func BeforeSyncCmd(callback func(*user.User, func(error)))

BeforeSyncCmd registers a command to be executed before field sync: Must be called before ExposeCommands()

func BeforeSyncInitCmd

func BeforeSyncInitCmd(callback func(*user.User, func(error)))

BeforeSyncInitCmd registers a command to be executed before field sync: Must be called before ExposeCommands()

func Broadcast

func Broadcast(userData *user.User, uList []*UserEntity, ver uint8, cmd uint16, msg []byte, reliable bool)

Broadcast broadcast a message to the list of users found by Sync or FindUsersByPosition function

func Disappear

func Disappear(userData *user.User, syncLimit int)

Disappear removes the user client from field map

func ExposeCommands

func ExposeCommands()

ExposeCommands exposes commands to the client to work with Field package

func GetGrid

func GetGrid() (int64, int64, int64, int64)

GetGrid returns node's grid x and grid y returns both positive value grid and negative value grid

func GetServerSyncLimit

func GetServerSyncLimit() int

GetServerSyncLimit returns serverSyncLimit

func GetUserPosition

func GetUserPosition(userData *user.User) (int64, int64, int64)

GetUserPosition returns the current user position: x, y, z

func IsUserInSight

func IsUserInSight(mySID, otherSID string) bool

IsUserInSight evalutes if the remote user is in sight or not

func IsWS

func IsWS()

IsWS called internally by commands.go

func Reconnect

func Reconnect(meshEndPoint string, userData *user.User, callback func(error, string))

Reconnect returns the end point of the node for the client to reconnect to

func SetCustomFilter

func SetCustomFilter(customFilterID uint8, filter func(*user.User, []*UserEntity) []*UserEntity)

SetCustomFilter defines a custom filter and create an association to the ID

func SetOnGridUpdated

func SetOnGridUpdated(callback func(int64, int64, int64, int64))

SetOnGridUpdated registers a callback function on grid map updated.

The callback receives grid x1, y1 and grid x2, y2.

Each node has two sets of grid x and y

func Setup

func Setup(confpath string)

Setup setup Field module

func Sync

func Sync(userData *user.User, x, y, z int64, syncLimit int, msg []byte) (string, []*UserEntity, []*UserEntity, [][]byte)

Sync updates its own position and find others within the sight (fieldOfVisionSize) - z is used as a literal value instead of range like x and y. Use z value to create "different" area.

// returned values:
meshNodeEndPoint, usersInSight, usersNotInSight, userMessageListInsight := field.Sync(userData, x, y, z, syncLimit, message)

func Update

func Update(userData *user.User, x int64, y int64, z int64) string

Update updates the given userData(client)'s position data and returns a mesh address if the client must reconnect to a new mesh node

type UserEntity

UserEntity a user data structure

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

func ApplyCustomFilter

func ApplyCustomFilter(customFilterID uint8, userData *user.User, uList []*UserEntity) []*UserEntity

ApplyCustomFilter executes pre-defined custom filter on the list of UserEntity to controll who to broadcast to

func FindUsersByPosition

func FindUsersByPosition(x, y, z int64, howMany int) ([]*UserEntity, []string)

FindUsersByPosition returns an array of user entities and an array of user IDs within the given area (x, y, z)