5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2002 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
26 #include "servers-setup.h"
27 #include "channels-setup.h"
28 #include "silc-servers.h"
29 #include "silc-channels.h"
30 #include "silc-queries.h"
31 #include "silc-nicklist.h"
33 EXPANDO_FUNC old_expando_usermode,
35 old_expando_cumode_space;
37 /* User mode in active server */
39 static char *expando_usermode(SERVER_REC *server, void *item, int *free_ret)
41 SILC_SERVER_REC *s = SILC_SERVER(server);
42 static char modes[128], stat[128];
46 if (old_expando_usermode)
47 return old_expando_usermode(server, item, free_ret);
52 memset(modes, 0, sizeof(modes));
53 memset(stat, 0, sizeof(stat));
55 if (s->umode & SILC_UMODE_GONE)
57 if (s->umode & SILC_UMODE_INDISPOSED)
59 if (s->umode & SILC_UMODE_BUSY)
61 if (s->umode & SILC_UMODE_PAGE)
63 if (s->umode & SILC_UMODE_HYPER)
65 if (s->umode & SILC_UMODE_ROBOT)
67 if (s->umode & SILC_UMODE_ANONYMOUS)
69 if (s->umode & SILC_UMODE_BLOCK_PRIVMSG)
71 if (s->umode & SILC_UMODE_REJECT_WATCHING)
73 if (s->umode & SILC_UMODE_BLOCK_INVITE)
76 se = strlen(stat) > 0;
77 snprintf(modes, sizeof(modes) - 1, "%s%s%s%s",
78 ((s->umode & SILC_UMODE_SERVER_OPERATOR) ? "Server Operator" :
79 (s->umode & SILC_UMODE_ROUTER_OPERATOR) ? "Router Operator" : ""),
80 se ? "[" : "", se ? stat : "", se ? "]" : "");
85 /* Expands to your usermode on channel */
87 static char *expando_cumode(SERVER_REC *server, void *item, int *free_ret)
89 SILC_SERVER_REC *s = SILC_SERVER(server);
92 if (old_expando_cumode)
93 return old_expando_cumode(server, item, free_ret);
98 if (IS_SILC_CHANNEL(item) && CHANNEL(item)->ownnick) {
99 SILC_NICK_REC *nick = (SILC_NICK_REC *)CHANNEL(item)->ownnick;
100 return (nick->op && nick->founder) ? "*@" :
101 nick->op ? "@" : nick->founder ? "*" : "";
107 static char *expando_cumode_space(SERVER_REC *server, void *item,
110 SILC_SERVER_REC *s = SILC_SERVER(server);
114 if (old_expando_cumode_space)
115 return old_expando_cumode_space(server, item, free_ret);
120 ret = expando_cumode(server, item, free_ret);
121 return *ret == '\0' ? " " : ret;
124 static char *expando_silc_version(SERVER_REC *server, void *item,
130 void silc_expandos_init(void)
132 old_expando_usermode = expando_find_long("usermode");
133 old_expando_cumode = expando_find_long("cumode");
134 old_expando_cumode_space = expando_find_long("cumode_space");
135 expando_create("usermode", expando_usermode,
136 "window changed", EXPANDO_ARG_NONE,
137 "window server changed", EXPANDO_ARG_WINDOW,
138 "user mode changed", EXPANDO_ARG_SERVER, NULL);
139 expando_create("cumode", expando_cumode,
140 "window changed", EXPANDO_ARG_NONE,
141 "window item changed", EXPANDO_ARG_WINDOW,
142 "nick mode changed", EXPANDO_ARG_WINDOW_ITEM, NULL);
143 expando_create("cumode_space", expando_cumode_space,
144 "window changed", EXPANDO_ARG_NONE,
145 "window item changed", EXPANDO_ARG_WINDOW,
146 "nick mode changed", EXPANDO_ARG_WINDOW_ITEM, NULL);
147 expando_create("j", expando_silc_version, NULL);
150 void silc_expandos_deinit(void)
152 expando_destroy("j", expando_silc_version);
153 expando_destroy("usermode", expando_usermode);
154 expando_destroy("cumode", expando_cumode);
155 expando_destroy("cumode_space", expando_cumode_space);
156 if (old_expando_usermode)
157 expando_create("usermode", old_expando_usermode, NULL);
158 if (old_expando_cumode)
159 expando_create("cumode", old_expando_cumode, NULL);
160 if (old_expando_cumode_space)
161 expando_create("cumode_space", old_expando_cumode_space, NULL);