Skyline Lua API  Version 1.0 RC1
Lua Script Reference for Skyline Game Engine.
raknet Class Reference

#include <LUA_API_RakNet.h>

Public Member Functions

void dissconnect ()
 Stops a server or client when called. More...
 
void OpenServer (String port, int maxConnections, String Password, GlobalEnum THREAD_TYPE)
 Opens a server. More...
 
void OpenClient (int IP, String port, String password, GlobalEnum THREAD_TYPE)
 Opens a Client. More...
 
void Subscribe (GlobalEnum ID, functionCall)
 Special Lua callback to connect messages with user functions. More...
 
void Send (int Stream)
 Sends a prepared message to the network. : Stream this is a returned value from the raknet.bitStreamCreate() command.
: ClientID: if called from a server then the client id is pass as a second arg.

Note: the enums NETTYPE_UINT8 is used for Ints and NETTYPE_STRING for passing strings. More...
 
void SendImmediate (int Stream, int clientID)
 Sends a prepared message to the network. : Stream this is a returned value from the raknet.bitStreamCreate() command.
: ClientID: client id is passed as a second arg.

Note: the enums NETTYPE_UINT8 is used for Ints and NETTYPE_STRING for passing strings. More...
 
void update ()
 Updates the raknet system and sends any messages throught the subscribe() option. More...
 
void Ban (user, value)
 Bans a user. More...
 
void RemoveBan (user, value)
 Remove a Ban. More...
 
int id IsBanned ()
 check for ban More...
 
void Kick ()
 Kick out a user. More...
 
void GetUserNetwork ()
 GetUserNetwork. More...
 
String Ping ()
 Ping returns in ms. More...
 
String Stats (int clientID)
 display current server Statistics More...
 
void Sleep (int ms)
 Puse the system for x ms. More...
 
void bitStreamCreate ()
 Creats a bitsteam for writing to. More...
 
void bitStreamWrite ()
 Write to a created bitsteam. This message can be repeated many times for various data. More...
 
void bitStreamRead ()
 Read data from a bitsteam in the same order that is was created. More...
 
void SendPosition (int objID, float x, float y, float z)
 Sends a prepared entity setPosition to the network. The player doesnt get a signal back
all users appart from the sender. : Stream this is a returned value from the raknet.bitStreamCreate() command.
: objID:
: x:
: y:
: z:

Here is a Small Example of how to use this function: More...
 

Detailed Description

This area covers RakNet networking functions. Tools to create your server and clients in Lua
Use as raknet.function()
A server is required for both lan or wan and the clients then connect to this server.
Please see the examples in the scritps folder.

For more information on how these functions can be used please visit the User Manual - http://www.chi-ad.com/Skyline/SDN/

Member Function Documentation

void raknet::Ban ( user  ,
value   
)

Bans a user.

Here is a Small Example of how to use this function:

 
void raknet::bitStreamCreate ( )

Creats a bitsteam for writing to.

Here is a Small Example of how to use this function:

function sendMessage(ID_TYPE, NETTYPE, msgStr) -- sends a single message good for chat and /commands
    bsOut = raknet.bitStreamCreate(ID_TYPE)
    raknet.bitStreamCreate(bsOut, msgStr, NETTYPE)
    raknet.Send(bsOut)
end
void raknet::bitStreamRead ( )

Read data from a bitsteam in the same order that is was created.

Here is a Small Example of how to use this function:

raknet.Subscribe(ID_VEHICLE_SPAWN, function(bs)
    local iID =  raknet.bitStreamRead(bs, NETTYPE_TUINT8)
    local posX = raknet.bitStreamRead(bs, NETTYPE_TFLOAT)
    local posY = raknet.bitStreamRead(bs, NETTYPE_TFLOAT)
    local posZ = raknet.bitStreamRead(bs, NETTYPE_TFLOAT)
    local rotX = raknet.bitStreamRead(bs, NETTYPE_TFLOAT)
    local rotY = raknet.bitStreamRead(bs, NETTYPE_TFLOAT)
    local rotZ = raknet.bitStreamRead(bs, NETTYPE_TFLOAT)
    local sMesh =raknet.bitStreamRead(bs, NETTYPE_TSTRING)
    local sMat = raknet.bitStreamRead(bs, NETTYPE_TSTRING)
    --plus any other vars that may be required

    lprint("A Vehicle has spawned in.\n")
    -- ***************************************
    -- DO WHATEVER WITH THE RECEIVED INFO HERE
    --   DON'T FORGET TO INCLUDE PREDICTION!
    -- ***************************************
end)
void raknet::bitStreamWrite ( )

Write to a created bitsteam. This message can be repeated many times for various data.

Here is a Small Example of how to use this function:

