Module Server

Keeps clients up to date by sending messages back and forth

Info:

  • Release: 0.0.1
  • Author: Will

Functions

start (port) First call, used to initialize the server.
on (cmd, callback) Used to set callbacks which are called when the clients send a certain command.
send (ip, port, cmd, params, playerID) Sends a message to the clients
broadcast (cmd, params, playerID) Send a message from one player to every player on the server
instantiate (params, senderID) Spawn an object accross all clients
update () Update the network.
Deserialize (ser) Deserialize a string by running it with Lua
newID () Create a new ID used for either entities or players.
log (str) Print to the command line and log to a file

Tables

Network Stores network variables and callbacks


Functions

start (port)
First call, used to initialize the server. Sets up UDP to listen for clients

Parameters:

  • port number Port number to host server on
on (cmd, callback)
Used to set callbacks which are called when the clients send a certain command. The function can return a string and a table as a parameter, which will then be broadcasted to all players on the server.

Parameters:

  • cmd string The command to listen for. Ex: 'update'
  • callback function The function called when this command arrives
send (ip, port, cmd, params, playerID)
Sends a message to the clients

Parameters:

  • ip string IP to send the command to
  • port number Port to send the command to
  • cmd string The command to send. This should be the same as the listener on the client side
  • params table Parameters to send to the listeners. It will be serialized to a string and deserialized later
  • playerID number The ID of the player sending the command
broadcast (cmd, params, playerID)
Send a message from one player to every player on the server

Parameters:

  • cmd string The command to send. This should be the same as the listener on the client side
  • params table Parameters to send to the listeners. It will be serialized to a string and deserialized later
  • playerID number The ID of the player sending the command
instantiate (params, senderID)
Spawn an object accross all clients

Parameters:

  • params table Parameters to send to the listeners. It will be serialized to a string and deserialized later
  • senderID number The ID of the player sending the command
update ()
Update the network. Loops through all messages, handling them by calling their callbacks
Deserialize (ser)
Deserialize a string by running it with Lua

Parameters:

  • ser
newID ()
Create a new ID used for either entities or players. The ID is unique and ranges from [0, 999999]

Returns:

    number The newly created ID
log (str)
Print to the command line and log to a file

Parameters:

  • str string The string to log

Tables

Network
Stores network variables and callbacks

Fields:

  • udp The interface with the clients
  • callbacks A table filled with callbacks that the user creates
  • id The ID assigned to the server. Default: -1
  • players A table filled with player objects
  • numPlayers Keeps track of the number of players connected to the server
  • entities Keeps track of any entities spawned into the game with instantiate
generated by LDoc 1.4.3 Last updated 2016-04-04 22:06:14