From 1ecfdb8eef2e1cf5c9f017708b6313ea5d4093d7 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Fri, 25 Sep 2020 22:19:00 +0200 Subject: server: Send _push invite to self on create_room --- command.c | 29 +++++++++++++++++++++++------ command.h | 4 ++-- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/command.c b/command.c index 39a50b7..69f40b2 100644 --- a/command.c +++ b/command.c @@ -164,14 +164,31 @@ static struct cmd_retval cmd_list_members(struct conn_data *data,const char *tag static struct cmd_retval cmd_create_room(struct conn_data *data,const char *tag,const char **args){ (void)args; - if(data->userid==-1){ - net_send_error(data->fd,tag,"Not logged in"); + if (data->userid == -1) { + net_send_error(data->fd, tag, "Not logged in"); return RET_OK; } - userdata_mark_active(data->userid,data->fd,true); - struct db_name_id room=db_create_room(); - db_add_member(room.id,data->userid); - bool closed=net_send_name(data->fd,tag,room.name); + userdata_mark_active(data->userid, data->fd, true); + + struct db_name_id room = db_create_room(); + db_add_member(room.id, data->userid); + + char *username = db_get_username(data->userid); + char *invitebuf = NULL; + i64 invitebuflen = asprintf(&invitebuf, "_push invite %s %s\n", room.name, username); + free(username); + + i64 nfds; + const int *fds = userdata_online(data->userid, &nfds); + for (i64 j = 0; j < nfds; j++) { + if (fds[j] != data->fd) { + net_send_raw_text(fds[j], invitebuf, invitebuflen); + } + } + + free(invitebuf); + + bool closed = net_send_name(data->fd, tag, room.name); db_nullify_name_id(room); return RET_CLOSE(closed); } diff --git a/command.h b/command.h index ebfec8c..68ec014 100644 --- a/command.h +++ b/command.h @@ -4,8 +4,8 @@ #include "conn_data.h" -#define PROTOCOL_VERSION 2 -#define MIN_SUPPORTED_PROTOCOL_VERSION 2 +#define PROTOCOL_VERSION 3 +#define MIN_SUPPORTED_PROTOCOL_VERSION 3 // Returns true if socket should be closed. -- cgit v1.2.3-70-g09d2