aboutsummaryrefslogtreecommitdiff
path: root/command.c
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-04-15 16:05:28 +0200
committertomsmeding <tom.smeding@gmail.com>2017-04-15 16:05:28 +0200
commit3b3f2f3168c80e53055891f9afcfc5c5120dabd7 (patch)
tree415c701933364f283f8eadac1bb0e0543f9fb97f /command.c
parent9800ecb1e93d398988a6904d5e4dc6c4e11aedb0 (diff)
server: Support cmd_is_online
Diffstat (limited to 'command.c')
-rw-r--r--command.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/command.c b/command.c
index b966a75..e66eb12 100644
--- a/command.c
+++ b/command.c
@@ -263,6 +263,17 @@ static bool cmd_ping(struct conn_data *data,const char *tag,const char **args){
return net_send_pong(data->fd,tag);
}
+static bool cmd_is_online(struct conn_data *data,const char *tag,const char **args){
+ i64 userid=db_find_user(args[0]);
+ if(userid==-1){
+ net_send_error(data->fd,tag,"User not found");
+ return false;
+ }
+ i64 nfds;
+ (void)userdata_online(userid,&nfds);
+ return net_send_number(data->fd,tag,nfds);
+}
+
struct cmd_info{
const char *cmdname;
@@ -281,6 +292,7 @@ static const struct cmd_info commands[]={
{"send",2,true,cmd_send},
{"history",2,false,cmd_history},
{"ping",0,false,cmd_ping},
+ {"is_online",1,false,cmd_is_online},
};
#define NCOMMANDS (sizeof(commands)/sizeof(commands[0]))