raknet.Subscribe(ID_VEHICLE_SPAWN, function(Sender, bsIn)
    local iID =  raknet.bitStreamRead(bsIn, NETTYPE_TUINT8)
    local posX = raknet.bitStreamRead(bsIn, NETTYPE_TFLOAT)
    local posY = raknet.bitStreamRead(bsIn, NETTYPE_TFLOAT)
    local posZ = raknet.bitStreamRead(bsIn, NETTYPE_TFLOAT)
    local rotX = raknet.bitStreamRead(bsIn, NETTYPE_TFLOAT)
    local rotY = raknet.bitStreamRead(bsIn, NETTYPE_TFLOAT)
    local rotZ = raknet.bitStreamRead(bsIn, NETTYPE_TFLOAT)
    --To reduce size of packet, the next two vars could be reduced to NETTYPE_TUINT8 or NETTYPE_TUINT16
    --using an enum or similar
    local sMesh = raknet.bitStreamRead(bsIn, NETTYPE_TSTRING)
    local sMat =  raknet.bitStreamRead(bsIn, NETTYPE_TSTRING)
    --plus any other vars that may be required

    -- *********************************
    -- Check Data for consistency here??
    -- *********************************

    local bsOut = raknet.bitStreamCreate(ID_SPAWN)
    bsOut = genSpawnWrite(bsOut, SKYLINE_ID)
    --plus any other vars that may be required

    for Key, User in pairs(Users) do
        if (not User["isBanned"] and not User["isKicked"] and User["isConnected"]) then
            raknet.Send(bsOut, Key)
        end
    end
end)

function genSpawnWrite(bsIn, iDIn)
    raknet.bitStreamWrite(bsIn, iDIn.iD, NETTYPE_TUINT8)
    raknet.bitStreamWrite(bsIn, iDIn.posX, NETTYPE_TFLOAT)
    raknet.bitStreamWrite(bsIn, iDIn.posY, NETTYPE_TFLOAT)
    raknet.bitStreamWrite(bsIn, iDIn.posZ, NETTYPE_TFLOAT)
    raknet.bitStreamWrite(bsIn, iDIn.rotX, NETTYPE_TFLOAT)
    raknet.bitStreamWrite(bsIn, iDIn.rotY, NETTYPE_TFLOAT)
    raknet.bitStreamWrite(bsIn, iDIn.rotZ, NETTYPE_TFLOAT)
    --To reduce size of packet, the next two vars could be reduced to NETTYPE_TUINT8 or NETTYPE_TUINT16
    --using an enum or similar
    raknet.bitStreamWrite(bsIn, iDIn.sMesh, NETTYPE_TSTRING)
    raknet.bitStreamWrite(bsIn, iDIn.sMat, NETTYPE_TSTRING)

    return bsIn
end
void raknet::dissconnect ( )

Stops a server or client when called.

Here is a Small Example of how to use this function:

function onStop()
    raknet.dissconnect();
end
void raknet::GetUserNetwork ( )

GetUserNetwork.

Here is a Small Example of how to use this function:

 
int id raknet::IsBanned ( )

check for ban

Here is a Small Example of how to use this function:

 
void raknet::Kick ( )

Kick out a user.

Here is a Small Example of how to use this function:

 
void raknet::OpenClient ( int  IP,
String  port,
String  password,
GlobalEnum  THREAD_TYPE 
)

Opens a Client.

Parameters
IP: Int IP "127.0.0.1" for use on single pc with server and client otherwise use pc ip
this can be obtained from a DOS console by typing ipconfig.
port: String port to connect with
Password: String for password
THREAD_TYPE: Global Enum or either NET_SINGLETHREADED or NET_MULTITHREADED

Here is a Small Example of how to use this function:

function logIn(password)
    lprint(">>> Attempting to connect.... \n")
    raknet.OpenClient("127.0.0.1", 1337, password, NET_SINGLETHREADED);
end
void raknet::OpenServer ( String  port,
int  maxConnections,
String  Password,
GlobalEnum  THREAD_TYPE 
)

Opens a server.

Parameters
port: String port to connect with
maxConnections: int max number of simultanious connections
Password: String for password
THREAD_TYPE: Global Enum or either NET_SINGLETHREADED or NET_MULTITHREADED

Here is a Small Example of how to use this function:

RakNet.OpenServer(1337, 500, "", NET_SINGLETHREADED)
String raknet::Ping ( )

Ping returns in ms.

Here is a Small Example of how to use this function:

raknet.Subscribe(ID_PING, function(Sender, bsIn)
    local sTmp =raknet.bitStreamRead(bsIn, NETTYPE_TSTRING)
    lprint(sTmp)
end)

