Subversion Repositories Kolibri OS

Rev

Rev 6026 | Rev 7300 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3545 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
6023 hidnplayr 3
;; Copyright (C) KolibriOS team 2004-2016. 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
 
6027 hidnplayr 16
        mov     ebp, [window_active]                    ; print to the current window
4710 hidnplayr 17
        mov     [window_print], ebp
4143 hidnplayr 18
 
6027 hidnplayr 19
        mov     ecx, [edit1.size]
20
        test    ecx, ecx
4477 hidnplayr 21
        jz      .ret                                    ; ignore empty commands
3545 hidnplayr 22
 
6027 hidnplayr 23
        mov     esi, input_text
24
        mov     edi, user_command
25
        call    recode                                  ; Convert to UTF-8
26
        mov     word[edi], 0x0a0d                       ; terminate the line
27
        sub     edi, user_command
28
        mov     [user_command.size], edi
29
 
30
        cmp     byte[user_command], '/'                 ; is it a server command ?
4710 hidnplayr 31
        je      .command
3545 hidnplayr 32
 
6027 hidnplayr 33
        cmp     [status], STATUS_LOGGED_IN
34
        jne     .not_loggedin
3545 hidnplayr 35
 
4710 hidnplayr 36
        cmp     [ebp + window.type], WINDOWTYPE_CHANNEL
37
        je      .send_privmsg
38
        cmp     [ebp + window.type], WINDOWTYPE_CHAT
39
        jne     .not_channel
3545 hidnplayr 40
 
4710 hidnplayr 41
  .send_privmsg:
4143 hidnplayr 42
        if TIMESTAMP
3545 hidnplayr 43
        call    print_timestamp
4143 hidnplayr 44
        end if
3545 hidnplayr 45
 
4623 hidnplayr 46
        mov     al, '<'
47
        call    print_char
3545 hidnplayr 48
 
49
        mov     esi, user_nick
4623 hidnplayr 50
        call    print_asciiz
3545 hidnplayr 51
 
4623 hidnplayr 52
        mov     al, '>'
53
        call    print_char
54
        mov     al, ' '
55
        call    print_char
3545 hidnplayr 56
 
6027 hidnplayr 57
        mov     eax, [user_command.size]
58
        mov     byte[user_command + eax],0
59
        mov     esi, user_command
4623 hidnplayr 60
        call    print_asciiz
3545 hidnplayr 61
 
4623 hidnplayr 62
        mov     al, 10
63
        call    print_char
3545 hidnplayr 64
 
65
; and now send it to the server
4143 hidnplayr 66
        mov     dword[packetbuf], 'PRIV'
67
        mov     dword[packetbuf+4], 'MSG '
3545 hidnplayr 68
 
4710 hidnplayr 69
        lea     esi, [ebp + window.name]
3545 hidnplayr 70
        mov     edi, packetbuf+8
71
        mov     ecx, MAX_WINDOWNAME_LEN
72
  .loop:
73
        lodsb
74
        test    al, al
75
        jz      .done
76
        stosb
77
        dec     ecx
78
        jnz     .loop
79
  .done:
80
 
81
        mov     ax, ' :'
82
        stosw
83
 
6027 hidnplayr 84
        mov     esi, user_command
85
        mov     ecx, [user_command.size]
86
;        inc     ecx
87
        rep     movsb
3545 hidnplayr 88
 
4143 hidnplayr 89
; end the command with a CRLF
90
        mov     ax, 0x0a0d
91
        stosw
3545 hidnplayr 92
 
93
        lea     esi, [edi - packetbuf]
94
        mcall   send, [socketnum], packetbuf, , 0
4710 hidnplayr 95
 
4477 hidnplayr 96
  .ret:
97
        ret
3545 hidnplayr 98
 
4710 hidnplayr 99
; Text begins with a '/' lets try to find the command in the lookup table.
100
  .command:
6027 hidnplayr 101
        mov     eax, dword[user_command+1]      ; skip '/'
4477 hidnplayr 102
        or      eax, 0x20202020                 ; convert to lowercase
3545 hidnplayr 103
 
104
        mov     edi, user_commands
105
        mov     ecx, user_commands.number
4477 hidnplayr 106
        cmp     [status], STATUS_CONNECTED
6027 hidnplayr 107
        jae     .cmd_loop
4477 hidnplayr 108
        mov     ecx, user_commands.number2
4710 hidnplayr 109
  .cmd_loop:
