+
+
Module ExpGamingCore.Server
+
Adds a thread system and event listening and a admin bypass (recommend to disable /c and use optional /interface)
+
+
Info:
+
+ - License: https://github.com/explosivegaming/scenario/blob/master/LICENSE
+ - Author: Cooldude2606
+
+
+
+
+
+
+
+
+
+
+ | uuid |
+ Used to generate a new uuid for the thread system |
+
+
+ | threads |
+ Redirect to the thread index |
+
+
+
+
+
+
+
+ | _comment () |
+ This file will be loaded when ExpGamingCore.Commands is present |
+
+
+ | interface |
+ Runs the given input from the script |
+
+
+
+
+
+
+
+
+
+
+ -
+
+ new_thread (obj)
+
+ -
+ Generates a new thread object
+
+
+
Parameters:
+
+ - obj
+ table
+ the atributes to give to the thread
+
+
+
+ Returns:
+
+
+ Server._thread
+ the new thread created
+
+
+
+
+ Usage:
+ Server.new_thread{name='foo',data={}}
+
+
+
+ -
+
+ get_thread (mixed)
+
+ -
+ Used to get a thread via uuid or name (if one is assied)
+
+
+
Parameters:
+
+ - mixed
+ either a uuid or the name given to a thread
+
+
+
+ Returns:
+
+
+ Server._thread
+ the thread by that name or uuid
+
+ Or
+
+
+ boolean
+ if false is returned then no thread existes
+
+
+
+
+ Usage:
+ Server.get_thread('decon')
+
+
+
+ -
+
+ queue_thread (thread_to_queue)
+
+ -
+ Adds a thread into the resolve queue, can be used to lower lag
+
+
+
Parameters:
+
+ - thread_to_queue
+ Server._thread
+ the thread to be added to the queue, must be open and have a on_resolve function
+
+
+
+ Returns:
+
+
+ boolean
+ was it added successfuly
+
+
+
+
+ Usage:
+ Server.queue_thread(thread)
+
+
+
+ -
+
+ close_all_threads (with_force)
+
+ -
+ Closes all active threads, can use force if it causes errors
+
+
+
Parameters:
+
+ - with_force
+ bolean
+ use force when closing
+
+
+
+
+
+
+ Usage:
+
+
+
+ -
+
+ run_tick_threads ()
+
+ -
+ Runs all the theads which have opened with an on_tick event
+
+
+
+
+
+
+
Usage:
+ Server.run_tick_threads()
+
+
+
+ -
+
+ check_timeouts ()
+
+ -
+ Checks the timeout on all active timeout threads
+
+
+
+
+
+
+
Usage:
+ Server.check_timeouts()
+
+
+
+ -
+
+ _thread_debuger (player, event[, state=toggle])
+
+ -
+ Used to print event info to a player
+
+
+
Parameters:
+
+ - player
+ name, index or LuaPlayer
+ the player that the info will be returned to
+
+ - event
+ name or index
+ the event that info will be returned fo
+
+ - state
+ boolean
+ will info be returned, nil to toggle current state
+ (default toggle)
+
+
+
+
+
+
+ Usage:
+ Server._thread_debuger('Cooldude2606','on_player_died',true)
+
+
+
+ -
+
+ interface (callback[, use_thread[, env[, ...]]])
+
+ -
+ Acts as a bypass for running functions, can accept a string
+
+
+
Parameters:
+
+ - callback
+ string or function
+ function to be ran
+
+ - use_thread
+ Server._thread or true
+ run the command on a premade thread or let it make its own
+ (optional)
+
+ - env
+ table
+ run the env to run the command in must have _env key as true to be
+ (optional)
+
+ - ...
+ any args you want to pass to the function
+ (optional)
+
+
+
+ Returns:
+
+
+ if no thread then it will return the value(s) returned by the callback
+
+
+
+
+ Usage:
+
+
+
+
+
+
+
+ -
+
+ global
+
+ -
+ Global Table
+
+
+
Fields:
+
+ - all
+ a list of every thread (indexed by uuid)
+
+ - queue
+ an index for threads which will be resolved (contains uuids)
+
+ - tick
+ an index for threads which will run every tick (contains uuids)
+
+ - timeout
+ an index for threads which will timeout (contains uuids)
+
+ - events
+ an index of threads based on event ids (contains uuids)
+
+ - paused
+ an index of pasued threads (contains uuids)
+
+ - named
+ a name index for thread uuids
+
+ - print_to
+ contains players that event details will be printed to
+
+ - uuid
+ contains the random number generator for the uuid system
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+ uuid
+
+ -
+ Used to generate a new uuid for the thread system
+
+
+
+
+
+
+
Usage:
+ local uuid = tostring(Server.uuid)
+
+
+
+ -
+
+ threads
+
+ -
+ Redirect to the thread index
+
+
+
+
+
+
+
Usage:
+
+ Server.threads
+ Server.threads
+
+
+
+
+
+
+
+ The class for the server threads, allows abbilty to run async function
+
+
+ -
+
+ Server._thread:create ([obj={}])
+
+ -
+ Returns a new thread object
+
+
+
Parameters:
+
+ - obj
+ table
+ all values are opt {timeout=int,name=str,data=any}
+ (default {})
+
+
+
+ Returns:
+
+
+ Server._thread
+ the new thread object
+
+
+
+
+ Usage:
+ new_thread = thread:create()
+
+
+
+ -
+
+ Server._thread:queue ()
+
+ -
+ Opens and queses a thread
+
+
+
+
Returns:
+
+
+ boolean
+ was the thread queued successfuly
+
+
+
+ See also:
+
+
+ Usage:
+ Server._thread:queue()
+
+
+
+ -
+
+ Server._thread:valid ([skip_location_check=false])
+
+ -
+ Test if the thread has all requied parts
+
+
+
Parameters:
+
+ - skip_location_check
+ bolean
+ true to skip the location checking
+ (default false)
+
+
+
+ Returns:
+
+
+ boolean
+ is the thread valid
+
+
+
+
+ Usage:
+ if thread:valid() then end
+
+
+
+ -
+
+ Server._thread:open ()
+
+ -
+ Opens the thread; indexs this thread in the global index
+
+
+
+
Returns:
+
+
+ bolean
+ if the thread was opened successfuly
+
+
+
+
+ Usage:
+ thread:open()
+
+
+
+ -
+
+ Server._thread:close ()
+
+ -
+ Inverse of thread:open() - Removes all indexs to this thread, most cases this will cause it to become inassible
+
+
+
+
Returns:
+
+
+ boolean
+ if the thread had a on_close function
+
+
+
+
+ Usage:
+ thread:close()
+
+
+
+ -
+
+ Server._thread:resolve ([...])
+
+ -
+ Trigger the on_resolve function and closes the thread - error and success called based on result of pcall (useful for async)
+
+
+
Parameters:
+
+ - ...
+ any arguments you want to pass to the resolve function
+ (optional)
+
+
+
+ Returns:
+
+
+ bolean
+ true if the thread called on_success or on_error
+
+
+
+
+ Usage:
+ thread:resolve(x,y,z)
+
+
+
+ -
+
+ Server._thread:check_timeout ()
+
+ -
+ Checks the timeout on a thread - if timed out then it calles on_timeout and closes
+
+
+
+
Returns:
+
+
+ bolean
+ if the thread timed out
+
+
+
+
+ Usage:
+ thread:check_timeout()
+
+
+
+ -
+
+ Server._thread:error (err)
+
+ -
+ Used to check and raise the error handler of the thread, if not present it raises an error
+
+
+
Parameters:
+
+ - err
+ string
+ the err to be rasied
+
+
+
+ Returns:
+
+
+ boolean
+ did the thread have an error handler
+
+
+
+
+ Usage:
+ thread:error(err)
+
+
+
+ -
+
+ Server._thread:on_event (event, callback)
+
+ -
+ Set function to run then an event is triggered, none of them are 'needed' but you are advised to have atleast one
+
+
+
Parameters:
+
+ - event
+ string or index
+ the name of the event that the function should be called on
+
+ - callback
+ function
+ the function which is called by the event trigger
+
+
+
+ Returns:
+
+
+ table
+ returns self so that they can be chained together
+
+
+
+
+ Usage:
+
+ thread:on_event('close',function)
+ thread_only_events = ['close','timeout','tick','resolve','success','error']
+
+
+
+
+
+
+
+ -
+
+ _comment ()
+
+ -
+ This file will be loaded when ExpGamingCore.Commands is present
+
+
+
+
+
+
+
+
+ -
+
+ interface
+
+ -
+ Runs the given input from the script
+
+
+
param:
+
+ - code
+ The code that will be ran
+
+
+
+
+
+
+
+
+
+
+
+