Subversion Repositories Kolibri OS

Rev

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