Skip to content

New Network Protocol

XHawk87 edited this page Jan 29, 2025 · 8 revisions

This wiki page is a scratch pad for the team to capture notes/thoughts on the implementation of a new network protocol.

Sending Lua around

As a ruleset modder, I'd like to be able to send custom data from Lua and Lua scripts to the client, and use them to customise the interface to make advanced ruleset changes more intuitive for the user. -Hawk

I'd like to avoid arbitrary code execution on the client, even if in a sandbox. However attaching custom properties to objects can be considered. -louis94

I guess it need not require active code so long as there are extensive customisation options that we can configure for the interface, such as template strings for any text, adding custom sections or tabs to screens with some kind of markup, adding extra columns to tables etc, then any data sent over the network can be used in those. -Hawk

For example, we might want to add a new stat to units, like how much water they have on them. The client-side script could then use that custom data attached to a unit to display a bar on the unit sprite for how much water they have left, and display a warning red line when a go-to would put them in danger of running out of water in a desert or salt-water ocean like we have for fuel and HP loss. -Hawk

Overall protocol structure

Packets as they are are highly specialized. This means we need to implement the update operation separately for each object type. I think the protocol's job should be to synchronize objects from the server to the client and send change requests the other way around. This means the engine would store a list of objects with automatic sync and notification signals for changes. -louis94

It'd be really useful to lift the arbitrary restrictions on number of custom action enablers, unit type and class flags etc. It would make it a lot more flexible for creating custom rulesets. -Hawk

WebSocket

Using raw sockets means we need to implement many things ourselves. WebSocket would take care of some of the annoying bits for us (encryption, compression, message segmentation). It also offers multiplexing multiple games over a single port and would pave the way for browsers to connect. -louis94

Sending tilesets

A recurring problem faced by ruleset designers is the need for graphics to be present on the client side. Servers could serve resources over HTTP and signal that to the client. -louis94

Bridging servers

Multiple maps could be implemented by bridging servers together with a server-server protocol, allowing scripts to exchange data between them such as when a unit moves between maps, or to keep nation data synchronised. The primary server in a cluster could act as a relay for clients so that multiple maps could be integrated into the client, rather than having to switch between servers manually or open several simultaneously. -Hawk