Subversion Repositories Kolibri OS

Rev

Rev 4659 | Rev 4710 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;; Copyright (C) KolibriOS team 2004-2014. All rights reserved.    ;;
  4. ;; Distributed under terms of the GNU General Public License       ;;
  5. ;;                                                                 ;;
  6. ;;  IRC client for KolibriOS                                       ;;
  7. ;;                                                                 ;;
  8. ;;   Written by hidnplayr@kolibrios.org,                           ;;
  9. ;;     text encoder/decoder by Clevermouse.                        ;;
  10. ;;                                                                 ;;
  11. ;;         GNU GENERAL PUBLIC LICENSE                              ;;
  12. ;;          Version 2, June 1991                                   ;;
  13. ;;                                                                 ;;
  14. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15.  
  16. version equ '0.21'
  17.  
  18. ; connection status
  19. STATUS_DISCONNECTED     = 0
  20. STATUS_RESOLVING        = 1
  21. STATUS_CONNECTING       = 2
  22. STATUS_CONNECTED        = 3
  23.  
  24. ; window flags
  25. FLAG_UPDATED            = 1 shl 0
  26. FLAG_RECEIVING_NAMES    = 1 shl 1
  27.  
  28. ; window types
  29. WINDOWTYPE_NONE         = 0
  30. WINDOWTYPE_SERVER       = 1
  31. WINDOWTYPE_CHANNEL      = 2
  32. WINDOWTYPE_CHAT         = 3
  33. WINDOWTYPE_LIST         = 4
  34. WINDOWTYPE_DCC          = 5
  35.  
  36. ; supported encodings
  37. CP866                   = 0
  38. CP1251                  = 1
  39. UTF8                    = 2
  40.  
  41. ; settings
  42. USERCMD_MAX_SIZE        = 400
  43.  
  44. WIN_MIN_X               = 600
  45. WIN_MIN_Y               = 170
  46.  
  47. TEXT_X                  = 5
  48. TEXT_Y                  = TOP_Y + 2
  49.  
  50. TOP_Y                   = 24
  51. BOTTOM_Y                = 15
  52.  
  53. MAX_WINDOWS             = 20
  54. MAX_USERS               = 4096
  55. TEXT_BUFFERSIZE         = 1024*1024
  56.  
  57. MAX_NICK_LEN            = 32
  58. MAX_REAL_LEN            = 32    ; realname
  59. MAX_SERVER_NAME         = 256
  60.  
  61. MAX_CHANNEL_LEN         = 40
  62. MAX_CHANNELS            = 37
  63.  
  64. MAX_COMMAND_LEN         = 512
  65.  
  66. TIMESTAMP               = 3     ; 3 = hh:mm:ss, 2 = hh:mm, 0 = no timestamp
  67.  
  68. MAX_WINDOWNAME_LEN      = 256
  69.  
  70. WINDOW_BTN_START        = 100
  71. WINDOW_BTN_CLOSE        = 2
  72. WINDOW_BTN_LIST         = 3
  73.  
  74. SCROLLBAR_WIDTH         = 14
  75. USERLIST_WIDTH          = 100
  76.  
  77. FONT_HEIGHT             = 9
  78. FONT_WIDTH              = 6
  79.  
  80. format binary as ""
  81.  
  82. use32
  83.  
  84.         org     0x0
  85.  
  86.         db      'MENUET01'              ; 8 byte id
  87.         dd      1                       ; header version
  88.         dd      START                   ; program start
  89.         dd      I_END                   ; program image size
  90.         dd      IM_END+2048             ; required amount of memory
  91.         dd      IM_END+2048
  92.         dd      param
  93.         dd      path
  94.  
  95. include "../../macros.inc"
  96. include "../../proc32.inc"
  97. include "../../dll.inc"
  98. include "../../network.inc"
  99. include "../../struct.inc"
  100. include "../../develop/libraries/box_lib/trunk/box_lib.mac"
  101.  
  102. struct  window
  103.         data_ptr        dd ?
  104.         flags           db ?
  105.         type            db ?
  106.         name            rb MAX_WINDOWNAME_LEN
  107.         users           dd ?
  108.         users_scroll    dd ?
  109.         selected        dd ?            ; selected user, 0 if none selected
  110.  
  111.         text_start      dd ?            ; pointer to current textbox data
  112.         text_end        dd ?
  113.         text_print      dd ?            ; pointer to first character to print on screen
  114.         text_line_print dd ?            ; line number of that character
  115.         text_write      dd ?            ; write pointer
  116.         text_lines      dd ?            ; total number of lines
  117.         text_scanned    dd ?            ; pointer to beginning of unscanned data (we still need to count number of lines, insert newline characters,..)
  118.  
  119. ends
  120.  
  121. struct  window_data
  122.         text            rb TEXT_BUFFERSIZE
  123.         names           rb MAX_NICK_LEN * MAX_USERS
  124. ends
  125.  
  126. include "encodings.inc"
  127. include "window.inc"
  128. include "serverparser.inc"
  129. include "userparser.inc"
  130. include "socket.inc"
  131. include "gui.inc"
  132. include "users.inc"
  133. include "textbox.inc"
  134.  
  135.  
  136. START:
  137.  
  138.         mcall   68, 11                  ; init heap so we can allocate memory dynamically
  139.  
  140. ; wanted events
  141.         mcall   40, EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_STACK+EVM_MOUSE+EVM_MOUSE_FILTER
  142.  
  143. ; load libraries
  144.         stdcall dll.Load, @IMPORT
  145.         test    eax, eax
  146.         jnz     exit
  147.  
  148. ; find path to main settings file (ircc.ini)
  149.         mov     edi, path               ; Calculate the length of zero-terminated string
  150.         xor     al, al
  151.         mov     ecx, 1024
  152.         repne   scasb
  153.         dec     edi
  154.         mov     eax, '.ini'
  155.         stosd
  156.         xor     al, al
  157.         stosb
  158.  
  159. ; Fill the window buffer with zeros
  160.         mov     edi, windows
  161.         mov     ecx, (sizeof.window*MAX_WINDOWS+3)/4
  162.         xor     eax, eax
  163.         rep     stosd
  164.  
  165. ; clear command area too
  166.         mov     edi, servercommand
  167.         mov     ecx, 600/4
  168.         rep     stosd
  169.  
  170. ; allocate window data block
  171.         mov     ebx, windows
  172.         call    window_create_textbox
  173.         test    eax, eax
  174.         jz      error
  175.         mov     [ebx + window.type], WINDOWTYPE_SERVER
  176.  
  177. ; get system colors
  178.         mcall   48, 3, colors, 40
  179.  
  180. ; set edit box and scrollbar colors
  181.         mov     eax, [colors.work]
  182.         mov     [scroll1.bg_color], eax
  183.         mov     [scroll2.bg_color], eax
  184.  
  185.         mov     eax, [colors.work_button]
  186.         mov     [scroll1.front_color], eax
  187.         mov     [scroll2.front_color], eax
  188.  
  189.         mov     eax, [colors.work_text]
  190.         mov     [scroll1.line_color], eax
  191.         mov     [scroll2.line_color], eax
  192.  
  193.         mov     [scroll1.type], 1               ; 0 = simple, 1 = skinned
  194.         mov     [scroll2.type], 1
  195.  
  196. ; get settings from ini
  197.         invoke  ini.get_str, path, str_user, str_nick, user_nick, MAX_NICK_LEN, default_nick
  198.         invoke  ini.get_str, path, str_user, str_real, user_real_name, MAX_REAL_LEN, default_real
  199.         invoke  ini.get_str, path, str_user, str_quitmsg, quit_msg, 250, default_quit
  200.  
  201. ; Welcome user
  202.         mov     esi, str_welcome
  203.         call    print_asciiz
  204.  
  205. ; Check if parameter contains an URL
  206.         cmp     byte[param], 0
  207.         je      @f
  208.         mov     esi, param
  209.         mov     ecx, 1024
  210.         call    cmd_usr_server.now
  211.   @@:
  212.  
  213. ; Draw window a first time, so we can figure out skin size
  214.         call    draw_window
  215.  
  216. redraw:
  217.         call    draw_window
  218.  
  219. mainloop:
  220.         mcall   10              ; wait for event
  221.  
  222.         dec     eax
  223.         jz      redraw
  224.  
  225.         dec     eax
  226.         jz      main_window_key
  227.  
  228.         dec     eax
  229.         jz      button
  230.  
  231.         cmp     al, 3
  232.         je      mouse
  233.  
  234.         call    process_network_event
  235.  
  236.         mov     edi, [window_active]
  237.         test    [edi + window.flags], FLAG_UPDATED
  238.         jz      .no_update
  239.         call    draw_channel_text
  240.         mov     edi, [window_active]
  241.         cmp     [edi + window.type], WINDOWTYPE_CHANNEL
  242.         jne     .no_update
  243.         call    draw_channel_list
  244.   .no_update:
  245.         call    highlight_updated_tabs
  246.  
  247.         jmp     mainloop
  248.  
  249. button:
  250.  
  251.         mcall   17              ; get id
  252.         ror     eax, 8
  253.  
  254.         cmp     ax, 1           ; close program
  255.         je      exit
  256.  
  257.         cmp     ax, WINDOW_BTN_CLOSE
  258.         jne     @f
  259.         call    cmd_usr_close_window
  260.         jmp     mainloop
  261.  
  262.   @@:
  263.         cmp     ax, WINDOW_BTN_LIST
  264.         jne     @f
  265.  
  266.         push    eax
  267.  
  268.         mcall   37, 1           ; Get mouse position
  269.         sub     ax, TEXT_Y
  270.         mov     bl, FONT_HEIGHT
  271.         div     bl
  272.         and     eax, 0x000000ff
  273.         inc     eax
  274.         add     eax, [scroll1.position]
  275.         mov     ebx, [window_active]
  276.         mov     [ebx + window.selected], eax
  277.  
  278.         call    draw_channel_list
  279.  
  280.         pop     eax
  281.         test    eax, 1 shl 25   ; Right mouse button pressed?
  282.         jz      mainloop
  283.  
  284. ; TODO: check if selected nick is my nick!
  285.  
  286. ; Right mouse BTN was pressed, open chat window
  287.         mov     ebx, [window_active]
  288.         mov     eax, [ebx + window.selected]
  289.         dec     eax
  290.         imul    eax, MAX_NICK_LEN
  291.         mov     ebx, [ebx + window.data_ptr]
  292.         lea     esi, [ebx + window_data.names + eax]
  293.         call    window_open
  294.         test    ebx, ebx
  295.         jz      mainloop
  296.         mov     [window_active], ebx
  297.         call    redraw
  298.  
  299.         jmp     mainloop
  300.  
  301.   @@:
  302.         sub     ax, WINDOW_BTN_START
  303.         jb      exit
  304.  
  305.         cmp     ax, MAX_WINDOWS
  306.         ja      exit
  307.  
  308. ; Save users scrollbar position
  309.         push    [scroll1.position]
  310.         mov     edx, [window_active]
  311.         pop     [edx + window.users_scroll]
  312.  
  313. ; OK, time to switch to another window.
  314.         mov     dx, sizeof.window
  315.         mul     dx
  316.         shl     edx, 16
  317.         mov     dx, ax
  318.         add     edx, windows
  319.         cmp     [edx + window.type], WINDOWTYPE_NONE
  320.         je      exit
  321.         mov     [window_active], edx
  322.  
  323.         push    [edx + window.text_line_print]
  324.         pop     [scroll2.position]
  325.  
  326.         push    [edx + window.users_scroll]
  327.         pop     [scroll1.position]
  328.  
  329.         call    draw_window
  330.         jmp     mainloop
  331.  
  332. exit:
  333.  
  334.         cmp     [socketnum], 0
  335.         je      @f
  336.         mov     esi, quit_msg
  337.         call    cmd_usr_quit_server
  338.   @@:
  339.  
  340. error:
  341.  
  342.         mcall   -1
  343.  
  344.  
  345.  
  346. main_window_key:
  347.  
  348.         mcall   2
  349.  
  350.         push    dword edit1
  351.         call    [edit_box_key]
  352.  
  353. ;        cmp     ah, 178
  354. ;        jne     .no_up
  355. ;
  356. ;        jmp     mainloop
  357. ;
  358. ;
  359. ;  .no_up:
  360. ;        cmp     ah, 177
  361. ;        jne     .no_down
  362. ;
  363. ;        jmp     mainloop
  364. ;
  365. ;  .no_down:
  366.         cmp     ah, 13          ; enter
  367.         jne     no_send2
  368.  
  369.         call    user_parser
  370.  
  371.         mov     eax, [edit1.size]
  372.  
  373.         mov     [edit1.size], 0
  374.         mov     [edit1.pos], 0
  375.  
  376.         push    dword edit1
  377.         call    [edit_box_draw]
  378.  
  379.         call    draw_channel_text
  380.  
  381.         jmp     mainloop
  382.   no_send2:
  383.  
  384.         jmp     mainloop
  385.  
  386. mouse:
  387.         push    dword edit1
  388.         call    [edit_box_mouse]
  389.  
  390. ;        mcall   37, 7
  391. ;        movsx   eax, ax
  392. ;        add     [scroll2.position], eax
  393.  
  394. ; TODO: check if scrollbar is active?
  395.         mov     edi, [window_active]
  396.         cmp     [edi + window.type], WINDOWTYPE_CHANNEL
  397.         jne     @f
  398.         push    [scroll1.position]
  399.         push    dword scroll1
  400.         call    [scrollbar_mouse]
  401.         pop     eax
  402.         cmp     eax, [scroll1.position] ; did the scrollbar move?
  403.         je      @f
  404.         call    draw_channel_list
  405.   @@:
  406.  
  407. ; TODO: check if scrollbar is active?
  408.         mov     edi, [window_active]
  409.         mov     eax, [edi + window.text_lines]
  410.         cmp     eax, [textbox_height]
  411.         jbe     @f
  412.         push    dword scroll2
  413.         call    [scrollbar_mouse]
  414.         mov     edi, [window_active]
  415.         mov     edx, [scroll2.position]
  416.         sub     edx, [edi + window.text_line_print]
  417.         je      @f
  418.         call    draw_channel_text.scroll_to_pos
  419.   @@:
  420.  
  421.         jmp     mainloop
  422.  
  423.  
  424. ; DATA AREA
  425.  
  426. encoding_text:
  427. db      'CP866 '
  428. db      'CP1251'
  429. db      'UTF-8 '
  430. encoding_text_len = 6
  431.  
  432. join_header             db 3, '3* ', 0
  433. quit_header             db 3, '5* ', 0
  434. nick_header             db 3, '2* ', 0
  435. kick_header             db 3, '5* ', 0
  436. mode_header             db 3, '2* ', 0
  437. part_header             db 3, '5* ', 0
  438. topic_header            db 3, '3* ', 0
  439. action_header           db 3, '6* ', 0
  440. ctcp_header             db 3, '13-> [', 0
  441. msg_header              db 3, '7-> *', 0
  442. ctcp_version            db '] VERSION', 10, 0
  443. ctcp_ping               db '] PING', 10, 0
  444. ctcp_time               db '] TIME', 10, 0
  445.  
  446. has_left_channel        db ' has left ', 0
  447. joins_channel           db ' has joined ', 0
  448. is_now_known_as         db ' is now known as ', 0
  449. has_quit_irc            db ' has quit IRC', 10, 0
  450.  
  451. sets_mode               db ' sets mode ', 0
  452. str_kicked              db ' is kicked from ', 0
  453. str_by                  db ' by ', 0
  454. str_nickchange          db 'Nickname is now ', 0
  455. str_realchange          db 'Real name is now ', 0
  456. str_talking             db 'Now talking in ', 0
  457. str_topic               db 'Topic is "', 0
  458. str_topic_end           db '"', 10, 0
  459. str_setby               db 'Set by ', 0
  460.  
  461. str_connecting          db 3, '3* Connecting to ', 0
  462. str_sockerr             db 3, '5* Socket error', 10, 0
  463. str_dnserr              db 3, '5* Unable to resolve hostname', 10, 0
  464. str_refused             db 3, '5* Connection refused', 10, 0
  465. str_disconnected        db 3, '5* Server disconnected', 10, 0
  466. str_reconnect           db 3, '5* Connection reset by user', 10, 0
  467. str_notconnected        db 3, '5* Not connected to server', 10, 0
  468.  
  469. str_1                   db 3, '13 -', 0
  470. str_2                   db '- ', 0
  471.  
  472. str_list                db 'list', 0
  473.  
  474. str_help                db 'The following commands are available:', 10
  475.                         db 10
  476.                         db '/nick <nick>        : change nickname', 10
  477.                         db '/real <real name>   : change real name', 10
  478.                         db '/server <address>   : connect to server', 10
  479.                         db '/code <code>        : change codepage (cp866, cp1251, or utf8)', 10
  480.                         db '/join <channel>     : join a channel', 10
  481.                         db '/part <channel>     : part from a channel', 10
  482.                         db '/quit               : quit server', 10
  483.                         db '/msg <user>         : send a private message', 10
  484.                         db '/ctcp <user>        : send a message using client to client protocol', 10
  485.                         db 10
  486.                         db 'Other commands are send straight to server.', 10
  487.                         db 10, 0
  488.  
  489. str_welcome             db 3, '3 ___', 3, '7__________', 3, '6_________  ', 3, '4         __   __               __', 10
  490.                         db 3, '3|   \', 3, '7______   \', 3, '6_   ___ \ ', 3, '4   ____ |  | |__| ____   _____/  |_', 10
  491.                         db 3, '3|   |', 3, '7|       _/', 3, '6    \  \/ ', 3, '4 _/ ___\|  | |  |/ __ \ /    \   __\', 10
  492.                         db 3, '3|   |', 3, '7|    |   \', 3, '6     \____', 3, '4 \  \___|  |_|  \  ___/|   |  \  |', 10
  493.                         db 3, '3|___|', 3, '7|____|_  /', 3, '6\______  /', 3, '4  \___  >____/__|\___  >___|  /__|', 10
  494.                         db 3, '3     ', 3, '7       \/ ', 3, '6       \/ ', 3, '4      \/             \/     \/', 10
  495.                         db 10
  496.                         db 'Welcome to the KolibriOS IRC client v', version, 10
  497.                         db 10
  498.                         db 'Type /help for help', 10, 10, 0
  499.  
  500. str_version             db 'VERSION '
  501. str_programname         db 'KolibriOS IRC client v', version, 0
  502.  
  503. str_user                db 'user', 0
  504. str_nick                db 'nick', 0
  505. str_real                db 'realname', 0
  506. str_email               db 'email', 0
  507. str_quitmsg             db 'quitmsg', 0
  508.  
  509. default_nick            db 'kolibri_user', 0
  510. default_real            db 'Kolibri User', 0
  511. default_quit            db 'KolibriOS forever', 0
  512.  
  513. irc_colors              dd 0xffffff     ;  0 white
  514.                         dd 0x000000     ;  1 black
  515.                         dd 0x00007f     ;  2 blue (navy)
  516.                         dd 0x009300     ;  3 green
  517.                         dd 0xff0000     ;  4 red
  518.                         dd 0x7f0000     ;  5 brown (maroon)
  519.                         dd 0x9c009c     ;  6 purple
  520.                         dd 0xfc7f00     ;  7 olive
  521.                         dd 0xffff00     ;  8 yellow
  522.                         dd 0x00fc00     ;  9 light green
  523.                         dd 0x009393     ; 10 teal
  524.                         dd 0x00ffff     ; 11 cyan
  525.                         dd 0x0000fc     ; 12 royal blue
  526.                         dd 0xff00ff     ; 13 pink
  527.                         dd 0x7f7f7f     ; 14 grey
  528.                         dd 0xd4d0c4     ; 15 light grey (silver)
  529.  
  530. sockaddr1:
  531.         dw AF_INET4
  532. .port   dw 0x0b1a       ; 6667          FIXMEEEEEE
  533. .ip     dd 0
  534.         rb 10
  535.  
  536.  
  537. status                  dd STATUS_DISCONNECTED
  538.  
  539. window_active           dd windows
  540. window_print            dd windows
  541.  
  542. align 4
  543. @IMPORT:
  544.  
  545. library network,        'network.obj',\
  546.         libini,         'libini.obj',\
  547.         boxlib,         'box_lib.obj'
  548.  
  549. import  network,\
  550.         getaddrinfo,    'getaddrinfo',\
  551.         freeaddrinfo,   'freeaddrinfo',\
  552.         inet_ntoa,      'inet_ntoa'
  553.  
  554. import  libini,\
  555.         ini.get_str,    'ini_get_str',\
  556.         ini.get_int,    'ini_get_int'
  557.  
  558. import  boxlib,\
  559.         edit_box_draw,  'edit_box',\
  560.         edit_box_key,   'edit_box_key',\
  561.         edit_box_mouse, 'edit_box_mouse',\
  562.         scrollbar_draw, 'scrollbar_v_draw',\
  563.         scrollbar_mouse,'scrollbar_v_mouse'
  564.  
  565.         ;         width, left, top
  566. edit1   edit_box  0, 0, 0, 0xffffff, 0x6f9480, 0, 0, 0, USERCMD_MAX_SIZE, usercommand, mouse_dd, ed_always_focus, 25, 25
  567.         ;         xsize, xpos, ysize, ypos, btn_height, max, cur, pos, bgcol, frcol, linecol
  568. scroll1 scrollbar SCROLLBAR_WIDTH, 0, 0, TOP_Y, SCROLLBAR_WIDTH, 0, 0, 0, 0, 0, 0, 1
  569. scroll2 scrollbar SCROLLBAR_WIDTH, 0, 0, TOP_Y, SCROLLBAR_WIDTH, 0, 0, 0, 0, 0, 0, 1
  570.  
  571. usercommand     db '/server chat.freenode.net', 0
  572.                 rb MAX_COMMAND_LEN
  573.  
  574. I_END:
  575.  
  576. utf8_bytes_rest dd ?            ; bytes rest in current UTF8 sequence
  577. utf8_char       dd ?            ; first bits of current UTF8 character
  578.  
  579. packetbuf       rb 1024         ; buffer for packets to server
  580. path            rb 1024
  581. param           rb 1024
  582.  
  583. servercommand   rb 600
  584.  
  585. thread_info     process_information
  586. xsize           dd ?
  587. ysize           dd ?
  588. mouse_dd        dd ?
  589.  
  590. textbox_height  dd ?            ; in characters
  591. textbox_width   dd ?            ; in characters, not pixels ;)
  592.  
  593. colors          system_colors
  594.  
  595. irc_server_name rb MAX_SERVER_NAME      ; TODO: move this server URL into window struct
  596. socketnum       dd ?                    ; TODO: same for socket
  597.  
  598. user_nick       rb MAX_NICK_LEN
  599. user_real_name  rb MAX_REAL_LEN
  600. quit_msg        rb 250
  601.  
  602. windows         rb MAX_WINDOWS*sizeof.window
  603.  
  604. IM_END: