Rev 3981 | Rev 4477 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3545 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;; |
||
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;; ;; |
||
4143 | hidnplayr | 6 | ;; Written by hidnplayr@kolibrios.org ;; |
3545 | hidnplayr | 7 | ;; ;; |
8 | ;; GNU GENERAL PUBLIC LICENSE ;; |
||
9 | ;; Version 2, June 1991 ;; |
||
10 | ;; ;; |
||
11 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
12 | |||
13 | |||
14 | user_parser: |
||
15 | |||
4143 | hidnplayr | 16 | push [window_active] ; print to the current window |
17 | pop [window_print] |
||
18 | |||
3545 | hidnplayr | 19 | mov eax, [edit1.size] |
3563 | hidnplayr | 20 | test eax, eax |
21 | jz sdts_ret ; ignore empty commands |
||
3545 | hidnplayr | 22 | mov word [usercommand + eax], 0x0a0d ; terminate the line |
23 | |||
24 | cmp byte[usercommand], '/' ; is it a server command ? |
||
25 | je server_command |
||
26 | |||
27 | ; Ignore data commands when not connected. |
||
28 | cmp [status], STATUS_CONNECTED |
||
29 | jne sdts_ret |
||
30 | |||
31 | ; Ok, we said something, print it to our textbox |
||
32 | ; TODO: dont send if it's a server window? |
||
33 | |||
4143 | hidnplayr | 34 | if TIMESTAMP |
3545 | hidnplayr | 35 | call print_timestamp |
4143 | hidnplayr | 36 | end if |
3545 | hidnplayr | 37 | |
38 | mov bl, '<' |
||
39 | call print_character |
||
40 | |||
41 | mov esi, user_nick |
||
42 | call print_text2 |
||
43 | |||
3981 | hidnplayr | 44 | mov bl, '>' |
3545 | hidnplayr | 45 | call print_character |
3981 | hidnplayr | 46 | mov bl, ' ' |
3545 | hidnplayr | 47 | call print_character |
48 | |||
49 | mov eax, [edit1.size] |
||
50 | mov byte[usercommand + eax],0 |
||
51 | |||
52 | mov esi, usercommand |
||
53 | call print_text2 |
||
54 | |||
55 | mov bl, 10 |
||
56 | call print_character |
||
57 | |||
58 | ; and now send it to the server |
||
4143 | hidnplayr | 59 | mov dword[packetbuf], 'PRIV' |
60 | mov dword[packetbuf+4], 'MSG ' |
||
3545 | hidnplayr | 61 | |
3981 | hidnplayr | 62 | mov esi, [window_active] |
3545 | hidnplayr | 63 | add esi, window.name |
64 | mov edi, packetbuf+8 |
||
65 | mov ecx, MAX_WINDOWNAME_LEN |
||
66 | .loop: |
||
67 | lodsb |
||
68 | test al, al |
||
69 | jz .done |
||
70 | stosb |
||
71 | dec ecx |
||
72 | jnz .loop |
||
73 | .done: |
||
74 | |||
75 | mov ax, ' :' |
||
76 | stosw |
||
77 | |||
78 | mov esi, usercommand |
||
79 | mov ecx, [edit1.size] |
||
80 | inc ecx |
||
81 | call recode |
||
82 | |||
4143 | hidnplayr | 83 | ; end the command with a CRLF |
84 | mov ax, 0x0a0d |
||
85 | stosw |
||
3545 | hidnplayr | 86 | |
87 | lea esi, [edi - packetbuf] |
||
88 | mcall send, [socketnum], packetbuf, , 0 |
||
89 | |||
90 | sdts_ret: |
||
91 | |||
92 | ret |
||
93 | |||
94 | |||
95 | |||
96 | user_commands: |
||
97 | dd 'nick', cmd_usr_nick |
||
98 | dd 'real', cmd_usr_real |
||
99 | dd 'serv', cmd_usr_server |
||
100 | dd 'help', cmd_usr_help |
||
101 | dd 'code', cmd_usr_code |
||
4143 | hidnplayr | 102 | |
103 | ; All following commands require a connection to the server. TODO: verify connection |
||
3545 | hidnplayr | 104 | dd 'quer', cmd_usr_quer |
105 | dd 'quit', cmd_usr_quit |
||
3981 | hidnplayr | 106 | dd 'part', cmd_usr_part |
4143 | hidnplayr | 107 | dd 'ctcp', cmd_usr_ctcp |
108 | dd 'msg ', cmd_usr_msg |
||
3545 | hidnplayr | 109 | |
110 | .number = ($ - user_commands) / 8 |
||
111 | |||
112 | |||
113 | |||
114 | server_command: |
||
115 | |||
116 | mov eax, dword[usercommand+1] |
||
117 | or eax, 0x20202020 |
||
118 | |||
119 | mov edi, user_commands |
||
120 | mov ecx, user_commands.number |
||
121 | .loop: |
||
122 | scasd |
||
123 | je .got_cmd |
||
124 | add edi, 4 |
||
125 | dec ecx |
||
126 | jnz .loop |
||
127 | jmp cmd_usr_send ; If none of the previous commands, just send to server |
||
128 | |||
129 | .got_cmd: |
||
130 | jmp dword[edi] |
||
131 | |||
132 | |||
133 | |||
134 | |||
135 | |||
4143 | hidnplayr | 136 | cmd_usr_msg: |
137 | |||
138 | lea esi, [usercommand+5] |
||
139 | |||
140 | mov dword[packetbuf], 'PRIV' |
||
141 | mov dword[packetbuf+4], 'MSG ' |
||
142 | lea edi, [packetbuf+8] |
||
143 | |||
144 | @@: |
||
145 | lodsb |
||
146 | test al, al |
||
147 | jz .fail |
||
148 | cmp al, 10 |
||
149 | je .fail |
||
150 | cmp al, 13 |
||
151 | je .fail |
||
152 | stosb |
||
153 | cmp al, ' ' |
||
154 | jne @r |
||
155 | |||
156 | mov al, ':' |
||
157 | stosb |
||
158 | |||
159 | push edi |
||
160 | @@: |
||
161 | lodsb |
||
162 | test al, al |
||
163 | jz @f |
||
164 | cmp al, 10 |
||
165 | je @f |
||
166 | cmp al, 13 |
||
167 | je @f |
||
168 | stosb |
||
169 | jmp @r |
||
170 | @@: |
||
171 | ; end the command with a CRLF |
||
172 | mov ax, 0x0a0d |
||
173 | stosw |
||
174 | mov byte[edi], 0 |
||
175 | |||
176 | lea esi, [edi - packetbuf] |
||
177 | mcall send, [socketnum], packetbuf, , 0 |
||
178 | |||
179 | ; now print to the window |
||
180 | if TIMESTAMP |
||
181 | call print_timestamp |
||
182 | end if |
||
183 | |||
184 | mov esi, msg_header |
||
185 | call print_text2 |
||
186 | |||
187 | mov eax, packetbuf+8 |
||
188 | mov dl, ' ' |
||
189 | call print_text |
||
190 | |||
191 | mov bl, '*' |
||
192 | call print_character |
||
193 | |||
194 | mov bl, ' ' |
||
195 | call print_character |
||
196 | |||
197 | pop esi |
||
198 | call print_text2 |
||
199 | |||
200 | .fail: |
||
201 | ret |
||
202 | |||
203 | |||
204 | |||
3545 | hidnplayr | 205 | cmd_usr_quit: |
3981 | hidnplayr | 206 | mov esi, quit_msg |
207 | |||
3545 | hidnplayr | 208 | cmp byte[usercommand+5], ' ' |
4143 | hidnplayr | 209 | jne .with_message |
210 | lea esi, [usercommand+6] |
||
211 | .with_message: |
||
3981 | hidnplayr | 212 | call cmd_usr_quit_server |
3545 | hidnplayr | 213 | |
214 | mcall close, [socketnum] |
||
4143 | hidnplayr | 215 | mov [status], STATUS_DISCONNECTED |
3545 | hidnplayr | 216 | |
217 | mov ecx, MAX_WINDOWS |
||
218 | mov edi, windows |
||
219 | .loop: |
||
4143 | hidnplayr | 220 | mov [window_print], edi |
221 | push edi ecx |
||
222 | call window_close |
||
223 | pop ecx edi |
||
3545 | hidnplayr | 224 | add edi, sizeof.window |
225 | dec ecx |
||
226 | jnz .loop |
||
227 | |||
228 | ret |
||
229 | |||
230 | |||
231 | |||
3981 | hidnplayr | 232 | ; esi = quit message |
233 | cmd_usr_quit_server: |
||
3545 | hidnplayr | 234 | |
3981 | hidnplayr | 235 | ; User wants to close a channel, send PART command to server |
236 | mov dword[packetbuf], 'QUIT' |
||
237 | mov word[packetbuf+4], ' :' |
||
238 | lea edi, [packetbuf+6] |
||
239 | ; Append our quit msg |
||
240 | @@: |
||
241 | lodsb |
||
4143 | hidnplayr | 242 | cmp al, 13 |
243 | je @f |
||
244 | test al, al |
||
245 | jz @f |
||
3981 | hidnplayr | 246 | stosb |
4143 | hidnplayr | 247 | jmp @r |
248 | @@: |
||
3981 | hidnplayr | 249 | ; end the command with a CRLF |
250 | mov ax, 0x0a0d |
||
251 | stosw |
||
252 | |||
253 | lea esi, [edi - packetbuf] ; calculate length |
||
254 | mcall send, [socketnum], packetbuf, , 0 ; and finally send to server |
||
255 | |||
256 | ret |
||
257 | |||
258 | |||
259 | |||
260 | |||
3545 | hidnplayr | 261 | cmd_usr_nick: |
262 | |||
263 | cmp [edit1.size], 5 |
||
4143 | hidnplayr | 264 | je .dontsend |
3545 | hidnplayr | 265 | cmp byte[usercommand+5], ' ' |
4143 | hidnplayr | 266 | jne .fail |
267 | cmp [socketnum], 0 |
||
268 | je .dontsend |
||
3545 | hidnplayr | 269 | |
4143 | hidnplayr | 270 | mov dword[usercommand+1], 'NICK' |
271 | mov esi, [edit1.size] |
||
272 | mov word[usercommand + esi], 0x0a0d |
||
273 | inc esi |
||
274 | mcall send, [socketnum], usercommand+1, , 0 |
||
275 | |||
276 | .fail: |
||
277 | |||
278 | ret |
||
279 | |||
280 | .dontsend: |
||
3545 | hidnplayr | 281 | mov ecx, MAX_NICK_LEN |
282 | mov esi, usercommand+6 |
||
283 | mov edi, user_nick |
||
4143 | hidnplayr | 284 | @@: |
3545 | hidnplayr | 285 | lodsb |
286 | cmp al, 13 |
||
4143 | hidnplayr | 287 | je @f |
3545 | hidnplayr | 288 | stosb |
289 | dec ecx |
||
4143 | hidnplayr | 290 | jnz @r |
291 | @@: |
||
3545 | hidnplayr | 292 | xor al, al |
293 | stosb |
||
294 | |||
295 | mov esi, str_nickchange |
||
296 | call print_text2 |
||
297 | mov esi, user_nick |
||
298 | call print_text2 |
||
299 | mov esi, str_dotnewline |
||
300 | call print_text2 |
||
301 | |||
302 | ret |
||
303 | |||
304 | |||
305 | |||
306 | cmd_usr_real: |
||
307 | |||
308 | cmp byte[usercommand+5], ' ' |
||
309 | jne cmd_usr_send |
||
310 | |||
311 | mov ecx, MAX_REAL_LEN |
||
312 | mov esi, usercommand+6 |
||
313 | mov edi, user_real_name |
||
314 | .loop: |
||
315 | lodsb |
||
316 | cmp al, 13 |
||
317 | je .done |
||
318 | stosb |
||
319 | dec ecx |
||
320 | jnz .loop |
||
321 | .done: |
||
322 | xor al, al |
||
323 | stosb |
||
324 | |||
325 | mov esi, str_realchange |
||
326 | call print_text2 |
||
327 | mov esi, user_real_name |
||
328 | call print_text2 |
||
329 | mov esi, str_dotnewline |
||
330 | call print_text2 |
||
331 | |||
332 | ret |
||
333 | |||
334 | |||
335 | |||
336 | cmd_usr_server: |
||
337 | |||
338 | mov eax, dword[usercommand+5] ; check for 'er ', we only checked 'serv' |
||
339 | or eax, 0x00002020 |
||
340 | and eax, 0x00ffffff |
||
341 | cmp eax, 'er ' |
||
342 | jne cmd_usr_send |
||
343 | |||
344 | mov ecx, [edit1.size] ; ok now set the address |
||
345 | sub ecx, 8 |
||
346 | |||
347 | mov esi, usercommand+8 |
||
348 | push esi |
||
349 | mov edi, irc_server_name |
||
350 | rep movsb |
||
351 | xor al, al |
||
352 | stosb |
||
353 | pop esi |
||
354 | |||
355 | ; set it also in window name |
||
356 | mov ebx, [window_print] |
||
357 | call window_set_name |
||
358 | |||
359 | ; now connect |
||
360 | call socket_connect |
||
361 | |||
362 | ret |
||
363 | |||
364 | |||
365 | cmd_usr_quer: |
||
366 | |||
367 | mov ecx, MAX_WINDOWS |
||
368 | mov ebx, windows |
||
369 | .loop: |
||
370 | cmp [ebx + window.data_ptr], 0 |
||
371 | je .found |
||
372 | add ebx, sizeof.window |
||
373 | dec ecx |
||
374 | jnz .loop |
||
375 | |||
376 | ; error: no available channels ! FIXME |
||
377 | |||
378 | ret |
||
379 | |||
380 | |||
381 | .found: |
||
382 | call window_create |
||
383 | test eax, eax |
||
384 | jz .error |
||
4143 | hidnplayr | 385 | mov [ebx + window.type], WINDOWTYPE_CHAT |
3545 | hidnplayr | 386 | |
387 | mov esi, usercommand+7 |
||
388 | call window_set_name |
||
389 | |||
390 | |||
391 | .error: |
||
392 | |||
393 | ret |
||
394 | |||
395 | |||
396 | |||
397 | cmd_usr_help: |
||
398 | |||
399 | mov esi, str_help |
||
400 | call print_text2 |
||
401 | |||
402 | ret |
||
403 | |||
404 | |||
405 | |||
406 | cmd_usr_code: |
||
407 | |||
408 | ; TODO |
||
409 | |||
410 | ret |
||
411 | |||
412 | |||
413 | |||
3981 | hidnplayr | 414 | ; User typed a part command |
415 | cmd_usr_part: |
||
416 | |||
4143 | hidnplayr | 417 | cmp byte[usercommand+5], 13 ; parameters given? |
418 | jne cmd_usr_send ; yes, send command straight to server |
||
3981 | hidnplayr | 419 | |
4143 | hidnplayr | 420 | ; close active window |
421 | cmd_usr_close_window: |
||
422 | |||
423 | mov esi, [window_active] |
||
424 | mov [window_print], esi |
||
3981 | hidnplayr | 425 | cmp [esi + window.type], WINDOWTYPE_SERVER |
4143 | hidnplayr | 426 | je .not_channel |
3981 | hidnplayr | 427 | |
4143 | hidnplayr | 428 | lea esi, [esi + window.name] |
429 | call cmd_usr_part_channel |
||
430 | call window_close |
||
431 | ret |
||
3981 | hidnplayr | 432 | |
4143 | hidnplayr | 433 | .not_channel: |
434 | cmp [esi + window.type], WINDOWTYPE_CHAT |
||
435 | jne .not_chat |
||
436 | |||
437 | call window_close |
||
438 | .not_chat: |
||
439 | |||
3981 | hidnplayr | 440 | ret |
441 | |||
4143 | hidnplayr | 442 | |
443 | |||
3981 | hidnplayr | 444 | ; Send part command to server |
445 | ; esi must point to channel name (ASCIIZ) |
||
446 | cmd_usr_part_channel: |
||
447 | |||
448 | ; User wants to close a channel, send PART command to server |
||
449 | mov dword[packetbuf], 'PART' |
||
450 | mov byte[packetbuf+4], ' ' |
||
451 | lea edi, [packetbuf+5] |
||
452 | @@: |
||
453 | lodsb |
||
4143 | hidnplayr | 454 | test al, al |
455 | jz @f |
||
456 | cmp al, 13 |
||
457 | je @f |
||
458 | cmp al, 10 |
||
459 | je @f |
||
3981 | hidnplayr | 460 | stosb |
4143 | hidnplayr | 461 | jmp @r |
462 | @@: |
||
3981 | hidnplayr | 463 | ; end the command with a CRLF |
464 | mov ax, 0x0a0d |
||
465 | stosw |
||
466 | |||
467 | lea esi, [edi - packetbuf] ; calculate length |
||
468 | mcall send, [socketnum], packetbuf, , 0 ; and finally send to server |
||
469 | |||
470 | ret |
||
471 | |||
472 | |||
4143 | hidnplayr | 473 | cmd_usr_ctcp: |
474 | |||
475 | cmp byte[usercommand+5], ' ' |
||
476 | jne cmd_usr_send |
||
477 | |||
478 | mov esi, usercommand+6 |
||
479 | ; prepare a 'PRIVMSG ' |
||
480 | mov dword[packetbuf], 'PRIV' |
||
481 | mov dword[packetbuf+4], 'MSG ' |
||
482 | lea edi, [packetbuf+8] |
||
483 | |||
484 | ; append the destination (nickname/channel) |
||
485 | @@: |
||
486 | lodsb |
||
487 | test al, al |
||
488 | jz .fail |
||
489 | cmp al, ' ' |
||
490 | je @f |
||
491 | stosb |
||
492 | jmp @r |
||
493 | @@: |
||
494 | |||
495 | mov ax, ' :' |
||
496 | stosw |
||
497 | mov al, 0x01 |
||
498 | stosb |
||
499 | |||
500 | ; copy the message itself |
||
501 | @@: |
||
502 | lodsb |
||
503 | test al, al |
||
504 | jz @f |
||
505 | cmp al, 13 |
||
506 | je @f |
||
507 | cmp al, 10 |
||
508 | je @f |
||
509 | stosb |
||
510 | jmp @r |
||
511 | @@: |
||
512 | |||
513 | ; end of message |
||
514 | mov al, 0x01 |
||
515 | stosb |
||
516 | mov ax, 0x0a0d |
||
517 | stosw |
||
518 | |||
519 | ; now send it away |
||
520 | lea esi, [edi - packetbuf] ; calculate length |
||
521 | mcall send, [socketnum], packetbuf, , 0 ; and finally send to server |
||
522 | |||
523 | ;; TODO: print to window |
||
524 | |||
525 | .fail: |
||
526 | |||
527 | ret |
||
528 | |||
529 | |||
3981 | hidnplayr | 530 | ; The user typed some undefined command, just recode it and send to the server |
3545 | hidnplayr | 531 | cmd_usr_send: |
532 | |||
533 | mov esi, usercommand+1 |
||
534 | mov ecx, [edit1.size] |
||
535 | inc ecx |
||
536 | mov edi, packetbuf |
||
537 | call recode |
||
538 | |||
539 | lea esi, [edi - packetbuf] |
||
540 | mcall send, [socketnum], packetbuf, , 0 |
||
541 | |||
542 | ret' |
||
543 | |||
4143 | hidnplayr | 544 |