Subversion Repositories Kolibri OS

Rev

Rev 4623 | Rev 4710 | 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
server_command:
121
 
4477 hidnplayr 122
        mov     eax, dword[usercommand+1]       ; skip '/'
123
        or      eax, 0x20202020                 ; convert to lowercase
3545 hidnplayr 124
 
125
        mov     edi, user_commands
126
        mov     ecx, user_commands.number
4477 hidnplayr 127
        cmp     [status], STATUS_CONNECTED
4659 hidnplayr 128
        je      .loop
4477 hidnplayr 129
        mov     ecx, user_commands.number2
3545 hidnplayr 130
  .loop:
131
        scasd
132
        je      .got_cmd
133
        add     edi, 4
134
        dec     ecx
135
        jnz     .loop
136
 
4477 hidnplayr 137
        cmp     [status], STATUS_CONNECTED
138
        jne     .notconnected
4659 hidnplayr 139
; Commands shorter then 3 chars are placed here
140
        and     eax, 0x00ffffff
141
        cmp     eax, 'me '
142
        je      cmd_usr_me
4477 hidnplayr 143
 
144
        jmp     cmd_usr_send                    ; If none of the previous commands, just send to server
145
 
3545 hidnplayr 146
  .got_cmd:
147
        jmp     dword[edi]
148
 
4477 hidnplayr 149
  .notconnected:
150
        mov     esi, str_notconnected
4623 hidnplayr 151
        call    print_asciiz
3545 hidnplayr 152
 
4477 hidnplayr 153
        ret
3545 hidnplayr 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:
3981 hidnplayr 227
        mov     esi, quit_msg
228
 
3545 hidnplayr 229
        cmp     byte[usercommand+5], ' '
4143 hidnplayr 230
        jne     .with_message
231
        lea     esi, [usercommand+6]
232
  .with_message:
3981 hidnplayr 233
        call    cmd_usr_quit_server
3545 hidnplayr 234
 
235
        mcall   close, [socketnum]
4143 hidnplayr 236
        mov     [status], STATUS_DISCONNECTED
3545 hidnplayr 237
 
238
        mov     ecx, MAX_WINDOWS
239
        mov     edi, windows
240
  .loop:
4143 hidnplayr 241
        mov     [window_print], edi
242
        push    edi ecx
243
        call    window_close
244
        pop     ecx edi
3545 hidnplayr 245
        add     edi, sizeof.window
246
        dec     ecx
247
        jnz     .loop
248
 
249
        ret
250
 
251
 
252
 
3981 hidnplayr 253
; esi = quit message
254
cmd_usr_quit_server:
3545 hidnplayr 255
 
3981 hidnplayr 256
; User wants to close a channel, send PART command to server
257
        mov     dword[packetbuf], 'QUIT'
258
        mov     word[packetbuf+4], ' :'
259
        lea     edi, [packetbuf+6]
260
; Append our quit msg
261
  @@:
262
        lodsb
4143 hidnplayr 263
        cmp     al, 13
264
        je      @f
265
        test    al, al
266
        jz      @f
3981 hidnplayr 267
        stosb
4143 hidnplayr 268
        jmp     @r
269
  @@:
3981 hidnplayr 270
; end the command with a CRLF
271
        mov     ax, 0x0a0d
272
        stosw
273
 
274
        lea     esi, [edi - packetbuf]                  ; calculate length
275
        mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
276
 
277
        ret
278
 
279
 
280
 
281
 
3545 hidnplayr 282
cmd_usr_nick:
283
 
284
        cmp     [edit1.size], 5
4143 hidnplayr 285
        je      .dontsend
3545 hidnplayr 286
        cmp     byte[usercommand+5], ' '
4143 hidnplayr 287
        jne     .fail
288
        cmp     [socketnum], 0
289
        je      .dontsend
3545 hidnplayr 290
 
4617 hidnplayr 291
; Request nickname change to server
4143 hidnplayr 292
        mov     dword[usercommand+1], 'NICK'
293
        mov     esi, [edit1.size]
294
        mov     word[usercommand + esi], 0x0a0d
295
        inc     esi
296
        mcall   send, [socketnum], usercommand+1, , 0
297
 
298
  .fail:
299
 
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
 
318
        mov     esi, str_nickchange
4623 hidnplayr 319
        call    print_asciiz
320
 
3545 hidnplayr 321
        mov     esi, user_nick
4623 hidnplayr 322
        call    print_asciiz
