Rev 3981 | Rev 4659 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3981 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;; |
||
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;; ;; |
||
4143 | hidnplayr | 6 | ;; Written by hidnplayr@kolibrios.org ;; |
3981 | hidnplayr | 7 | ;; ;; |
8 | ;; GNU GENERAL PUBLIC LICENSE ;; |
||
9 | ;; Version 2, June 1991 ;; |
||
10 | ;; ;; |
||
11 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
3545 | hidnplayr | 12 | |
4143 | hidnplayr | 13 | ; TODO: work correctly with user prefixes. |
14 | ; use first byte of nick for prefix ONLY (use a space for those that do not have special powers..) |
||
3545 | hidnplayr | 15 | |
4143 | hidnplayr | 16 | user_prefixes db '~&@%+ ', 0 ; in descending order |
17 | |||
3545 | hidnplayr | 18 | ; esi is ptr to nick |
19 | ; ebx is ptr to window |
||
20 | align 4 |
||
21 | user_add: |
||
22 | |||
23 | cmp [ebx + window.users], MAX_USERS |
||
24 | jae fail |
||
25 | |||
26 | mov edi, [ebx + window.data_ptr] |
||
27 | add edi, window_data.names |
||
28 | mov ebp, [ebx + window.users] |
||
4143 | hidnplayr | 29 | inc ebp ; CHECKME |
3545 | hidnplayr | 30 | |
31 | push esi edi |
||
32 | .restart: |
||
33 | mov ecx, MAX_NICK_LEN |
||
34 | .loop1: |
||
35 | lodsb |
||
36 | cmp al, '@' |
||
37 | jne @f |
||
38 | mov al, ' ' ; give @ highest priority |
||
39 | @@: |
||
40 | cmp al, 'A' |
||
41 | jb @f |
||
42 | cmp al, 'Z' |
||
43 | ja @f |
||
44 | add al, 'a' - 'A' ; convert to lowercase |
||
45 | @@: |
||
46 | dec ecx |
||
47 | jz .got_it |
||
48 | |||
49 | .loop2: |
||
50 | mov dl, [edi] |
||
51 | cmp dl, 0 |
||
52 | je .got_it |
||
53 | cmp dl, '@' |
||
54 | jne @f |
||
55 | mov dl, ' ' ; give @ highest priority |
||
56 | @@: |
||
57 | cmp dl, 'A' |
||
58 | jb @f |
||
59 | cmp dl, 'Z' |
||
60 | ja @f |
||
61 | add dl, 'a' - 'A' ; convert to lowercase |
||
62 | @@: |
||
63 | cmp al, dl |
||
64 | jb .got_it |
||
65 | je .check_next |
||
66 | |||
67 | pop edi esi |
||
68 | add edi, MAX_NICK_LEN |
||
69 | push esi edi |
||
70 | |||
71 | dec ebp |
||
72 | jnz .restart |
||
73 | |||
74 | .check_next: |
||
75 | inc edi |
||
76 | jmp .loop1 |
||
77 | |||
78 | .got_it: |
||
79 | pop edi esi |
||
80 | |||
81 | ; OK, insert it here.. |
||
82 | |||
83 | ; mov all trailing usernames by MAX_NICK_LEN bytes |
||
84 | push esi edi |
||
85 | mov esi, [ebx + window.data_ptr] |
||
4143 | hidnplayr | 86 | add esi, window_data.names + MAX_NICK_LEN * (MAX_USERS - 1) - 4 ; -4 because we're copying backward, dword wise |
3545 | hidnplayr | 87 | mov ecx, esi |
88 | sub ecx, edi |
||
89 | add ecx, MAX_NICK_LEN |
||
90 | shr ecx, 2 |
||
91 | lea edi, [esi + MAX_NICK_LEN] |
||
92 | std |
||
93 | rep movsd |
||
94 | cld |
||
95 | pop edi esi |
||
96 | |||
97 | ; Now insert our new username |
||
98 | mov ecx, MAX_NICK_LEN-1 |
||
99 | .fill: |
||
100 | lodsb |
||
101 | cmp al, ' ' |
||
102 | je .done |
||
103 | cmp al, '!' |
||
104 | je .done |
||
4143 | hidnplayr | 105 | cmp al, 13 |
106 | je .done |
||
107 | cmp al, 10 |
||
108 | je .done |
||
3545 | hidnplayr | 109 | stosb |
110 | loop .fill |
||
111 | .done: |
||
112 | xor al, al |
||
113 | stosb |
||
114 | |||
115 | inc [ebx + window.users] |
||
4143 | hidnplayr | 116 | or [ebx + window.flags], FLAG_UPDATED |
3545 | hidnplayr | 117 | |
118 | ret |
||
119 | |||
120 | |||
121 | |||
122 | |||
123 | |||
124 | ; esi is ptr to nick |
||
125 | ; ebx is ptr to window |
||
126 | align 4 |
||
127 | user_remove: |
||
128 | |||
129 | call user_find |
||
130 | jz fail |
||
131 | |||
132 | lea esi, [edi + MAX_NICK_LEN] |
||
133 | mov ecx, [ebx + window.data_ptr] |
||
134 | add ecx, window_data.names + MAX_NICK_LEN * MAX_USERS |
||
135 | sub ecx, esi |
||
136 | shr ecx, 2 |
||
137 | rep movsd |
||
138 | |||
139 | dec [ebx + window.users] |
||
4143 | hidnplayr | 140 | or [ebx + window.flags], FLAG_UPDATED |
3545 | hidnplayr | 141 | |
142 | ret |
||
143 | |||
144 | |||
145 | |||
146 | ; IN: |
||
147 | ; esi is ptr to nick |
||
148 | ; ebx is ptr to window |
||
149 | ; OUT: |
||
150 | ; edi is ptr to nick in userlist |
||
151 | align 4 |
||
152 | user_find: |
||
153 | |||
154 | mov eax, [ebx + window.users] |
||
155 | test eax, eax |
||
156 | jz fail |
||
157 | mov edi, [ebx + window.data_ptr] |
||
158 | add edi, window_data.names |
||
159 | |||
160 | .loop: |
||
161 | push esi edi |
||
162 | mov ecx, MAX_NICK_LEN |
||
163 | repe cmpsb |
||
164 | cmp byte[edi-1], 0 |
||
165 | je .got_it |
||
166 | ; TODO: check byte[esi] too! |
||
167 | pop edi esi |
||
168 | add edi, MAX_NICK_LEN |
||
169 | dec eax |
||
170 | jnz .loop |
||
171 | jmp fail |
||
172 | |||
173 | .got_it: |
||
174 | pop edi esi |
||
175 | test edi, edi ; to clear zero flag |
||
176 | |||
177 | ret |
||
178 | |||
179 | |||
180 | fail: |
||
181 | |||
182 | xor edi, edi |
||
183 | ret |