func AddUserPositionValidation(validator func(*user.User, int64, int64, int64) bool)
AddUserPositionValidation registers a validation function to be called on Sync
[IMPORTANT] This function can be used ONLY on the front servers (UDP or TCP). validator - Custom function to be invoked for position validation.
func AfterDisappearCmd(callback func(ver uint8, cmd uint16, payload []byte, userData *user.User, next func(error)))
AfterDisappearCmd registers a command to be executed after field disappear: Must be called before ExposeCommands()
Parameters
ver - Command ver sent from the client. cmd - Command ID sent from the client. payload - Command payload sent from the client. userData - User data representing the client that sent the command. next - The function to signal the command to move on to the next operation of the same ver and command ID. This function must be called at the end of all operations in the callback. If you pass an error, it will not proceed to the next operations of the same command ver and ID.
func AfterLeaveCmd(callback func(ver uint8, cmd uint16, payload []byte, userData *user.User, next func(error)))
AfterLeaveCmd registers a command to be executed after field leave: Must be called before ExposeCommands()
Parameters
ver - Command ver sent from the client. cmd - Command ID sent from the client. payload - Command payload sent from the client. userData - User data representing the client that sent the command. next - The function to signal the command to move on to the next operation of the same ver and command ID. This function must be called at the end of all operations in the callback. If you pass an error, it will not proceed to the next operations of the same command ver and ID.
func AfterSyncCmd(callback func(ver uint8, cmd uint16, payload []byte, userData *user.User, next func(error)))
AfterSyncCmd registers a command to be executed after field sync: Must be called before ExposeCommands()
Parameters
ver - Command ver sent from the client. cmd - Command ID sent from the client. payload - Command payload sent from the client. userData - User data representing the client that sent the command. next - The function to signal the command to move on to the next operation of the same ver and command ID. This function must be called at the end of all operations in the callback. If you pass an error, it will not proceed to the next operations of the same command ver and ID.
func BeforeDisappearCmd(callback func(ver uint8, cmd uint16, payload []byte, userData *user.User, next func(error)))
BeforeDisappearCmd registers a command to be executed before field disappear: Must be called before ExposeCommands()
Parameters
ver - Command ver sent from the client. cmd - Command ID sent from the client. payload - Command payload sent from the client. userData - User data representing the client that sent the command. next - The function to signal the command to move on to the next operation of the same ver and command ID. This function must be called at the end of all operations in the callback. If you pass an error, it will not proceed to the next operations of the same command ver and ID.
func BeforeLeaveCmd(callback func(ver uint8, cmd uint16, payload []byte, userData *user.User, next func(error)))
BeforeLeaveCmd registers a command to be executed before field leave: Must be called before ExposeCommands()
Parameters
ver - Command ver sent from the client. cmd - Command ID sent from the client. payload - Command payload sent from the client. userData - User data representing the client that sent the command. next - The function to signal the command to move on to the next operation of the same ver and command ID. This function must be called at the end of all operations in the callback. If you pass an error, it will not proceed to the next operations of the same command ver and ID.
func BeforeSyncCmd(callback func(ver uint8, cmd uint16, payload []byte, userData *user.User, next func(error)))
BeforeSyncCmd registers a command to be executed before field sync: Must be called before ExposeCommands()
Parameters
ver - Command ver sent from the client. cmd - Command ID sent from the client. payload - Command payload sent from the client. userData - User data representing the client that sent the command. next - The function to signal the command to move on to the next operation of the same ver and command ID. This function must be called at the end of all operations in the callback. If you pass an error, it will not proceed to the next operations of the same command ver and ID.
func CalcDistance(myX, myY, yourX, yourY int64) int64
CalcDistance calculates distance using triangle
┌───────────────▶︎ (Me) │ ╱│ │ ╱ │ │ ╱ │ Distance ╱ │ Y │ ╱ │ │ ╱ │ │ ╱ ┏━┥ └──▶︎ (You) ─────┸─┘ X
Parameters
myX - X coordinate to calculate the distance against yourX. myY - Y coordinate to calculate the distance against yourY. yourX - X coordinate to calculate the distance against myX. yourY - Y coordinate to calculate the distance against myY.
func Disappear(userData *user.User)
Disappear removes the user from the user entity list to stop from synchronization.
[IMPORTANT] This function is the alias for Leave [IMPORTANT] This function can be used ONLY on the front servers (UDP or TCP).
Parameters
userData - User that will propagate the synchronization the data to the users in view.
func ExposeCommands()
ExposeCommands exposes commands to the client to work with Field package
func GetFieldOfVisionSize() int64
GetFieldOfVisionSize returns the current field of view size.
func GetFieldSize() int64
GetFieldSize returns the current field size.
func GetGridKeyByNodeType(x, y int64, nodeType string) string
GetGridKeyByNodeType returns the calculated grid key based on X and Y coordinate given.
This function has been deprecated and should not be used.
[IMPORTANT] Use GetGridKeyByPosition instead.
func GetGridKeyByPosition(x, y, z int64) string
GetGridKeyByPosition returns the grid key based on X, Y, and Z coordinate.
func GetGridSize() int64
GetGridSize returns the size of a grid.
func GetNodeNum() int
GetNodeNum returns the number of grid storage servers
func GetNumberOfGrids() int
GetNumberOfGrids returns the current number of grids.
func GetUserPosition(userData *user.User) (int64, int64, int64)
GetUserPosition returns the given user's current coordinate: X, Y, and Z.
[IMPORTANT] This function can be used ONLY on the front servers (UDP or TCP). [IMPORTANT] This function uses mutex lock on userData internally.
func Join(userData *user.User, x, y, z int64, data []byte, syncLimit int, filterID uint8, reliable bool) error
Join initializes the user. The user must "Join" the Field in order to use Sync, Disappear, and Leave.
[IMPORTANT] This function can be used ONLY on the front servers (UDP or TCP). [NOTE] Z space is not a coordinate, but it describes dimension or space. For example, users with the same x and y with different z will not "see" each other.
Parameters
userData - User that will propagate the synchronization the data to the users in view. x - X position of the user to synchronize. y - Y position of the user to synchronize. z - Z space of the user to synchronize. data - Synchronize byte array data. The data byte array must NOT be empty. syncLimit - Maximum number of the sync and disappear packets the user allows to receive. This limit applies to the packets the user receives NOT the packets the user sends.
func Leave(userData *user.User) error
Leave allows the user to cleanly leave from the Field and resets all Field data of the user.
[IMPORTANT] This function can be used ONLY on the front servers (UDP or TCP).
Parameters
userData - User that will propagate the synchronization the data to the users in view.
func SetCustomFilter(customFilterID uint8, filter FilterCallback)
SetCustomFilter defines a custom filter that will be invoked when user client indicates while synchronizing. The purpose of the filter is to manipulate the users in sight for synchronizing.
[IMPORTANT] Custom callbacks are executed on the front node servers (UDP or TCP). [IMPORTANT] The callback will have both sender and receiver UID, however, the sender user data is not be accessible from the callback. [NOTE] If the callback returns false, the receiver will NOT receive the synchronizing message.
Parameters
customFilterID - Unique ID to identify the custom filter. filter - Custom operation function to perform filtering.
func Setup(confpath string)
Setup setup Field module.
Parameters
confpath - Absolute path of the configuration file to be loaded.
func Sync(userData *user.User, x, y, z int64, data []byte, syncLimit int, filterID uint8, reliable bool) error
Sync updates synchronization data.
[IMPORTANT] This function can be used ONLY on the front servers (UDP or TCP). [NOTE] Z space is not a coordinate, but it describes dimension or space. For example, users with the same x and y with different z will not "see" each other.
Parameters
userData - User that will propagate the synchronization the data to the users in view. x - X position of the user to synchronize. y - Y position of the user to synchronize. z - Z space of the user to synchronize. data - Synchronize byte array data. maximum allowed length is 3000 bytes The data byte array must NOT be empty. syncLimit - Maximum number of the sync and disappear packets the user allows to receive. This limit applies to the packets the user receives NOT the packets the user sends.
FilterCallback is a callback to decide if you want to send a sync message to the receiver user or not.
type FilterCallback func(receiverUser *user.User, senderUID string, distance int64, cmd uint16, payload []byte) bool
MeshData represents internally used data transport
type MeshData struct { Packed []byte `json:"p"` sync.RWMutex }