1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
#include <string.h>
#include <ncurses.h>
#include "command.h"
#include "jabber.h"
#include "windows.h"
static int cmd_quit(void);
static int cmd_help(void);
static int cmd_who(void);
static int cmd_msg(char *cmd);
static int cmd_close(char *cmd);
static int cmd_default(char *cmd);
int handle_command(char *cmd)
{
int result = FALSE;
if (strcmp(cmd, "/quit") == 0) {
result = cmd_quit();
} else if (strncmp(cmd, "/help", 5) == 0) {
result = cmd_help();
} else if (strncmp(cmd, "/who", 4) == 0) {
result = cmd_who();
} else if (strncmp(cmd, "/msg ", 5) == 0) {
result = cmd_msg(cmd);
} else if (strncmp(cmd, "/close", 6) == 0) {
result = cmd_close(cmd);
} else {
result = cmd_default(cmd);
}
return result;
}
static int cmd_quit(void)
{
return FALSE;
}
static int cmd_help(void)
{
cons_help();
inp_clear();
return TRUE;
}
static int cmd_who(void)
{
jabber_roster_request();
inp_clear();
return TRUE;
}
static int cmd_msg(char *cmd)
{
char *usr_msg = NULL;
char *usr = NULL;
char *msg = NULL;
usr_msg = strndup(cmd+5, strlen(cmd)-5);
usr = strtok(usr_msg, " ");
if (usr != NULL) {
msg = strndup(cmd+5+strlen(usr)+1, strlen(cmd)-(5+strlen(usr)+1));
if (msg != NULL) {
jabber_send(msg, usr);
show_outgoing_msg("me", usr, msg);
}
}
inp_clear();
return TRUE;
}
static int cmd_close(char *cmd)
{
if (in_chat()) {
close_win();
} else {
cons_bad_command(cmd);
}
inp_clear();
return TRUE;
}
static int cmd_default(char *cmd)
{
if (in_chat()) {
char recipient[100] = "";
get_recipient(recipient);
jabber_send(cmd, recipient);
show_outgoing_msg("me", recipient, cmd);
} else {
cons_bad_command(cmd);
}
inp_clear();
return TRUE;
}
|