Subversion Repositories Kolibri OS

Rev

Rev 3549 | Rev 3949 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3545 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2013. 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.1'
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_CLOSE              = 1 shl 1
27
FLAG_RECEIVING_NAMES    = 1 shl 2
28
 
29
; window types
30
WINDOWTYPE_SERVER       = 0
31
WINDOWTYPE_CHANNEL      = 1
32
WINDOWTYPE_CHAT         = 2
33
WINDOWTYPE_LIST         = 3
34
WINDOWTYPE_DCC          = 4
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               = 165
46
 
47
TEXT_X                  = 5
48
TEXT_Y                  = 30
49
 
50
TOP_Y                   = 25
51
 
52
MAX_WINDOWS             = 20
53
MAX_USERS               = 4096
54
 
55
MAX_NICK_LEN            = 32
56
MAX_REAL_LEN            = 32    ; realname
57
MAX_SERVER_NAME         = 256
58
 
59
MAX_CHANNEL_LEN         = 40
60
MAX_CHANNELS            = 37
61
 
62
MAX_COMMAND_LEN         = 512
63
 
64
TIMESTAMP               = 3     ; 3 = hh:mm:ss, 2 = hh:mm, 0 = no timestamp
65
 
66
MAX_WINDOWNAME_LEN      = 256
67
 
68
WINDOW_BTN_START        = 100
69
 
70
SCROLLBAR_WIDTH         = 12
71
 
72
USERLIST_X              = 98
73
 
74
 
75
format binary as ""
76
 
77
use32
78
 
79
        org     0x0
80
 
81
        db      'MENUET01'              ; 8 byte id
82
        dd      1                       ; header version
83
        dd      START                   ; program start
84
        dd      I_END                   ; program image size
85
        dd      IM_END+2048             ; required amount of memory
86
        dd      IM_END+2048
87
        dd      param
88
        dd      path
89
 
3618 hidnplayr 90
include "../../macros.inc"
91
include "../../proc32.inc"
92
include "../../dll.inc"
93
include "../../network.inc"
94
include "../../struct.inc"
3549 yogev_ezra 95
include '../../develop/libraries/box_lib/trunk/box_lib.mac'
3545 hidnplayr 96
 
97
struct  window
98
        data_ptr        dd ?            ; zero if not used
99
        flags           db ?
100
        type            db ?
101
        name            rb MAX_WINDOWNAME_LEN
102
        users           dd ?
103
        users_scroll    dd ?
104
        selected        dd ?            ; selected user, 0 if none selected
105
ends
106
 
107
struct  window_data
108
        text            rb 120*60
109
        title           rb 256
110
        names           rb MAX_NICK_LEN * MAX_USERS
111
        usertext        rb 256
112
        usertextlen     dd ?
113
ends
114
 
115
include "encodings.inc"
116
include "window.inc"                    ; also contains text print routines
117
include "serverparser.inc"
118
include "userparser.inc"
119
include "socket.inc"
120
include "gui.inc"
121
include "users.inc"
122
 
123
 
124
START:
125
 
126
        mcall   68, 11                  ; init heap so we can allocate memory dynamically
127
 
128
; wanted events
129
        mcall   40, EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_STACK + EVM_MOUSE
130
 
131
; load libraries
132
        stdcall dll.Load, @IMPORT
133
        test    eax, eax
134
        jnz     exit
135
 
136
; find path to main settings file (ircc.ini)
137
        mov     edi, path               ; Calculate the length of zero-terminated string
138
        xor     al, al
139
        mov     ecx, 1024
140
        repne   scasb
141
        dec     edi
142
        mov     eax, '.ini'
143
        stosd
144
        xor     al, al
145
        stosb
146
 
147
; Fill the window buffer with zeros
148
        mov     edi, windows
149
        mov     ecx, (sizeof.window*MAX_WINDOWS+3)/4
150
        xor     eax, eax
151
        rep     stosd
152
 
153
; clear command area too
154
        mov     edi, servercommand
155
        mov     ecx, 600/4
156
        rep     stosd
157
 
158
; allocate window data block
159
        call    window_create
160
        mov     ebx, windows
161
        mov     [ebx + window.data_ptr], eax
162
        mov     [ebx + window.flags], 0
163
        mov     [ebx + window.type], WINDOWTYPE_SERVER
164
        add     eax, window_data.text
165
        mov     [text_start], eax
166
 
167
        call    window_refresh
168
 
169
; get system colors
170
        mcall   48, 3, colors, 40
171
 
172
; set edit box and scrollbar colors
173
        mov     eax, [colors.work]
174
        mov     [scroll1.bg_color], eax
175
 
176
        mov     eax, [colors.work_button]
177
        mov     [scroll1.front_color], eax
178
 
179
        mov     eax, [colors.work_text]
180
        mov     [scroll1.line_color], eax
181
 
182
; get settings from ini
183
        invoke  ini.get_str, path, str_user, str_nick, user_nick, MAX_NICK_LEN, default_nick