--check /ping
--/PING
if (string.lower(sCommand[1]) == "/ping") then
    local iLastPing = 0
    local iAvgPing = 0
    local iLowPing = 0

    iLastPing, iAvgPing, iLowPing = raknet.Ping(clientID)

    BroadcastImmediate(">>>    LAST PING = " .. iLastPing .. "ms", Sender, ID_PING)
    BroadcastImmediate(">>>    AVERAGE PING = " .. iAvgPing .. "ms", Sender, ID_PING)
    BroadcastImmediate(">>>    LOWEST PING = " .. iLowPing .. "ms", Sender, ID_PING)
end
void raknet::RemoveBan ( user  ,
value   
)

Remove a Ban.

Here is a Small Example of how to use this function:

 
void raknet::Send ( int  Stream)

Sends a prepared message to the network. : Stream this is a returned value from the raknet.bitStreamCreate() command.
: ClientID: if called from a server then the client id is pass as a second arg.

Note: the enums NETTYPE_UINT8 is used for Ints and NETTYPE_STRING for passing strings.

Here is a Small Example of how to use this function:

--[[CLIENT SCRIPT EXAMPLE]]
sendMessage(ID_CHAT, NETTYPE_STRING, "Hello World!")

function sendMessage(ID_TYPE, NETTYPE, msgStr) -- sends a single message good for chat and /commands
    bsOut = raknet.bitStreamCreate(ID_TYPE)
    raknet.bitStreamWrite(bsOut, msgStr, NETTYPE)
    raknet.Send(bsOut)
end

--[[CLIENT SCRIPT EXAMPLE]]
Broadcast("Server to Client message!", clientID, ID_CHAT);

function Broadcast(sText, To, iD)
    local bsOut = raknet.bitStreamCreate(iD)
    raknet.bitStreamWrite(bsOut, sText, NETTYPE_STRING)
    raknet.Send(bsOut, To)
end
void raknet::SendImmediate ( int  Stream,
int  clientID 
)

Sends a prepared message to the network. : Stream this is a returned value from the raknet.bitStreamCreate() command.
: ClientID: client id is passed as a second arg.

Note: the enums NETTYPE_UINT8 is used for Ints and NETTYPE_STRING for passing strings.

Here is a Small Example of how to use this function:

function BroadcastImmediate(sText, To, iD)
    local toNumber = tonumber
    local bsOut = raknet.bitStreamCreate(iD)
    raknet.bitStreamWrite(bsOut, sText, NETTYPE_STRING)
    local iTmp = raknet.SendImmediate(bsOut, To)
end
void raknet::SendPosition ( int  objID,
float  x,
float  y,
float  z 
)

Sends a prepared entity setPosition to the network. The player doesnt get a signal back
all users appart from the sender. : Stream this is a returned value from the raknet.bitStreamCreate() command.
: objID:
: x:
: y:
: z:

Here is a Small Example of how to use this function:

 
void raknet::Sleep ( int  ms)

Puse the system for x ms.

Here is a Small Example of how to use this function:

function onUpdate(td)
    raknet.Update()
    raknet.Sleep(20)
end
String raknet::Stats ( int  clientID)

display current server Statistics

Here is a Small Example of how to use this function:

sTmp = raknet.Stats(clientID)
lprint("[INFO]    Server Statistics:")
lprint(sTmp)
void raknet::Subscribe ( GlobalEnum  ID,
functionCall   
)

Special Lua callback to connect messages with user functions.

Parameters
ID: Special callback IDs for connecting events. See examples in the scrip folder for reference.

ID_CONNECTION_REQUEST_ACCEPTED = 16
ID_NO_FREE_INCOMING_CONNECTIONS = 20
ID_DISCONNECTION_NOTIFICATION = 21
ID_CONNECTION_LOST = 22
ID_NICK_NAME = 135
ID_CHAT = 136
ID_COMMAND = 137
ID_ADVERTISE = 138
ID_GONE = 139
ID_BAN = 140
ID_KICK = 141
ID_BANNING = 142
ID_KICKING = 143
ID_PING = 144

Here is a Small Example of how to use this function:
raknet.Subscribe(ID_CHAT, function(bs) subscribe_Chat(bs); end)

function readID(b_s)        if(not ServerConnected) then logNotConect(); return; end return raknet.bitStreamRead(b_s, NETTYPE_UINT8) end
function readString(b_s)    if(not ServerConnected) then logNotConect(); return; end return raknet.bitStreamRead(b_s, NETTYPE_STRING) end

function subscribe_Chat(bs)
    local iID   = readID(bs);
    local sChat = readString(bs);
    local uName = readString(bs);
    lprint(">>> ["..uName .. "] - " .. sChat)
end
void raknet::update ( )

Updates the raknet system and sends any messages throught the subscribe() option.

Here is a Small Example of how to use this function:

function onUpdate(td)
    raknet.Update()
    raknet.Sleep(50)
end

The documentation for this class was generated from the following file: