RakNetLua (updated)

Plugins y todo lo relacionado para Autoplay Media Studio.
RakNetLua
Documentation

THE CLIENT/SERVER LUA MODULE

Código: Seleccionar todo

RakNetLua is a raknet module for lua binding, that has enough api to open client/server communications at network level.
RakNet is a cross platform, open source, C++ networking engine for game programmers
INITIALIZATION
Just use require to load the module. no return values will be sent. Automaticly after this, both namespaces RakNet and BitStream will be available.
require("RakNetLua")

Working with the client

RakNet.OpenClient(string_ip_addr, number_port, string_password, boolean_treadkind)
This will request a connection opening to the server. If you didnt suscribed for packets, this is the moment to do it.
string_ip_addr: any ip or hostname string
number_port: port to server
string_password: string password used on the server, may use blank with empty string ""
boolean_treadkind: use MULTITHREADED or SINGLETHREADED, that got defined on pligin load.
No return will be sent
RakNet.OpenClient("127.0.0.1", 87, "", MULTITHREADED)
Remark on MULTITHREADED/SINGLETHREADED: multithread will spawn a process to read and send data trought network, if you use singlethreaded model you have to make calls to RakNet.Update() each a short value of milliseconds.
[hr][/hr]RakNet.Disconnect()
Closes the previously opened instance of raknet. Call this at least on you app closing event.
No arguments needed
No return will be sent

RakNet.Suscribe(number_packet_id, function_callback)
Closes the previously opened instance of raknet. Call this at least on you app closing event.
number_packet_id: The number of packet to suscribe
function_callback(BitStream): send a callback function where first argument is a BitStream instance. you can use anonymous function or named, just make sure it can handle the bitstream.
No return will be sent
PACKET_ID_CHAT=200
RakNet.Suscribe(PACKET_ID_CHAT, function(bsOut)
      --....do whatever with bsOut....
      print("Recieved chat data");
end)

RakNet.Send(bitstream_data)
Send a previously created (and filled) BitStream data to server.
bitstream_data Created with BitStream.Create(packet_id) or recieved on a suscription callback.
No return will be sent
local bsData = BitStream.Create(PACKET_ID_CHAT)
BitStream.Write(bsData, "test chat line", TSTRING)
RakNet.Send(bsData)

bitstream_data = BitStream.Create(number_packet_id)
Create a bitstream data object
number_packet_id The packet id to craft.
bitstream_data will be sent

data_value = BitStream.Read(bitstream_data, bitstream_type)
Read (next) chunk of data from a BitStram recieved on the suscription callback. it will read from the beggining of the packet and it will pop the data of bitstream for future readings.
bitstream_data the BitStream to read from.
bitstream_type the type of data
return data_value actual value of data
PACKET_ID_CHAT=200
RakNet.Suscribe(PACKET_ID_CHAT, function(bsOut)
      local chat_user = BitStream.Read(bsOut, TUINT8)
      local chat_text = BitStream.Read(bsOut, TSTRING)
      print("User id "..chat_user.." sent chat: "..chat_text);
end)

BitStream.Write(bitstream_data, data_value, bitstream_type)
Write (next) chunk of data on a BitStram. It will append the data on the packet.
bitstream_data the BitStream to write in.
bitstream_type the type of data
data_value the data to append.
no return will be sent
--see RakNet.Send example

Remark on BitSteam Types: The type of data determines how many data will consume the value on the packet, so always use lowest possible size for you data. All possible types are:
TBOOL, TUINT8, TINT8, TUINT16, TINT16, TUINT32, TINT32, TFLOAT, TDOUBLE, TLONG, TSTRING

Working with the server

RakNet.OpenServer(number_port, number_max_peers, string_password, boolean_treadkind)
This will open a server. If you didnt suscribed for packets, this is the moment to do it.
number_port: port to server
number_max_peers: maximum clients that can connect to the server
string_password: password of the servers that clients has to use, may be blank with ""
boolean_treadkind: use MULTITHREADED or SINGLETHREADED, that got defined on pligin load.
No return will be sent
RakNet.OpenServer(87, 500, "", MULTITHREADED)
Remark on MULTITHREADED/SINGLETHREADED: multithread will spawn a process to read and send data trought network, if you use singlethreaded model you have to make calls to RakNet.Update() each a short value of milliseconds.

All the client api are also available on server with few changes:
RakNet.Send(bitstream_data, number_peer_id)
RakNetSuscribe(number_packet_id, function_callback(bitstream_data, number_peer_id))
Both functions will recive extra parameters for user id number, in order to send data to correct client. on client version this is not used since you can only send data to 1 peer, the server.

string_ip, number_port, number_ping_avg = RakNet.GetUserNetwork(number_peer_id)
Get peer data from peer id number. returns ip, port and ping average.
RakNet.Kick(number_peer_id)
Kick some peer, dropping the connection.
RakNet.Ban(number_peer_id, number_seconds)
Kick a peer and disallow it from reconnecting in the given time.
RakNetLua_Server.exe

its an easy to use executable that runs a lua script called server.lua and loads raknetlua on it. Its a general propourse server for windows that also run on linux with wine.
It adds to server an HTTP interface, and command line input. see server.lua in examples.
DOWNLOAD & GIT

Git repo: http://git.euwebhost.com/Pabloko/lua-raknet/
Windows build (msvc aware) - dynamic lua vm 5.1.4 (luajit compatible) + demo
HIDE: ON
Hidebb Message Hidden Description
Imagen
let me play with this sir PLAY i tell you lol
In AMS how would I use it like I did before? do I have to call the update function then check the io ?

That part is the confusing part and I have a few problems with the demo just laggying or been really slow, but the old version I just added the function in to ams and then build up the returns, can I do that with this one? or don't I have access to the thread like we did before?

I not able to test in AMS just yet partner is unwell so not at my pc
Reading and testing the code I think I know how to make this work in AMS thank you so much for the update of this dll I really hope to update my idea with this better DLL the HTTP option is epic and I love it
I have been playing with this for a few hrs now.

What it can do is serv small static web pages or a website that loads most of its content from urls, I have found via the AMS UI you can only server the web browser about 8KB tops, I not tested the lua version of this what might be more since its much more optimized.

I feel its very slugish when you use the Multi Thread option, but the timer option seems to work very well.

Thanks for the update DLL, I still going to use the old one for my own project and build a mini server with this one, thanks for your hard work bud


:dealwithit-1414024955:
graças
Thanks
thanks
Thanks for this, really useful!

Just one issue, I get a '502 Bad Gateway' message when trying to access the repo (tried with Edge, Firefox & IE)?? Does anyone have a recently downloaded copy of the repo that they could post?

Thanks in advance

Shando
esto icluso serviria para un game online gracias
Muchas gracias
greats, thanks :D
gracias
thankkkkkkkkkssssssssssssss
thnksssssssssssssssssssssss
gracias
teşekkürler
Thanks
Dead Project but thanks
gracias pabloko