diff options
-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. |