1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-23 06:33:02 +01:00

added cmuch smaller client-specific maximum name length

This commit is contained in:
Jfreegman 2013-09-13 00:35:48 -04:00
parent d4f365e28f
commit 863121273e
4 changed files with 27 additions and 10 deletions

View File

@ -316,8 +316,14 @@ static void execute(ToxWindow *self, ChatContext *ctx, StatusBar *statusbar, Tox
return; return;
} }
nick++; int len = strlen(++nick);
tox_setname(m, nick, strlen(nick) + 1);
if (len > TOXIC_MAX_NAME_LENGTH) {
nick[TOXIC_MAX_NAME_LENGTH] = L'\0';
len = TOXIC_MAX_NAME_LENGTH;
}
tox_setname(m, nick, len+1);
prompt_update_nick(self->prompt, nick); prompt_update_nick(self->prompt, nick);
wprintw(ctx->history, "Nickname set to: %s\n", nick); wprintw(ctx->history, "Nickname set to: %s\n", nick);
} }

View File

@ -384,10 +384,19 @@ void cmd_nick(ToxWindow *self, Tox *m, int argc, char **argv)
return; return;
} }
if (nick[0] == '\"') int len = strlen(nick);
nick[strlen(++nick)-1] = L'\0';
tox_setname(m, nick, strlen(nick) + 1); if (nick[0] == '\"') {
++nick;
nick[--len-1] = L'\0';
}
if (len > TOXIC_MAX_NAME_LENGTH) {
nick[TOXIC_MAX_NAME_LENGTH] = L'\0';
len = TOXIC_MAX_NAME_LENGTH;
}
tox_setname(m, nick, len+1);
prompt_update_nick(self, nick); prompt_update_nick(self, nick);
store_data(m, DATA_FILE); store_data(m, DATA_FILE);

View File

@ -16,12 +16,9 @@
#define MAX_FRIENDS_NUM 100 #define MAX_FRIENDS_NUM 100
#define MAX_STR_SIZE 256 #define MAX_STR_SIZE 256
#define KEY_SIZE_BYTES 32 #define KEY_SIZE_BYTES 32
#define TOXIC_MAX_NAME_LENGTH 30 /* Not to be confused with TOX_MAX_NAME_LENGTH */
/* number of permanent default windows */ #define N_DEFAULT_WINS 3 /* number of permanent default windows */
#define N_DEFAULT_WINS 3
#define UNKNOWN_NAME "Unknown" #define UNKNOWN_NAME "Unknown"
#define EXIT_SUCCESS 0 #define EXIT_SUCCESS 0
#define EXIT_FAILURE 1 #define EXIT_FAILURE 1

View File

@ -81,6 +81,11 @@ void on_action(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void
void on_nickchange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata) void on_nickchange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata)
{ {
if (length >= TOXIC_MAX_NAME_LENGTH) { /* length includes null byte */
string[TOXIC_MAX_NAME_LENGTH] = L'\0';
length = TOXIC_MAX_NAME_LENGTH+1;
}
int i; int i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) { for (i = 0; i < MAX_WINDOWS_NUM; ++i) {