Skip to content

Commit

Permalink
Changed mumble.client:sendPluginData() to use varargs rather than a t…
Browse files Browse the repository at this point in the history
…able

Updated stb_vorbis.c to latest
Added mumble.user:listen(mumble.channel)
Added mumble.user:unlisten(mumble.channel)
Added mumble.user:getListens()
Added mumble.voicetarget:getUsers()
Added mumble.voicetarget:getGroup()
Added mumble.voicetarget:getLinks()
Added mumble.voicetarget:getChildren()
  • Loading branch information
bkacjios committed May 28, 2021
1 parent ff421ab commit 61691ef
Show file tree
Hide file tree
Showing 10 changed files with 433 additions and 106 deletions.
58 changes: 47 additions & 11 deletions README.md
Expand Up @@ -101,7 +101,7 @@ mumble.client:disconnect()

-- Transmit a plugin data packet
-- Users table can be a table of mumble.user's OR session numbers
mumble.client:sendPluginData(String dataID, String plugindata, Table users)
mumble.client:sendPluginData(String dataID, String plugindata, [mumble.user, Number session] ...)

-- Transmit a raw, encoded, opus packet
-- Set speaking to false at the end of a stream
Expand Down Expand Up @@ -143,7 +143,8 @@ Table hooks = {
["OnServerPing"] = {
["hook"] = function: 0xffffffff,
["do stuff on ping"] = function: 0xffffffff,
}
},
...
}

-- Register a mumble.voicetarget to the server
Expand Down Expand Up @@ -178,25 +179,21 @@ Table users = mumble.client:getUsers()
Table users = {
[session] = mumble.user,
[session] = mumble.user,
[session] = mumble.user,
[session] = mumble.user,
[session] = mumble.user,
...
}

mumble.channel channel = mumble.client:getChannel(String path)

-- Returns a table of all mumble.channels
Table channels = mumble.client:getChannels()

mumble.channel channel = mumble.client:getChannel(String path)

-- Structure
-- Key: channel id
-- Value: mumble.channel
Table channels = {
[id] = mumble.channel,
[id] = mumble.channel,
[id] = mumble.channel,
[id] = mumble.channel,
[id] = mumble.channel,
...
}
```

Expand Down Expand Up @@ -287,6 +284,24 @@ String hash = mumble.user:getHash()

-- Sets the users avatar image using a string of bytes
mumble.user:setTexure(String bytes)

-- Adds a channel to the list of channels the user is listening to
mumble.user:listen(mumble.channel ...)

-- Removes a channel from the list of channels the user is listening to
mumble.user:unlisten(mumble.channel ...)

-- Returns a table of all channels the user is currently listening to
Table listens = mumble.user:getListens()

-- Structure
-- Key: channel id
-- Value: mumble.channel
Table channels = {
[id] = mumble.channel,
[id] = mumble.channel,
...
}
```

### mumble.channel
Expand Down Expand Up @@ -400,6 +415,18 @@ mumble.timer:stop()
-- Add a user to whisper to
mumble.voicetarget:addUser(mumble.user user)

-- Return a table of all the users currently in the voicetarget
Table users = mumble.voicetarget:getUsers()

-- Structure
-- Key: index
-- Value: Number session
Table channels = {
Number session,
Number session,
...
}

-- Sets the channel that is be shouted to
mumble.voicetarget:setChannel(mumble.channel channel)

Expand All @@ -409,11 +436,20 @@ mumble.voicetarget:getChannel()
-- Sets the specific user group to whisper to
mumble.voicetarget:setGroup(String group)

-- Gets the group name we are whispering to
String group = mumble.voicetarget:getGroup()

-- Shout to the linked channels of the set channel
mumble.voicetarget:setLinks(Boolean followlinks)

-- Returns if we are currently shouting to linked channels of the set channel
Boolean links = mumble.voicetarget:getLinks()

-- Shout to the children of the set channel
mumble.voicetarget:setChildren(Boolean followchildren)

