Works now
This commit is contained in:
parent
b72ca69a8a
commit
8a6e08470e
@ -189,7 +189,7 @@ static int const twc_bootstrap_count =
|
||||
* tox_bootstrap_from_address.
|
||||
*/
|
||||
int
|
||||
twc_bootstrap_tox(Tox *tox, const char *address, uint16_t port,
|
||||
twc_bootstrap_dht(Tox *tox, const char *address, uint16_t port,
|
||||
const char *public_key)
|
||||
{
|
||||
uint8_t binary_key[TOX_ADDRESS_SIZE];
|
||||
@ -224,12 +224,12 @@ twc_bootstrap_relay(Tox *tox, const char *address, uint16_t port,
|
||||
* Bootstrap a Tox object with a random DHT bootstrap node.
|
||||
*/
|
||||
int
|
||||
twc_bootstrap_random_node(Tox *tox)
|
||||
twc_bootstrap_random_dht(Tox *tox)
|
||||
{
|
||||
int i = rand() % twc_bootstrap_count;
|
||||
struct t_twc_bootstrap_node const *const node = &twc_bootstrap_nodes[i];
|
||||
int result;
|
||||
result = twc_bootstrap_tox(tox, node->address, node->port, node->key);
|
||||
result = twc_bootstrap_dht(tox, node->address, node->port, node->key);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -23,11 +23,11 @@
|
||||
#include <tox/tox.h>
|
||||
|
||||
int
|
||||
twc_bootstrap_tox(Tox *tox, const char *address, uint16_t port,
|
||||
twc_bootstrap_dht(Tox *tox, const char *address, uint16_t port,
|
||||
const char *public_key);
|
||||
|
||||
int
|
||||
twc_bootstrap_random_node(Tox *tox);
|
||||
twc_bootstrap_random_dht(Tox *tox);
|
||||
|
||||
int
|
||||
twc_bootstrap_relay(Tox *tox, const char *address, uint16_t port,
|
||||
|
@ -234,7 +234,7 @@ twc_chat_search_friend(struct t_twc_profile *profile, int32_t friend_number,
|
||||
* create a new one.
|
||||
*/
|
||||
struct t_twc_chat *
|
||||
twc_chat_search_group(struct t_twc_profile *profile, int32_t group_number,
|
||||
twc_chat_search_conf(struct t_twc_profile *profile, int32_t group_number,
|
||||
bool create_new)
|
||||
{
|
||||
size_t index;
|
||||
|
@ -46,7 +46,7 @@ twc_chat_search_friend(struct t_twc_profile *profile, int32_t friend_number,
|
||||
bool create_new);
|
||||
|
||||
struct t_twc_chat *
|
||||
twc_chat_search_group(struct t_twc_profile *profile, int32_t group_number,
|
||||
twc_chat_search_conf(struct t_twc_profile *profile, int32_t group_number,
|
||||
bool create_new);
|
||||
|
||||
struct t_twc_chat *
|
||||
|
@ -77,14 +77,14 @@ enum TWC_FRIEND_MATCH
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure a command is executed in a group chat buffer. If not, warn user
|
||||
* Make sure a command is executed in a conf chat buffer. If not, warn user
|
||||
* and abort.
|
||||
*/
|
||||
#define TWC_CHECK_GROUP_CHAT(chat) \
|
||||
if (!chat || chat->group_number < 0) \
|
||||
{ \
|
||||
weechat_printf(NULL, \
|
||||
"%s%s: command \"%s\" must be executed in a group " \
|
||||
"%s%s: command \"%s\" must be executed in a conf " \
|
||||
"chat buffer ", \
|
||||
weechat_prefix("error"), weechat_plugin->name, \
|
||||
argv[0]); \
|
||||
@ -222,7 +222,7 @@ twc_cmd_bootstrap(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
||||
uint16_t port = atoi(argv[3]);
|
||||
char *public_key = argv[4];
|
||||
|
||||
if (!twc_bootstrap_tox(profile->tox, address, port, public_key))
|
||||
if (!twc_bootstrap_dht(profile->tox, address, port, public_key))
|
||||
{
|
||||
weechat_printf(profile->buffer,
|
||||
"%sBootstrap could not open address \"%s\"",
|
||||
@ -241,15 +241,30 @@ twc_cmd_bootstrap(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
||||
"%sBootstrap not connected.",
|
||||
weechat_prefix("network"));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
uint16_t i = 0;
|
||||
uint16_t num = atoi(argv[2]);
|
||||
while (i < num) {
|
||||
num = num + 1;
|
||||
if (!twc_bootstrap_random_dht(profile->tox))
|
||||
{
|
||||
weechat_printf(profile->buffer,
|
||||
"%sBootstrap could not open random dht",
|
||||
weechat_prefix("error"));
|
||||
}
|
||||
};
|
||||
weechat_printf(profile->buffer,
|
||||
"%sBootstraped random dht %d times",
|
||||
weechat_prefix("network"), num);
|
||||
};
|
||||
} else {
|
||||
if (!twc_bootstrap_random_node(profile->tox))
|
||||
{
|
||||
weechat_printf(profile->buffer,
|
||||
"%sBootstrap could not open random DHT",
|
||||
weechat_prefix("error"));
|
||||
}
|
||||
};
|
||||
if (!twc_bootstrap_random_dht(profile->tox))
|
||||
{
|
||||
weechat_printf(profile->buffer,
|
||||
"%sBootstrap could not open random DHT",
|
||||
weechat_prefix("error"));
|
||||
}
|
||||
};
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
@ -280,6 +295,21 @@ twc_cmd_bootstrap(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
||||
"%sBootstrap not connected.",
|
||||
weechat_prefix("network"));
|
||||
}
|
||||
} else {
|
||||
uint16_t i = 0;
|
||||
uint16_t num = atoi(argv[2]);
|
||||
while (i < num) {
|
||||
num = num + 1;
|
||||
if (!twc_bootstrap_random_relay(profile->tox))
|
||||
{
|
||||
weechat_printf(profile->buffer,
|
||||
"%sBootstrap could not open random relay",
|
||||
weechat_prefix("error"));
|
||||
}
|
||||
}
|
||||
weechat_printf(profile->buffer,
|
||||
"%sBootstraped random relay %d times",
|
||||
weechat_prefix("network"), num);
|
||||
}
|
||||
} else {
|
||||
if (!twc_bootstrap_random_relay(profile->tox))
|
||||
@ -595,10 +625,10 @@ twc_cmd_friend(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
||||
}
|
||||
|
||||
/**
|
||||
* Command /group callback.
|
||||
* Command /conf callback.
|
||||
*/
|
||||
int
|
||||
twc_cmd_group(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
||||
twc_cmd_conf(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
||||
int argc, char **argv, char **argv_eol)
|
||||
{
|
||||
struct t_twc_profile *profile = twc_profile_search_buffer(buffer);
|
||||
@ -606,12 +636,12 @@ twc_cmd_group(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
||||
TWC_CHECK_PROFILE(profile);
|
||||
TWC_CHECK_PROFILE_LOADED(profile);
|
||||
|
||||
/* /group create */
|
||||
/* /conf create */
|
||||
if (argc == 2 && weechat_strcasecmp(argv[1], "create") == 0)
|
||||
{
|
||||
int rc = tox_conference_new(profile->tox, &err);
|
||||
if (err == TOX_ERR_CONFERENCE_NEW_OK)
|
||||
twc_chat_search_group(profile, rc, true);
|
||||
twc_chat_search_conf(profile, rc, true);
|
||||
else
|
||||
weechat_printf(profile->buffer,
|
||||
"%sCould not create group chat with error %d",
|
||||
@ -631,7 +661,7 @@ twc_cmd_group(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
||||
char *endptr;
|
||||
unsigned long num = strtoul(argv[2], &endptr, 10);
|
||||
if (endptr == argv[2] ||
|
||||
(invite = twc_group_chat_invite_with_index(profile, num)) == NULL)
|
||||
(invite = twc_conf_chat_invite_with_index(profile, num)) == NULL)
|
||||
{
|
||||
weechat_printf(profile->buffer, "%sInvalid group chat invite ID.",
|
||||
weechat_prefix("error"));
|
||||
@ -644,7 +674,7 @@ twc_cmd_group(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
||||
|
||||
/* create a buffer for the new group chat */
|
||||
if (group_number >= 0)
|
||||
twc_chat_search_group(profile, group_number, true);
|
||||
twc_chat_search_conf(profile, group_number, true);
|
||||
else
|
||||
weechat_printf(profile->buffer,
|
||||
"%sCould not join group chat (unknown error)",
|
||||
@ -652,7 +682,7 @@ twc_cmd_group(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
||||
}
|
||||
else
|
||||
{
|
||||
twc_group_chat_invite_remove(invite);
|
||||
twc_conf_chat_invite_remove(invite);
|
||||
}
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
@ -1427,22 +1457,22 @@ twc_commands_init()
|
||||
" || decline",
|
||||
twc_cmd_friend, NULL, NULL);
|
||||
|
||||
weechat_hook_command("group", "manage group chats",
|
||||
weechat_hook_command("conf", "manage conf chats",
|
||||
"create"
|
||||
" || invites"
|
||||
" || join <number>"
|
||||
" || decline <number>",
|
||||
" create: create a new group chat\n"
|
||||
"invites: list group chat invites\n"
|
||||
" join: join a group chat by its invite ID\n"
|
||||
"decline: decline a group chat invite\n",
|
||||
" create: create a new conf chat\n"
|
||||
"invites: list conf chat invites\n"
|
||||
" join: join a conf chat by its invite ID\n"
|
||||
"decline: decline a conf chat invite\n",
|
||||
"create"
|
||||
" || invites"
|
||||
" || join",
|
||||
twc_cmd_group, NULL, NULL);
|
||||
twc_cmd_conf, NULL, NULL);
|
||||
|
||||
weechat_hook_command(
|
||||
"invite", "invite someone to a group chat", "<number>|<name>|<Tox ID>",
|
||||
"invite", "invite someone to a conf chat", "<number>|<name>|<Tox ID>",
|
||||
"number, name, Tox ID: friend to message\n",
|
||||
"%(tox_friend_name)|%(tox_friend_tox_id)", twc_cmd_invite, NULL, NULL);
|
||||
|
||||
@ -1470,7 +1500,7 @@ twc_commands_init()
|
||||
weechat_hook_command("name", "change your Tox name", "<name>",
|
||||
"name: your new name", NULL, twc_cmd_name, NULL, NULL);
|
||||
|
||||
weechat_hook_command("names", "list names in a group chat", "", "", NULL,
|
||||
weechat_hook_command("names", "list names in a conf chat", "", "", NULL,
|
||||
twc_cmd_names, NULL, NULL);
|
||||
|
||||
weechat_hook_command("nospam", "change nospam value", "[<hex value>]",
|
||||
@ -1480,7 +1510,7 @@ twc_commands_init()
|
||||
"Tox ID!",
|
||||
NULL, twc_cmd_nospam, NULL, NULL);
|
||||
|
||||
weechat_hook_command("part", "leave a group chat", "", "", NULL,
|
||||
weechat_hook_command("part", "leave a conf chat", "", "", NULL,
|
||||
twc_cmd_part, NULL, NULL);
|
||||
|
||||
weechat_hook_command_run("/save", twc_cmd_save, NULL, NULL);
|
||||
@ -1492,8 +1522,8 @@ twc_commands_init()
|
||||
"[<message>]", "message: your new status message",
|
||||
NULL, twc_cmd_statusmsg, NULL, NULL);
|
||||
|
||||
weechat_hook_command("topic", "set a group chat topic", "<topic>",
|
||||
"topic: new group chat topic", NULL, twc_cmd_topic,
|
||||
weechat_hook_command("topic", "set a conf chat topic", "<topic>",
|
||||
"topic: new conf chat topic", NULL, twc_cmd_topic,
|
||||
NULL, NULL);
|
||||
|
||||
weechat_hook_command(
|
||||
|
@ -96,7 +96,7 @@ twc_group_chat_invite_join(struct t_twc_group_chat_invite *invite)
|
||||
break;
|
||||
}
|
||||
|
||||
twc_group_chat_invite_remove(invite);
|
||||
twc_conf_chat_invite_remove(invite);
|
||||
|
||||
if (err != TOX_ERR_CONFERENCE_JOIN_OK)
|
||||
return -1;
|
||||
@ -107,7 +107,7 @@ twc_group_chat_invite_join(struct t_twc_group_chat_invite *invite)
|
||||
* Remove and free a group chat invite.
|
||||
*/
|
||||
void
|
||||
twc_group_chat_invite_remove(struct t_twc_group_chat_invite *invite)
|
||||
twc_conf_chat_invite_remove(struct t_twc_group_chat_invite *invite)
|
||||
{
|
||||
twc_list_remove_with_data(invite->profile->group_chat_invites, invite);
|
||||
twc_group_chat_invite_free(invite);
|
||||
@ -117,7 +117,7 @@ twc_group_chat_invite_remove(struct t_twc_group_chat_invite *invite)
|
||||
* Get group chat invite with a given index.
|
||||
*/
|
||||
struct t_twc_group_chat_invite *
|
||||
twc_group_chat_invite_with_index(struct t_twc_profile *profile, size_t index)
|
||||
twc_conf_chat_invite_with_index(struct t_twc_profile *profile, size_t index)
|
||||
{
|
||||
struct t_twc_list_item *item =
|
||||
twc_list_get(profile->group_chat_invites, index);
|
||||
|
@ -48,10 +48,10 @@ int
|
||||
twc_group_chat_invite_join(struct t_twc_group_chat_invite *invite);
|
||||
|
||||
void
|
||||
twc_group_chat_invite_remove(struct t_twc_group_chat_invite *invite);
|
||||
twc_conf_chat_invite_remove(struct t_twc_group_chat_invite *invite);
|
||||
|
||||
struct t_twc_group_chat_invite *
|
||||
twc_group_chat_invite_with_index(struct t_twc_profile *profile, size_t index);
|
||||
twc_conf_chat_invite_with_index(struct t_twc_profile *profile, size_t index);
|
||||
|
||||
void
|
||||
twc_group_chat_invite_free(struct t_twc_group_chat_invite *invite);
|
||||
|
@ -33,7 +33,7 @@
|
||||
#include "twc-chat.h"
|
||||
#include "twc-config.h"
|
||||
#include "twc-friend-request.h"
|
||||
#include "twc-group-invite.h"
|
||||
#include "twc-conf-invite.h"
|
||||
#include "twc-list.h"
|
||||
#include "twc-message-queue.h"
|
||||
#include "twc-tox-callbacks.h"
|
||||
@ -439,9 +439,9 @@ twc_profile_load(struct t_twc_profile *profile)
|
||||
|
||||
/* bootstrap DHT
|
||||
* TODO: add count to config */
|
||||
int bootstrap_node_count = 5;
|
||||
int bootstrap_node_count = 8;
|
||||
for (int i = 0; i < bootstrap_node_count; ++i)
|
||||
twc_bootstrap_random_node(profile->tox);
|
||||
twc_bootstrap_random_dht(profile->tox);
|
||||
|
||||
/* start tox_iterate loop */
|
||||
twc_do_timer_cb(profile, NULL, 0);
|
||||
@ -532,14 +532,21 @@ twc_profile_refresh_online_status(struct t_twc_profile *profile)
|
||||
void
|
||||
twc_profile_set_online_status(struct t_twc_profile *profile, bool status)
|
||||
{
|
||||
TOX_CONNECTION connection = tox_self_get_connection_status(profile->tox);
|
||||
|
||||
if (profile->tox_online ^ status)
|
||||
{
|
||||
profile->tox_online = status;
|
||||
twc_profile_refresh_online_status(profile);
|
||||
|
||||
if (profile->tox_online)
|
||||
if (connection == TOX_CONNECTION_TCP)
|
||||
{
|
||||
weechat_printf(profile->buffer, "%sprofile %s connected",
|
||||
weechat_printf(profile->buffer, "%sprofile %s TCP",
|
||||
weechat_prefix("network"), profile->name);
|
||||
}
|
||||
else if (connection == TOX_CONNECTION_UDP)
|
||||
{
|
||||
weechat_printf(profile->buffer, "%sprofile %s UDP",
|
||||
weechat_prefix("network"), profile->name);
|
||||
}
|
||||
else
|
||||
|
@ -150,7 +150,7 @@ void
|
||||
twc_tfer_buffer_update(struct t_twc_tfer *tfer);
|
||||
|
||||
void
|
||||
twc_tfer_file_err_send_message(char *message, enum TOX_ERR_FILE_SEND error);
|
||||
twc_tfer_file_err_send_message(char *message, enum Tox_Err_File_Send error);
|
||||
|
||||
void
|
||||
twc_tfer_file_free(struct t_twc_tfer_file *file);
|
||||
|
@ -71,7 +71,7 @@ twc_do_timer_cb(const void *pointer, void *data, int remaining_calls)
|
||||
if (TWC_PROFILE_OPTION_BOOLEAN(profile, TWC_PROFILE_OPTION_AUTOJOIN))
|
||||
{
|
||||
struct t_twc_group_chat_invite *invite;
|
||||
for (i = 0; (invite = twc_group_chat_invite_with_index(profile, i));
|
||||
for (i = 0; (invite = twc_conf_chat_invite_with_index(profile, i));
|
||||
i++)
|
||||
if (invite->autojoin_delay <= 0)
|
||||
{
|
||||
@ -408,7 +408,7 @@ twc_handle_group_message(Tox *tox, int32_t group_number, int32_t peer_number,
|
||||
struct t_twc_profile *profile = data;
|
||||
|
||||
struct t_twc_chat *chat =
|
||||
twc_chat_search_group(profile, group_number, true);
|
||||
twc_chat_search_conf(profile, group_number, true);
|
||||
|
||||
char *myname = twc_get_self_name_nt(profile->tox);
|
||||
char *name = twc_get_peer_name_nt(profile->tox, group_number, peer_number);
|
||||
@ -448,7 +448,7 @@ twc_group_peer_list_changed_callback(Tox *tox, uint32_t group_number,
|
||||
{
|
||||
struct t_twc_profile *profile = data;
|
||||
struct t_twc_chat *chat =
|
||||
twc_chat_search_group(profile, group_number, true);
|
||||
twc_chat_search_conf(profile, group_number, true);
|
||||
|
||||
struct t_gui_nick *nick = NULL;
|
||||
int i, npeers;
|
||||
@ -517,7 +517,7 @@ twc_group_peer_name_callback(Tox *tox, uint32_t group_number,
|
||||
{
|
||||
struct t_twc_profile *profile = data;
|
||||
struct t_twc_chat *chat =
|
||||
twc_chat_search_group(profile, group_number, true);
|
||||
twc_chat_search_conf(profile, group_number, true);
|
||||
|
||||
int npeers, len;
|
||||
struct t_gui_nick *nick = NULL;
|
||||
@ -580,7 +580,7 @@ twc_group_title_callback(Tox *tox, uint32_t group_number, uint32_t peer_number,
|
||||
{
|
||||
struct t_twc_profile *profile = data;
|
||||
struct t_twc_chat *chat =
|
||||
twc_chat_search_group(profile, group_number, true);
|
||||
twc_chat_search_conf(profile, group_number, true);
|
||||
twc_chat_queue_refresh(chat);
|
||||
|
||||
char *name = twc_get_peer_name_nt(profile->tox, group_number, peer_number);
|
||||
|
Loading…
Reference in New Issue
Block a user