2014-02-25 08:28:24 +01:00
|
|
|
/* global_commands.c
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Toxic All Rights Reserved.
|
|
|
|
*
|
|
|
|
* This file is part of Toxic.
|
|
|
|
*
|
|
|
|
* Toxic is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Toxic is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Toxic. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
2013-11-10 03:43:56 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2020-04-18 02:00:00 +02:00
|
|
|
#include "avatars.h"
|
2020-11-08 16:08:24 +01:00
|
|
|
#include "conference.h"
|
2020-04-18 02:00:00 +02:00
|
|
|
#include "friendlist.h"
|
2014-07-04 09:24:29 +02:00
|
|
|
#include "help.h"
|
2020-04-18 02:00:00 +02:00
|
|
|
#include "line_info.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "misc_tools.h"
|
2015-10-28 22:14:17 +01:00
|
|
|
#include "name_lookup.h"
|
2020-04-18 02:00:00 +02:00
|
|
|
#include "prompt.h"
|
2015-11-09 04:51:46 +01:00
|
|
|
#include "qr_code.h"
|
2020-04-18 02:00:00 +02:00
|
|
|
#include "term_mplex.h"
|
|
|
|
#include "toxic.h"
|
2015-12-04 20:15:31 +01:00
|
|
|
#include "toxic_strings.h"
|
2020-04-18 02:00:00 +02:00
|
|
|
#include "windows.h"
|
2013-11-10 03:43:56 +01:00
|
|
|
|
|
|
|
extern char *DATA_FILE;
|
2013-11-19 21:32:35 +01:00
|
|
|
extern ToxWindow *prompt;
|
2014-09-28 23:49:48 +02:00
|
|
|
extern FriendsList Friends;
|
2020-10-25 18:48:14 +01:00
|
|
|
extern FriendRequests FrndRequests;
|
2013-11-30 00:52:21 +01:00
|
|
|
|
2013-11-10 03:43:56 +01:00
|
|
|
/* command functions */
|
2013-11-19 21:32:35 +01:00
|
|
|
void cmd_accept(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
2013-11-10 03:43:56 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(window);
|
|
|
|
|
2014-08-04 20:35:34 +02:00
|
|
|
if (argc < 1) {
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Request ID required.");
|
2014-03-25 08:17:22 +01:00
|
|
|
return;
|
2013-11-10 03:43:56 +01:00
|
|
|
}
|
|
|
|
|
2015-09-03 01:41:21 +02:00
|
|
|
long int req = strtol(argv[1], NULL, 10);
|
2013-11-10 03:43:56 +01:00
|
|
|
|
2015-09-03 01:41:21 +02:00
|
|
|
if ((req == 0 && strcmp(argv[1], "0")) || req < 0 || req >= MAX_FRIEND_REQUESTS) {
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No pending friend request with that ID.");
|
2013-11-10 03:43:56 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-28 23:49:48 +02:00
|
|
|
if (!FrndRequests.request[req].active) {
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No pending friend request with that ID.");
|
2013-11-10 03:43:56 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_Err_Friend_Add err;
|
2015-03-26 03:56:45 +01:00
|
|
|
uint32_t friendnum = tox_friend_add_norequest(m, FrndRequests.request[req].key, &err);
|
2013-11-10 03:43:56 +01:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
if (err != TOX_ERR_FRIEND_ADD_OK) {
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to add friend (error %d\n)", err);
|
2015-03-26 03:56:45 +01:00
|
|
|
return;
|
|
|
|
} else {
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Friend request accepted.");
|
2018-07-18 17:41:17 +02:00
|
|
|
on_friend_added(m, friendnum, true);
|
2013-11-10 03:43:56 +01:00
|
|
|
}
|
|
|
|
|
2020-11-11 03:25:27 +01:00
|
|
|
FrndRequests.request[req] = (struct friend_request) {
|
|
|
|
0
|
|
|
|
};
|
2013-11-10 03:43:56 +01:00
|
|
|
|
|
|
|
int i;
|
|
|
|
|
2014-09-28 23:49:48 +02:00
|
|
|
for (i = FrndRequests.max_idx; i > 0; --i) {
|
2018-07-18 17:33:16 +02:00
|
|
|
if (FrndRequests.request[i - 1].active) {
|
2013-11-10 03:43:56 +01:00
|
|
|
break;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-11-10 03:43:56 +01:00
|
|
|
}
|
|
|
|
|
2014-09-28 23:49:48 +02:00
|
|
|
FrndRequests.max_idx = i;
|
|
|
|
--FrndRequests.num_requests;
|
2013-11-10 03:43:56 +01:00
|
|
|
}
|
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
void cmd_add_helper(ToxWindow *self, Tox *m, const char *id_bin, const char *msg)
|
2014-06-18 01:10:25 +02:00
|
|
|
{
|
2014-07-29 20:54:34 +02:00
|
|
|
const char *errmsg;
|
2014-06-18 01:10:25 +02:00
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_Err_Friend_Add err;
|
2018-09-14 01:47:47 +02:00
|
|
|
uint32_t f_num = tox_friend_add(m, (const uint8_t *) id_bin, (const uint8_t *) msg, strlen(msg), &err);
|
2015-03-26 03:56:45 +01:00
|
|
|
|
|
|
|
switch (err) {
|
|
|
|
case TOX_ERR_FRIEND_ADD_TOO_LONG:
|
2015-07-04 07:19:16 +02:00
|
|
|
errmsg = "Message is too long.";
|
2014-06-18 01:10:25 +02:00
|
|
|
break;
|
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
case TOX_ERR_FRIEND_ADD_NO_MESSAGE:
|
2015-07-04 07:19:16 +02:00
|
|
|
errmsg = "Please add a message to your request.";
|
2014-06-18 01:10:25 +02:00
|
|
|
break;
|
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
case TOX_ERR_FRIEND_ADD_OWN_KEY:
|
2015-07-04 07:19:16 +02:00
|
|
|
errmsg = "That appears to be your own ID.";
|
2014-06-18 01:10:25 +02:00
|
|
|
break;
|
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
case TOX_ERR_FRIEND_ADD_ALREADY_SENT:
|
2015-07-04 07:19:16 +02:00
|
|
|
errmsg = "Friend request has already been sent.";
|
2014-06-18 01:10:25 +02:00
|
|
|
break;
|
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
case TOX_ERR_FRIEND_ADD_BAD_CHECKSUM:
|
2015-07-04 07:19:16 +02:00
|
|
|
errmsg = "Bad checksum in address.";
|
2014-06-18 01:10:25 +02:00
|
|
|
break;
|
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
case TOX_ERR_FRIEND_ADD_SET_NEW_NOSPAM:
|
2015-07-04 07:19:16 +02:00
|
|
|
errmsg = "Nospam was different.";
|
2014-06-18 01:10:25 +02:00
|
|
|
break;
|
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
case TOX_ERR_FRIEND_ADD_MALLOC:
|
2015-07-04 07:19:16 +02:00
|
|
|
errmsg = "Core memory allocation failed.";
|
2015-03-26 03:56:45 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOX_ERR_FRIEND_ADD_OK:
|
2015-07-04 07:19:16 +02:00
|
|
|
errmsg = "Friend request sent.";
|
2018-07-18 17:41:17 +02:00
|
|
|
on_friend_added(m, f_num, true);
|
2014-06-18 01:10:25 +02:00
|
|
|
break;
|
2015-03-26 03:56:45 +01:00
|
|
|
|
|
|
|
case TOX_ERR_FRIEND_ADD_NULL:
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2016-10-05 11:55:45 +02:00
|
|
|
/* fallthrough */
|
2015-03-26 03:56:45 +01:00
|
|
|
default:
|
2019-11-16 07:55:47 +01:00
|
|
|
errmsg = "Failed to add friend: Unknown error.";
|
2015-03-28 07:56:54 +01:00
|
|
|
break;
|
|
|
|
}
|
2014-06-18 01:10:25 +02:00
|
|
|
|
2014-07-25 04:43:32 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
|
2014-06-18 01:10:25 +02:00
|
|
|
}
|
|
|
|
|
2013-11-19 21:32:35 +01:00
|
|
|
void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
2013-11-10 03:43:56 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(window);
|
|
|
|
|
2013-11-10 03:43:56 +01:00
|
|
|
if (argc < 1) {
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Tox ID or address required.");
|
2013-11-10 03:43:56 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-29 20:54:34 +02:00
|
|
|
const char *id = argv[1];
|
2014-07-07 04:15:35 +02:00
|
|
|
char msg[MAX_STR_SIZE];
|
2013-11-10 03:43:56 +01:00
|
|
|
|
|
|
|
if (argc > 1) {
|
2014-07-29 20:54:34 +02:00
|
|
|
if (argv[2][0] != '\"') {
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Message must be enclosed in quotes.");
|
2013-11-10 03:43:56 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-29 20:54:34 +02:00
|
|
|
/* remove opening and closing quotes */
|
|
|
|
char tmp[MAX_STR_SIZE];
|
|
|
|
snprintf(tmp, sizeof(tmp), "%s", &argv[2][1]);
|
|
|
|
int len = strlen(tmp) - 1;
|
|
|
|
tmp[len] = '\0';
|
|
|
|
snprintf(msg, sizeof(msg), "%s", tmp);
|
2013-11-18 05:14:27 +01:00
|
|
|
} else {
|
2014-07-07 04:15:35 +02:00
|
|
|
char selfname[TOX_MAX_NAME_LENGTH];
|
2015-03-26 03:56:45 +01:00
|
|
|
tox_self_get_name(m, (uint8_t *) selfname);
|
|
|
|
|
|
|
|
size_t n_len = tox_self_get_name_size(m);
|
2014-04-01 04:00:17 +02:00
|
|
|
selfname[n_len] = '\0';
|
2015-07-04 07:19:16 +02:00
|
|
|
snprintf(msg, sizeof(msg), "Hello, my name is %s. Care to Tox?", selfname);
|
2013-11-18 05:14:27 +01:00
|
|
|
}
|
2013-11-10 03:43:56 +01:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
char id_bin[TOX_ADDRESS_SIZE] = {0};
|
2014-07-07 04:15:35 +02:00
|
|
|
uint16_t id_len = (uint16_t) strlen(id);
|
2013-11-10 03:43:56 +01:00
|
|
|
|
2014-06-17 03:22:26 +02:00
|
|
|
/* try to add tox ID */
|
2015-03-26 03:56:45 +01:00
|
|
|
if (id_len == 2 * TOX_ADDRESS_SIZE) {
|
2014-06-17 03:22:26 +02:00
|
|
|
size_t i;
|
|
|
|
char xx[3];
|
|
|
|
uint32_t x;
|
2013-11-10 03:43:56 +01:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
for (i = 0; i < TOX_ADDRESS_SIZE; ++i) {
|
2014-06-17 03:22:26 +02:00
|
|
|
xx[0] = id[2 * i];
|
|
|
|
xx[1] = id[2 * i + 1];
|
|
|
|
xx[2] = '\0';
|
2013-11-10 03:43:56 +01:00
|
|
|
|
2014-06-17 03:22:26 +02:00
|
|
|
if (sscanf(xx, "%02x", &x) != 1) {
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid Tox ID.");
|
2014-06-17 03:22:26 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-11-10 03:43:56 +01:00
|
|
|
|
2014-06-17 03:22:26 +02:00
|
|
|
id_bin[i] = x;
|
|
|
|
}
|
2013-11-10 03:43:56 +01:00
|
|
|
|
2019-11-16 07:55:47 +01:00
|
|
|
if (friend_is_blocked(id_bin)) {
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Friend is in your block list.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-18 01:10:25 +02:00
|
|
|
cmd_add_helper(self, m, id_bin, msg);
|
2015-10-28 22:14:17 +01:00
|
|
|
} else { /* assume id is a username@domain address and do http name server lookup */
|
|
|
|
name_lookup(self, m, id_bin, id, msg);
|
2013-11-10 03:43:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-26 09:10:44 +02:00
|
|
|
void cmd_avatar(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(window);
|
|
|
|
|
2018-10-08 06:47:51 +02:00
|
|
|
if (argc != 1 || strlen(argv[1]) < 3) {
|
2015-04-04 09:26:38 +02:00
|
|
|
avatar_unset(m);
|
2018-10-08 06:47:51 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Avatar has been unset.");
|
2015-04-04 09:26:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
char path[MAX_STR_SIZE];
|
2018-10-08 06:47:51 +02:00
|
|
|
snprintf(path, sizeof(path), "%s", argv[1]);
|
|
|
|
int len = strlen(path);
|
2015-04-04 09:26:38 +02:00
|
|
|
|
|
|
|
if (len <= 0) {
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid path.");
|
2015-04-04 09:26:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
path[len] = '\0';
|
|
|
|
char filename[MAX_STR_SIZE];
|
|
|
|
get_file_name(filename, sizeof(filename), path);
|
|
|
|
|
|
|
|
if (avatar_set(m, path, len) == -1) {
|
2015-04-05 03:15:34 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0,
|
2015-07-04 07:19:16 +02:00
|
|
|
"Failed to set avatar. Avatars must be in PNG format and may not exceed %d bytes.",
|
2015-04-05 03:15:34 +02:00
|
|
|
MAX_AVATAR_FILE_SIZE);
|
2015-04-04 09:26:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Avatar set to '%s'", filename);
|
2014-09-26 09:10:44 +02:00
|
|
|
}
|
|
|
|
|
2013-11-19 21:32:35 +01:00
|
|
|
void cmd_clear(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
2013-11-10 03:43:56 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(m);
|
|
|
|
UNUSED_VAR(argc);
|
|
|
|
UNUSED_VAR(argv);
|
|
|
|
|
2014-03-26 02:43:49 +01:00
|
|
|
line_info_clear(self->chatwin->hst);
|
2014-10-01 22:24:36 +02:00
|
|
|
force_refresh(window);
|
2013-11-10 03:43:56 +01:00
|
|
|
}
|
|
|
|
|
2013-11-19 21:32:35 +01:00
|
|
|
void cmd_connect(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
2013-11-10 03:43:56 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(window);
|
|
|
|
|
2013-11-10 03:43:56 +01:00
|
|
|
if (argc != 3) {
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Require: <ip> <port> <key>");
|
2014-04-19 23:58:13 +02:00
|
|
|
return;
|
2013-11-10 03:43:56 +01:00
|
|
|
}
|
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
const char *ip = argv[1];
|
2015-09-03 01:41:21 +02:00
|
|
|
const char *port_str = argv[2];
|
2015-08-27 09:38:08 +02:00
|
|
|
const char *ascii_key = argv[3];
|
2013-11-10 03:43:56 +01:00
|
|
|
|
2015-09-03 01:41:21 +02:00
|
|
|
long int port = strtol(port_str, NULL, 10);
|
|
|
|
|
|
|
|
if (port <= 0 || port > MAX_PORT_RANGE) {
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid port.");
|
2013-11-10 03:43:56 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-27 09:38:08 +02:00
|
|
|
char key_binary[TOX_PUBLIC_KEY_SIZE * 2 + 1];
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2015-08-27 09:38:08 +02:00
|
|
|
if (hex_string_to_bin(ascii_key, strlen(ascii_key), key_binary, TOX_PUBLIC_KEY_SIZE) == -1) {
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid key.");
|
|
|
|
return;
|
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_Err_Bootstrap err;
|
2015-09-03 01:41:21 +02:00
|
|
|
tox_bootstrap(m, ip, port, (uint8_t *) key_binary, &err);
|
|
|
|
tox_add_tcp_relay(m, ip, port, (uint8_t *) key_binary, &err);
|
2015-03-28 07:56:54 +01:00
|
|
|
|
|
|
|
switch (err) {
|
|
|
|
case TOX_ERR_BOOTSTRAP_BAD_HOST:
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Bootstrap failed: Invalid IP.");
|
2015-03-28 07:56:54 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOX_ERR_BOOTSTRAP_BAD_PORT:
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Bootstrap failed: Invalid port.");
|
2015-03-28 07:56:54 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOX_ERR_BOOTSTRAP_NULL:
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Bootstrap failed.");
|
2015-03-28 07:56:54 +01:00
|
|
|
break;
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2015-03-28 07:56:54 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-11-10 03:43:56 +01:00
|
|
|
}
|
|
|
|
|
2014-08-25 20:08:01 +02:00
|
|
|
void cmd_decline(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(window);
|
|
|
|
UNUSED_VAR(m);
|
|
|
|
|
2014-08-25 20:08:01 +02:00
|
|
|
if (argc < 1) {
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Request ID required.");
|
2014-08-25 20:08:01 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-03 01:41:21 +02:00
|
|
|
long int req = strtol(argv[1], NULL, 10);
|
2014-08-25 20:08:01 +02:00
|
|
|
|
2015-09-03 01:41:21 +02:00
|
|
|
if ((req == 0 && strcmp(argv[1], "0")) || req < 0 || req >= MAX_FRIEND_REQUESTS) {
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No pending friend request with that ID.");
|
2014-08-25 20:08:01 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-28 23:49:48 +02:00
|
|
|
if (!FrndRequests.request[req].active) {
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No pending friend request with that ID.");
|
2014-08-25 20:08:01 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-11 03:25:27 +01:00
|
|
|
FrndRequests.request[req] = (struct friend_request) {
|
|
|
|
0
|
|
|
|
};
|
2014-08-25 20:08:01 +02:00
|
|
|
|
|
|
|
int i;
|
|
|
|
|
2014-09-28 23:49:48 +02:00
|
|
|
for (i = FrndRequests.max_idx; i > 0; --i) {
|
2018-07-18 17:33:16 +02:00
|
|
|
if (FrndRequests.request[i - 1].active) {
|
2014-08-25 20:08:01 +02:00
|
|
|
break;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-08-25 20:08:01 +02:00
|
|
|
}
|
|
|
|
|
2014-09-28 23:49:48 +02:00
|
|
|
FrndRequests.max_idx = i;
|
|
|
|
--FrndRequests.num_requests;
|
2014-08-25 20:08:01 +02:00
|
|
|
}
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
void cmd_conference(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
2013-11-10 03:43:56 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(window);
|
|
|
|
|
2014-03-07 01:39:57 +01:00
|
|
|
if (get_num_active_windows() >= MAX_WINDOWS_NUM) {
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Warning: Too many windows are open.");
|
2013-11-10 03:43:56 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-12 02:49:05 +01:00
|
|
|
if (argc < 1) {
|
2020-11-08 16:08:24 +01:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Please specify conference type: text | audio");
|
2014-11-12 02:49:05 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-15 21:55:45 +01:00
|
|
|
uint8_t type;
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!strcasecmp(argv[1], "audio")) {
|
2016-12-18 06:01:51 +01:00
|
|
|
type = TOX_CONFERENCE_TYPE_AV;
|
2018-07-18 17:33:16 +02:00
|
|
|
} else if (!strcasecmp(argv[1], "text")) {
|
2016-12-18 06:01:51 +01:00
|
|
|
type = TOX_CONFERENCE_TYPE_TEXT;
|
2018-07-18 17:33:16 +02:00
|
|
|
} else {
|
2020-11-08 16:08:24 +01:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Valid conference types are: text | audio");
|
2014-11-15 21:55:45 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-11-12 02:49:05 +01:00
|
|
|
|
2020-11-21 17:25:41 +01:00
|
|
|
uint32_t conferencenum = 0;
|
2020-05-07 02:00:00 +02:00
|
|
|
|
|
|
|
if (type == TOX_CONFERENCE_TYPE_TEXT) {
|
|
|
|
Tox_Err_Conference_New err;
|
|
|
|
|
|
|
|
conferencenum = tox_conference_new(m, &err);
|
2014-11-12 02:49:05 +01:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
if (err != TOX_ERR_CONFERENCE_NEW_OK) {
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Conference instance failed to initialize (error %d)", err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (type == TOX_CONFERENCE_TYPE_AV) {
|
|
|
|
#ifdef AUDIO
|
|
|
|
conferencenum = toxav_add_av_groupchat(m, audio_conference_callback, NULL);
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
if (conferencenum == (uint32_t) -1) {
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Audio conference instance failed to initialize");
|
|
|
|
return;
|
|
|
|
}
|
2013-11-10 03:43:56 +01:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
#else
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Audio support disabled by compile-time option.");
|
|
|
|
return;
|
|
|
|
#endif
|
2013-11-10 03:43:56 +01:00
|
|
|
}
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
if (init_conference_win(m, conferencenum, type, NULL, 0) == -1) {
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Conference window failed to initialize.");
|
|
|
|
tox_conference_delete(m, conferencenum, NULL);
|
2013-11-10 03:43:56 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
#ifdef AUDIO
|
|
|
|
|
|
|
|
if (type == TOX_CONFERENCE_TYPE_AV) {
|
|
|
|
if (!init_conference_audio_input(m, conferencenum)) {
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Audio capture failed; use \"/audio on\" to try again.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Conference [%d] created.", conferencenum);
|
2013-11-10 03:43:56 +01:00
|
|
|
}
|
|
|
|
|
2014-02-27 01:00:13 +01:00
|
|
|
void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(window);
|
|
|
|
|
2014-07-29 20:54:34 +02:00
|
|
|
const char *msg;
|
2014-03-24 12:37:52 +01:00
|
|
|
struct chatlog *log = self->chatwin->log;
|
2014-02-27 01:00:13 +01:00
|
|
|
|
2014-03-24 12:37:52 +01:00
|
|
|
if (argc == 0) {
|
2018-07-18 17:33:16 +02:00
|
|
|
if (log->log_on) {
|
2015-10-23 01:55:48 +02:00
|
|
|
msg = "Logging for this window is ON; type \"/log off\" to disable. (Logs are not encrypted)";
|
2018-07-18 17:33:16 +02:00
|
|
|
} else {
|
2015-10-23 01:55:48 +02:00
|
|
|
msg = "Logging for this window is OFF; type \"/log on\" to enable.";
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-02-27 01:45:11 +01:00
|
|
|
|
2014-07-25 04:43:32 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
|
2014-02-27 01:00:13 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-29 20:54:34 +02:00
|
|
|
const char *swch = argv[1];
|
2014-02-27 01:00:13 +01:00
|
|
|
|
|
|
|
if (!strcmp(swch, "1") || !strcmp(swch, "on")) {
|
2020-11-17 22:05:20 +01:00
|
|
|
msg = log_enable(log) == 0 ? "Logging enabled." : "Warning: Failed to enable log.";
|
2014-07-25 04:43:32 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
|
2014-02-27 01:00:13 +01:00
|
|
|
return;
|
|
|
|
} else if (!strcmp(swch, "0") || !strcmp(swch, "off")) {
|
2020-11-09 23:01:22 +01:00
|
|
|
if (self->type == WINDOW_TYPE_CHAT) {
|
2014-08-07 19:05:42 +02:00
|
|
|
Friends.list[self->num].logging_on = false;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-03-24 12:37:52 +01:00
|
|
|
|
|
|
|
log_disable(log);
|
2014-02-27 01:00:13 +01:00
|
|
|
|
2015-08-19 06:42:28 +02:00
|
|
|
msg = "Logging disabled.";
|
2014-07-25 04:43:32 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
|
2014-02-27 01:00:13 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-04 07:19:16 +02:00
|
|
|
msg = "Invalid option. Use \"/log on\" and \"/log off\" to toggle logging.";
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
|
2014-02-27 01:00:13 +01:00
|
|
|
}
|
|
|
|
|
2013-11-19 21:32:35 +01:00
|
|
|
void cmd_myid(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
2013-11-10 03:43:56 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(window);
|
|
|
|
UNUSED_VAR(argc);
|
|
|
|
UNUSED_VAR(argv);
|
|
|
|
|
2015-11-09 04:51:46 +01:00
|
|
|
char id_string[TOX_ADDRESS_SIZE * 2 + 1];
|
|
|
|
char bin_id[TOX_ADDRESS_SIZE];
|
|
|
|
tox_self_get_address(m, (uint8_t *) bin_id);
|
2013-11-10 03:43:56 +01:00
|
|
|
|
2015-11-09 04:51:46 +01:00
|
|
|
if (bin_id_to_string(bin_id, sizeof(bin_id), id_string, sizeof(id_string)) == -1) {
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to print ID.");
|
|
|
|
return;
|
|
|
|
}
|
2013-11-10 03:43:56 +01:00
|
|
|
|
2015-11-09 04:51:46 +01:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", id_string);
|
|
|
|
}
|
|
|
|
|
2018-06-16 05:07:16 +02:00
|
|
|
#ifdef QRCODE
|
2015-11-09 04:51:46 +01:00
|
|
|
void cmd_myqr(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(window);
|
|
|
|
|
2015-11-09 04:51:46 +01:00
|
|
|
char id_string[TOX_ADDRESS_SIZE * 2 + 1];
|
|
|
|
char bin_id[TOX_ADDRESS_SIZE];
|
|
|
|
tox_self_get_address(m, (uint8_t *) bin_id);
|
|
|
|
|
|
|
|
if (bin_id_to_string(bin_id, sizeof(bin_id), id_string, sizeof(id_string)) == -1) {
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to create QR code.");
|
|
|
|
return;
|
2013-11-10 03:43:56 +01:00
|
|
|
}
|
|
|
|
|
2015-11-09 04:51:46 +01:00
|
|
|
char nick[TOX_MAX_NAME_LENGTH];
|
|
|
|
tox_self_get_name(m, (uint8_t *) nick);
|
|
|
|
size_t nick_len = tox_self_get_name_size(m);
|
|
|
|
nick[nick_len] = '\0';
|
|
|
|
|
|
|
|
size_t data_file_len = strlen(DATA_FILE);
|
2020-10-28 05:54:06 +01:00
|
|
|
char *dir = malloc(data_file_len + 1);
|
|
|
|
|
|
|
|
if (dir == NULL) {
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to create QR code: Out of memory.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-09 04:51:46 +01:00
|
|
|
size_t dir_len = get_base_dir(DATA_FILE, data_file_len, dir);
|
|
|
|
|
2016-10-05 11:55:45 +02:00
|
|
|
#ifdef QRPNG
|
2015-11-09 04:51:46 +01:00
|
|
|
|
2016-10-05 11:55:45 +02:00
|
|
|
if (argc == 0) {
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Required 'txt' or 'png'");
|
2020-10-28 05:54:06 +01:00
|
|
|
free(dir);
|
2015-11-09 04:51:46 +01:00
|
|
|
return;
|
2016-10-05 11:55:45 +02:00
|
|
|
} else if (!strcmp(argv[1], "txt")) {
|
2015-11-09 04:51:46 +01:00
|
|
|
|
2016-10-05 11:55:45 +02:00
|
|
|
#endif /* QRPNG */
|
2020-10-30 01:28:09 +01:00
|
|
|
size_t qr_path_buf_size = dir_len + nick_len + sizeof(QRCODE_FILENAME_EXT);
|
2020-10-28 05:54:06 +01:00
|
|
|
char *qr_path = malloc(qr_path_buf_size);
|
|
|
|
|
|
|
|
if (qr_path == NULL) {
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to create QR code: Out of memory");
|
|
|
|
free(dir);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(qr_path, qr_path_buf_size, "%s%s%s", dir, nick, QRCODE_FILENAME_EXT);
|
2016-10-05 11:55:45 +02:00
|
|
|
|
|
|
|
if (ID_to_QRcode_txt(id_string, qr_path) == -1) {
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to create QR code.");
|
2020-10-28 05:54:06 +01:00
|
|
|
free(dir);
|
|
|
|
free(qr_path);
|
2016-10-05 11:55:45 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "QR code has been printed to the file '%s'", qr_path);
|
|
|
|
|
2020-10-28 05:54:06 +01:00
|
|
|
free(qr_path);
|
|
|
|
|
2016-10-05 11:55:45 +02:00
|
|
|
#ifdef QRPNG
|
|
|
|
} else if (!strcmp(argv[1], "png")) {
|
2020-10-30 01:28:09 +01:00
|
|
|
size_t qr_path_buf_size = dir_len + nick_len + sizeof(QRCODE_FILENAME_EXT_PNG);
|
2020-10-28 05:54:06 +01:00
|
|
|
char *qr_path = malloc(qr_path_buf_size);
|
|
|
|
|
|
|
|
if (qr_path == NULL) {
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to create QR code: Out of memory");
|
|
|
|
free(dir);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(qr_path, qr_path_buf_size, "%s%s%s", dir, nick, QRCODE_FILENAME_EXT_PNG);
|
2016-10-05 11:55:45 +02:00
|
|
|
|
|
|
|
if (ID_to_QRcode_png(id_string, qr_path) == -1) {
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to create QR code.");
|
2020-10-28 05:54:06 +01:00
|
|
|
free(dir);
|
|
|
|
free(qr_path);
|
2016-10-05 11:55:45 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "QR code has been printed to the file '%s'", qr_path);
|
|
|
|
|
2020-10-28 05:54:06 +01:00
|
|
|
free(qr_path);
|
|
|
|
|
2016-10-05 11:55:45 +02:00
|
|
|
} else {
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Unknown option '%s' -- Required 'txt' or 'png'", argv[1]);
|
2020-10-28 05:54:06 +01:00
|
|
|
free(dir);
|
2015-11-09 04:51:46 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-05 11:55:45 +02:00
|
|
|
#endif /* QRPNG */
|
2020-10-28 05:54:06 +01:00
|
|
|
|
|
|
|
free(dir);
|
2013-11-10 03:43:56 +01:00
|
|
|
}
|
2018-06-16 05:07:16 +02:00
|
|
|
#endif /* QRCODE */
|
2013-11-10 03:43:56 +01:00
|
|
|
|
2013-11-19 21:32:35 +01:00
|
|
|
void cmd_nick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
2013-11-10 03:43:56 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(window);
|
|
|
|
|
2013-11-26 23:39:11 +01:00
|
|
|
if (argc < 1) {
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Input required.");
|
2014-04-19 23:58:13 +02:00
|
|
|
return;
|
2013-11-10 03:43:56 +01:00
|
|
|
}
|
|
|
|
|
2014-07-29 20:54:34 +02:00
|
|
|
char nick[MAX_STR_SIZE];
|
2018-10-08 06:47:51 +02:00
|
|
|
snprintf(nick, sizeof(nick), "%s", argv[1]);
|
|
|
|
size_t len = strlen(nick);
|
2013-11-10 03:43:56 +01:00
|
|
|
|
2013-11-28 08:53:43 +01:00
|
|
|
if (!valid_nick(nick)) {
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid name.");
|
2013-11-28 08:53:43 +01:00
|
|
|
return;
|
2013-11-28 01:34:15 +01:00
|
|
|
}
|
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
|
2014-07-07 04:15:35 +02:00
|
|
|
nick[len] = '\0';
|
2013-11-10 03:43:56 +01:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
tox_self_set_name(m, (uint8_t *) nick, len, NULL);
|
2014-07-07 04:15:35 +02:00
|
|
|
prompt_update_nick(prompt, nick);
|
2013-11-10 03:43:56 +01:00
|
|
|
|
|
|
|
store_data(m, DATA_FILE);
|
|
|
|
}
|
|
|
|
|
2013-11-19 21:32:35 +01:00
|
|
|
void cmd_note(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
2013-11-10 03:43:56 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(window);
|
|
|
|
|
2013-11-10 03:43:56 +01:00
|
|
|
if (argc < 1) {
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Input required.");
|
2013-11-10 03:43:56 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-07 23:30:43 +02:00
|
|
|
prompt_update_statusmessage(prompt, m, argv[1]);
|
2013-11-10 03:43:56 +01:00
|
|
|
}
|
|
|
|
|
2015-10-23 01:44:05 +02:00
|
|
|
void cmd_nospam(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
|
|
|
{
|
2015-11-13 00:03:45 +01:00
|
|
|
long int nospam = rand();
|
|
|
|
|
|
|
|
if (argc > 0) {
|
|
|
|
nospam = strtol(argv[1], NULL, 16);
|
|
|
|
|
|
|
|
if ((nospam == 0 && strcmp(argv[1], "0")) || nospam < 0) {
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid nospam value.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t old_nospam = tox_self_get_nospam(m);
|
|
|
|
tox_self_set_nospam(m, (uint32_t) nospam);
|
|
|
|
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Your new Tox ID is:");
|
2015-10-23 01:44:05 +02:00
|
|
|
cmd_myid(window, self, m, 0, NULL);
|
2015-11-13 00:03:45 +01:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "");
|
2016-09-25 03:07:04 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0,
|
|
|
|
"Any services that relied on your old ID will need to be updated manually.");
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "If you ever want your old Tox ID back, type '/nospam %X'",
|
|
|
|
old_nospam);
|
2015-10-23 01:44:05 +02:00
|
|
|
}
|
|
|
|
|
2013-11-19 21:32:35 +01:00
|
|
|
void cmd_prompt_help(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
2013-11-15 20:38:58 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(window);
|
|
|
|
UNUSED_VAR(m);
|
|
|
|
UNUSED_VAR(argc);
|
|
|
|
UNUSED_VAR(argv);
|
|
|
|
|
2014-07-04 09:24:29 +02:00
|
|
|
help_init_menu(self);
|
2013-11-15 20:38:58 +01:00
|
|
|
}
|
|
|
|
|
2013-11-19 21:32:35 +01:00
|
|
|
void cmd_quit(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
2013-11-10 03:43:56 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(window);
|
|
|
|
UNUSED_VAR(argc);
|
|
|
|
UNUSED_VAR(argv);
|
|
|
|
UNUSED_VAR(self);
|
|
|
|
|
2014-06-18 21:54:05 +02:00
|
|
|
exit_toxic_success(m);
|
2013-11-10 03:43:56 +01:00
|
|
|
}
|
|
|
|
|
2014-08-20 02:49:29 +02:00
|
|
|
void cmd_requests(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(window);
|
|
|
|
UNUSED_VAR(m);
|
|
|
|
UNUSED_VAR(argc);
|
|
|
|
UNUSED_VAR(argv);
|
|
|
|
|
2014-09-28 23:49:48 +02:00
|
|
|
if (FrndRequests.num_requests == 0) {
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No pending friend requests.");
|
2014-08-20 02:49:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-20 05:40:49 +02:00
|
|
|
int i, j;
|
2014-08-20 02:49:29 +02:00
|
|
|
int count = 0;
|
|
|
|
|
2014-09-28 23:49:48 +02:00
|
|
|
for (i = 0; i < FrndRequests.max_idx; ++i) {
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!FrndRequests.request[i].active) {
|
2014-08-20 02:49:29 +02:00
|
|
|
continue;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-08-20 02:49:29 +02:00
|
|
|
|
2015-02-01 21:09:48 +01:00
|
|
|
char id[TOX_PUBLIC_KEY_SIZE * 2 + 1] = {0};
|
2014-08-20 02:49:29 +02:00
|
|
|
|
2015-02-01 21:09:48 +01:00
|
|
|
for (j = 0; j < TOX_PUBLIC_KEY_SIZE; ++j) {
|
2014-08-20 02:49:29 +02:00
|
|
|
char d[3];
|
2014-09-28 23:49:48 +02:00
|
|
|
snprintf(d, sizeof(d), "%02X", FrndRequests.request[i].key[j] & 0xff);
|
2014-08-20 02:49:29 +02:00
|
|
|
strcat(id, d);
|
|
|
|
}
|
|
|
|
|
2014-08-20 05:40:49 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%d : %s", i, id);
|
2014-09-28 23:49:48 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", FrndRequests.request[i].msg);
|
2014-08-20 02:49:29 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (++count < FrndRequests.num_requests) {
|
2014-08-20 02:49:29 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-08-20 02:49:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-19 21:32:35 +01:00
|
|
|
void cmd_status(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
2015-03-11 23:38:07 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(window);
|
|
|
|
|
2014-07-29 20:54:34 +02:00
|
|
|
const char *errmsg;
|
2013-11-10 03:43:56 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
lock_status();
|
2015-02-26 22:51:20 +01:00
|
|
|
|
2018-10-08 19:47:08 +02:00
|
|
|
if (argc < 1) {
|
2015-07-04 07:19:16 +02:00
|
|
|
errmsg = "Require a status. Statuses are: online, busy and away.";
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
|
2015-02-26 22:51:20 +01:00
|
|
|
goto finish;
|
2013-11-10 03:43:56 +01:00
|
|
|
}
|
|
|
|
|
2015-03-28 07:56:54 +01:00
|
|
|
const char *status_str = argv[1];
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_User_Status status;
|
2013-11-10 03:43:56 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!strcasecmp(status_str, "online")) {
|
2015-03-26 03:56:45 +01:00
|
|
|
status = TOX_USER_STATUS_NONE;
|
2018-07-18 17:33:16 +02:00
|
|
|
} else if (!strcasecmp(status_str, "away")) {
|
2015-03-26 03:56:45 +01:00
|
|
|
status = TOX_USER_STATUS_AWAY;
|
2018-07-18 17:33:16 +02:00
|
|
|
} else if (!strcasecmp(status_str, "busy")) {
|
2015-03-26 03:56:45 +01:00
|
|
|
status = TOX_USER_STATUS_BUSY;
|
2018-07-18 17:33:16 +02:00
|
|
|
} else {
|
2015-07-04 07:19:16 +02:00
|
|
|
errmsg = "Invalid status. Valid statuses are: online, busy and away.";
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
|
2015-02-26 22:51:20 +01:00
|
|
|
goto finish;
|
2013-11-10 03:43:56 +01:00
|
|
|
}
|
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
tox_self_set_status(m, status);
|
|
|
|
prompt_update_status(prompt, status);
|
2018-10-08 19:47:08 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Your status has been changed to %s.", status_str);
|
2013-11-10 03:43:56 +01:00
|
|
|
|
2015-02-26 22:51:20 +01:00
|
|
|
|
|
|
|
finish:
|
2018-07-18 17:33:16 +02:00
|
|
|
unlock_status();
|
2013-11-10 03:43:56 +01:00
|
|
|
}
|