diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2020-09-25 22:19:00 +0200 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2020-09-29 22:19:13 +0200 |
commit | 1ecfdb8eef2e1cf5c9f017708b6313ea5d4093d7 (patch) | |
tree | eb9c3462ca2ae147ac5f342fef77411149dab778 | |
parent | c8524b6076d322107bef3de1449c45bcaec7b7aa (diff) |
server: Send _push invite to self on create_room
-rw-r--r-- | command.c | 29 | ||||
-rw-r--r-- | command.h | 4 |
2 files changed, 25 insertions, 8 deletions
@@ -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); } @@ -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. |