diff options
-rw-r--r-- | agni.c | 53 | ||||
-rw-r--r-- | tbl_qcmd.c | 18 | ||||
-rw-r--r-- | tbl_qcmd.h | 2 |
3 files changed, 65 insertions, 8 deletions
@@ -368,8 +368,8 @@ int th_start_client(void *data) //PNL(); //PRINT("SERVER:%s PORT:%s USER:%s\n", cfg->server, cfg->port, cfg->user); - //conn = irc_connect(cfg->server, cfg->port); - conn = irc_connect("irc.freenode.net", "6667"); + conn = irc_connect(cfg->server, cfg->port); + //conn = irc_connect("irc.freenode.net", "6667"); //PNL(); if (conn < 0) { @@ -777,11 +777,6 @@ int th_event_manager(void *data) } tbl_exec_print_tbl(etbl, TBL_PF_EXEC_ALL); - etbl = tbl_exec_list_c(10); - if (etbl == NULL) - { - PERM(); - } //create command table qtbl = tbl_qcmd_c(10);//well 10 should be ok right? @@ -835,8 +830,19 @@ int th_event_manager(void *data) //PNL(); if (recv_cmd != NULL) { + + char *recv_cmd_param=NULL; + size_t recv_cmd_param_sz=-1; + PNL(); PRINT("MQ:CMD %s\n", mq_cmd_buf(recv_cmd)); + + + //get command fields + mq_cmd_param(recv_cmd, &recv_cmd_param, &recv_cmd_param_sz); + + + if (mq_cmd_o_cmp_cmd(recv_cmd,"QUIT") == 0) { printf("QUIT recieved lets quit main loop\n"); @@ -852,6 +858,7 @@ int th_event_manager(void *data) mq_cmd_free(privcmd); } else if (mq_cmd_o_cmp_cmd(recv_cmd,"PRIVMSG") == 0) { + /* printf("Some private message\n"); if (mq_cmd_o_cmp_param(recv_cmd, ":DATE") == 0) { @@ -880,8 +887,25 @@ int th_event_manager(void *data) mq_cmd_free(privcmd); privcmd = NULL; + } else if (mq_cmd_o_cmp_param(recv_cmd, ":HELLO") == 0) + { + char msg[] = "PONG TO HELLO"; + 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); + + char *cmdBuf = mq_cmd_buf(privcmd); + mq_ntf_write(mq, MQ_IN, cmdBuf, strlen(cmdBuf)); + cmdBuf = NULL; + + mq_cmd_free(privcmd); + privcmd = NULL; } else { + char msg[] = "PONG EVENT THREAD"; mq_cmd *privcmd = mq_cmd_create(mq_cmd_id(recv_cmd),"PRIVMSG",strlen("PRIVMSG"),msg,strlen(msg)); @@ -890,6 +914,21 @@ int th_event_manager(void *data) mq_ntf_write(mq, MQ_IN, cmdBuf, strlen(cmdBuf)); mq_cmd_free(privcmd); + + } + */ + + + //check if command callback excists + if (recv_cmd_param!=NULL) + { + if (tbl_exec_in_s(etbl, recv_cmd_param+1)>=0) //there is ':' in front of command, check if ptr not null otherwise die + { + + } else + { + PRINT("Command not found\n"); + } } } else if (mq_cmd_o_cmp_cmd(recv_cmd,"CMD2") == 0) @@ -49,6 +49,24 @@ int tbl_exec_add(tbl_exec *tbl, tble_exec *cmd) int tbl_exec_in_s(tbl_exec *tbl, char *cmd) { + int i; + tble_exec *el=NULL; + + if ((tbl == NULL) || (cmd == NULL)) + { + PERM(); + return -1; + } + + for (i=0; i<tbl->size; i++) + { + el = tbl->cmd[i]; + if (strncmp(el->cmd, cmd, strlen(el->cmd))==0) + { + return i; + } + } + return -1; } @@ -168,7 +168,7 @@ Input: tbl - table of executed commands cmd - command name to search in the list Output: - >=0 - if everything whent ok + >=0 - if everything whent ok, return position of command in array -1 - if there was some kind of mistake */ int tbl_exec_in_s(tbl_exec *tbl, char *cmd); |