184
        invoke  ini.get_str, path, str_user, str_real, user_real_name, MAX_REAL_LEN, default_real
185
 
186
; Welcome user
187
        mov     esi, str_welcome
188
        call    print_text2
189
 
190
        call    draw_window ;;; FIXME (gui is not correctly drawn first time)
191
 
192
redraw:
193
        call    draw_window
194
 
195
still:
196
 
197
; wait here for event
198
        mcall   10
199
 
200
        dec     eax
201
        jz      redraw
202
 
203
        dec     eax
204
        jz      main_window_key
205
 
206
        dec     eax
207
        jz      button
208
 
209
        cmp     al, 3
210
        je      mouse
211
 
212
        call    process_network_event
213
 
214
        mov     edx, [window_open]
215
        test    [edx + window.flags], FLAG_UPDATED
216
        jz      .no_update
217
        and     [edx + window.flags], not FLAG_UPDATED
218
        mov     edx, [edx + window.data_ptr]
219
        add     edx, window_data.text
220
        call    draw_channel_text
221
  .no_update:
222
        call    print_channel_list
223
 
224
        jmp     still
225
 
226
button:
227
 
228
        mcall   17              ; get id
229
        shr     eax, 8
230
 
231
        cmp     ax, 1           ; close program
232
        je      exit
233
 
234
        cmp     ax, 50
235
        jne     @f
236
 
237
        mcall   37, 1           ; Get mouse position
238
        sub     ax, TEXT_Y
239
        mov     bl, 10
240
        div     bl
241
        and     eax, 0x000000ff
242
        inc     eax
243
        add     eax, [scroll1.position]
244
        mov     ebx, [window_open]
245
        mov     [ebx + window.selected], eax
246
 
247
        call    print_channel_list
248
 
249
        jmp     still
250
 
251
  @@:
252
        sub     ax, WINDOW_BTN_START
253
        jb      exit
254
 
255
        cmp     ax, MAX_WINDOWS
256
        ja      exit
257
 
258
        mov     dx, sizeof.window
259
        mul     dx
260
        shl     edx, 16
261
        mov     dx, ax
262
        add     edx, windows
263
        cmp     [edx + window.data_ptr], 0
264
        je      exit
265
        mov     [window_open], edx
266
        call    window_refresh
267
        call    draw_window
268
 
269
        jmp     still
270
exit:
271
        mcall   -1
272
 
273
 
274
 
275
main_window_key:
276
 
277
        mcall   2
278
 
279
        push    dword edit1
280
        call    [edit_box_key]
281
 
282
        cmp     ah, 13          ; enter
283
        jne     no_send2
284
 
285
        call    user_parser
286
 
287
        mov     [edit1.size], 0
288
        mov     [edit1.pos], 0
289
 
290
        push    dword edit1
291
        call    [edit_box_draw]
292
 
293
        mov     edx, [window_open]
294
        mov     edx, [edx + window.data_ptr]
295
        add     edx, window_data.text
296
        call    draw_channel_text
297
 
298
        jmp     still
299
  no_send2:
300
 
301
        jmp     still
302
 
303
mouse:
304
        push    dword edit1
305
        call    [edit_box_mouse]
306
 
307
; TODO: check if scrollbar is active
308
        push    [scroll1.position]
309
        push    dword scroll1
310
        call    [scrollbar_v_mouse]
311
        pop     eax
312
        cmp     eax, [scroll1.position] ; did the scrollbar move?
313
        je      @f
314
        call    print_channel_list
315
  @@:
316
 
317
        jmp     still
318
 
319
 
320
; DATA AREA
321
 
322
encoding_text:
323
db      'CP866 '
324
db      'CP1251'
325
db      'UTF-8 '
326
encoding_text_len = 6
327
 
328
action_header           db '*** ', 0
329
action_header_short     db '* ', 0
330
ctcp_header             db '-> [',0
331
ctcp_version            db '] VERSION',10,0
332
ctcp_ping               db '] PING',10,0
333
ctcp_time               db '] TIME',10,0
334
has_left_channel        db ' has left ', 0
335
joins_channel           db ' has joined ', 0
336
is_now_known_as         db ' is now known as ', 0
337
has_quit_irc            db ' has quit IRC', 10, 0
338
sets_mode               db ' sets mode ', 0
339
kicked                  db ' is kicked from ', 0
340
str_talking             db 'Now talking in ',0
341
str_topic               db 'Topic is ',0
342
str_setby               db 'Set by ',0
343
 
344
str_version             db 'VERSION '
345
str_programname         db 'KolibriOS IRC client ', version, 0
346
 
347
str_user                db 'user', 0
348
str_nick                db 'nick', 0
349
str_real                db 'realname', 0
350
str_email               db 'email', 0
351
 
352
default_nick            db 'kolibri_user', 0
353
default_real            db 'Kolibri User', 0
354
 
355
str_welcome             db 10
356
                        db ' ______________________           __   __               __',10