-- Returns if we are currently shouting to children of the set channel
Boolean children = mumble.voicetarget:getChildren()
```

### mumble.encoder
Expand Down Expand Up @@ -937,7 +973,7 @@ ___

### `OnPluginData (mumble.client client, Table event)`

Called when the servers suggest the client to use specific settings.
Called when the client receives plugin data from the server.

``` lua
Table event = {
Expand Down
150 changes: 150 additions & 0 deletions banentry.c
@@ -0,0 +1,150 @@
#include "mumble.h"

#include "channel.h"
#include "user.h"
#include "banentry.h"

int mumble_banentry_new(lua_State *l)
{
MumbleProto__BanList__BanEntry *entry = lua_newuserdata(l, sizeof(MumbleProto__BanList__BanEntry));
mumble_proto__ban_list__ban_entry__init(entry);

entry->address.data = (uint8_t *) luaL_checklstring(l, 1, &entry->address.len);
entry->mask = luaL_checkinteger(l, 2);

luaL_getmetatable(l, METATABLE_BANENTRY);
lua_setmetatable(l, -2);
return 1;
}

static int banentry_setAddress(lua_State *l)
{
MumbleProto__BanList__BanEntry *entry = luaL_checkudata(l, 1, METATABLE_BANENTRY);
entry->address.data = (uint8_t *) luaL_checklstring(l, 2, &entry->address.len);
return 0;
}


static int banentry_getAddress(lua_State *l)
{
MumbleProto__BanList__BanEntry *entry = luaL_checkudata(l, 1, METATABLE_BANENTRY);
mumble_push_address(l, entry->address);
return 1;
}

static int banentry_setMask(lua_State *l)
{
MumbleProto__BanList__BanEntry *entry = luaL_checkudata(l, 1, METATABLE_BANENTRY);
entry->mask = luaL_checkinteger(l, 2);
return 0;
}

static int banentry_getMask(lua_State *l)
{
MumbleProto__BanList__BanEntry *entry = luaL_checkudata(l, 1, METATABLE_BANENTRY);
lua_pushinteger(l, entry->mask);
return 1;
}

static int banentry_setName(lua_State *l)
{
MumbleProto__BanList__BanEntry *entry = luaL_checkudata(l, 1, METATABLE_BANENTRY);
entry->name = (char*) luaL_checkstring(l, 2);
return 0;
}


static int banentry_getName(lua_State *l)
{
MumbleProto__BanList__BanEntry *entry = luaL_checkudata(l, 1, METATABLE_BANENTRY);
lua_pushstring(l, entry->name);
return 1;
}

static int banentry_setHash(lua_State *l)
{
MumbleProto__BanList__BanEntry *entry = luaL_checkudata(l, 1, METATABLE_BANENTRY);
entry->hash = (char*) luaL_checkstring(l, 2);
return 0;
}


static int banentry_getHash(lua_State *l)
{
MumbleProto__BanList__BanEntry *entry = luaL_checkudata(l, 1, METATABLE_BANENTRY);
lua_pushstring(l, entry->hash);
return 1;
}

static int banentry_setReason(lua_State *l)
{
MumbleProto__BanList__BanEntry *entry = luaL_checkudata(l, 1, METATABLE_BANENTRY);
entry->reason = (char*) luaL_checkstring(l, 2);
return 0;
}


static int banentry_getReason(lua_State *l)
{
MumbleProto__BanList__BanEntry *entry = luaL_checkudata(l, 1, METATABLE_BANENTRY);
lua_pushstring(l, entry->reason);
return 1;
}

static int banentry_setStart(lua_State *l)
{
MumbleProto__BanList__BanEntry *entry = luaL_checkudata(l, 1, METATABLE_BANENTRY);
entry->start = (char*) luaL_checkstring(l, 2);
return 0;
}


static int banentry_getStart(lua_State *l)
{
MumbleProto__BanList__BanEntry *entry = luaL_checkudata(l, 1, METATABLE_BANENTRY);
lua_pushstring(l, entry->start);
return 1;
}

static int banentry_setDuration(lua_State *l)
{
MumbleProto__BanList__BanEntry *entry = luaL_checkudata(l, 1, METATABLE_BANENTRY);
entry->duration = luaL_checkinteger(l, 2);
return 0;
}


static int banentry_getDuration(lua_State *l)
{
MumbleProto__BanList__BanEntry *entry = luaL_checkudata(l, 1, METATABLE_BANENTRY);
lua_pushinteger(l, entry->duration);
return 1;
}

static int banentry_tostring(lua_State *l)
{
MumbleProto__BanList__BanEntry *entry = luaL_checkudata(l, 1, METATABLE_BANENTRY);

lua_pushfstring(l, "%s: %p", METATABLE_BANENTRY, entry);
return 1;
}


const luaL_Reg mumble_banentry[] = {
{"setAddress", banentry_setAddress},
{"getAddress", banentry_setAddress},
{"setMask", banentry_setMask},
{"getMask", banentry_getMask},
{"setName", banentry_setName},
{"getName", banentry_getName},
{"setHash", banentry_setHash},
{"getHash", banentry_getHash},
{"setReason", banentry_setReason},
{"getReason", banentry_getReason},
{"setStart", banentry_setStart},
{"getStart", banentry_getStart},
{"setDuration", banentry_setDuration},
{"getDuration", banentry_getDuration},
{"__tostring", banentry_tostring},
{NULL, NULL}
};
6 changes: 6 additions & 0 deletions banentry.h
@@ -0,0 +1,6 @@
#pragma once

#define METATABLE_BANENTRY "mumble.banentry"

extern int mumble_banentry_new(lua_State *l);
extern const luaL_Reg mumble_banentry[];
41 changes: 20 additions & 21 deletions client.c
Expand Up @@ -5,6 +5,7 @@
#include "channel.h"
#include "packet.h"
#include "target.h"
#include "user.h"

/*--------------------------------
MUMBLE CLIENT META METHODS
Expand Down Expand Up @@ -156,34 +157,32 @@ static int client_sendPluginData(lua_State *l)
data.has_data = true;
data.data = cbdata;

luaL_checktype(l, 4, LUA_TTABLE);
lua_pushvalue(l, 4);
lua_pushnil(l);

int i = 0;
int len = lua_objlen(l, 4);
int n_receiversessions = lua_gettop(l) - 3;

data.receiversessions = malloc(sizeof(uint32_t) * len);
data.n_receiversessions = len;
data.n_receiversessions = n_receiversessions;
data.receiversessions = malloc(sizeof(uint32_t) * n_receiversessions);

while (lua_next(l, -2)) {
lua_pushvalue(l, -2);
if (i < len) {
// Allow a table of users or session IDs
if (lua_isuserdata(l, -2)) {
MumbleUser *user = lua_touserdata(l, -2);
data.receiversessions[i++] = user->session;
} else if (lua_isnumber(l, -2)) {
uint32_t session = (uint32_t) lua_tonumber(l, -2);
data.receiversessions[i++] = session;
for (int i = 0; i < n_receiversessions; i++) {
int sp = 4+i;
switch (lua_type(l, sp)) {
case LUA_TNUMBER:
{
// Use direct session number
uint32_t session = (uint32_t) lua_tonumber(l, sp);
data.receiversessions[i] = session;
break;
}
case LUA_TTABLE:
{
// Make sure the "table" is a user metatable
MumbleUser *user = luaL_checkudata(l, sp, METATABLE_USER);
data.receiversessions[i] = user->session;
break;
}
}
lua_pop(l, 2);
}
lua_pop(l, 1);

packet_send(client, PACKET_PLUGINDATA, &data);

free(data.receiversessions);
return 0;
}
Expand Down

0 comments on commit 61691ef

Please sign in to comment.