0% found this document useful (0 votes)
5 views

Implement

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Implement

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

--the thing is, u need to implement ur own process collection.

it can just be a
library, or set of libraries
--in mine, a collection is an interface that wraps around nameless libraries with
uniquely named fields, that can run some validation checks on each member of the
library
--lets me split up data across multiple files while keeping them consistent

--service
local service = {}

--core services
local global = _G.import "global"
local event = _G.import "event"

--util
local dictUtil = _G.import "dictUtil"

--data
local processCollection = _G.import "processCollection"

--roblox services
local runService = game:GetService("RunService")
local httpService = game:GetService("HttpService")

--private functions
local function processShared(player, eventName, playerSave, playerSession, ...)
local sharedProcess = processCollection:get(eventName)
if not sharedProcess then warn('No Shared process named ' .. eventName) return
end

--response
local response = {sharedProcess(player, playerSave, playerSession, ...)}
local status = table.remove(response, 1)

return status, response


end

--setup network
if runService:IsServer() then

function service.listen(eventName, func)


event.remoteConnect(eventName, function(player, ...)
--data
local playerSave = global.get('playerSave',player)
local playerSession = global.get('playerSession',player)
local args = {...}

--processShared
local status, response = processShared(player, eventName, playerSave,
playerSession, unpack(args))
if status == true and func then
return {func(unpack(response))}
else
return {status}
end
end, {Returning=true})
end
else
function service.request(eventName, clientFunc, errorFunc, serverResponse,
getSharedResponse, makeRequestId)
return function(...)
--ref n
local player = game.Players.LocalPlayer
local playerSave = global.get('playerSave',player)
local playerSession = global.get('playerSession',player)

--processShared
local args = {...}

if makeRequestId then table.insert(args, httpService:GenerateGUID())


end

--
local status, response = processShared(player, eventName, playerSave,
playerSession, ...)

if status == true then


task.spawn(function()
local serverResponsePack = event.remoteFire(eventName,
unpack(dictUtil.arrayMerge(args, getSharedResponse and response or {}))) or {}
if serverResponse then
serverResponse(unpack(serverResponsePack))
end
end)

if clientFunc then clientFunc(unpack(response)) end


elseif status ~= nil and errorFunc then
errorFunc(status)
end

return status
end
end

end

return service

--this is just the sync library for u to copy ok

You might also like