Cache server class.

Fields

read only asyncWorker:AsyncWorker

Asynchronous worker thread.

read only autosaveManager:AutosaveManager

Autosave manager.

read only cacheManager:CacheManager

Data blocks cache manager.

read only clients:List<SlaveClient>

Slave servers list. May be needed for sending notifications to a list of servers. Do not modify in any way.

read only config:Config

Server configuration.

coreCalendarModule:CalendarModuleCacheCore

Core calendar events module.

read only coreModuleParams:_CoreModuleParamsCache

Core module parameters.

coreShopModule:ShopModuleCacheCore

Core shop module.

coreVarsModule:VarsModuleCacheCore

Core game variables module.

externalMethods:Array<String>

List of module methods that can be called without server login.

read only state:String

Server state: (init, run, stopping).

read only temp:Temp

Temp directory reader/writer.

read only timer:TimerCache

Timer for running tasks periodically.

Methods

inline addModule (m:Dynamic):Void

Adds initialized module to the server list.

Parameters:

m

Initialized server module.

inline broadcast (type:String, msg:Dynamic):Void

Broadcasts a notification to all servers of this type.

Server notifications are described in Notifications article.

The message object has to have _type string field with message type.

Parameters:

type

Server type.

msg

Server message. Anonymous object.

disconnect (c:SlaveClient):Void

Forcibly disconnects a client.

Parameters:

c

Slave client.

getClient (id:Int):SlaveClient

Returns slave client by its ID.

Parameters:

id

Slave client ID.

Returns:

Slave client. Returns null if no client was found.

getClientByConnectionID (id:Int):SlaveClient

Returns slave client by its connection ID. Only works for slave clients connected through network.

Parameters:

id

Slave client connection ID.

Returns:

Slave client instance. Returns null if no client was found.

getClientByType (t:String):SlaveClient

Returns first slave client with this type.

Parameters:

t

Slave client type.

Returns:

Slave client. Returns null if no clients were found.

getModule (name:String):Dynamic

Returns a server module by its name.

Parameters:

name

Server module name.

Returns:

Server module.

getModuleList ():List<ModuleCache<CacheServer>>

Returns a list of available server modules.

Returns:

Server modules list.

getRandomClient (t:String):SlaveClient

Returns random slave client with this type.

Parameters:

t

Slave client type.

Returns:

Slave client.

getSubscribedMethods (tag:String):Null<List<Dynamic>>

Returns a list of subscribed methods for a given event type. Module subscription API is described in detail in Subscriptions article.

Parameters:

tag

Event type.

Returns:

List of methods subscribed to this event type.

getSubscribedModules (tag:String):List<ModuleCache<CacheServer>>

Returns subscribed modules list for this event name.

Parameters:

tag

Event name.

Returns:

Server modules list.

dynamic initModules ():Void

Initializes project server modules. Called at the end of initServer().

initServer ():Void

Initializes cache server state and variables. Must be called before calling start().

loadModules (list:Array<Dynamic>):Void

Loads and initializes specified server modules.

Parameters:

list

List of server module classes.

inline log (type:String, s:String, ?logStack:Bool):Void

Adds a typed message to cache server log.

Parameters:

type

Log message type.

s

Log message.

logStack

Log call stack.

nextID (t:String):Int

Returns next available row ID from sequence for given database table.

Parameters:

t

Database table name.

Returns:

Next available row ID.

inline pending (q:String):Void

Adds pending SQL query to the queue. Does not wait for result.

Parameters:

q

SQL query string.

inline print (s:String):Void

Prints a string to stdout.

Parameters:

s

String.

inline query (q:String):ResultSet

Runs SQL query through one of the database manager connections.

Parameters:

q

SQL query string.

Returns:

The result of the query.

inline quote (s:String):String

Escapes a string for using in SQL query as a row field.

Parameters:

s

String.

Returns:

Escaped string.

start ():Void

Starts cache server. Does not return until the application stops working.

inline stats (s:String):Void

Adds stats message to cache server real-time stats log.

Parameters:

s

Log message.

subscribeMethod (tag:String, method:Dynamic):Void

Subscribes method to an event. Module subscription API is described in detail in Subscriptions article.

Parameters:

tag

Event type.

method

Method.

subscribeModule (tag:String, module:Dynamic):Void

Subscribes module to an event. Server subscriptions are described in detail in Subscriptions article.

Parameters:

tag

Event name.

module

Server module.