summaryrefslogtreecommitdiff
path: root/agni.c
diff options
context:
space:
mode:
Diffstat (limited to 'agni.c')
-rw-r--r--agni.c100
1 files changed, 23 insertions, 77 deletions
diff --git a/agni.c b/agni.c
index dc91a93..4f8b220 100644
--- a/agni.c
+++ b/agni.c
@@ -44,11 +44,6 @@ void *cmd_pong(void *data)
char *param = (char *)data;
char *ret = NULL;
- if (param == NULL)
- {
- return NULL;
- }
-
printf("PONG\n");
ret = alloc_new_str("PONG");
@@ -61,11 +56,6 @@ void *cmd_uptime(void *data)
char *param = (char *)data;
char *ret = NULL;
- if (param == NULL)
- {
- return NULL;
- }
-
printf("UPTIME\n");
ret = alloc_new_str("UpTime is infinite\n");
@@ -78,11 +68,6 @@ void *cmd_date(void *data)
char *param = (char *)data;
char *ret = NULL;
- if (param == NULL)
- {
- return NULL;
- }
-
printf("DATE\n");
ret = alloc_new_str("I dont whant to date with you\n");
@@ -858,73 +843,34 @@ 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)
- {
- char msg[] = "No date";
- mq_cmd *privcmd = mq_cmd_create(mq_cmd_id(recv_cmd),"PRIVMSG",strlen("PRIVMSG"),msg,strlen(msg));
-
- char *cmdBuf = mq_cmd_buf(privcmd);
- mq_ntf_write(mq, MQ_IN, cmdBuf, strlen(cmdBuf));
- cmdBuf = NULL;
-
- mq_cmd_free(privcmd);
- privcmd = NULL;
- } else if (mq_cmd_o_cmp_param(recv_cmd, ":UPTIME") == 0)
- {
- 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);
-
- char *cmdBuf = mq_cmd_buf(privcmd);
- mq_ntf_write(mq, MQ_IN, cmdBuf, strlen(cmdBuf));
- cmdBuf = NULL;
-
- 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));
-
- char *cmdBuf = mq_cmd_buf(privcmd);
- 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
{
-
+ void *ret_msg = NULL;
+
+ if (tbl_exec_run(etbl, recv_cmd_param+1, &ret_msg)>=0)
+ {
+ if (ret_msg!=NULL)
+ {
+ mq_cmd *privcmd = mq_cmd_create(
+ mq_cmd_id(recv_cmd),
+ "PRIVMSG",
+ strlen("PRIVMSG"),
+ ret_msg,
+ strlen(ret_msg)
+ );
+
+ char *cmdBuf = mq_cmd_buf(privcmd);
+ mq_ntf_write(mq, MQ_IN, cmdBuf, strlen(cmdBuf));
+
+ mq_cmd_free(privcmd);
+ }
+ } else
+ {
+ PRINT("Command execution error\n");
+ }
} else
{
PRINT("Command not found\n");