Multiplayer is based on modified version of DefNet. The core of the game can be copied and with a couple of changes the server can be launched outside the game client.
The game client for network-dependent actions accesses the network table, which stores various functions, depending on what game mode is currently.
Something like:
network.war(land1, land2)
Different actions are performed depending on the game mode:
- Single - do something
- Client - send data to server
- Server - do something and send data to clients
Interface is one. The server also supports various plugins. So I write logic in them. For example, a chat plugin create and attribute messages. Plugin system allows kick players. Plugins are completely independent of each other. They can register commands, also have a common space. That is, the chat plugin makes the chat feature publicly available to all plugins. And the kick plugin can use it to create message that someone was kicked from the game
To search for local games, I wrote two modules that use UDP.