Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;; Copyright (C) KolibriOS team 2004-2013. All rights reserved.    ;;
  4. ;; Distributed under terms of the GNU General Public License       ;;
  5. ;;                                                                 ;;
  6. ;;                                                                 ;;
  7. ;;         GNU GENERAL PUBLIC LICENSE                              ;;
  8. ;;          Version 2, June 1991                                   ;;
  9. ;;                                                                 ;;
  10. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11.  
  12.  
  13. user_parser:
  14.  
  15.         mov     eax, [edit1.size]
  16.         mov     word [usercommand + eax], 0x0a0d        ; terminate the line
  17.  
  18.         cmp     byte[usercommand], '/'                  ; is it a server command ?
  19.         je      server_command
  20.  
  21. ; Ignore data commands when not connected.
  22.         cmp     [status], STATUS_CONNECTED
  23.         jne     sdts_ret
  24.  
  25. ; Ok, we said something, print it to our textbox
  26.  
  27.         if      TIMESTAMP
  28.         call    print_timestamp
  29.         end     if
  30.  
  31.         mov     bl, '<'
  32.         call    print_character
  33.  
  34.         mov     esi, user_nick
  35.         call    print_text2
  36.  
  37.         mov     bl,'>'
  38.         call    print_character
  39.         mov     bl,' '
  40.         call    print_character
  41.  
  42.         mov     eax, [edit1.size]
  43.         mov     byte[usercommand + eax],0
  44.  
  45.         mov     esi, usercommand
  46.         call    print_text2
  47.  
  48.         mov     bl, 10
  49.         call    print_character
  50.  
  51. ; and now send it to the server
  52.  
  53.         mov     dword[packetbuf], 'priv'
  54.         mov     dword[packetbuf+4], 'msg '
  55.  
  56.         mov     esi, [window_print]
  57.         add     esi, window.name
  58.         mov     edi, packetbuf+8
  59.         mov     ecx, MAX_WINDOWNAME_LEN
  60.   .loop:
  61.         lodsb
  62.         test    al, al
  63.         jz      .done
  64.         stosb
  65.         dec     ecx
  66.         jnz     .loop
  67.   .done:
  68.  
  69.         mov     ax, ' :'
  70.         stosw
  71.  
  72.         mov     esi, usercommand
  73.         mov     ecx, [edit1.size]
  74.         inc     ecx
  75.         call    recode
  76.  
  77.         mov     al, 10
  78.         stosb
  79.  
  80.         lea     esi, [edi - packetbuf]
  81.         mcall   send, [socketnum], packetbuf, , 0
  82.  
  83. sdts_ret:
  84.  
  85.         ret
  86.  
  87.  
  88.  
  89. user_commands:
  90.         dd      'nick', cmd_usr_nick
  91.         dd      'real', cmd_usr_real
  92.         dd      'serv', cmd_usr_server
  93.         dd      'help', cmd_usr_help
  94.         dd      'code', cmd_usr_code
  95. ; TODO: All other commands require a connection to the server.
  96.         dd      'quer', cmd_usr_quer
  97.         dd      'quit', cmd_usr_quit
  98.  
  99.         .number = ($ - user_commands) / 8
  100.  
  101.  
  102.  
  103. server_command:
  104.  
  105.         mov     eax, dword[usercommand+1]
  106.         or      eax, 0x20202020
  107.  
  108.         mov     edi, user_commands
  109.         mov     ecx, user_commands.number
  110.   .loop:
  111.         scasd
  112.         je      .got_cmd
  113.         add     edi, 4
  114.         dec     ecx
  115.         jnz     .loop
  116.         jmp     cmd_usr_send            ; If none of the previous commands, just send to server
  117.  
  118.   .got_cmd:
  119.         jmp     dword[edi]
  120.  
  121.  
  122.  
  123.  
  124.  
  125. cmd_usr_quit:
  126.  
  127.         cmp     [edit1.size], 5
  128.         je      .ok
  129.         jb      cmd_usr_send
  130.         cmp     byte[usercommand+5], ' '
  131.         jne     cmd_usr_send
  132.  
  133.   .ok:
  134.         call    cmd_usr_send
  135.  
  136.         mcall   close, [socketnum]
  137.  
  138.         mov     ecx, MAX_WINDOWS
  139.         mov     edi, windows
  140.   .loop:
  141.         mov     [edi+window.flags], FLAG_CLOSE
  142. ;        call    notify_channel_thread
  143.         add     edi, sizeof.window
  144.         dec     ecx
  145.         jnz     .loop
  146.  
  147.         ret
  148.  
  149.  
  150.  
  151.  
  152. cmd_usr_nick:
  153.  
  154.         cmp     [edit1.size], 5
  155.         je      .justprint
  156.         cmp     byte[usercommand+5], ' '
  157.         jne     cmd_usr_send
  158.  
  159.         mov     ecx, MAX_NICK_LEN
  160.         mov     esi, usercommand+6
  161.         mov     edi, user_nick
  162.   .loop:
  163.         lodsb
  164.         cmp     al, 13
  165.         je      .done
  166.         stosb
  167.         dec     ecx
  168.         jnz     .loop
  169.   .done:
  170.         xor     al, al
  171.         stosb
  172.  
  173.         cmp     [socketnum], 0
  174.         je      .justprint
  175.  
  176.         lea     esi, [edi - usercommand]
  177.         mcall   send, [socketnum], usercommand+1, , 0
  178.  
  179.   .justprint:
  180.         mov     esi, str_nickchange
  181.         call    print_text2
  182.         mov     esi, user_nick
  183.         call    print_text2
  184.         mov     esi, str_dotnewline
  185.         call    print_text2
  186.  
  187.         ret
  188.  
  189.  
  190.  
  191. cmd_usr_real:
  192.  
  193.         cmp     byte[usercommand+5], ' '
  194.         jne     cmd_usr_send
  195.  
  196.         mov     ecx, MAX_REAL_LEN
  197.         mov     esi, usercommand+6
  198.         mov     edi, user_real_name
  199.   .loop:
  200.         lodsb
  201.         cmp     al, 13
  202.         je      .done
  203.         stosb
  204.         dec     ecx
  205.         jnz     .loop
  206.   .done:
  207.         xor     al, al
  208.         stosb
  209.  
  210.         mov     esi, str_realchange
  211.         call    print_text2
  212.         mov     esi, user_real_name
  213.         call    print_text2
  214.         mov     esi, str_dotnewline
  215.         call    print_text2
  216.  
  217.         ret
  218.  
  219.  
  220.  
  221. cmd_usr_server:
  222.  
  223.         mov     eax, dword[usercommand+5]       ; check for 'er ', we only checked 'serv'
  224.         or      eax, 0x00002020
  225.         and     eax, 0x00ffffff
  226.         cmp     eax, 'er '
  227.         jne     cmd_usr_send
  228.  
  229.         mov     ecx, [edit1.size]         ; ok now set the address
  230.         sub     ecx, 8
  231.  
  232.         mov     esi, usercommand+8
  233.         push    esi
  234.         mov     edi, irc_server_name
  235.         rep     movsb
  236.         xor     al, al
  237.         stosb
  238.         pop     esi
  239.  
  240. ; set it also in window name
  241.         mov     ebx, [window_print]
  242.         call    window_set_name
  243.  
  244. ; now connect
  245.         call    socket_connect
  246.  
  247.         ret
  248.  
  249.  
  250. cmd_usr_quer:
  251.  
  252.         mov     ecx, MAX_WINDOWS
  253.         mov     ebx, windows
  254.   .loop:
  255.         cmp     [ebx + window.data_ptr], 0
  256.         je      .found
  257.         add     ebx, sizeof.window
  258.         dec     ecx
  259.         jnz     .loop
  260.  
  261. ; error: no available channels ! FIXME
  262.  
  263.         ret
  264.  
  265.  
  266.   .found:
  267.         call    window_create
  268.         test    eax, eax
  269.         jz      .error
  270.         mov     [ebx + window.data_ptr], eax
  271.  
  272.         mov     esi, usercommand+7
  273.         call    window_set_name
  274.  
  275.         mov     [ebx + window.type], WINDOWTYPE_CHAT
  276.         mov     [ebx + window.flags], 0
  277.  
  278.   .error:
  279.  
  280.         ret
  281.  
  282.  
  283.  
  284. cmd_usr_help:
  285.  
  286.         mov     esi, str_help
  287.         call    print_text2
  288.  
  289.         ret
  290.  
  291.  
  292.  
  293. cmd_usr_code:
  294.  
  295.         ; TODO
  296.  
  297.         ret
  298.  
  299.  
  300.  
  301. cmd_usr_send:
  302.  
  303.         mov     esi, usercommand+1
  304.         mov     ecx, [edit1.size]
  305.         inc     ecx
  306.         mov     edi, packetbuf
  307.         call    recode
  308.  
  309.         lea     esi, [edi - packetbuf]
  310.         mcall   send, [socketnum], packetbuf, , 0
  311.  
  312.         ret
  313.  
  314.