NeoNet
Based off of 'Net' by sleitnick with added features similar to other networking modules.
Types
RemoteSetupInfo
type
RemoteSetupInfo =
{
RemoteEvents:
{
string
}
,
RemoteFunctions:
{
string
}
,
RemoteValues:
{
string:
any
}
,
}
The information that should be sent into NeoNet:Setup
RemoteClientMiddleware
type
RemoteClientMiddleware =
(
Parameters:
{
number:
any
}
,
)
→
(
boolean
,
{
number:
any
}
)
Type for client middleware. See how to create your own middleware here.
RemoteServerMiddleware
Type for server middleware. See how to create your own middleware here.
Properties
Middleware
For access to the built-in middleware that comes with NeoNet such as RateLimiter and TypeChecker.
Functions
UseParent
This method is only intended to be used for combining with/adapting to other systems or to organize your remotes in a more accessible place.
caution
It will make NeoNet unable to access remotes created without calling UseParent with the same Parent in the other scripts.
NeoNet:UseParent(ReplicatedStorage.Remotes)
local remoteEvent = NeoNet:RemoteEvent("PointsChanged")
RemoteEvent
Gets a RemoteEvent with the given name. On the server, if the RemoteEvent does not exist, then it will be created with the given name. On the client, if the RemoteEvent does not exist, then it will wait until it exists for at least 10 seconds. If the RemoteEvent does not exist after 10 seconds, an error will be thrown.
local remoteEvent = NeoNet:RemoteEvent("PointsChanged")
RemoteFunction
Gets a RemoteFunction with the given name. On the server, if the RemoteFunction does not exist, then it will be created with the given name. On the client, if the RemoteFunction does not exist, then it will wait until it exists for at least 10 seconds. If the RemoteFunction does not exist after 10 seconds, an error will be thrown.
local remoteFunction = NeoNet:RemoteFunction("GetPoints")
RemoteValue
NeoNet:
RemoteValue
(
name:
string
,
value:
T
) →
{
Ready:
boolean
,
Value:
any
,
Specific:
{
}
?
,
_connection:
RBXScriptConnection
}
Gets a RemoteValue with the given name. On the server, if the RemoteValue does not exist, then it will be created with the given name. On the client, if the RemoteValue does not exist, then it will wait until it exists for at least 10 seconds. If the RemoteValue does not exist after 10 seconds, an error will be thrown.
local remoteValue = NeoNet:RemoteValue("ButtonClicks")
GetValue
NeoNet:
GetValue
(
name:
string
) →
any
Gets the current value of a RemoteValue.
print(NeoNet:GetValue("ButtonClicks"), "Clicks")
Fire
NeoNet:
Fire
(
name:
string
,
...:
any
) →
(
)
Fires the given RemoteEvent. Will Fire to all clients if used from the server
NeoNet:Fire("SomeEvent", someParameters, middleware?)
tip
If the last parameter is a function then it will use that as middleware
Listen
Returns an iterator for use in a loop or ECS context. Arguments are iterated through from oldest to newest.
caution
Breaking the loop MAY drop all arguments gathered at that moment since it clears the storage every time NeoNet:Listen is called.
Middleware also doesn't work yet.
game:GetService("RunService").Heartbeat:Connect(function()
for index: number, arg1, arg2 in NeoNet:Listen("DropItem") do
--drop the item or whatever
end
end)
ConnectOnce
NeoNet:
ConnectOnce
(
) →
(
)
Connects a handler function to the given RemoteEvent and disconnects after the first event.
caution
If the middleware drops the request it will still be disconnected, use NeoNet:ConnectUntil if you want to only disconnect after middleware passes an event.
NeoNet:ConnectOnce("SomeEvent", function(...) end)
ConnectUntil
NeoNet:
ConnectUntil
(
) →
(
)
Connects a handler function to the given RemoteEvent and disconnects after the first event that passes the middleware. (Similar to :ConnectOnce but it only disconnects after the middleware has continued a request.)
NeoNet:ConnectUntil("SomeEvent", function(...) end, someMiddleware)
Setup
This item only works when running on the server. Servercaution
deprecated (as of v1.2.0) or something please don't use; this type of setup was exactly what I wanted to avoid with NeoNet
Sets up all the defined RemoteEvents, RemoteFunctions, and RemoteValues.
NeoNet:Setup {
RemoteEvents = {
"ClickRequest"
},
RemoteValues = {
ButtonClicks = 0
}
}
FireFor
This item only works when running on the server. ServerFires the given RemoteEvent to the specified player.
NeoNet:FireFor("SomeEvent", somePlayer, someParameters, middleware?)
FireExcept
This item only works when running on the server. ServerFires the given RemoteEvent to all players except the specified player.
NeoNet:FireExcept("SomeEvent", somePlayer, someParameters, middleware?)
FireList
This item only works when running on the server. ServerFires the given RemoteEvent to all specified players.
NeoNet:FireList("SomeEvent", {somePlayer1, somePlayer2}, someParameters, middleware?)
caution
Uses RemoteClientMiddleware for now due to uncertainty around how to handle a list of players for middleware.
Connect
Connects a handler function to the given RemoteEvent. (Server & Client)
-- Client
NeoNet:Connect("PointsChanged", function(points)
print("Points", points)
end)
-- Server
NeoNet:Connect("SomeEvent", function(player, ...) end)
Handle
This item only works when running on the server. ServerNeoNet:
Handle
(
) →
(
)
Sets the invocation function for the given RemoteFunction.
NeoNet:Handle("GetPoints", function(player)
return 10
end)
SetValue
This item only works when running on the server. ServerNeoNet:
SetValue
(
name:
string
,
value:
any
) →
(
)
Sets the value for the given RemoteValue.
caution
This will completely ignore player-specific values and change the top value.
NeoNet:SetValue("ButtonClicks", 0)
SetTop
This item only works when running on the server. ServerNeoNet:
SetTop
(
name:
string
,
value:
any
) →
(
)
Sets the top value for the given RemoteValue.
NeoNet:SetValue("ButtonClicks", 0)
SetFor
This item only works when running on the server. ServerSets the player-specific value for the given RemoteValue.
NeoNet:Setfor("Role", SomePlayer, "Monster")
SetList
This item only works when running on the server. ServerSets the player-specific value for the given set of players, for the given RemoteValue.
NeoNet:SetList("Role", SomePlayers, "Survivors")
ClearValues
This item only works when running on the server. ServerNeoNet:
ClearValues
(
name:
string
) →
(
)
Removes all player-specific values for the given RemoteValue.
NeoNet:ClearValues("Role") --maybe the game ended in this example
ClearValueFor
This item only works when running on the server. ServerRemoves the player-specific value for the given RemoteValue.
NeoNet:ClearValueFor("Role", SomePlayer) --maybe a survivor died so we remove their role
ClearValuesList
This item only works when running on the server. ServerRemoves the player-specific value for the given set of players, for the given RemoteValue.
NeoNet:ClearValuesList("Role", SomePlayer) --no idea what the example could be here
GetFor
This item only works when running on the server. ServerGets the player-specific value for the given RemoteValue. If there is no player-specific value, the top value will be returned.
local role = NeoNet:GetFor("Role", SomePlayer)
Clean
This item only works when running on the server. ServerNeoNet:
Clean
(
) →
(
)
Destroys all remotes. This should really only be used in testing environments and not during runtime.
Observe
This item only works when running on the client. ClientConnects a function to the given RemoteValue, which will be called each time the value changes + when initially observed.
NeoNet:Observe("ButtonClicks", function(newValue)
print(tostring(newValue) .. " Clicks")
end)
Invoke
This item only works when running on the client. ClientNeoNet:
Invoke
(
name:
string
,
...:
any
) →
...any
Invokes the RemoteFunction with the given arguments.
local points = NeoNet:Invoke("GetPoints")
IsValueReady
This item only works when running on the client. ClientNeoNet:
IsValueReady
(
name:
string
) →
boolean
Invokes the RemoteFunction with the given arguments.
local points = NeoNet:Invoke("GetPoints")