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