From fc6970fcd404305c3e16d2e90d6d0dec4b03c160 Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Thu, 7 Sep 2017 23:00:20 +0100 Subject: Basic stat command implemented --- agni.c | 39 +++++++++++++++++++++++++++++++-------- cmd/cmd_stat.c | 2 +- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/agni.c b/agni.c index fa16b31..4cd93a7 100644 --- a/agni.c +++ b/agni.c @@ -379,27 +379,50 @@ int th_start_client(void *data) char *user = alloc_new_str(cmd->ircident); //BUGGY user[sep-cmd->ircident] = 0x0; char *resp_user = token_new_str(cmd->tok, 2); - PRINT("resp_user %s\n",resp_user); + //PRINT("resp_user %s\n",resp_user); + int formated_size = -1; + + int count; + sds str_out; + sds *tokens; + int out_i; if (resp_user[0]=='#') { //printf("RESPONSE :%s PRIVMSG %s :%s\n", cfg->user, user, resp->result); - int fret = snprintf(cmd_buf, TH_CONN_BUF_SZ,":%s PRIVMSG %s :%s \r\n", cfg->user, resp_user, resp->result); - PRINT("%s\n",cmd_buf); - write(conn.conn_fd, cmd_buf, fret); + //formated_size = snprintf(cmd_buf, TH_CONN_BUF_SZ,":%s PRIVMSG %s :%s \r\n", cfg->user, resp_user, resp->result); + snprintf(cmd_buf, TH_CONN_BUF_SZ,":%s PRIVMSG %s :", cfg->user, resp_user); + //PRINT("%s\n",cmd_buf); + } else { //printf("RESPONSE :%s PRIVMSG %s :%s\n", user, resp_user, resp->result); - int fret = snprintf(cmd_buf, TH_CONN_BUF_SZ,":%s PRIVMSG %s :%s \r\n", resp_user, user, resp->result); - PRINT("%s\n",cmd_buf); - write(conn.conn_fd, cmd_buf, fret); + //formated_size = snprintf(cmd_buf, TH_CONN_BUF_SZ,":%s PRIVMSG %s :%s \r\n", resp_user, user, resp->result); + snprintf(cmd_buf, TH_CONN_BUF_SZ,":%s PRIVMSG %s :", resp_user, user); + //PRINT("%s\n",cmd_buf); } + str_out = sdsnew(resp->result); + tokens = sdssplitlen(str_out,sdslen(str_out),"\n",1,&count); + + for (out_i=0; out_i>>>%s",sending); + write(conn.conn_fd, sending, sdslen(sending)); + sdsfree(sending); + } + + sdsfreesplitres(tokens, count); + sdsfree(str_out); + FREE(user); FREE(resp_user); //remove command by id - //for now just remove command without checkings its state + //for now just remove command without checkings its state tbl_qcmd_del_by_id(qtbl, cmd_id); } } diff --git a/cmd/cmd_stat.c b/cmd/cmd_stat.c index ce19085..73b7fa6 100644 --- a/cmd/cmd_stat.c +++ b/cmd/cmd_stat.c @@ -37,7 +37,7 @@ void *cmd_stat(void *data) snprintf(buf,buf_size,"| IPC_RX | %08s |\n", tokens[3]); out_result = sdscat(out_result, buf); - out_result = sdscat(out_result,"+----------+----------+\n"); + out_result = sdscat(out_result,"+----------+----------+"); sdsfreesplitres(tokens, count); -- cgit v1.2.3