From a441b302c2c11c291df60fe642ec0d51646218dd Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Wed, 15 Mar 2017 10:20:55 +0100 Subject: Start with implementing online status etc for broadcasting --- command.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'command.c') diff --git a/command.c b/command.c index 30d2223..3ede1cc 100644 --- a/command.c +++ b/command.c @@ -3,11 +3,19 @@ #include #include #include +#include #include #include "command.h" #include "db.h" +static i64 make_timestamp(void){ + struct timeval tv; + gettimeofday(&tv,NULL); + return (i64)tv.tv_sec+tv.tv_usec; +} + + static bool send_raw_text(int fd,const char *text,i64 len){ i64 cursor=0; while(cursorfd,tag); } +static bool cmd_send(struct conn_data *data,const char *tag,const char **args){ + if(data->userid==-1){ + send_error(data->fd,tag,"Not logged in"); + return false; + } + i64 roomid=db_find_room(args[0]); + if(roomid==-1){ + send_error(data->fd,tag,"Room not found"); + return false; + } + if(!db_is_member(roomid,data->userid)){ + send_error(data->fd,tag,"Not in that room"); + return false; + } + + db_create_message(roomid,data->userid,make_timestamp(),args[1]); + bool closed=send_ok(data->fd,tag); + +#warning TODO: broadcast +} + struct cmd_info{ const char *cmdname; @@ -184,6 +213,7 @@ static const struct cmd_info commands[]={ {"list_rooms",0,false,cmd_list_rooms}, {"create_room",0,false,cmd_create_room}, {"invite",2,false,cmd_invite}, + {"send",2,true,cmd_send}, }; #define NCOMMANDS (sizeof(commands)/sizeof(commands[0])) -- cgit v1.2.3-70-g09d2