Attempting to get Bungeecord Teleportation Functional
Using as a reference, but it seems the "hack" broke (or I just programmed it wrong), and I just learned Lua today so I have no idea where to go from here.

function Initialize(Plugin)
	-- Hooks
	PLUGIN = Plugin -- NOTE: only needed if you want OnDisable() to use GetName() or something like that
	-- Command Bindings
	cPluginManager.BindCommand("/serverchange", "test.node", ServerChange, " - Description of command")
	LOG("Initialised " .. Plugin:GetName() .. " v." .. Plugin:GetVersion())
	return true

function ServerChange(a_Script,a_Player)
	local server = "TestServer1";
	local StringLen = server:len();
	local bytearray = ""
	for i = 1, StringLen do
		bytearray = bytearray .. "\\";
		local nextbyte = string.byte(server,i)
		local nextstring = tostring(nextbyte);
		bytearray = bytearray .. nextstring;
--	cClientHandle:SendPluginMessage("BungeeCord", "\0\7Connect\0\14" .. bytearray);
	cClientHandle:SendPluginMessage("BungeeCord", "\0\7Connect\0\14TestServer1");

function OnDisable()
	LOG(PLUGIN:GetName() .. " is shutting down...")

This isn't the actual plugin, but this is a quick test one I made to see if Bungeecord Teleporting works (yes I realize I could just use /server or the slash server bungee plugin to do this exact thing, this is just a proof of concept plugin that you can do Bungee TP using Plugin Messages through Cuberite).

If you notice, I have two Plugin Message lines. The first (currently commented) spits out this error:
[22:03:45] LUA: Plugins/BungeeTest/Main.lua:29: error in function 'SendPluginMessage'.
     argument #1 is 'class cClientHandle'; 'cClientHandle' expected.

[22:03:45] Stack trace:
[22:03:45]   [C](-1): SendPluginMessage
[22:03:45]   Plugins/BungeeTest/Main.lua(29): (no name)
[22:03:45] Stack trace end
[22:03:45] Error in plugin BungeeTest calling function <callback>()
The second (currently in used) spits this error.
The Exact same thing but one line later:
[21:52:28] LUA: Plugins/BungeeTest/Main.lua:30: error in function 'SendPluginMessage'.
     argument #1 is 'class cClientHandle'; 'cClientHandle' expected.

[21:52:28] Stack trace:
[21:52:28]   [C](-1): SendPluginMessage
[21:52:28]   Plugins/BungeeTest/Main.lua(30): (no name)
[21:52:28] Stack trace end
[21:52:28] Error in plugin BungeeTest calling function <callback>()

I'm really hoping this is just me screwing up the code. If it isn't, it's probably something that only VERY few people can explain.

Edit: Just attempted converting everything to Byte (including the Connect), and it's the same error with a new line number.
Thanks given by:
Hello, and welcome to the forum Smile

The problem is that you're using the table of cClientHandle. Try replacing that with a_Player:GetClientHandle()
Thanks given by:
(10-21-2015, 03:44 PM)NiLSPACE Wrote: The problem is that you're using the table of cClientHandle. Try replacing that with a_Player:GetClientHandle()

Thanks for the welcome! It no longer shoots an error.

It still doesn't work though. It IS disconnecting me from one server. However, Bungeecord is just putting me on the default server. If I start on the default server (lobby), it disconnects me with

EOFException : null @

If I go from TestServer1 to lobby, it says in chat "The server you were previously on went down, you have been connected to the lobby". I can make it push me off the server with
a_Player:GetClientHandle():SendPluginMessage("BungeeCord", "\0\7Connect\0\14lobby");
Either of the other two versions say an error has occurred in chat, but don't put an error in console (I haven't looked up how to get the debug mode version yet, so I'll probably do that soon.).

I've already checked. The server pointing is all correct. I'm telling it to connect to lobby from the plugins on TestServer1 and vice versa, and the ports are accurate. The bungeecord /server works as expected, to further that point. For now, I'm going to finish the rest of the coding with my plugin idea, and I'll jump back on this sometime soonish, although it is nearly when I should go to sleep.

Edit: Side question. Let's say I have a table like table={a={aa=1,ab=2},b={},...}. How would I find the name/key of table[1]? So, what would I do to get table[1] -> a, table[2] -> b?
Thanks given by:
Strange, perhaps someone with more experience with the protocol can help you with that.

There are multiple ways you can access tables. You can use brackets (table['a']['aa']), but also periods(table.a.aa). If you want to loop through a table you can use this:
for Key, Value in pairs(table) do
   print(Key, Value)
Thanks given by:
Been messing with the code to no luck. However, I did find one thing...
function ServerChange(a_Script,a_Player)
	local server = "lobby";
	local player = a_Player:GetName();
	local StringLen = server:len();
	local bytearray = {};
	local bytestring = "";
	local connectarray = "\\0\\7";
	local connect = "Connect";
	local ConnectLen = connect:len();
--	local cHandle = a_Player:cClientHandle();
	for i = 1, ConnectLen do
		connectarray = connectarray .. "\\";
		local nextbyte2 = string.byte(connect,i)
		local nextstring2 = tostring(nextbyte2);
		connectarray = connectarray .. nextstring2;
	connectarray = connectarray .. "\\0\\14";
	table.insert(bytearray,string.byte(" "))
	for i = 1, StringLen do
		bytestring = bytestring .. "\\";
		local nextbyte = string.byte(server,i)
		local nextstring = tostring(nextbyte);
		bytestring = bytestring .. nextstring;