3545 hidnplayr 110
        scasd
111
        je      .got_cmd
112
        add     edi, 4
113
        dec     ecx
4710 hidnplayr 114
        jnz     .cmd_loop
3545 hidnplayr 115
 
4477 hidnplayr 116
        cmp     [status], STATUS_CONNECTED
6027 hidnplayr 117
        jb      .not_connected
4710 hidnplayr 118
 
4659 hidnplayr 119
; Commands shorter then 3 chars are placed here
120
        and     eax, 0x00ffffff
121
        cmp     eax, 'me '
122
        je      cmd_usr_me
4477 hidnplayr 123
 
4710 hidnplayr 124
; If none of the listed commands, send text straight to server
125
        jmp     cmd_usr_send
4477 hidnplayr 126
 
3545 hidnplayr 127
  .got_cmd:
128
        jmp     dword[edi]
129
 
6027 hidnplayr 130
  .not_loggedin:
131
        mov     esi, str_notloggedin
132
        call    print_asciiz
133
        ret
134
 
4710 hidnplayr 135
  .not_connected:
4477 hidnplayr 136
        mov     esi, str_notconnected
4623 hidnplayr 137
        call    print_asciiz
4710 hidnplayr 138
        ret
3545 hidnplayr 139
 
4710 hidnplayr 140
  .not_channel:
141
        mov     esi, str_notchannel
142
        call    print_asciiz
4477 hidnplayr 143
        ret
3545 hidnplayr 144
 
145
 
4710 hidnplayr 146
; user commands lookup table
147
user_commands:
148
        dd      'nick', cmd_usr_nick
149
        dd      'real', cmd_usr_real
150
        dd      'serv', cmd_usr_server
151
        dd      'help', cmd_usr_help
152
        dd      'code', cmd_usr_code
3545 hidnplayr 153
 
4710 hidnplayr 154
        .number2 = ($ - user_commands) / 8
155
 
156
; All following commands require a connection to the server.
157
        dd      'quer', cmd_usr_quer
158
        dd      'quit', cmd_usr_quit
159
        dd      'part', cmd_usr_part
160
        dd      'ctcp', cmd_usr_ctcp
161
        dd      'msg ', cmd_usr_msg
162
 
163
        .number = ($ - user_commands) / 8
164
 
165
 
166
 
4143 hidnplayr 167
cmd_usr_msg:
168
 
6027 hidnplayr 169
        lea     esi, [user_command+5]
4143 hidnplayr 170
 
171
        mov     dword[packetbuf], 'PRIV'
172
        mov     dword[packetbuf+4], 'MSG '
173
        lea     edi, [packetbuf+8]
174
 
175
  @@:
176
        lodsb
177
        test    al, al
178
        jz      .fail
179
        cmp     al, 10
180
        je      .fail
181
        cmp     al, 13
182
        je      .fail
183
        stosb
184
        cmp     al, ' '
185
        jne     @r
186
 
187
        mov     al, ':'
188
        stosb
189
 
190
        push    edi
191
  @@:
192
        lodsb
193
        test    al, al
194
        jz      @f
195
        cmp     al, 10
196
        je      @f
197
        cmp     al, 13
198
        je      @f
199
        stosb
200
        jmp     @r
201
  @@:
202
; end the command with a CRLF
203
        mov     ax, 0x0a0d
204
        stosw
205
        mov     byte[edi], 0
206
 
207
        lea     esi, [edi - packetbuf]
208
        mcall   send, [socketnum], packetbuf, , 0
209
 
210
; now print to the window
211
        if TIMESTAMP
212
        call    print_timestamp
213
        end if
214
 
215
        mov     esi, msg_header
4623 hidnplayr 216
        call    print_asciiz
4143 hidnplayr 217
 
4623 hidnplayr 218
        mov     esi, packetbuf+8
219
        mov     bl, ' '
220
        call    print_string
4143 hidnplayr 221
 
4623 hidnplayr 222
        mov     al, '*'
223
        call    print_char
4143 hidnplayr 224
 
4623 hidnplayr 225
        mov     al, ' '
226
        call    print_char
4143 hidnplayr 227
 
228
        pop     esi
4623 hidnplayr 229
        call    print_asciiz
4143 hidnplayr 230
 
231
  .fail:
232
        ret
233
 
234
 
235
 
3545 hidnplayr 236
cmd_usr_quit:
4710 hidnplayr 237
 
3981 hidnplayr 238
        mov     esi, quit_msg
