10-24-2015, 06:55 PM
(10-22-2015, 04:50 PM)NiLSPACE Wrote:function StringLenToASCII(a_Player, a_String) local template = ("return \0\%s"):format(a_String:len()) local loader = loadstring(template); -- Sandbox the loader setfenv(loader, {}); local succes, res = pcall(loader) if (not succes) 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; else return res; end end
(10-22-2015, 05:31 PM)xoft Wrote:--- Returns the string prefixed with its length, as used in the BungeeCord protocol local function writeProtocolString(a_Str) local len = a_Str:len() return string.format("%c%c%s", math.floor(len / 256), math.floor(len % 256), a_Str) end -- usage: client:SendPluginMessage("BungeeCord", writeProtocolString("Connect") .. writeProtocolString("SomeServer"))
Finally got around to looking at these. Attempted both methods, trying xoft's first. String was improperly formed and led to kick by fake DC (same issue as when I was using \0\14 for a 5 digit string, so the string is being returned as "\0\\" .. "#" instead of "\0\#"). Attempted using %x and %u to identical results.
NilSPACE's function isn't even correct as far as I can tell. No idea how to use setfenv, so yeah.
Code:
[03:27:53] LUA: Plugins/BungeeButtons/main.lua:40: bad argument #1 to 'setfenv'
(number expected, got nil)
[03:27:53] Stack trace:
[03:27:53] [C](-1): setfenv
[03:27:53] Plugins/BungeeButtons/main.lua(40): StringLenToASCII
[03:27:53] Plugins/BungeeButtons/main.lua(188): (no name)
[03:27:53] Stack trace end
[03:27:53] Error in plugin BungeeButtons calling function <callback>()
function StringLenToASCII(a_Player, a_String) local template = ("return '\0\%s'"):format(a_String:len()) local loader = loadstring(template); return assert(loader,"weird ass error")() endbut it just returns "\0\\" .. "#", which won't work. Also tried with %u to identical results (the fake offline kick).
BACK TO THE ARRAY OF VALUES!
Also I don't WANT to use the array of values. I'm currently working on a plugin that could send plugin messages of incredible lengths (like 200+ characters) and that doesn't sound super fun to make an array for. It's just, if a method can't be found, I'll have to.
I'll probably ask on stackoverflow at some point.