3545 hidnplayr 323
 
4623 hidnplayr 324
        mov     al, 10
325
        call    print_char
326
 
3545 hidnplayr 327
        ret
328
 
329
 
330
 
331
cmd_usr_real:
332
 
333
        cmp     byte[usercommand+5], ' '
334
        jne     cmd_usr_send
335
 
336
        mov     ecx, MAX_REAL_LEN
337
        mov     esi, usercommand+6
338
        mov     edi, user_real_name
339
  .loop:
340
        lodsb
341
        cmp     al, 13
342
        je      .done
343
        stosb
344
        dec     ecx
345
        jnz     .loop
346
  .done:
347
        xor     al, al
348
        stosb
349
 
350
        mov     esi, str_realchange
4623 hidnplayr 351
        call    print_asciiz
352
 
3545 hidnplayr 353
        mov     esi, user_real_name
4623 hidnplayr 354
        call    print_asciiz
3545 hidnplayr 355
 
4623 hidnplayr 356
        mov     al, 10
357
        call    print_char
358
 
3545 hidnplayr 359
        ret
360
 
361
 
362
 
363
cmd_usr_server:
364
 
365
        mov     eax, dword[usercommand+5]       ; check for 'er ', we only checked 'serv'
366
        or      eax, 0x00002020
367
        and     eax, 0x00ffffff
368
        cmp     eax, 'er '
369
        jne     cmd_usr_send
370
 
4477 hidnplayr 371
        mov     ecx, [edit1.size]               ; ok now set the address
3545 hidnplayr 372
        sub     ecx, 8
373
 
374
        mov     esi, usercommand+8
4477 hidnplayr 375
  .now:
3545 hidnplayr 376
        push    esi
377
        mov     edi, irc_server_name
4477 hidnplayr 378
  .loop:                                        ; copy until zero byte, or ecx reaches zero.
379
        lodsb
380
        stosb
381
        test    al, al
382
        jz      .done
383
        dec     ecx
384
        jnz     .loop
3545 hidnplayr 385
        xor     al, al
386
        stosb
4477 hidnplayr 387
  .done:
3545 hidnplayr 388
        pop     esi
389
 
390
; set it also in window name
391
        mov     ebx, [window_print]
392
        call    window_set_name
393
 
394
; now connect
395
        call    socket_connect
396
 
397
        ret
398
 
399
 
400
cmd_usr_quer:
401
 
402
        mov     esi, usercommand+7
4477 hidnplayr 403
        call    window_open
4623 hidnplayr 404
;        test    ebx, ebx
405
;        jz      .fail
3545 hidnplayr 406
 
407
        ret
408
 
409
 
410
 
411
cmd_usr_help:
412
 
413
        mov     esi, str_help
4623 hidnplayr 414
        call    print_asciiz
3545 hidnplayr 415
 
416
        ret
417
 
418
 
419
 
420
cmd_usr_code:
421
 
422
        ; TODO
423
 
424
        ret
425
 
426
 
427
 
3981 hidnplayr 428
; User typed a part command
429
cmd_usr_part:
430
 
4143 hidnplayr 431
        cmp     byte[usercommand+5], 13         ; parameters given?
432
        jne     cmd_usr_send                    ; yes, send command straight to server
3981 hidnplayr 433
 
4143 hidnplayr 434
; close active window
435
cmd_usr_close_window:
436
 
437
        mov     esi, [window_active]
3981 hidnplayr 438
        cmp     [esi + window.type], WINDOWTYPE_SERVER
4143 hidnplayr 439
        je      .not_channel
3981 hidnplayr 440
 
4143 hidnplayr 441
        lea     esi, [esi + window.name]
442
        call    cmd_usr_part_channel
443
        call    window_close
444
        ret
3981 hidnplayr 445
 
4143 hidnplayr 446
  .not_channel:
447
        cmp     [esi + window.type], WINDOWTYPE_CHAT
448
        jne     .not_chat
449
 
450
        call    window_close
451
  .not_chat:
452
 
3981 hidnplayr 453
        ret
454
 
4143 hidnplayr 455
 
456
 
3981 hidnplayr 457
; Send part command to server
458
; esi must point to channel name (ASCIIZ)
459
cmd_usr_part_channel:
460
 
461
; User wants to close a channel, send PART command to server
462
        mov     dword[packetbuf], 'PART'
463
        mov     byte[packetbuf+4], ' '
464
        lea     edi, [packetbuf+5]