--	a_Player:GetClientHandle():SendPluginMessage("BungeeCord", "\0\7Connect\0\14" .. bytestring);
--	a_Player:GetClientHandle():SendPluginMessage("BungeeCord", "\0\7Connect\0\14TestServer1");
--	a_Player:GetClientHandle():SendPluginMessage("BungeeCord", connectarray);
--	a_Player:GetClientHandle():SendPluginMessage("BungeeCord", bytearray);
--	a_Player:GetClientHandle():SendPluginMessage("BungeeCord", "Connect" .. server);
--	a_Player:GetClientHandle():SendPluginMessage("BungeeCord", "ConnectOther " .. player .. " " .. server);
	a_Player:GetClientHandle():SendPluginMessage("BungeeCord", "");

If you send a blank or nonsensical message, you get disconnected in the exact same manner. Maybe the problem isn't the code, but a limitation due to the implementation of plugin messages? That was mentioned in the GitHub posts, and the working solution was a "hack", so.. Otherwise I'm worried I'll need to do a lot of digging into things I don't know to find the possible solution.

On the other topic: I know how to read the value. I want to get the key name of an index. With that same array, I want


to print


not to print {aa=1,ab=2}.
Thanks given by:
I have just checked and the plugin messages are sent correctly even when they contain funny characters. Your code should work (with "\0\7Connect\0\14TestServer1")
Thanks given by:
Even commenting out everything except

    a_Player:GetClientHandle():SendPluginMessage("BungeeCord", "\0\7Connect\0\14lobby");

It has the same result (kicks me but no errors). I thought this might just mean I royally screwed up the program, so I tested it on a Cuberite instance that was not connected to Bungeecord. "An error has occured" message in chat, but didn't get kicked.

Could it have something to do with me testing on windows?

Pastebin of full code

Edit: Just finished compiling a build on CentOS 7 and tested it out. Same issue, except the Minecraft Client shows a slightly different disconnect error:

EOFException : null @

The 197 was a -1 when I tested on Windows.
Thanks given by:
The message is wrong, "lobby" is 5 chars long, so it should be "\0\5" instead of "\0\14".

Perhaps the bungee server could be configured for a more verbose logging output, so it would log what's wrong with the message.
Thanks given by:
THAT'S IT! I've had 0 idea what the \0\# meant, so I was just copying it. Thanks for the assist! So I should just need to use

"\0\7Connect" .. tostring(getn(server_name_variable)) .. server)name_variable

and it will work in my main code. Thanks for the help!

Edit: derp getn is for tables. I'll figure it out soon, this is just a google away. string.length or something.
Thanks given by:
Getting the thing in there in the way I put in my previous post... yeah that doesn't work. Figured out it was because those are ascii encoded characters.... I think. That's my best guess. So I went and reworked the code and made a "switch statement". New relevant code:
function StringLenToASCII(Player,a_String)
  local StringLen = tostring(string.len(a_String));
  local t = {
    ["1"] = "\0\1",
    ["2"] = "\0\2",
    ["3"] = "\0\3",
    ["4"] = "\0\4",
    ["5"] = "\0\5",
    ["6"] = "\0\6",
    ["7"] = "\0\7",
    ["8"] = "\0\8",
    ["9"] = "\0\9",
    ["10"] = "\0\10",
    ["11"] = "\0\11",
    ["12"] = "\0\12",
    ["13"] = "\0\13",
    ["14"] = "\0\14",
    ["15"] = "\0\15",
    ["16"] = "\0\16",
    ["17"] = "\0\17",
    ["18"] = "\0\18",
    ["19"] = "\0\19",
    ["20"] = "\0\20",
    ["21"] = "\0\21",
    ["22"] = "\0\22",
    ["23"] = "\0\23",
    ["24"] = "\0\24",
    ["25"] = "\0\25",
    ["26"] = "\0\26",
    ["27"] = "\0\27",
    ["28"] = "\0\28",
    ["29"] = "\0\29",
    ["30"] = "\0\30",
  if(t[StringLen] == Nil) then
    LOG("The server name is incompatible with this plugin! Please make sure it is 30 characters or less!");
    Player:SendMessageFailure("The server name is incompatible with this plugin! Please make sure it is 30 characters or less!");
    return false
    return t[StringLen]

function ServerChange(a_Script,a_Player)
    local server = "TestServer1";
    a_Player:GetClientHandle():SendPluginMessage("BungeeCord", "\0\7Connect" .. StringLenToASCII(a_Player,server) .. server);

It works! This means I'm limiting a servers name in bungeecord to at most 30 characters, but 1) not many people would find a problem with that and 2) at a simple request, I can increase that to w/e number is needed relatively easily.

I did it with string.len instead of just indexes because I forgot about indexes and coded it that way. Hehe...

By the way, if I understand this right, that means that the second part is literally {NULL} {Start Of Heading} {Connect} {NULL} {Enquiry for 5, Shift out for 14} {Server name} which I find really funny if that's the case. I'd love any explanation/correction about this if it isn't just careful "bit hacking".

Edit: Fixed the code box
Thanks given by:

Users browsing this thread: 1 Guest(s)