6027 hidnplayr 239
        cmp     byte[user_command+5], ' '
4710 hidnplayr 240
        jne     quit_server
6027 hidnplayr 241
        lea     esi, [user_command+6]
3545 hidnplayr 242
 
3981 hidnplayr 243
; esi = quit message
4710 hidnplayr 244
quit_server:
3545 hidnplayr 245
 
3981 hidnplayr 246
; User wants to close a channel, send PART command to server
247
        mov     dword[packetbuf], 'QUIT'
248
        mov     word[packetbuf+4], ' :'
249
        lea     edi, [packetbuf+6]
250
; Append our quit msg
251
  @@:
252
        lodsb
4143 hidnplayr 253
        cmp     al, 13
254
        je      @f
255
        test    al, al
256
        jz      @f
3981 hidnplayr 257
        stosb
4143 hidnplayr 258
        jmp     @r
259
  @@:
3981 hidnplayr 260
; end the command with a CRLF
261
        mov     ax, 0x0a0d
262
        stosw
263
 
264
        lea     esi, [edi - packetbuf]                  ; calculate length
265
        mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
266
 
4710 hidnplayr 267
        mov     ebp, windows
268
  .window_loop:
269
        cmp     [ebp + window.type], WINDOWTYPE_NONE
270
        je      .next_window
271
        mov     [window_print], ebp
272
        if TIMESTAMP
273
        call    print_timestamp
274
        end if
275
        mov     esi, str_disconnected
276
        call    print_asciiz
277
        cmp     [ebp + window.type], WINDOWTYPE_CHANNEL
278
        jne     .next_window
279
        call    user_remove_all
280
  .next_window:
281
        add     ebp, sizeof.window
282
        cmp     ebp, windows + (MAX_WINDOWS * sizeof.window)
283
        jb      .window_loop
284
 
285
        mov     [status], STATUS_DISCONNECTED
286
        mcall   close, [socketnum]
287
 
3981 hidnplayr 288
        ret
289
 
290
 
291
 
292
 
3545 hidnplayr 293
cmd_usr_nick:
294
 
6027 hidnplayr 295
        cmp     [user_command.size], 5
4981 hidnplayr 296
        je      .justprint
6027 hidnplayr 297
        cmp     byte[user_command+5], ' '
4143 hidnplayr 298
        jne     .fail
299
        cmp     [socketnum], 0
300
        je      .dontsend
3545 hidnplayr 301
 
4617 hidnplayr 302
; Request nickname change to server
6027 hidnplayr 303
        mov     dword[user_command+1], 'NICK'
304
        mov     esi, [user_command.size]
305
        mov     word[user_command + esi], 0x0a0d
4143 hidnplayr 306
        inc     esi
6027 hidnplayr 307
        mcall   send, [socketnum], user_command+1, , 0
4143 hidnplayr 308
 
309
  .fail:
310
        ret
311
 
4617 hidnplayr 312
; We arent logged in yet, directly change user_nick field and print notification to user.
4143 hidnplayr 313
  .dontsend:
3545 hidnplayr 314
        mov     ecx, MAX_NICK_LEN
6027 hidnplayr 315
        mov     esi, user_command+6
3545 hidnplayr 316
        mov     edi, user_nick
4143 hidnplayr 317
  @@:
3545 hidnplayr 318
        lodsb
319
        cmp     al, 13
4143 hidnplayr 320
        je      @f
3545 hidnplayr 321
        stosb
322
        dec     ecx
4143 hidnplayr 323
        jnz     @r
324
  @@:
3545 hidnplayr 325
        xor     al, al
326
        stosb
327
 
4981 hidnplayr 328
  .justprint:
3545 hidnplayr 329
        mov     esi, str_nickchange
4623 hidnplayr 330
        call    print_asciiz
331
 
3545 hidnplayr 332
        mov     esi, user_nick
4623 hidnplayr 333
        call    print_asciiz
3545 hidnplayr 334
 
4623 hidnplayr 335
        mov     al, 10
336
        call    print_char
337
 
3545 hidnplayr 338
        ret
339
 
340
 
341
 
342
cmd_usr_real:
343
 
6027 hidnplayr 344
        cmp     byte[user_command+5], ' '
3545 hidnplayr 345
        jne     cmd_usr_send
346
 
347
        mov     ecx, MAX_REAL_LEN
6027 hidnplayr 348
        mov     esi, user_command+6
3545 hidnplayr 349
        mov     edi, user_real_name