357
                        db '|   \______   \_   ___ \    ____ |  | |__| ____   _____/  |_',10
358
                        db '|   ||       _/    \  \/  _/ ___\|  | |  |/ __ \ /    \   __\',10
359
                        db '|   ||    |   \     \____ \  \___|  |_|  \  ___/|   |  \  |',10
360
                        db '|___||____|_  /\______  /  \___  >____/__|\___  >___|  /__|',10
361
                        db '            \/        \/       \/             \/     \/',10
362
                        db 10
363
                        db 'Welcome to IRC client ',version,' for KolibriOS',10
364
                        db 10
365
                        db 'Type /help for help',10,0
366
 
367
str_nickchange          db 'Nickname is now ',0
368
str_realchange          db 'Real name is now ',0
369
str_dotnewline          db '.',10, 0
370
str_newline             db 10, 0
371
str_connecting          db 10,'* Connecting to ',0
372
str_help                db 10,'following commands are available:',10
373
                        db 10
374
                        db '/nick         : change nickname to ',10
375
                        db '/real    : change real name to ',10
376
                        db '/server 
: connect to server
',10
377
                        db '/code         : change codepage to cp866, cp1251, or utf8',10,0
378
 
379
str_1                   db ' -',0
380
str_2                   db '- ',0
381
 
382
str_sockerr             db 'Socket Error',10,0
383
str_dnserr              db 'Unable to resolve hostname.',10,0
384
str_refused             db 'Connection refused',10,0
385
 
386
sockaddr1:
387
        dw AF_INET4
388
.port   dw 0x0b1a       ; 6667
389
.ip     dd 0
390
        rb 10
391
 
392
 
393
status                  dd STATUS_DISCONNECTED
394
 
395
text_start              dd ?                    ; pointer to current textbox data
396
irc_data                dd 0x0                  ; encoder
397
textbox_width           dd 80                   ; in characters, not pixels ;)
398
pos                     dd 66 * 11              ; encoder
399
 
400
window_open             dd windows
401
window_print            dd windows
402
 
403
scroll                  dd 1
404
                        dd 12
405
 
406
align 4
407
@IMPORT:
408
 
409
library network,        'network.obj',\
410
        libini,         'libini.obj',\
411
        boxlib,         'box_lib.obj'
412
 
413
import  network,\
414
        getaddrinfo,    'getaddrinfo',\
415
        freeaddrinfo,   'freeaddrinfo',\
416
        inet_ntoa,      'inet_ntoa'
417
 
418
import  libini,\
419
        ini.get_str,    'ini_get_str',\
420
        ini.get_int,    'ini_get_int'
421
 
422
import  boxlib,\
423
        edit_box_draw    ,'edit_box'            ,\
424
        edit_box_key     ,'edit_box_key'        ,\
425
        edit_box_mouse   ,'edit_box_mouse'      ,\
426
        scrollbar_v_draw ,'scrollbar_v_draw'    ,\
427
        scrollbar_v_mouse,'scrollbar_v_mouse'
428
 
429
I_END:
430
 
431
        ;         width, left, top
432
edit1   edit_box  0, 0, 0, 0xffffff, 0x6f9480, 0, 0, 0, USERCMD_MAX_SIZE, usercommand, mouse_dd, ed_focus, 25, 25
433
        ;         xsize, xpos, ysize, ypos, max, cur, pos, bgcol, frcol, linecol
434
scroll1 scrollbar SCROLLBAR_WIDTH, 300, 150, TOP_Y, 10, 100, 0, 0, 0, 0, 0, 1
435
scroll2 scrollbar SCROLLBAR_WIDTH, 300, 150, TOP_Y, 10, 100, 0, 0, 0, 0, 0, 1
436
 
3618 hidnplayr 437
usercommand     db '/server chat.freenode.net', 0
438
                rb MAX_COMMAND_LEN
439
 
3545 hidnplayr 440
main_PID        dd ?            ; identifier of main thread
441
utf8_bytes_rest dd ?            ; bytes rest in current UTF8 sequence
442
utf8_char       dd ?            ; first bits of current UTF8 character
443
gai_reqdata     rb 32           ; buffer for getaddrinfo_start/process
444
ip_list         dd ?            ; will be filled as pointer to addrinfo list
445
packetbuf       rb 1024         ; buffer for packets to server
446
path            rb 1024
447
param           rb 1024
448
 
449
socketnum       dd ?
450
 
451
servercommand   rb 600
452
 
453
thread_info     rb 1024
454
xsize           dd ?
455
ysize           dd ?
456
 
457
colors          system_colors
458
 
459
irc_server_name rb MAX_SERVER_NAME
460
 
461
user_nick       rb MAX_NICK_LEN
462
user_real_name  rb MAX_REAL_LEN
463
 
464
windows         rb MAX_WINDOWS*sizeof.window
465
 
466
mouse_dd        dd ?
467
 
468
IM_END:
469