Subversion Repositories Kolibri OS

Rev

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