Subversion Repositories Kolibri OS

Rev

Rev 4710 | Rev 6023 | 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
 
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]
3981 hidnplayr 443
        cmp     [esi + window.type], WINDOWTYPE_SERVER
4143 hidnplayr 444
        je      .not_channel
3981 hidnplayr 445
 
4143 hidnplayr 446
        lea     esi, [esi + window.name]
447
        call    cmd_usr_part_channel
448
        call    window_close
449
        ret
3981 hidnplayr 450
 
4143 hidnplayr 451
  .not_channel:
452
        cmp     [esi + window.type], WINDOWTYPE_CHAT
453
        jne     .not_chat
454
 
455
        call    window_close
456
  .not_chat:
457
 
3981 hidnplayr 458
        ret
459
 
4143 hidnplayr 460
 
461
 
3981 hidnplayr 462
; Send part command to server
463
; esi must point to channel name (ASCIIZ)
464
cmd_usr_part_channel:
465
 
466
; User wants to close a channel, send PART command to server
467
        mov     dword[packetbuf], 'PART'
468
        mov     byte[packetbuf+4], ' '
469
        lea     edi, [packetbuf+5]
470
  @@:
471
        lodsb
4143 hidnplayr 472
        test    al, al
473
        jz      @f
474
        cmp     al, 13
475
        je      @f
476
        cmp     al, 10
477
        je      @f
3981 hidnplayr 478
        stosb
4143 hidnplayr 479
        jmp     @r
480
  @@:
3981 hidnplayr 481
; end the command with a CRLF
482
        mov     ax, 0x0a0d
483
        stosw
484
 
485
        lea     esi, [edi - packetbuf]                  ; calculate length
486
        mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
487
 
488
        ret
489
 
490
 
4477 hidnplayr 491
 
4143 hidnplayr 492
cmd_usr_ctcp:
493
 
494
        cmp     byte[usercommand+5], ' '
495
        jne     cmd_usr_send
496
 
497
        mov     esi, usercommand+6
498
; prepare a 'PRIVMSG '
499
        mov     dword[packetbuf], 'PRIV'
500
        mov     dword[packetbuf+4], 'MSG '
501
        lea     edi, [packetbuf+8]
502
 
503
; append the destination (nickname/channel)
504
  @@:
505
        lodsb
506
        test    al, al
507
        jz      .fail
508
        cmp     al, ' '
509
        je      @f
510
        stosb
511
        jmp     @r
512
  @@:
513
 
514
        mov     ax, ' :'
515
        stosw
516
        mov     al, 0x01
517
        stosb
518
 
519
; copy the message itself
520
  @@:
521
        lodsb
522
        test    al, al
523
        jz      @f
524
        cmp     al, 13
525
        je      @f
526
        cmp     al, 10
527
        je      @f
528
        stosb
529
        jmp     @r
530
  @@:
531
 
532
; end of message
533
        mov     al, 0x01
534
        stosb
535
        mov     ax, 0x0a0d
536
        stosw
537
 
538
; now send it away
539
        lea     esi, [edi - packetbuf]                  ; calculate length
540
        mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
541
 
542
;; TODO: print to window
543
 
544
  .fail:
545
 
546
        ret
547
 
548
 
4477 hidnplayr 549
 
4659 hidnplayr 550
cmd_usr_me:
551
 
552
; prepare a 'PRIVMSG '
553
        mov     dword[packetbuf], 'PRIV'
554
        mov     dword[packetbuf+4], 'MSG '
555
        lea     edi, [packetbuf+8]
556
 
557
; append the destination (nickname/channel)
558
        mov     esi, [window_active]
559
        lea     esi, [esi + window.name]
560
  @@:
561
        lodsb
562
        test    al, al
563
        je      @f
564
        stosb
565
        jmp     @r
566
  @@:
567
 
568
; Make the CTCP action header
569
        mov     eax, ' :' + 0x01 shl 16 + 'A' shl 24
570
        stosd
571
        mov     eax, 'CTIO'
572
        stosd
573
        mov     al, 'N'
574
        stosb
575
 
576
; copy the message itself (including first space)
577
        mov     esi, usercommand+3
578
  @@:
579
        lodsb
580
        cmp     al, 13
581
        je      @f
582
        stosb
583
        jmp     @r
584
  @@:
585
 
586
; end of CTCP message
587
        mov     al, 0x01
588
        stosb
589
        mov     ax, 0x0a0d
590
        stosw
591
 
592
; now send it to the server
593
        lea     esi, [edi - packetbuf]                  ; calculate length
594
        mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
595
 
596
; print to local window
597
        if TIMESTAMP
598
        call    print_timestamp
599
        end if
600
 
601
        mov     esi, action_header
602
        call    print_asciiz
603
 
604
        mov     esi, user_nick
605
        call    print_asciiz
606
 
607
        mov     esi, usercommand+3
608
        mov     bl, 13
609
        call    print_string
610
 
611
        mov     al, 10
612
        call    print_char
613
 
614
        ret
615
 
616
 
617
 
3981 hidnplayr 618
; The user typed some undefined command, just recode it and send to the server
3545 hidnplayr 619
cmd_usr_send:
620
 
621
        mov     esi, usercommand+1
622
        mov     ecx, [edit1.size]
623
        inc     ecx
624
        mov     edi, packetbuf
625
        call    recode
626
 
627
        lea     esi, [edi - packetbuf]
628
        mcall   send, [socketnum], packetbuf, , 0
629
 
630
        ret
631
 
4143 hidnplayr 632