1.2.6
This update implements Handlers in scripting, added media fetching, and upgrades to .NET 9! This update also contains many Scripting API changes, so be sure to read them below and in the Engine API.
Handler APIs
The Server Sandboxing has been updated to try and unify scripting with the Client by implementing Handlers. This is very simple to upgrade your code to be compatible. Let's look at an example outdated script and I'll explain how to upgrade it.
// Network Handling
Events.Subscribe(ScriptEvent.OnUserNetworkEvent, function(userid, eventName, eventArgs){
print(userid + " sent the message " + eventName + " with description " + eventArgs[0])
})
Very simple! All this script does is print events that it gets from a client. Now, let's upgrade it with the new Handlers.
// Get the Events Handler
let Events = instance.GetHandler("Events")
// Don't even need to change anything here!
Events.Subscribe(ScriptEvent.OnUserNetworkEvent, function(userid, eventName, eventArgs){
print(userid + " sent the message " + eventName + " with description " + eventArgs[0])
})
Some classes' handlers were renamed. For example, NetworkEvent became Network.
Streaming API
The new Streaming API on the server allows game servers to quickly pull download information for media using yt-dlp. This removes the need for yt-dlp to be installed on the client, allow for greater platform support. Let's take a look at an example of how this can be implemented on the server:
// Get our Handlers
let Events = instance.GetHandler("Events")
let Network = instance.GetHandler("Network")
// Wait for a message from the client
Events.Subscribe(ScriptEvent.OnUserNetworkEvent, function(userid, eventName, eventArgs) {
// Only handle the message if it's the one we're waiting for
if (eventName == "getVideo") {
// Get the media with default options (use GetWithOptions for greater control)
// using a URL provided from the client
Streaming.Get(eventArgs[1], function(videoRequest){
// VideoRequests will return null/undefined if no media is found at the specified URL
if (videoRequest === undefined || videoRequest === null) return
// Send the VideoRequest object (contains the media information) to every client
Network.SendToAllClients("loadVideo", [videoRequest])
}
}
})
This example above is a simplified example of a server waiting for a client to request information about media, then the server relaying it to every client if it is obtained. This can also be extended to cache the VideoRequest on the client, creating greater capabilities for management.
yt-dlp will download to path/to/Hypernex.Networking.Server/ytdlp/yt-dlp. After it downloads you MUST make it executable with the following command:
chmod +x ytdlp/yt-dlp
Not doing this will cause yt-dlp to fail to launch, meaning your clients will be unable to download media!
Changes
- Implement Instances and Handlers Scripting API
- Primarily done to match the Client Sandboxing
- Implement Streaming API with yt-dlp
- Allows the server to obtain information about media to relay to client(s)
- Bumped Nexport to latest
- This also implements support for DynamicNetworkObjects with NetworkedEvents
- Upgraded to .NET 9
- .NET 7 will no longer be supported