Rev 3226 | 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 |
||
3222 | hidnplayr | 27 | FLAG_RECEIVING_NAMES = 1 shl 2 |
3191 | hidnplayr | 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 |
||
3216 | hidnplayr | 45 | WIN_MIN_Y = 180 |
3191 | hidnplayr | 46 | |
47 | TEXT_X = 5 |
||
48 | TEXT_Y = 45 |
||
49 | |||
50 | TOP_Y = 40 |
||
51 | |||
52 | MAX_WINDOWS = 20 |
||
3222 | hidnplayr | 53 | MAX_USERS = 4096 |
3191 | hidnplayr | 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 | |||
3215 | hidnplayr | 72 | USERLIST_X = 98 |
3191 | hidnplayr | 73 | |
3215 | hidnplayr | 74 | |
3191 | hidnplayr | 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 |
||
3226 | hidnplayr | 87 | dd param |
3191 | hidnplayr | 88 | dd path |
89 | |||
90 | include "../macros.inc" |
||
91 | include "../proc32.inc" |
||
92 | include "../dll.inc" |
||
93 | include "../network.inc" |
||
94 | include "../struct.inc" |
||
95 | include '../../../../../programs/develop/libraries/box_lib/trunk/box_lib.mac' |
||
96 | |||
97 | struct window |
||
98 | data_ptr dd ? ; zero if not used |
||
99 | flags db ? |
||
100 | type db ? |
||
101 | name rb MAX_WINDOWNAME_LEN |
||
3215 | hidnplayr | 102 | users dd ? |
103 | users_scroll dd ? |
||
3191 | hidnplayr | 104 | ends |
105 | |||
106 | struct window_data |
||
107 | text rb 120*60 |
||
108 | title rb 256 |
||
3222 | hidnplayr | 109 | names rb MAX_NICK_LEN * MAX_USERS |
3191 | hidnplayr | 110 | usertext rb 256 |
111 | usertextlen dd ? |
||
112 | ends |
||
113 | |||
114 | include "encodings.inc" |
||
115 | include "window.inc" ; also contains text print routines |
||
116 | include "serverparser.inc" |
||
117 | include "userparser.inc" |
||
118 | include "socket.inc" |
||
119 | include "gui.inc" |
||
3233 | hidnplayr | 120 | include "users.inc" |
3191 | hidnplayr | 121 | |
122 | |||
123 | START: |
||
124 | |||
125 | mcall 68, 11 ; init heap so we can allocate memory dynamically |
||
126 | |||
127 | ; wanted events |
||
128 | mcall 40, EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_STACK + EVM_MOUSE |
||
129 | |||
130 | ; load libraries |
||
131 | stdcall dll.Load, @IMPORT |
||
132 | test eax, eax |
||
133 | jnz exit |
||
134 | |||
135 | ; find path to main settings file (ircc.ini) |
||
136 | mov edi, path ; Calculate the length of zero-terminated string |
||
137 | xor al, al |
||
138 | mov ecx, 1024 |
||
139 | repne scasb |
||
140 | dec edi |
||
141 | mov eax, '.ini' |
||
142 | stosd |
||
143 | xor al, al |
||
144 | stosb |
||
145 | |||
146 | ; Fill the window buffer with zeros |
||
147 | mov edi, windows |
||
148 | mov ecx, (sizeof.window*MAX_WINDOWS+3)/4 |
||
149 | xor eax, eax |
||
150 | rep stosd |
||
151 | |||
152 | ; clear command area too |
||
153 | mov edi, servercommand |
||
154 | mov ecx, 600/4 |
||
155 | rep stosd |
||
156 | |||
157 | ; allocate window data block |
||
158 | call window_create |
||
159 | mov ebx, windows |
||
160 | mov [ebx + window.data_ptr], eax |
||
161 | mov [ebx + window.flags], 0 |
||
162 | mov [ebx + window.type], WINDOWTYPE_SERVER |
||
163 | add eax, window_data.text |
||
164 | mov [text_start], eax |
||
165 | |||
166 | call window_refresh |
||
167 | |||
168 | ; get system colors |
||
169 | mcall 48, 3, colors, 40 |
||
170 | |||
171 | ; set edit box and scrollbar colors |
||
172 | |||
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 | sub ax, WINDOW_BTN_START |
||
235 | jb exit |
||
236 | |||
237 | cmp ax, MAX_WINDOWS |
||
238 | ja exit |
||
239 | |||
240 | mov dx, sizeof.window |
||
241 | mul dx |
||
242 | shl edx, 16 |
||
243 | mov dx, ax |
||
244 | add edx, windows |
||
245 | cmp [edx + window.data_ptr], 0 |
||
246 | je exit |
||
247 | mov [window_open], edx |
||
248 | call window_refresh |
||
249 | call draw_window |
||
250 | |||
251 | jmp still |
||
252 | exit: |
||
253 | mcall -1 |
||
254 | |||
255 | |||
256 | |||
257 | main_window_key: |
||
258 | |||
259 | mcall 2 |
||
260 | |||
261 | push dword edit1 |
||
262 | call [edit_box_key] |
||
263 | |||
264 | cmp ah, 13 ; enter |
||
265 | jne no_send2 |
||
266 | |||
267 | call user_parser |
||
268 | |||
269 | mov [edit1.size], 0 |
||
270 | mov [edit1.pos], 0 |
||
271 | |||
272 | push dword edit1 |
||
273 | call [edit_box_draw] |
||
274 | |||
275 | mov edx, [window_open] |
||
276 | mov edx, [edx + window.data_ptr] |
||
277 | add edx, window_data.text |
||
278 | call draw_channel_text |
||
279 | |||
280 | jmp still |
||
281 | no_send2: |
||
282 | |||
283 | jmp still |
||
284 | |||
285 | mouse: |
||
286 | push dword edit1 |
||
287 | call [edit_box_mouse] |
||
288 | |||
3220 | hidnplayr | 289 | ; TODO: check if scrollbar is active |
3191 | hidnplayr | 290 | push dword scroll1 |
291 | call [scrollbar_v_mouse] |
||
292 | |||
3215 | hidnplayr | 293 | ; TODO: check if scrollbar moved |
3220 | hidnplayr | 294 | call print_channel_list |
3215 | hidnplayr | 295 | |
3191 | hidnplayr | 296 | jmp still |
297 | |||
298 | |||
299 | ; DATA AREA |
||
300 | |||
301 | encoding_text: |
||
302 | db 'CP866 ' |
||
303 | db 'CP1251' |
||
304 | db 'UTF-8 ' |
||
305 | encoding_text_len = 6 |
||
306 | |||
307 | action_header db '*** ', 0 |
||
308 | action_header_short db '* ', 0 |
||
309 | ctcp_header db '-> [',0 |
||
310 | ctcp_version db '] VERSION',10,0 |
||
311 | ctcp_ping db '] PING',10,0 |
||
312 | ctcp_time db '] TIME',10,0 |
||
313 | has_left_channel db ' has left ', 0 |
||
314 | joins_channel db ' has joined ', 0 |
||
315 | is_now_known_as db ' is now known as ', 0 |
||
3222 | hidnplayr | 316 | has_quit_irc db ' has quit IRC', 10, 0 |
3191 | hidnplayr | 317 | sets_mode db ' sets mode ', 0 |
318 | kicked db ' is kicked from ', 0 |
||
319 | str_talking db 'Now talking in ',0 |
||
320 | str_topic db 'Topic is ',0 |
||
321 | str_setby db 'Set by ',0 |
||
322 | |||
323 | str_version db 'VERSION ' |
||
324 | str_programname db 'KolibriOS IRC client ', version, 0 |
||
325 | |||
326 | str_user db 'user', 0 |
||
327 | str_nick db 'nick', 0 |
||
328 | str_real db 'realname', 0 |
||
329 | str_email db 'email', 0 |
||
330 | |||
331 | default_nick db 'kolibri_user', 0 |
||
332 | default_real db 'Kolibri User', 0 |
||
333 | |||
334 | str_welcome db 10 |
||
3226 | hidnplayr | 335 | db ' ______________________ __ __ __',10 |
3191 | hidnplayr | 336 | db '| \______ \_ ___ \ ____ | | |__| ____ _____/ |_',10 |
337 | db '| || _/ \ \/ _/ ___\| | | |/ __ \ / \ __\',10 |
||
338 | db '| || | \ \____ \ \___| |_| \ ___/| | \ |',10 |
||
339 | db '|___||____|_ /\______ / \___ >____/__|\___ >___| /__|',10 |
||
340 | db ' \/ \/ \/ \/ \/',10 |
||
341 | db 10 |
||
342 | db 'Welcome to IRC client ',version,' for KolibriOS',10 |
||
343 | db 10 |
||
344 | db 'Type /help for help',10,0 |
||
345 | |||
3233 | hidnplayr | 346 | str_nickchange db 'Nickname is now ',0 |
347 | str_realchange db 'Real name is now ',0 |
||
3191 | hidnplayr | 348 | str_dotnewline db '.',10, 0 |
349 | str_newline db 10, 0 |
||
350 | str_connecting db 10,'* Connecting to ',0 |
||
351 | str_help db 10,'following commands are available:',10 |
||
352 | db 10 |
||
353 | db '/nick |
||
354 | db '/real |
||
355 | db '/server : connect to server ',10 |
||
356 | db '/code |
||
357 | |||
358 | str_1 db ' -',0 |
||
359 | str_2 db '- ',0 |
||
360 | |||
361 | str_sockerr db 'Socket Error',10,0 |
||
362 | str_dnserr db 'Unable to resolve hostname.',10,0 |
||
363 | str_refused db 'Connection refused',10,0 |
||
364 | |||
365 | sockaddr1: |
||
366 | dw AF_INET4 |
||
367 | .port dw 0x0b1a ; 6667 |
||
368 | .ip dd 0 |
||
369 | rb 10 |
||
370 | |||
371 | |||
372 | status dd STATUS_DISCONNECTED |
||
373 | |||
374 | channel_line_sun dd 0x9999ff |
||
375 | channel_line_shadow dd 0x666699 |
||
376 | index_list_2 dd 0x0000ff |
||
377 | |||
378 | text_start dd ? ; pointer to current textbox data |
||
379 | irc_data dd 0x0 ; encoder |
||
380 | textbox_width dd 80 ; in characters, not pixels ;) |
||
381 | pos dd 66 * 11 ; encoder |
||
382 | |||
383 | window_open dd windows |
||
384 | window_print dd windows |
||
385 | |||
386 | scroll dd 1 |
||
387 | dd 12 |
||
388 | |||
389 | align 4 |
||
390 | @IMPORT: |
||
391 | |||
392 | library network, 'network.obj',\ |
||
393 | libini, 'libini.obj',\ |
||
394 | boxlib, 'box_lib.obj' |
||
395 | |||
396 | import network,\ |
||
397 | getaddrinfo, 'getaddrinfo',\ |
||
398 | freeaddrinfo, 'freeaddrinfo',\ |
||
399 | inet_ntoa, 'inet_ntoa' |
||
400 | |||
401 | import libini,\ |
||
402 | ini.get_str, 'ini_get_str',\ |
||
3226 | hidnplayr | 403 | ini.get_int, 'ini_get_int' |
3191 | hidnplayr | 404 | |
405 | import boxlib,\ |
||
406 | edit_box_draw ,'edit_box' ,\ |
||
407 | edit_box_key ,'edit_box_key' ,\ |
||
408 | edit_box_mouse ,'edit_box_mouse' ,\ |
||
409 | scrollbar_v_draw ,'scrollbar_v_draw' ,\ |
||
410 | scrollbar_v_mouse,'scrollbar_v_mouse' |
||
411 | |||
412 | |||
413 | usercommand db '/server chat.freenode.net', 0 |
||
414 | rb MAX_COMMAND_LEN |
||
415 | |||
416 | I_END: |
||
417 | |||
418 | ; width, left, top |
||
3215 | hidnplayr | 419 | edit1 edit_box 0, 0, 0, 0xffffff, 0x6f9480, 0, 0, 0, USERCMD_MAX_SIZE, usercommand, mouse_dd, ed_focus, 25, 25 |
3191 | hidnplayr | 420 | ; xsize, xpos, ysize, ypos, max, cur, pos, bgcol, frcol, linecol |
3220 | hidnplayr | 421 | scroll1 scrollbar SCROLLBAR_WIDTH, 300, 150, TOP_Y, 10, 100, 0, 0, 0, 0, 0, 1 |
3191 | hidnplayr | 422 | |
423 | |||
3226 | hidnplayr | 424 | main_PID dd ? ; identifier of main thread |
425 | utf8_bytes_rest dd ? ; bytes rest in current UTF8 sequence |
||
426 | utf8_char dd ? ; first bits of current UTF8 character |
||
427 | gai_reqdata rb 32 ; buffer for getaddrinfo_start/process |
||
428 | ip_list dd ? ; will be filled as pointer to addrinfo list |
||
429 | packetbuf rb 1024 ; buffer for packets to server |
||
3191 | hidnplayr | 430 | path rb 1024 |
3226 | hidnplayr | 431 | param rb 1024 |
3191 | hidnplayr | 432 | |
433 | socketnum dd ? |
||
434 | |||
435 | servercommand rb 600 |
||
436 | |||
437 | thread_info rb 1024 |
||
438 | xsize dd ? |
||
439 | ysize dd ? |
||
440 | |||
441 | colors system_colors |
||
442 | |||
443 | irc_server_name rb MAX_SERVER_NAME |
||
444 | |||
445 | user_nick rb MAX_NICK_LEN |
||
446 | user_real_name rb MAX_REAL_LEN |
||
447 | |||
448 | windows rb MAX_WINDOWS*sizeof.window |
||
449 | |||
450 | mouse_dd dd ? |
||
451 | |||
452 | IM_END: |
||
453 |