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