Giter Site home page Giter Site logo

Comments (25)

bkacjios avatar bkacjios commented on May 27, 2024 2

No problem. Glad to know someone is making something cool with this side project of mine. :D

from lua-mumble.

bkacjios avatar bkacjios commented on May 27, 2024 1

Alright well, I decided on making mumble.client:getUsers() return an ordered table of users, rather than a key=session, value=user pair. This allows you to pass the table without modification to mumble.client:sendPluginData()

I removed the vararg functionality since mumble.client:sendPluginData(String dataID, String plugindata, Table {mumble.user, ...}) is for sending data to multiple clients.

mumble.user:sendPluginData(String dataID, String plugindata) would be for sending to individual clients

I think this makes more sense.

from lua-mumble.

hbeni avatar hbeni commented on May 27, 2024

The code is pretty old, and I'm very sure it worked before...

from lua-mumble.

hbeni avatar hbeni commented on May 27, 2024

I bisected it; was introduced by 61691ef

from lua-mumble.

hbeni avatar hbeni commented on May 27, 2024

OK, from what I understand, this not actually broken, but I need to pass the args different.

How can I pass the users of the table as variable argumentation?

from lua-mumble.

hbeni avatar hbeni commented on May 27, 2024

https://www.lua.org/pil/5.2.html

-> need to use unpack()

from lua-mumble.

hbeni avatar hbeni commented on May 27, 2024

Reopening: even with a simple example i don't get any data anymore:

Receiver bot, just dumps the data to terminal:

mumble = require("mumble")  -- get the mumble API

local host = "fgcom.hallinger.org"
local port = 64738
local cert = "bot.pem"
local key  = "bot.key"

print("connecting to "..host.." on port "..port.." (cert: "..cert.."; key: "..key..")")
local client = assert(mumble.connect(host, port, cert, key))
client:auth("test-rcv")
print("  connect and bind: OK")


client:hook("OnServerSync", function(client, event)
    print("Sync done; server greeted with: ", event.welcome_text)
           
    -- try to join fgcom-mumble channel
    local ch = client:getChannel("fgcom-mumble")
    event.user:move(ch)
    print("joined channel fgcom-mumble")
end)
    
    

client:hook("OnPluginData", function(client, event)
    --["sender"] = mumble.user sender, -- Who sent this data packet
	--["id"]     = Number id,          -- The data ID of this packet
	--["data"]   = String data,        -- The data sent (can be binary data)
	--["receivers"]				= {  -- A table of who is receiving this data
	--	[1] = mumble.user,
	--},
    print("DATA INCOMING FROM="..event.sender:getSession())
    print("  ID="..event.id)
    print("  DATA="..event.data)

end)

mumble.loop()

Sending bot, just spams data:

mumble = require("mumble")  -- get the mumble API

local host = "fgcom.hallinger.org"
local port = 64738
local cert = "bot.pem"
local key  = "bot.key"

print("connecting to "..host.." on port "..port.." (cert: "..cert.."; key: "..key..")")
local client = assert(mumble.connect(host, port, cert, key))
client:auth("test-send")
print("  connect and bind: OK")

local timer = mumble.timer()
client:hook("OnServerSync", function(client, event)
    print("Sync done; server greeted with: ", event.welcome_text)
           
    -- try to join fgcom-mumble channel
    local ch = client:getChannel("fgcom-mumble")
    event.user:move(ch)
    print("joined channel fgcom-mumble")
    
    o=0
    timer:start(function(t)
	    o=o+1
        print(o..": send plugin message to all users ")
        users = client:getUsers()
        i = 0
        for s,u in pairs(users) do
            i=i+1
            print("  "..i.." ("..s.."): "..u:getName())
            --client:sendPluginData("FGCOM:UPD_USR:0", "CALLSIGN=test-"..i, u)
        end
            
        client:sendPluginData("FGCOM:UPD_COM:0:0", "FRQ=123,PTT=0"..i, unpack(users))
        
    end, 1, 1)
    
    --segfault client:sendPluginData("FGCOM:UPD_LOC", "CALLSIGN=test", client:getUsers()) 

    print("send ok")
end)

mumble.loop()

from lua-mumble.

hbeni avatar hbeni commented on May 27, 2024

somehow it looks like sendPluginData is putting nothing on the wire...

from lua-mumble.

bkacjios avatar bkacjios commented on May 27, 2024

I believe to have found the issue..

I check if the argument is a table rather than a userdata

case LUA_TTABLE:

Theoretically, if you pass the session numbers instead of the user metatable it will work. I'll have a fix for this soon though.

from lua-mumble.

hbeni avatar hbeni commented on May 27, 2024

Hm, but when i pass the arguments (table of users) using the unpack(), it will sort-of-work again.
What then just does not work, is that nothing is sent anymore.

Or is this what you are talking about?

from lua-mumble.

bkacjios avatar bkacjios commented on May 27, 2024

Basically, if your table contained the actual user metatable, it would ignore it. The varargs were accepting numbers (the clients session number) OR a mumble.user metatable object (in which it would get the session number from) but due to me checking the wrong type value of the vararg, it was ignoring it.

Either way, this should be fixed now.

from lua-mumble.

