Subversion Repositories Kolibri OS

Rev

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

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