350
  .loop:
351
        lodsb
352
        cmp     al, 13
353
        je      .done
354
        stosb
355
        dec     ecx
356
        jnz     .loop
357
  .done:
358
        xor     al, al
359
        stosb
360
 
361
        mov     esi, str_realchange
4623 hidnplayr 362
        call    print_asciiz
363
 
3545 hidnplayr 364
        mov     esi, user_real_name
4623 hidnplayr 365
        call    print_asciiz
3545 hidnplayr 366
 
4623 hidnplayr 367
        mov     al, 10
368
        call    print_char
369
 
3545 hidnplayr 370
        ret
371
 
372
 
373
 
374
cmd_usr_server:
375
 
6027 hidnplayr 376
        mov     eax, dword[user_command+5]      ; check for 'er ', we only checked 'serv'
3545 hidnplayr 377
        or      eax, 0x00002020
378
        and     eax, 0x00ffffff
379
        cmp     eax, 'er '
380
        jne     cmd_usr_send
381
 
4710 hidnplayr 382
; Server window is always first window in the list, switch to it.
383
        mov     [window_print], windows
384
        mov     [window_active], windows
385
 
6027 hidnplayr 386
        mov     ecx, [user_command.size]        ; ok now set the address
3545 hidnplayr 387
        sub     ecx, 8
388
 
6027 hidnplayr 389
        mov     esi, user_command+8
4477 hidnplayr 390
  .now:
3545 hidnplayr 391
        push    esi
392
        mov     edi, irc_server_name
4477 hidnplayr 393
  .loop:                                        ; copy until zero byte, or ecx reaches zero.
394
        lodsb
395
        stosb
396
        test    al, al
397
        jz      .done
398
        dec     ecx
399
        jnz     .loop
3545 hidnplayr 400
        xor     al, al
401
        stosb
4477 hidnplayr 402
  .done:
3545 hidnplayr 403
        pop     esi
404
 
405
; set it also in window name
406
        mov     ebx, [window_print]
407
        call    window_set_name
408
 
409
; now connect
410
        call    socket_connect
411
 
412
        ret
413
 
414
 
415
cmd_usr_quer:
416
 
6027 hidnplayr 417
        mov     esi, user_command+7
4477 hidnplayr 418
        call    window_open
4623 hidnplayr 419
;        test    ebx, ebx
420
;        jz      .fail
3545 hidnplayr 421
 
422
        ret
423
 
424
 
425
 
426
cmd_usr_help:
427
 
428
        mov     esi, str_help
4623 hidnplayr 429
        call    print_asciiz
3545 hidnplayr 430
 
431
        ret
432
 
433
 
434
 
435
cmd_usr_code:
436
 
437
        ; TODO
438
 
439
        ret
440
 
441
 
442
 
3981 hidnplayr 443
; User typed a part command
444
cmd_usr_part:
445
 
6027 hidnplayr 446
        cmp     byte[user_command+5], 13        ; parameters given?
4143 hidnplayr 447
        jne     cmd_usr_send                    ; yes, send command straight to server
3981 hidnplayr 448
 
4143 hidnplayr 449
; close active window
450
cmd_usr_close_window:
451
 
452
        mov     esi, [window_active]
6026 hidnplayr 453
        mov     [window_print], esi
3981 hidnplayr 454
        cmp     [esi + window.type], WINDOWTYPE_SERVER
4143 hidnplayr 455
        je      .not_channel
3981 hidnplayr 456
 
4143 hidnplayr 457
        lea     esi, [esi + window.name]
458
        call    cmd_usr_part_channel
459
        call    window_close
460
        ret
3981 hidnplayr 461
 
4143 hidnplayr 462
  .not_channel:
463
        cmp     [esi + window.type], WINDOWTYPE_CHAT
464
        jne     .not_chat
465
 
466
        call    window_close
467
  .not_chat:
468
 
3981 hidnplayr 469
        ret
470
 
4143 hidnplayr 471
 
472
 
3981 hidnplayr 473
; Send part command to server
474
; esi must point to channel name (ASCIIZ)
475
cmd_usr_part_channel:
476
 
477
; User wants to close a channel, send PART command to server
478
        mov     dword[packetbuf], 'PART'
479
        mov     byte[packetbuf+4], ' '
480
        lea     edi, [packetbuf+5]
481
  @@:
482
        lodsb
4143 hidnplayr 483
        test    al, al
484
        jz      @f
485
        cmp     al, 13
486
        je      @f
487
        cmp     al, 10
488
        je      @f
3981 hidnplayr 489
        stosb
4143 hidnplayr 490
        jmp     @r
491
  @@:
3981 hidnplayr 492
; end the command with a CRLF
493
        mov     ax, 0x0a0d
494
        stosw
495
 
496
        lea     esi, [edi - packetbuf]                  ; calculate length
497
        mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
498
 
499
        ret
500
 
501
 
4477 hidnplayr 502
 
4143 hidnplayr 503
cmd_usr_ctcp:
504
 
6027 hidnplayr 505
        cmp     byte[user_command+5], ' '
4143 hidnplayr 506
        jne     cmd_usr_send
507
 
6027 hidnplayr 508
        mov     esi, user_command+6
4143 hidnplayr 509
; prepare a 'PRIVMSG '
510
        mov     dword[packetbuf], 'PRIV'
511
        mov     dword[packetbuf+4], 'MSG '
512
        lea     edi, [packetbuf+8]
513
 
514
; append the destination (nickname/channel)
515
  @@:
516
        lodsb
517
        test    al, al
518
        jz      .fail
519
        cmp     al, ' '
520
        je      @f
521
        stosb
522
        jmp     @r
523
  @@:
524
 
525
        mov     ax, ' :'
526
        stosw
527
        mov     al, 0x01
528
        stosb
529
 
530
; copy the message itself
531
  @@:
532
        lodsb
533
        test    al, al
534
        jz      @f
535
        cmp     al, 13
536
        je      @f
537
        cmp     al, 10
538
        je      @f
539
        stosb
540
        jmp     @r
541
  @@:
542
 
543
; end of message
544
        mov     al, 0x01
545
        stosb
546
        mov     ax, 0x0a0d
547
        stosw
548
 
549
; now send it away
550
        lea     esi, [edi - packetbuf]                  ; calculate length
551
        mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
552
 
553
;; TODO: print to window
554
 
555
  .fail:
556
 
557
        ret
558
 
559
 
4477 hidnplayr 560
 
4659 hidnplayr 561
cmd_usr_me:
562
 
563
; prepare a 'PRIVMSG '
564
        mov     dword[packetbuf], 'PRIV'
565
        mov     dword[packetbuf+4], 'MSG '
566
        lea     edi, [packetbuf+8]
567
 
568
; append the destination (nickname/channel)
569
        mov     esi, [window_active]
570
        lea     esi, [esi + window.name]
571
  @@:
572
        lodsb
573
        test    al, al
574
        je      @f
575
        stosb
576
        jmp     @r
577
  @@:
578
 
579
; Make the CTCP action header
580
        mov     eax, ' :' + 0x01 shl 16 + 'A' shl 24
581
        stosd
582
        mov     eax, 'CTIO'
583
        stosd
584
        mov     al, 'N'
585
        stosb
586
 
587
; copy the message itself (including first space)
6027 hidnplayr 588
        mov     esi, user_command+3
4659 hidnplayr 589
  @@:
590
        lodsb
591
        cmp     al, 13
592
        je      @f
593
        stosb
594
        jmp     @r
595
  @@:
596
 
597
; end of CTCP message
598
        mov     al, 0x01
599
        stosb
600
        mov     ax, 0x0a0d
601
        stosw
602
 
603
; now send it to the server
604
        lea     esi, [edi - packetbuf]                  ; calculate length
605
        mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
606
 
607
; print to local window
608
        if TIMESTAMP
609
        call    print_timestamp
610
        end if
611
 
612
        mov     esi, action_header
613
        call    print_asciiz
614
 
615
        mov     esi, user_nick
616
        call    print_asciiz
617
 
6027 hidnplayr 618
        mov     esi, user_command+3
4659 hidnplayr 619
        mov     bl, 13
620
        call    print_string
621
 
622
        mov     al, 10
623
        call    print_char
624
 
625
        ret
626
 
627
 
628
 
6027 hidnplayr 629
; The user typed some undefined command, just send it to the server
3545 hidnplayr 630
cmd_usr_send:
631
 
6027 hidnplayr 632
        mov     esi, [user_command.size]
633
        mov     eax, [user_command.size]
634
        add     eax, user_command+1
635
        mov     word[eax], 0x0d0a
636
        inc     esi
637
        mcall   send, [socketnum], user_command+1, , 0
3545 hidnplayr 638
 
639
        ret
640
 
4143 hidnplayr 641