hbeni avatar hbeni commented on May 27, 2024

Will test this! Thank you for the fast fix!

from lua-mumble.

hbeni avatar hbeni commented on May 27, 2024

Hm. The bot pair i posted above still has the issue....

from lua-mumble.

hbeni avatar hbeni commented on May 27, 2024

Like you said, this works:
client:sendPluginData("FGCOM:UPD_COM:0:0", "FRQ=123,PTT=0"..i, unpack({82,98}))

But this not:
client:sendPluginData("FGCOM:UPD_COM:0:0", "FRQ=123,PTT=0"..i, unpack(client:getUsers()))

from lua-mumble.

bkacjios avatar bkacjios commented on May 27, 2024

I think the problem is unpack(users) may not actually work, since it's keyvalues has the format of [session] = user
I think unpack only supports an ordered list when they keys increment by 1.

I just added the ability to pass a table to sendPluginData again, alongside the new behavior of allowing varargs as well. If you revert all your changes to your bot when using that latest commit, it should be working again.

from lua-mumble.

bkacjios avatar bkacjios commented on May 27, 2024

Also, it may be worth mentioning, but I also added a method to the mumble.user metatable as well for sending plugin data directly to that user.

-- Transmit a plugin data packet to this user
mumble.user:sendPluginData(String dataID, String plugindata)

from lua-mumble.

hbeni avatar hbeni commented on May 27, 2024

Cool, I will try it and report back.
Thanks again for the quick fixes!

from lua-mumble.

hbeni avatar hbeni commented on May 27, 2024

Tried it:

🆗 This works (using the old fashioned table containing user objects):

users = client:getUsers()
u_tbl = {}
i = 0
for s,u in pairs(users) do
  i=i+1
  print("  "..i.." ("..s.."): "..u:getName())
  table.insert(u_tbl, u)
end
client:sendPluginData("FGCOM:UPD_USR:0", "CALLSIGN=test-"..i, u_tbl)

🛑 This still doesn't (using the user table):
client:sendPluginData("FGCOM:UPD_COM:0:0", "FRQ=123,PTT=0"..i, users)

This is fine enough for me :) Thank you :)
But if you like, I can do more testing for the usertable invocation

from lua-mumble.

bkacjios avatar bkacjios commented on May 27, 2024

That.. kind of makes sense actually why that second case doesn't work.

client:getUsers() returns a table in the format of..

{
    [session] = mumble.user,
    [session] = mumble.user,
    [session] = mumble.user,
}

When you pass this table to sendPluginData() it tries to get the length of the table using lua_objlen. The problem is, since we have unordered table keys, it can't get the length, and thus fails.

Maybe I should add a method like client:getUserList() that just returns a proper ipairs-able table of mumble.user's

Like..

{
    [1] = mumble.user,
    [2] = mumble.user,
    [3] = mumble.user,
}

from lua-mumble.

bkacjios avatar bkacjios commented on May 27, 2024

I may also create a new meta object.. Something like..

local data = mumble.plugindata("FGCOM:UPD_USR:0")
data:setData("Hello world! {x=3, y=8}")
data:addUser(32) -- Session number
data:addUser(client.me) -- User object
data:addAllUsers() -- Adds all users in the server
data:addUsersIn(client.me:getChannel()) -- Adds all users in a given channel
data:clearUsers() -- Removes all users
client:sendPluginData(data)

You think this would make things easier and less ambiguous? I'm open to suggestions here, since you're the only person I know who's using this functionality.

from lua-mumble.

hbeni avatar hbeni commented on May 27, 2024

I think this makes more sense.

Indeed, i think that makes perfect sense. I can always get the session id from the user object easily, too; but this way it's much more easy to iterate and work with. Thanks for the addition, I will test and report back!

from lua-mumble.

hbeni avatar hbeni commented on May 27, 2024

tested commit 5734df4


Alright well, I decided on making mumble.client:getUsers() return an ordered table of users, rather than a key=session, value=user pair. This allows you to pass the table without modification to mumble.client:sendPluginData()

Tested OK 🆗


mumble.user:sendPluginData(String dataID, String plugindata) would be for sending to individual clients

Tested, but I get a failure:

client:hook("OnPluginData", function(client, event)
    if event.id:len() > 0 and event.id:find("FGCOM:ICANHAZDATAPLZ") then
        print("OnPluginData(): client asks for data: "..tostring(event.sender))
        event.sender:sendPluginData("FGCOM:TESTREPLY:0", "1234567890")
    end
end)

test/pluginSendtest.lua:62: attempt to call method 'sendPluginData' (a nil value)

from lua-mumble.

bkacjios avatar bkacjios commented on May 27, 2024

Turns out I forgot to register that function in the users metatable. Whoops. Fixed!

from lua-mumble.

hbeni avatar hbeni commented on May 27, 2024

Just tested e95fda6

EDIT: All is fine. Something went wrong with my compile.
The event.sender:sendPluginData() does work like expected, as does the client:sendPluginData() with user table

from lua-mumble.

hbeni avatar hbeni commented on May 27, 2024

As all is allright, I close this for you, okay?

Thank you again, for your fast response and fix :)
Much appreciated! Awesome lib, making my life easy! 🎉

from lua-mumble.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.