465
  @@:
466
        lodsb
4143 hidnplayr 467
        test    al, al
468
        jz      @f
469
        cmp     al, 13
470
        je      @f
471
        cmp     al, 10
472
        je      @f
3981 hidnplayr 473
        stosb
4143 hidnplayr 474
        jmp     @r
475
  @@:
3981 hidnplayr 476
; end the command with a CRLF
477
        mov     ax, 0x0a0d
478
        stosw
479
 
480
        lea     esi, [edi - packetbuf]                  ; calculate length
481
        mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
482
 
483
        ret
484
 
485
 
4477 hidnplayr 486
 
4143 hidnplayr 487
cmd_usr_ctcp:
488
 
489
        cmp     byte[usercommand+5], ' '
490
        jne     cmd_usr_send
491
 
492
        mov     esi, usercommand+6
493
; prepare a 'PRIVMSG '
494
        mov     dword[packetbuf], 'PRIV'
495
        mov     dword[packetbuf+4], 'MSG '
496
        lea     edi, [packetbuf+8]
497
 
498
; append the destination (nickname/channel)
499
  @@:
500
        lodsb
501
        test    al, al
502
        jz      .fail
503
        cmp     al, ' '
504
        je      @f
505
        stosb
506
        jmp     @r
507
  @@:
508
 
509
        mov     ax, ' :'
510
        stosw
511
        mov     al, 0x01
512
        stosb
513
 
514
; copy the message itself
515
  @@:
516
        lodsb
517
        test    al, al
518
        jz      @f
519
        cmp     al, 13
520
        je      @f
521
        cmp     al, 10
522
        je      @f
523
        stosb
524
        jmp     @r
525
  @@:
526
 
527
; end of message
528
        mov     al, 0x01
529
        stosb
530
        mov     ax, 0x0a0d
531
        stosw
532
 
533
; now send it away
534
        lea     esi, [edi - packetbuf]                  ; calculate length
535
        mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
536
 
537
;; TODO: print to window
538
 
539
  .fail:
540
 
541
        ret
542
 
543
 
4477 hidnplayr 544
 
4659 hidnplayr 545
cmd_usr_me:
546
 
547
; prepare a 'PRIVMSG '
548
        mov     dword[packetbuf], 'PRIV'
549
        mov     dword[packetbuf+4], 'MSG '
550
        lea     edi, [packetbuf+8]
551
 
552
; append the destination (nickname/channel)
553
        mov     esi, [window_active]
554
        lea     esi, [esi + window.name]
555
  @@:
556
        lodsb
557
        test    al, al
558
        je      @f
559
        stosb
560
        jmp     @r
561
  @@:
562
 
563
; Make the CTCP action header
564
        mov     eax, ' :' + 0x01 shl 16 + 'A' shl 24
565
        stosd
566
        mov     eax, 'CTIO'
567
        stosd
568
        mov     al, 'N'
569
        stosb
570
 
571
; copy the message itself (including first space)
572
        mov     esi, usercommand+3
573
  @@:
574
        lodsb
575
        cmp     al, 13
576
        je      @f
577
        stosb
578
        jmp     @r
579
  @@:
580
 
581
; end of CTCP message
582
        mov     al, 0x01
583
        stosb
584
        mov     ax, 0x0a0d
585
        stosw
586
 
587
; now send it to the server
588
        lea     esi, [edi - packetbuf]                  ; calculate length
589
        mcall   send, [socketnum], packetbuf, , 0       ; and finally send to server
590
 
591
; print to local window
592
        if TIMESTAMP
593
        call    print_timestamp
594
        end if
595
 
596
        mov     esi, action_header
597
        call    print_asciiz
598
 
599
        mov     esi, user_nick
600
        call    print_asciiz
601
 
602
        mov     esi, usercommand+3
603
        mov     bl, 13
604
        call    print_string
605
 
606
        mov     al, 10
607
        call    print_char
608
 
609
        ret
610
 
611
 
612
 
3981 hidnplayr 613
; The user typed some undefined command, just recode it and send to the server
3545 hidnplayr 614
cmd_usr_send:
615
 
616
        mov     esi, usercommand+1
617
        mov     ecx, [edit1.size]
618
        inc     ecx
619
        mov     edi, packetbuf
620
        call    recode
621
 
622
        lea     esi, [edi - packetbuf]
623
        mcall   send, [socketnum], packetbuf, , 0
624
 
625
        ret
626
 
4143 hidnplayr 627