summaryrefslogtreecommitdiff
path: root/vchat-protocol.c
diff options
context:
space:
mode:
Diffstat (limited to 'vchat-protocol.c')
-rwxr-xr-xvchat-protocol.c556
1 files changed, 257 insertions, 299 deletions
diff --git a/vchat-protocol.c b/vchat-protocol.c
index 2b98779..ac65639 100755
--- a/vchat-protocol.c
+++ b/vchat-protocol.c
@@ -10,49 +10,51 @@
10 * without even the implied warranty of merchantability or fitness for a 10 * without even the implied warranty of merchantability or fitness for a
11 * particular purpose. In no event shall the copyright holder be liable for 11 * particular purpose. In no event shall the copyright holder be liable for
12 * any direct, indirect, incidental or special damages arising in any way out 12 * any direct, indirect, incidental or special damages arising in any way out
13 * of the use of this software. 13 * of the use of this software.
14 * 14 *
15 */ 15 */
16 16
17/* general includes */ 17/* general includes */
18#include <stdlib.h> 18#include <errno.h>
19#include <langinfo.h>
20#include <locale.h>
19#include <stdio.h> 21#include <stdio.h>
22#include <stdlib.h>
20#include <string.h> 23#include <string.h>
21#include <errno.h> 24
22#include <readline/readline.h> 25#include <readline/readline.h>
23#include <locale.h>
24#include <langinfo.h>
25 26
26#ifdef DEBUG 27#ifdef DEBUG
27FILE * dumpfile; 28FILE *dumpfile;
28#endif 29#endif
29 30
30/* local includes */ 31/* local includes */
31#include "vchat.h"
32#include "vchat-user.h"
33#include "vchat-connection.h" 32#include "vchat-connection.h"
33#include "vchat-user.h"
34#include "vchat.h"
34 35
35/* version of this module */ 36/* version of this module */
36const char *vchat_io_version = "vchat-protocol.c $Id$"; 37const char *vchat_io_version =
38 "vchat-protocol.c $Id$";
37 39
38/* declaration of local helper functions */ 40/* declaration of local helper functions */
39static void usersignon (char *); 41static void usersignon(char *);
40static void usersignoff (char *); 42static void usersignoff(char *);
41static void usernickchange (char *); 43static void usernickchange(char *);
42static void userjoin (char *); 44static void userjoin(char *);
43static void userleave (char *); 45static void userleave(char *);
44static void receivenicks (char *message); 46static void receivenicks(char *message);
45static void justloggedin (char *message); 47static void justloggedin(char *message);
46static void nickerr (char *message); 48static void nickerr(char *message);
47static void login (char *message); 49static void login(char *message);
48static void anonlogin (char *message); 50static void anonlogin(char *message);
49static void topicinfo (char *message); 51static void topicinfo(char *message);
50static void pubaction (char *message); 52static void pubaction(char *message);
51static void pubthoughts (char *message); 53static void pubthoughts(char *message);
52static void serverlogin (char *message); 54static void serverlogin(char *message);
53static void idleprompt (char *message); 55static void idleprompt(char *message);
54static void topicchange (char *message); 56static void topicchange(char *message);
55static void pmnotsent (char *message); 57static void pmnotsent(char *message);
56 58
57/* declaration of server message array */ 59/* declaration of server message array */
58#include "vchat-messages.h" 60#include "vchat-messages.h"
@@ -61,61 +63,53 @@ char *encoding;
61 63
62/* handle a pm not sent error 64/* handle a pm not sent error
63 * format: 412 %s */ 65 * format: 412 %s */
64static void 66static void pmnotsent(char *message) {
65pmnotsent (char *message) 67 while (*message && *message != ' ')
66{ 68 message++;
67 while(*message && *message!=' ') message++; 69 snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_ERR), message + 1);
68 snprintf(tmpstr,TMPSTRSIZE,getformatstr(FS_ERR),message+1); 70 writepriv(tmpstr, 0);
69 writepriv( tmpstr, 0);
70
71} 71}
72 72
73/* parse and handle an action string 73/* parse and handle an action string
74 * format: 118 %s %s 74 * format: 118 %s %s
75 * vars: %s nick 75 * vars: %s nick
76 * %s action */ 76 * %s action */
77static void 77static void pubaction(char *message) {
78pubaction (char *message)
79{
80 char *nick = NULL, *action = NULL; 78 char *nick = NULL, *action = NULL;
81 nick = strchr (message, ' '); 79 nick = strchr(message, ' ');
82 nick[0] = '\0'; 80 nick[0] = '\0';
83 nick++; 81 nick++;
84 82
85 action = strchr (nick, ' '); 83 action = strchr(nick, ' ');
86 action[0] = '\0'; 84 action[0] = '\0';
87 action++; 85 action++;
88 86
89 ul_public_action(nick); 87 ul_public_action(nick);
90 snprintf(tmpstr,TMPSTRSIZE,getformatstr(FS_PUBACTION),nick,action); 88 snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_PUBACTION), nick, action);
91 writechan (tmpstr); 89 writechan(tmpstr);
92} 90}
93 91
94/* parse and handle an thought string 92/* parse and handle an thought string
95 * format: 124 %s %s 93 * format: 124 %s %s
96 * vars: %s nick 94 * vars: %s nick
97 * %s thought */ 95 * %s thought */
98static void 96static void pubthoughts(char *message) {
99pubthoughts (char *message)
100{
101 char *nick = NULL, *thoughts = NULL; 97 char *nick = NULL, *thoughts = NULL;
102 nick = strchr (message, ' '); 98 nick = strchr(message, ' ');
103 nick[0] = '\0'; 99 nick[0] = '\0';
104 nick++; 100 nick++;
105 101
106 thoughts = strchr (nick, ' '); 102 thoughts = strchr(nick, ' ');
107 thoughts[0] = '\0'; 103 thoughts[0] = '\0';
108 thoughts++; 104 thoughts++;
109 105
110 ul_public_action(nick); 106 ul_public_action(nick);
111 snprintf(tmpstr,TMPSTRSIZE,getformatstr(FS_PUBTHOUGHT),nick,thoughts); 107 snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_PUBTHOUGHT), nick, thoughts);
112 writechan (tmpstr); 108 writechan(tmpstr);
113} 109}
114 110
115/* parse and handle server logon */ 111/* parse and handle server logon */
116static void 112static void serverlogin(char *message) {
117serverlogin (char *message)
118{
119 (void)message; 113 (void)message;
120 int utf8 = !strcmp(nl_langinfo(CODESET), "UTF-8"); 114 int utf8 = !strcmp(nl_langinfo(CODESET), "UTF-8");
121 if (utf8) 115 if (utf8)
@@ -125,274 +119,257 @@ serverlogin (char *message)
125/* parse and handle an idle message 119/* parse and handle an idle message
126 * format: 305 120 * format: 305
127 * vars: %s message */ 121 * vars: %s message */
128static void 122static void idleprompt(char *message) {
129idleprompt (char *message)
130{
131 char *msg = NULL; 123 char *msg = NULL;
132 msg = strchr (message, ' '); 124 msg = strchr(message, ' ');
133 msg[0] = '\0'; 125 msg[0] = '\0';
134 msg++; 126 msg++;
135 127
136 snprintf(tmpstr,TMPSTRSIZE,getformatstr(FS_IDLE),msg); 128 snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_IDLE), msg);
137 writechan (tmpstr); 129 writechan(tmpstr);
138} 130}
139 131
140/* parse and handle a topic information string 132/* parse and handle a topic information string
141 * format: 115 %d %s 133 * format: 115 %d %s
142 * vars: %d chan - channel number 134 * vars: %d chan - channel number
143 * %s topic - topic */ 135 * %s topic - topic */
144static void 136static void topicinfo(char *message) {
145topicinfo (char *message)
146{
147 char *channel = NULL, *topic = NULL; 137 char *channel = NULL, *topic = NULL;
148 int tmpchan = 0, ownchan = own_channel_get(); 138 int tmpchan = 0, ownchan = own_channel_get();
149 139
150 /* search start of channel number */ 140 /* search start of channel number */
151 channel = strchr (message, ' '); 141 channel = strchr(message, ' ');
152 channel++; 142 channel++;
153 143
154 /* search start of topic and terminate channel number */ 144 /* search start of topic and terminate channel number */
155 topic = strchr (channel, ' '); 145 topic = strchr(channel, ' ');
156 topic[0] = '\0'; 146 topic[0] = '\0';
157 topic++; 147 topic++;
158 148
159 /* convert channel number to integer */ 149 /* convert channel number to integer */
160 tmpchan = atoi (channel); 150 tmpchan = atoi(channel);
161 151
162 if (tmpchan == ownchan ) { 152 if (tmpchan == ownchan) {
163 /* show change in topic window */ 153 /* show change in topic window */
164 if (strlen(topic)) 154 if (strlen(topic))
165 snprintf (topicstr, TOPICSTRSIZE, getformatstr(FS_TOPICW), ownchan, topic); 155 snprintf(topicstr, TOPICSTRSIZE, getformatstr(FS_TOPICW), ownchan, topic);
166 else 156 else
167 snprintf (topicstr, TOPICSTRSIZE, getformatstr(FS_NOTOPICW), ownchan ); 157 snprintf(topicstr, TOPICSTRSIZE, getformatstr(FS_NOTOPICW), ownchan);
168 topicline(NULL); 158 topicline(NULL);
169 } 159 }
170 160
171 /* announce change in channel window */ 161 /* announce change in channel window */
172 if (strlen(topic)) 162 if (strlen(topic))
173 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_TOPIC), tmpchan, topic); 163 snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_TOPIC), tmpchan, topic);
174 else 164 else
175 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_NOTOPIC), tmpchan); 165 snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_NOTOPIC), tmpchan);
176 writechan (tmpstr); 166 writechan(tmpstr);
177} 167}
178 168
179/* parse and handle a topic change string 169/* parse and handle a topic change string
180 * format: 114 %s changes topic to '%s' 170 * format: 114 %s changes topic to '%s'
181 * vars: %s nick 171 * vars: %s nick
182 * %s topic */ 172 * %s topic */
183static void 173static void topicchange(char *message) {
184topicchange (char *message)
185{
186 char *nick = NULL, *topic = NULL; 174 char *nick = NULL, *topic = NULL;
187 int len, ownchan = own_channel_get(); 175 int len, ownchan = own_channel_get();
188 176
189 /* search start of nickname */ 177 /* search start of nickname */
190 nick = strchr (message, ' '); 178 nick = strchr(message, ' ');
191 nick++; 179 nick++;
192 180
193 /* search start of message before topic, terminate nick */ 181 /* search start of message before topic, terminate nick */
194 topic = strchr (nick, ' '); 182 topic = strchr(nick, ' ');
195 topic[0] = '\0'; 183 topic[0] = '\0';
196 topic++; 184 topic++;
197 185
198 /* search start of real topic and terminate channel number */ 186 /* search start of real topic and terminate channel number */
199 topic = strchr (topic, '\''); 187 topic = strchr(topic, '\'');
200 topic[0] = '\0'; 188 topic[0] = '\0';
201 topic++; 189 topic++;
202 190
203 /* remove ending '\'', if there */ 191 /* remove ending '\'', if there */
204 len = strlen (topic); 192 len = strlen(topic);
205 if (topic[len-1] == '\'') 193 if (topic[len - 1] == '\'')
206 topic[len-1] = '\0'; 194 topic[len - 1] = '\0';
207 195
208 ul_public_action(nick); 196 ul_public_action(nick);
209 /* show change in topic window */ 197 /* show change in topic window */
210 snprintf (topicstr, TOPICSTRSIZE, getformatstr(FS_TOPICW), ownchan, topic); 198 snprintf(topicstr, TOPICSTRSIZE, getformatstr(FS_TOPICW), ownchan, topic);
211 topicline(NULL); 199 topicline(NULL);
212 200
213 /* announce change in channel window */ 201 /* announce change in channel window */
214 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_CHGTOPIC), nick, topic); 202 snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_CHGTOPIC), nick, topic);
215 writechan (tmpstr); 203 writechan(tmpstr);
216} 204}
217 205
218/* parse and handle a login message 206/* parse and handle a login message
219 * format: 212 %s %s 207 * format: 212 %s %s
220 * vars: %s str1 - nick used to login 208 * vars: %s str1 - nick used to login
221 * %s str2 - servers message */ 209 * %s str2 - servers message */
222static void 210static void justloggedin(char *message) {
223justloggedin (char *message)
224{
225 char *str1 = NULL, *str2 = NULL; 211 char *str1 = NULL, *str2 = NULL;
226 /* search start of nickname */ 212 /* search start of nickname */
227 str1 = strchr (message, ' '); 213 str1 = strchr(message, ' ');
228 str1++; 214 str1++;
229 215
230 /* search start of message, terminate nick */ 216 /* search start of message, terminate nick */
231 str2 = strchr (str1, ' '); 217 str2 = strchr(str1, ' ');
232 str2[0] = '\0'; 218 str2[0] = '\0';
233 str2++; 219 str2++;
234 220
235 /* if we have a new nick, store it */ 221 /* if we have a new nick, store it */
236 own_nick_set( str1 ); 222 own_nick_set(str1);
237 223
238 /* show change in console window */ 224 /* show change in console window */
239 snprintf (consolestr, CONSOLESTRSIZE, getformatstr(FS_CONSOLE), str1, getstroption (CF_SERVERHOST), getstroption (CF_SERVERPORT)); 225 snprintf(consolestr, CONSOLESTRSIZE, getformatstr(FS_CONSOLE), str1,
240 consoleline (NULL); 226 getstroption(CF_SERVERHOST), getstroption(CF_SERVERPORT));
227 consoleline(NULL);
241 228
242 /* announce login as servermessage */ 229 /* announce login as servermessage */
243 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_SIGNON), str1, str2); 230 snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_SIGNON), str1, str2);
244 writechan (tmpstr); 231 writechan(tmpstr);
245 232
246 /* we're not logged in, change status and request nicks */ 233 /* we're not logged in, change status and request nicks */
247 if (!loggedin) 234 if (!loggedin) {
248 { 235 loadcfg(getstroption(CF_LOGINSCRIPT), 0, handleline);
249 loadcfg(getstroption(CF_LOGINSCRIPT),0,handleline); 236 handleline(".S");
250 handleline(".S"); 237 loggedin = 1;
251 loggedin = 1; 238 }
252 }
253} 239}
254 240
255/* this user joins a different channel */ 241/* this user joins a different channel */
256void 242void ownjoin(int channel) {
257ownjoin (int channel)
258{
259 vc_sendmessage(".t"); 243 vc_sendmessage(".t");
260 snprintf(tmpstr, TMPSTRSIZE, ".S %d",channel); 244 snprintf(tmpstr, TMPSTRSIZE, ".S %d", channel);
261 vc_sendmessage(tmpstr); 245 vc_sendmessage(tmpstr);
262} 246}
263 247
264/* this user changes his nick */ 248/* this user changes his nick */
265void 249void ownnickchange(const char *newnick) { (void)newnick; }
266ownnickchange (const char *newnick)
267{
268 (void)newnick;
269}
270 250
271/* parse and handle a nick error message 251/* parse and handle a nick error message
272 * format: 401 %s 252 * format: 401 %s
273 * 403 %s 253 * 403 %s
274 * 415 %s 254 * 415 %s
275 * vars: %s - server message */ 255 * vars: %s - server message */
276static void 256static void nickerr(char *message) {
277nickerr (char *message)
278{
279 char *helpkiller = NULL; 257 char *helpkiller = NULL;
280 /* mutate message for output */ 258 /* mutate message for output */
281 message[2] = '!'; 259 message[2] = '!';
282 /* help information found? remove it. */ 260 /* help information found? remove it. */
283 if ((helpkiller = strstr (message, " Type .h for help"))) 261 if ((helpkiller = strstr(message, " Type .h for help")))
284 helpkiller[0] = '\0'; 262 helpkiller[0] = '\0';
285 /* nickchange not done? eliminate message */ 263 /* nickchange not done? eliminate message */
286 if (loggedin && (helpkiller = strstr (message, " - Nick not changed"))) 264 if (loggedin && (helpkiller = strstr(message, " - Nick not changed")))
287 helpkiller[0] = '\0'; 265 helpkiller[0] = '\0';
288 /* show errormessage */ 266 /* show errormessage */
289 writecf (FS_ERR,&message[2]); 267 writecf(FS_ERR, &message[2]);
290 268
291 /* not logged in? insist on getting a new nick */ 269 /* not logged in? insist on getting a new nick */
292 if (!loggedin) 270 if (!loggedin) {
293 { 271 /* free bogus nick */
294 /* free bogus nick */ 272 own_nick_set(NULL);
295 own_nick_set(NULL);
296 273
297 /* get new nick via vchat-ui.c */ 274 /* get new nick via vchat-ui.c */
298 nickprompt (); 275 nickprompt();
299 276
300 /* form login message and send it to server */ 277 /* form login message and send it to server */
301 snprintf (tmpstr, TMPSTRSIZE, ".l %s %s %d", own_nick_get(), getstroption (CF_FROM), getintoption (CF_CHANNEL)); 278 snprintf(tmpstr, TMPSTRSIZE, ".l %s %s %d", own_nick_get(),
302 vc_sendmessage (tmpstr); 279 getstroption(CF_FROM), getintoption(CF_CHANNEL));
303 } 280 vc_sendmessage(tmpstr);
281 }
304} 282}
305 283
306/* parse and handle a registered nick information 284/* parse and handle a registered nick information
307 * format: 120 %s %s 285 * format: 120 %s %s
308 * vars: %s - this users registered nick 286 * vars: %s - this users registered nick
309 * %s msg - server message */ 287 * %s msg - server message */
310static void 288static void login(char *message) {
311login (char *message) {
312 char *msg = NULL; 289 char *msg = NULL;
313 290
314 /* mutate message for output */ 291 /* mutate message for output */
315 message[2] = '*'; 292 message[2] = '*';
316 /* show message to user */ 293 /* show message to user */
317 writecf (FS_SERV,&message[2]); 294 writecf(FS_SERV, &message[2]);
318 295
319 /* we don't know our nick? */ 296 /* we don't know our nick? */
320 if (!own_nick_get() ) { 297 if (!own_nick_get()) {
321 /* find message after nick */ 298 /* find message after nick */
322 msg = strchr (&message[4], ' '); 299 msg = strchr(&message[4], ' ');
323 if (msg) { 300 if (msg) {
324 /* terminate string before message and copy nick */ 301 /* terminate string before message and copy nick */
325 msg[0] = '\0'; 302 msg[0] = '\0';
326 own_nick_set(&message[4]); 303 own_nick_set(&message[4]);
327 } else { 304 } else {
328 /* no string in servers message (huh?), ask user for nick */ 305 /* no string in servers message (huh?), ask user for nick */
329 nickprompt (); 306 nickprompt();
330 } 307 }
331 } 308 }
332 309
333 /* form login message and send it to server */ 310 /* form login message and send it to server */
334 snprintf (tmpstr, TMPSTRSIZE, ".l %s %s %d", own_nick_get(), getstroption (CF_FROM), getintoption (CF_CHANNEL)); 311 snprintf(tmpstr, TMPSTRSIZE, ".l %s %s %d", own_nick_get(),
335 vc_sendmessage (tmpstr); 312 getstroption(CF_FROM), getintoption(CF_CHANNEL));
313 vc_sendmessage(tmpstr);
336} 314}
337 315
338/* parse and handle anon login request 316/* parse and handle anon login request
339 * format: 121 %s 317 * format: 121 %s
340 * vars: %s - server message */ 318 * vars: %s - server message */
341static void 319static void anonlogin(char *message) {
342anonlogin (char *message)
343{
344 /* mutate message for output */ 320 /* mutate message for output */
345 message[2] = '*'; 321 message[2] = '*';
346 /* show message to user */ 322 /* show message to user */
347 writecf (FS_SERV,&message[2]); 323 writecf(FS_SERV, &message[2]);
348 324
349 /* we don't know our nick? ask for it! */ 325 /* we don't know our nick? ask for it! */
350 if (!own_nick_get()) 326 if (!own_nick_get())
351 nickprompt (); 327 nickprompt();
352 328
353 /* form login message and send it to server */ 329 /* form login message and send it to server */
354 snprintf (tmpstr, TMPSTRSIZE, ".l %s %s %d", own_nick_get(), getstroption (CF_FROM), getintoption (CF_CHANNEL)); 330 snprintf(tmpstr, TMPSTRSIZE, ".l %s %s %d", own_nick_get(),
355 vc_sendmessage (tmpstr); 331 getstroption(CF_FROM), getintoption(CF_CHANNEL));
332 vc_sendmessage(tmpstr);
356} 333}
357 334
358/* parse and handle list of nicks (from '.S') 335/* parse and handle list of nicks (from '.S')
359 * format: 119 %s .. 336 * format: 119 %s ..
360 * vars: %s nick - a users nick */ 337 * vars: %s nick - a users nick */
361static void 338static void receivenicks(char *message) {
362receivenicks (char *message) {
363 char *str1 = NULL, *str2 = NULL; 339 char *str1 = NULL, *str2 = NULL;
364 int chanflag = -1; 340 int chanflag = -1;
365 341
366 /* show message to user */ 342 /* show message to user */
367 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_USONLINE), &message[4]); 343 snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_USONLINE), &message[4]);
368 writechan (tmpstr); 344 writechan(tmpstr);
369 345
370 /* search for channelnumber */ 346 /* search for channelnumber */
371 if( !(str1 = strchr (message, ' ') ) ) return; 347 if (!(str1 = strchr(message, ' ')))
348 return;
372 str1++; 349 str1++;
373 350
374 if (str1[0] == '*') { 351 if (str1[0] == '*') {
375 ul_rebuild_list(); 352 ul_rebuild_list();
376 str1++; 353 str1++;
377 } else { 354 } else {
378 int mychan; 355 int mychan;
379 str2 = str1; 356 str2 = str1;
380 str1 = strchr(str2,' '); 357 str1 = strchr(str2, ' ');
381 str1[0] = '\0'; 358 str1[0] = '\0';
382 mychan = atoi(str2); 359 mychan = atoi(str2);
383 if( mychan != own_channel_get() ) 360 if (mychan != own_channel_get())
384 return; 361 return;
385 362
386 /* Kick all users from the IN_MY_CHANNEL list */ 363 /* Kick all users from the IN_MY_CHANNEL list */
387 own_channel_set( own_channel_get() ); 364 own_channel_set(own_channel_get());
388 chanflag = 1; 365 chanflag = 1;
389 } 366 }
390 str1++; 367 str1++;
391 368
392 /* while user .. */ 369 /* while user .. */
393 while (str1) { 370 while (str1) {
394 /* search next user */ 371 /* search next user */
395 str2 = strchr (str1, ' '); 372 str2 = strchr(str1, ' ');
396 /* there is another user? terminate this one */ 373 /* there is another user? terminate this one */
397 if (str2) { 374 if (str2) {
398 str2[0] = '\0'; 375 str2[0] = '\0';
@@ -412,52 +389,48 @@ receivenicks (char *message) {
412 * format: 211 %s %s 389 * format: 211 %s %s
413 * vars: %s nick - who logged on 390 * vars: %s nick - who logged on
414 * %s msg - servers message */ 391 * %s msg - servers message */
415static void 392static void usersignon(char *message) {
416usersignon (char *message)
417{
418 char *nick = NULL, *msg = NULL; 393 char *nick = NULL, *msg = NULL;
419 /* search start of nickname */ 394 /* search start of nickname */
420 nick = strchr (message, ' '); 395 nick = strchr(message, ' ');
421 nick++; 396 nick++;
422 397
423 /* search start of message, terminate nick */ 398 /* search start of message, terminate nick */
424 msg = strchr (nick, ' '); 399 msg = strchr(nick, ' ');
425 msg[0] = '\0'; 400 msg[0] = '\0';
426 msg++; 401 msg++;
427 402
428 /* add this user via vchat-user.c */ 403 /* add this user via vchat-user.c */
429 ul_add (nick, 0); 404 ul_add(nick, 0);
430 405
431 /* show message to user */ 406 /* show message to user */
432 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_SIGNON), nick, msg); 407 snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_SIGNON), nick, msg);
433 writechan (tmpstr); 408 writechan(tmpstr);
434} 409}
435 410
436/* parse and handle a logoff message 411/* parse and handle a logoff message
437 * format: 221 %s %s 412 * format: 221 %s %s
438 * vars: %s nick - who logged off 413 * vars: %s nick - who logged off
439 * %s msg - servers message */ 414 * %s msg - servers message */
440static void 415static void usersignoff(char *message) {
441usersignoff (char *message)
442{
443 char *nick = NULL, *msg = NULL; 416 char *nick = NULL, *msg = NULL;
444 /* search start of nickname */ 417 /* search start of nickname */
445 nick = strchr (message, ' '); 418 nick = strchr(message, ' ');
446 nick++; 419 nick++;
447 420
448 /* search start of message, terminate nick */ 421 /* search start of message, terminate nick */
449 msg = strchr (nick, ' '); 422 msg = strchr(nick, ' ');
450 if( msg ) { 423 if (msg) {
451 msg[0] = '\0'; 424 msg[0] = '\0';
452 msg++; 425 msg++;
453 } 426 }
454 427
455 /* delete this user via vchat-user.c */ 428 /* delete this user via vchat-user.c */
456 ul_del (nick); 429 ul_del(nick);
457 430
458 /* show message to user */ 431 /* show message to user */
459 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_SIGNOFF), nick, msg); 432 snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_SIGNOFF), nick, msg);
460 writechan (tmpstr); 433 writechan(tmpstr);
461} 434}
462 435
463/* parse and handle a join message 436/* parse and handle a join message
@@ -465,40 +438,38 @@ usersignoff (char *message)
465 * vars: %s nick - who joined 438 * vars: %s nick - who joined
466 * %s msg - servers message 439 * %s msg - servers message
467 * %d chan - channel joined */ 440 * %d chan - channel joined */
468static void 441static void userjoin(char *message) {
469userjoin (char *message)
470{
471 char *nick = NULL, *msg = NULL, *channel = NULL; 442 char *nick = NULL, *msg = NULL, *channel = NULL;
472 int chan = 0; 443 int chan = 0;
473 444
474 /* search start of nickname */ 445 /* search start of nickname */
475 nick = strchr (message, ' '); 446 nick = strchr(message, ' ');
476 nick++; 447 nick++;
477 448
478 /* search start of message, terminate nick */ 449 /* search start of message, terminate nick */
479 msg = strchr (nick, ' '); 450 msg = strchr(nick, ' ');
480 msg[0] = '\0'; 451 msg[0] = '\0';
481 msg++; 452 msg++;
482 453
483 /* search start of channel, terminate message */ 454 /* search start of channel, terminate message */
484 channel = strrchr (msg, ' '); 455 channel = strrchr(msg, ' ');
485 channel[0] = '\0'; 456 channel[0] = '\0';
486 channel++; 457 channel++;
487 458
488 /* convert channel to integer */ 459 /* convert channel to integer */
489 chan = atoi (channel); 460 chan = atoi(channel);
490 461
491 /* is it myself joining */ 462 /* is it myself joining */
492 if( own_nick_check(nick) ) 463 if (own_nick_check(nick))
493 own_channel_set(chan); 464 own_channel_set(chan);
494 465
495 /* notice channel join via vchat-user.c */ 466 /* notice channel join via vchat-user.c */
496 if( own_channel_get() == chan ) 467 if (own_channel_get() == chan)
497 ul_enter_chan(nick); 468 ul_enter_chan(nick);
498 469
499 /* show message to user */ 470 /* show message to user */
500 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_JOIN), nick, msg, chan); 471 snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_JOIN), nick, msg, chan);
501 writechan (tmpstr); 472 writechan(tmpstr);
502} 473}
503 474
504/* parse and handle a leave message 475/* parse and handle a leave message
@@ -506,35 +477,33 @@ userjoin (char *message)
506 * vars: %s nick - who left 477 * vars: %s nick - who left
507 * %s msg - servers message 478 * %s msg - servers message
508 * %d chan - channel joined */ 479 * %d chan - channel joined */
509static void 480static void userleave(char *message) {
510userleave (char *message)
511{
512 char *nick = NULL, *msg = NULL, *channel = NULL; 481 char *nick = NULL, *msg = NULL, *channel = NULL;
513 int chan = 0; 482 int chan = 0;
514 483
515 /* search start of nickname */ 484 /* search start of nickname */
516 nick = strchr (message, ' '); 485 nick = strchr(message, ' ');
517 nick++; 486 nick++;
518 487
519 /* search start of message, terminate nick */ 488 /* search start of message, terminate nick */
520 msg = strchr (nick, ' '); 489 msg = strchr(nick, ' ');
521 msg[0] = '\0'; 490 msg[0] = '\0';
522 msg++; 491 msg++;
523 492
524 /* convert channel to integer */ 493 /* convert channel to integer */
525 channel = strrchr (msg, ' '); 494 channel = strrchr(msg, ' ');
526 channel[0] = '\0'; 495 channel[0] = '\0';
527 channel++; 496 channel++;
528 497
529 /* convert channel to integer */ 498 /* convert channel to integer */
530 chan = atoi (channel); 499 chan = atoi(channel);
531 500
532 /* notice channel leave via vchat-user.c */ 501 /* notice channel leave via vchat-user.c */
533 ul_leave_chan(nick); 502 ul_leave_chan(nick);
534 503
535 /* show message to user */ 504 /* show message to user */
536 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_LEAVE), nick, msg, chan); 505 snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_LEAVE), nick, msg, chan);
537 writechan (tmpstr); 506 writechan(tmpstr);
538} 507}
539 508
540/* parse and handle a nickchange message 509/* parse and handle a nickchange message
@@ -542,151 +511,140 @@ userleave (char *message)
542 * vars: %s oldnick - users old nick 511 * vars: %s oldnick - users old nick
543 * %s newnick - users new nick 512 * %s newnick - users new nick
544 * %s msg - server message */ 513 * %s msg - server message */
545static void 514static void usernickchange(char *message) {
546usernickchange (char *message)
547{
548 char *oldnick = NULL, *newnick = NULL, *msg = NULL; 515 char *oldnick = NULL, *newnick = NULL, *msg = NULL;
549 516
550 /* search start of old nickname */ 517 /* search start of old nickname */
551 oldnick = strchr (message, ' '); 518 oldnick = strchr(message, ' ');
552 oldnick++; 519 oldnick++;
553 520
554 /* search start of new nickname, terminate old nick */ 521 /* search start of new nickname, terminate old nick */
555 newnick = strchr (oldnick, ' '); 522 newnick = strchr(oldnick, ' ');
556 newnick[0] = '\0'; 523 newnick[0] = '\0';
557 newnick++; 524 newnick++;
558 525
559 /* search start of message, terminate new nick */ 526 /* search start of message, terminate new nick */
560 msg = strchr (newnick, ' '); 527 msg = strchr(newnick, ' ');
561 msg[0] = '\0'; 528 msg[0] = '\0';
562 msg++; 529 msg++;
563 530
564 /* notice nickchange via vchat-user.c */ 531 /* notice nickchange via vchat-user.c */
565 ul_rename (oldnick, newnick); 532 ul_rename(oldnick, newnick);
566 533
567 if( own_nick_check(newnick) ) { 534 if (own_nick_check(newnick)) {
568 /* show change in console window */ 535 /* show change in console window */
569 snprintf (consolestr, CONSOLESTRSIZE, getformatstr(FS_CONSOLE), newnick, getstroption (CF_SERVERHOST), getstroption (CF_SERVERPORT)); 536 snprintf(consolestr, CONSOLESTRSIZE, getformatstr(FS_CONSOLE), newnick,
570 consoleline (NULL); 537 getstroption(CF_SERVERHOST), getstroption(CF_SERVERPORT));
538 consoleline(NULL);
571 } 539 }
572 540
573 /* show message to user */ 541 /* show message to user */
574 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_NICKCHANGE), oldnick, newnick, msg); 542 snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_NICKCHANGE), oldnick, newnick,
575 writechan (tmpstr); 543 msg);
544 writechan(tmpstr);
576} 545}
577 546
578/* handle received message from server */ 547/* handle received message from server */
579void 548void protocol_parsemsg(char *message) {
580protocol_parsemsg (char *message)
581{
582 char *str1, *str2; 549 char *str1, *str2;
583 int i; 550 int i;
584 /* message to short or starts with '<'? must be channel */ 551 /* message to short or starts with '<'? must be channel */
585 if (message[0] == '<') 552 if (message[0] == '<') {
586 {
587 str1 = &message[1]; 553 str1 = &message[1];
588 str2 = strchr(str1,'>'); 554 str2 = strchr(str1, '>');
589 str2[0] = '\0'; 555 str2[0] = '\0';
590 str2++; 556 str2++;
591 if (str2[0] == ' ') str2++; 557 if (str2[0] == ' ')
558 str2++;
592 if (own_nick_check(str1)) 559 if (own_nick_check(str1))
593 snprintf(tmpstr,TMPSTRSIZE,getformatstr(FS_MYPUBMSG),str1,str2); 560 snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_MYPUBMSG), str1, str2);
594 else 561 else
595 snprintf(tmpstr,TMPSTRSIZE,getformatstr(FS_RXPUBMSG),str1,str2); 562 snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_RXPUBMSG), str1, str2);
596 writechan (tmpstr); 563 writechan(tmpstr);
597 564
598 ul_public_action(str1); 565 ul_public_action(str1);
599 } 566 } else if (message[0] == '[') {
600 else if (message[0] == '[')
601 {
602 str1 = &message[1]; 567 str1 = &message[1];
603 str2 = strchr(str1,']'); 568 str2 = strchr(str1, ']');
604 str2[0] = '\0'; 569 str2[0] = '\0';
605 str2++; 570 str2++;
606 if (str2[0] == ' ') str2++; 571 if (str2[0] == ' ')
607 if (own_nick_check( str1 )) 572 str2++;
608 snprintf(tmpstr,TMPSTRSIZE,getformatstr(FS_MYPUBURL),str1,str2); 573 if (own_nick_check(str1))
574 snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_MYPUBURL), str1, str2);
609 else 575 else
610 snprintf(tmpstr,TMPSTRSIZE,getformatstr(FS_RXPUBURL),str1,str2); 576 snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_RXPUBURL), str1, str2);
611 ul_public_action(str1); 577 ul_public_action(str1);
612 writechan (tmpstr); 578 writechan(tmpstr);
613 } 579 }
614 /* message starts with '*'? must be private */ 580 /* message starts with '*'? must be private */
615 else if (message[0] == '*') 581 else if (message[0] == '*') {
616 {
617 str1 = &message[1]; 582 str1 = &message[1];
618 str2 = strchr(str1,'*'); 583 str2 = strchr(str1, '*');
619 str2[0] = '\0'; 584 str2[0] = '\0';
620 str2++; 585 str2++;
621 if (str2[0] == ' ') str2++; 586 if (str2[0] == ' ')
622 snprintf(tmpstr,TMPSTRSIZE,getformatstr(FS_RXPRIVMSG),str1,str2); 587 str2++;
623 writepriv (tmpstr, 1); 588 snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_RXPRIVMSG), str1, str2);
589 writepriv(tmpstr, 1);
624 ul_private_action(str1); 590 ul_private_action(str1);
625 } 591 }
626 /* message starts with a number? must be a servermessage */ 592 /* message starts with a number? must be a servermessage */
627 else if ((message[0] >= '0') && (message[0] <= '9')) 593 else if ((message[0] >= '0') && (message[0] <= '9')) {
628 { 594 /* walk server message array */
629 /* walk server message array */ 595 for (i = 0; servermessages[i].id[0]; i++) {
630 for (i = 0; servermessages[i].id[0]; i++) 596 /* is this the message? */
631 { 597 if (!(strncmp(servermessages[i].id, message, 3))) {
632 /* is this the message? */ 598 /* scripting hook available - call it */
633 if (!(strncmp (servermessages[i].id, message, 3))) 599 if (servermessages[i].hook)
634 { 600 servermessages[i].hook(message);
635 /* scripting hook available - call it */ 601 /* function available - call it */
636 if (servermessages[i].hook) 602 else if (servermessages[i].funct)
637 servermessages[i].hook (message); 603 servermessages[i].funct(message);
638 /* function available - call it */ 604 /* no function available, but known - give output */
639 else if (servermessages[i].funct) 605 else {
640 servermessages[i].funct (message); 606 /* remove continutation mark */
641 /* no function available, but known - give output */ 607 if (message[3] == '-')
642 else 608 message[3] = ' ';
643 { 609
644 /* remove continutation mark */ 610 /* mutate message for display */
645 if (message[3] == '-') 611 message[2] = '*';
646 message[3] = ' '; 612 /* giveout message by type */
647 613 switch (servermessages[i].type) {
648 /* mutate message for display */ 614 case SM_IGNORE:
649 message[2] = '*'; 615 break;
650 /* giveout message by type */ 616 case SM_INFO:
651 switch (servermessages[i].type) 617 /* change marker and send as servermessage */
652 { 618 message[2] = '#';
653 case SM_IGNORE: 619 writecf(FS_SERV, &message[2]);
654 break; 620 break;
655 case SM_INFO: 621 case SM_USERINFO:
656 /* change marker and send as servermessage */ 622 /* keep marker and send as servermessage */
657 message[2] = '#'; 623 writecf(FS_SERV, &message[2]);
658 writecf (FS_SERV,&message[2]); 624 break;
659 break; 625 case SM_CHANNEL:
660 case SM_USERINFO: 626 /* keep marker and send as channelmessage */
661 /* keep marker and send as servermessage */ 627 writechan(&message[2]);
662 writecf (FS_SERV,&message[2]); 628 break;
663 break; 629 case SM_ERROR:
664 case SM_CHANNEL: 630 /* change marker and send as errormessage */
665 /* keep marker and send as channelmessage */ 631 message[2] = '!';
666 writechan (&message[2]); 632 writecf(FS_ERR, &message[2]);
667 break; 633 break;
668 case SM_ERROR: 634 default:
669 /* change marker and send as errormessage */ 635 /* fallback: keep marker and send as servermessage */
670 message[2] = '!'; 636 writecf(FS_SERV, &message[2]);
671 writecf (FS_ERR,&message[2]); 637 }
672 break; 638 }
673 default: 639 return;
674 /* fallback: keep marker and send as servermessage */ 640 }
675 writecf (FS_SERV,&message[2]);
676 }
677 }
678 return;
679 }
680 }
681 /* message not in list, raise errormessage */
682 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_UNKNOWNMSG), message);
683 writecf (FS_ERR,tmpstr);
684 }
685 else
686 {
687 /* message neither public, private or server, raise errormessage */
688 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_BOGUSMSG), message);
689 writecf (FS_ERR,tmpstr);
690 } 641 }
642 /* message not in list, raise errormessage */
643 snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_UNKNOWNMSG), message);
644 writecf(FS_ERR, tmpstr);
645 } else {
646 /* message neither public, private or server, raise errormessage */
647 snprintf(tmpstr, TMPSTRSIZE, getformatstr(FS_BOGUSMSG), message);
648 writecf(FS_ERR, tmpstr);
649 }
691} 650}
692