Cuberite Forum

Full Version: Network API
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
I tried testing it, but when I used restart to update the webadmin users I got this error:
[Image: 391b0a9221.png]
After that the server wasn't responding to anything.
Nice catch. Both errors (socket not freed and server not aborting on error) should be fixed in 0edf7ceb28b289f96314bb9b2f7030b61ba4f313.
Great, everything worked for me exept that. Smile
I've rebased the branch on top of current master. I guess I'll start a parallel branch with the Lua API in the meantime, until we have more confirmations that the migration is working properly.
Ooooh, that was quite fast Smile The first actual usage of the Lua API is working:
Code:
[8863cdd6|14:26:22] Startup complete, took 6040ms!
net client
[af4780c4|14:26:29] Executing console command: "net client"
[af4780c4|14:26:29] Client connection request queued.
[aac7ff14|14:26:29] Connected to google.com:80. Sending HTTP request for front page.
[aac7ff14|14:26:32] Received data from google.com:80:
HTTP/1.0 302 Found
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Location: http://www.google.cz/?gfe_rd=cr&ei=hePIVKjQM-ik8wfh0oGYAg
Content-Length: 258
Date: Wed, 28 Jan 2015 13:26:29 GMT
Server: GFE/2.0
Alternate-Protocol: 80:quic,p=0.02

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.cz/?gfe_rd=cr&amp;ei=hePIVKjQM-ik8wfh0oGYAg">here</A>.
</BODY></HTML>

And this is the complete code from the plugin:
function HandleConsoleNetClient(a_Split)
	-- Get the address to connect to:
	local Host = a_Split[3] or "google.com"
	local Port = a_Split[4] or 80

	-- Create the callbacks "personalised" for the address:
	local Callbacks =
	{
		OnConnected = function (a_Link)
			LOG("Connected to " .. Host .. ":" .. Port .. ". Sending HTTP request for front page.")
			a_Link:Send("GET / HTTP/1.0\r\nHost: " .. Host .. "\r\n\r\n")
		end,
		
		OnError = function (a_ErrorCode, a_ErrorMsg)
			LOG("Connection to " .. Host .. ":" .. Port .. " failed: " .. a_ErrorCode .. " (" .. a_ErrorMsg .. ")")
		end,
		
		OnReceivedData = function (a_Data)
			LOG("Received data from " .. Host .. ":" .. Port .. ":\r\n" .. a_Data)
		end,
	}
	
	-- Queue a connect request:
	local res = cNetwork:Connect(Host, Port, Callbacks)
	if not(res) then
		LOGWARNING("cNetwork:Connect call failed immediately")
		return true
	end
	
	return true, "Client connection request queued."
end
That's awesomeBig Grin
I pushed all the code in a new PR. The cNetwork::Connect() function and cTCPLink class are more or less complete. I also pushed the network plugin test code as a new plugin, NetworkTest.
(01-29-2015, 12:19 AM)xoft Wrote: [ -> ]I pushed all the code in a new PR. The cNetwork::Connect() function and cTCPLink class are more or less complete. I also pushed the network plugin test code as a new plugin, NetworkTest.

Sweet!
I've got server functionality exported as well, it seems to work nicely. I have written two servers, the traditional Echo server, and a Text-Fortune server.

There's only one problem that I've run into now. Object ownership. Sometimes we want Lua to own the object (so that it is garbage-collected), and sometimes we want the same object to direct its own lifetime. This will need some detailed thinking.
I think it should be all sorted out, I've been testing with the NetworkTest plugin and it all seems to work. Feel free to review and comment on the PR: https://github.com/mc-server/MCServer/pull/1718
There's still an issue of missing documentation for the new classes. That will be a tough one, with the callback tables being returned in a callback from a table Smile

Bah! It still doesn't compile on Linux Sad
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15