aboutsummaryrefslogtreecommitdiffstats
path: root/agni.c
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2017-03-20 22:34:11 +0000
committerFreeArtMan <dos21h@gmail.com>2017-03-20 22:34:11 +0000
commitac515d5ab9cebc863d5c34eaa2183c67c6e412d5 (patch)
treeb9ba872bfe35cd9832121bdab80fade9d961c096 /agni.c
parent3402dd6ff49bb1567def4e7bfba1f877ffbd0786 (diff)
downloadagni-ac515d5ab9cebc863d5c34eaa2183c67c6e412d5.tar.gz
agni-ac515d5ab9cebc863d5c34eaa2183c67c6e412d5.zip
Now basic funcionality works. Preparing to wrap up all code
Diffstat (limited to 'agni.c')
-rw-r--r--agni.c123
1 files changed, 82 insertions, 41 deletions
diff --git a/agni.c b/agni.c
index e4dbe34..03c9f2b 100644
--- a/agni.c
+++ b/agni.c
@@ -327,6 +327,7 @@ int th_start_client(void *data)
//mq_cmd *qcmd=NULL; //queue command
int run;
int mq_event;
+ int byte_num;
server_cfg *cfg = data;
mq_ntf_mdt *mq = cfg->mq;
@@ -442,12 +443,12 @@ int th_start_client(void *data)
break;
case 1:
PRINT("MQ_EVENT IN\n");
- if (mq_ntf_read(mq, MQ_IN, in_buf, in_attr.mq_msgsize) == -1)
+ if ((byte_num = mq_ntf_read(mq, MQ_IN, in_buf, in_attr.mq_msgsize)) == -1)
{
printf("Cant read input message \n");
} else
{
- in_buf[in_attr.mq_msgsize-1] = 0x0;
+ in_buf[byte_num] = 0x0;
PRINT("Recieve %s\n", in_buf);
}
break;
@@ -494,17 +495,32 @@ int th_start_client(void *data)
tble_qcmd *cmd = tbl_qcmd_match_id(qtbl, cmd_id);
if (cmd != NULL)
{
- int buf_sz = TH_CONN_BUF_SZ>128?128:TH_CONN_BUF_SZ;
-
char *resp_user = token_new_str(cmd->tok,0);
+ char *dest_user = token_new_str(cmd->tok,2);
char *sep = strchr(resp_user,'!');
resp_user[sep-resp_user] = 0x0;
- memset(cmd_buf, 0, buf_sz);
- //prepare response
- int fret = snprintf(cmd_buf, buf_sz,":%s PRIVMSG %s :%s \r\n",cfg->user,resp_user,match_resp->resp);
- write(conn, cmd_buf, fret);
-
+ memset(cmd_buf, 0, TH_CONN_BUF_SZ);
+
+ if (dest_user[0] == '#')
+ {
+ //response for chan PRIVMSG
+ //prepare response
+ int fret = snprintf(cmd_buf, TH_CONN_BUF_SZ,":%s PRIVMSG %s :%s \r\n", cfg->user, dest_user, match_resp->resp);
+ PRINT("%s\n",cmd_buf);
+ write(conn, cmd_buf, fret);
+ }
+ else
+ {
+ //response for user PRIVMSG
+
+ //prepare response
+ int fret = snprintf(cmd_buf, TH_CONN_BUF_SZ,":%s PRIVMSG %s :%s \r\n", dest_user, resp_user, match_resp->resp);
+ PRINT("%s\n",cmd_buf);
+ write(conn, cmd_buf, fret);
+ }
+
+ free(dest_user);
free(resp_user);
}
@@ -563,6 +579,7 @@ int th_start_client(void *data)
fret = write(conn,"PONG",strlen("PONG"));
printf("OUT<<Send %d\n", fret);
}
+ //something is sended to cbot
if (token_cmp(itok,1,"PRIVMSG") == 1)
{
int fret,fret2;
@@ -572,45 +589,67 @@ int th_start_client(void *data)
memset(cmd_buf,0,128);
char *uname = token_new_str(itok,0);
- char *msg = token_new_str(itok,3);
+ char *dest_name = token_new_str(itok,2);
+ char *msg = token_new_str(itok,3); //could send without first symbol pal
char *sep = strchr(uname,'!');
uname[sep-uname] = 0x0;
- //just send to test that thos commands works mate
- //fret2=snprintf(cmd_buf,128,":%s PRIVMSG %s PONGER\r\n",cfg->user,uname);
- //printf("FORMATED [%s]",cmd_buf);
- //fret = write(conn,cmd_buf,fret2);
-
- //create cmd table command and set into table
- qcmd = tbl_qcmd_cmd_c();
- if (qcmd != NULL)
+ PRINT()
+ //if (token_cmp(itok,3,":join") == 1)
+ if (strncmp(":join",msg,5)==0)
+ {
+ PNL();
+ //lets check if one more argument is there
+
+ {
+ PNL();
+ char *sep_chan = strchr(msg,' ');
+
+ //lets join channel
+ memset(cmd_buf, 0, TH_CONN_BUF_SZ);
+ int fret = snprintf(cmd_buf, TH_CONN_BUF_SZ, ":%s JOIN %s\r\n", dest_name, sep_chan);
+ PRINT("cmd_buf %s\n", cmd_buf);
+ write(conn, cmd_buf, fret);
+
+ }
+ } else
{
- qcmd->cid = uniq_id();
- qcmd->state = QCMD_NONE;
- qcmd->cmd = alloc_new_str("PRIVMSG");
- qcmd->param = alloc_new_str(msg);
- tbl_qcmd_add_tok(qcmd, itok);
- tbl_qcmd_add(qtbl, qcmd);
- tbl_qcmd_print_tbl(qtbl,TBL_PF_QCMD_ID
- |TBL_PF_QCMD_CID
- |TBL_PF_QCMD_STATE
- |TBL_PF_QCMD_CMD
- |TBL_PF_QCMD_PARAM
- |TBL_PF_QCMD_TID
- |TBL_PF_QCMD_TIDX);
+ //just send to test that thos commands works mate
+ //fret2=snprintf(cmd_buf,128,":%s PRIVMSG %s PONGER\r\n",cfg->user,uname);
+ //printf("FORMATED [%s]",cmd_buf);
+ //fret = write(conn,cmd_buf,fret2);
+
+ //create cmd table command and set into table
+ qcmd = tbl_qcmd_cmd_c();
+ if (qcmd != NULL)
+ {
+ qcmd->cid = uniq_id();
+ qcmd->state = QCMD_NONE;
+ qcmd->cmd = alloc_new_str("PRIVMSG");
+ qcmd->param = alloc_new_str(msg);
+ tbl_qcmd_add_tok(qcmd, itok);
+ tbl_qcmd_add(qtbl, qcmd);
+ tbl_qcmd_print_tbl(qtbl,TBL_PF_QCMD_ID
+ |TBL_PF_QCMD_CID
+ |TBL_PF_QCMD_STATE
+ |TBL_PF_QCMD_CMD
+ |TBL_PF_QCMD_PARAM
+ |TBL_PF_QCMD_TID
+ |TBL_PF_QCMD_TIDX);
+ }
+
+ //create command and send to mq
+ mq_cmd *privcmd = mq_cmd_create(qcmd->cid,"PRIVMSG",strlen("PRIVMSG"),msg,strlen(msg));
+ char *bufPtr;
+ bufPtr = mq_cmd_buf(privcmd);
+ mq_ntf_write(mq, MQ_OUT, bufPtr, strlen(bufPtr));
+ mq_cmd_free(privcmd);
+
+ //for safety make null, as no one should use it anymore
+ qcmd = NULL;
}
- //create command and send to mq
- mq_cmd *privcmd = mq_cmd_create(qcmd->cid,"PRIVMSG",strlen("PRIVMSG"),msg,strlen(msg));
- char *bufPtr;
- bufPtr = mq_cmd_buf(privcmd);
- mq_ntf_write(mq, MQ_OUT, bufPtr, strlen(bufPtr));
- mq_cmd_free(privcmd);
-
- //for safety make null, as no one should use it anymore
- qcmd = NULL;
-
free(msg);
free(uname);
@@ -830,6 +869,8 @@ int th_event_manager(void *data)
char msg[] = "Forever";
mq_cmd *privcmd = mq_cmd_create(mq_cmd_id(recv_cmd),"PRIVMSG",strlen("PRIVMSG"),msg,strlen(msg));
+ PRINT("%s\n", privcmd->buf);
+
int id = mq_cmd_id(recv_cmd);
PRINT("%d\n",id);