User:RossyMiles/Flatline

From OniGalore
Jump to navigation Jump to search

Flatline is the most recent proposed multiplayer mod for Oni. This document is a work in progress.

Flatline API

Both the Flatline clients and dedicated servers will run inside Daodan inside an official build of Oni. This is because a copy of Oni is needed to fully simulate the scripting and physics in a game.

Two sets of functions will be provided. The Net* functions will provide a basic, non-blocking UDP sockets library. The FLr* functions will be the rest of the code required.

NetPlatform_*

These functions provide all the platform specific functionality required by Net*.

bool NetPlatform_Initalize()
This function is called when the network functionality is required. On Windows, it makes a call to WSAStartup.

void NetPlatform_Shutdown()
For every call to NetPlatform_Initalize, there has to be a corresponsing call to NetPlatform_Shutdown. On Windows, this function calls WSACleanup.

NetUPnP

These functions provide basic automatic port forwarding for computers behind a router.

bool NetUPnP_Initalize(char** localip, char** routerip) Initializes the UPnP library. Places the local ip address in localip and places the router's ip address in routerip.

bool NetUPnP_Shutdown() Closes the NetUPnP library. Frees the strings pointed to by localip and routerip.

NetUDPSocket_*

int NetUDPSocket_Create(uint16_t port)
Creates a new, non-blocking, UDP socket and binds it to the port specified. If the specified port is 0, the socket is automatically bound to an unused port.

bool NetUDPSocket_Close(int socket)
Destroys a UDP socket created with NetUDPSocket_Create.

bool NetUDPSocket_Send(int socket, sockaddr_in/sockaddr_in6 address, const char* data, uint16_t datalen)
Sends a packet of data to the specified address using the specified socket.

bool NetUDPSocket_Recieve(int socket, char* data, uint16_t* datalen, sockaddr_in*/sockaddr_in6* address)
Recieves a single packet from the specified socket. Places the received data in "data", the length of the data returned in datalen, and the address the packet was received from in address. If there are no packets in the buffer, the function returns immediately.