aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2020-09-25 22:19:00 +0200
committerTom Smeding <tom.smeding@gmail.com>2020-09-29 22:19:13 +0200
commit1ecfdb8eef2e1cf5c9f017708b6313ea5d4093d7 (patch)
treeeb9c3462ca2ae147ac5f342fef77411149dab778
parentc8524b6076d322107bef3de1449c45bcaec7b7aa (diff)
server: Send _push invite to self on create_room
-rw-r--r--command.c29
-rw-r--r--command.h4
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.