aboutsummaryrefslogtreecommitdiff
path: root/command.c
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-03-15 10:20:55 +0100
committertomsmeding <tom.smeding@gmail.com>2017-03-15 10:20:55 +0100
commita441b302c2c11c291df60fe642ec0d51646218dd (patch)
tree22200cb885c3b7e38871f3827490700606c025c2 /command.c
parentf1634688d62f2a6115739b65a311ab2b1cf79764 (diff)
Start with implementing online status etc for broadcasting
Diffstat (limited to 'command.c')
-rw-r--r--command.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/command.c b/command.c
index 30d2223..3ede1cc 100644
--- a/command.c
+++ b/command.c
@@ -3,11 +3,19 @@
#include <string.h>
#include <errno.h>
#include <assert.h>
+#include <sys/time.h>
#include <sys/socket.h>
#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(cursor<len){
@@ -170,6 +178,27 @@ static bool cmd_invite(struct conn_data *data,const char *tag,const char **args)
return send_ok(data->fd,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]))