Added alphabetic sorting for users in IRCc

git-svn-id: svn://kolibrios.org@3233 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2013-02-07 13:29:24 +00:00
parent 5690f9671b
commit 1373a38089
4 changed files with 219 additions and 51 deletions

View File

@ -261,7 +261,7 @@ draw_windownames:
inc edx inc edx
add ebx, 125 shl 16 add ebx, 125 shl 16
add edi, sizeof.window add edi, sizeof.window
cmp [edi + + window.data_ptr], 0 cmp [edi + window.data_ptr], 0
jne .more_btn jne .more_btn
mov eax, 4 mov eax, 4

View File

@ -117,6 +117,7 @@ include "serverparser.inc"
include "userparser.inc" include "userparser.inc"
include "socket.inc" include "socket.inc"
include "gui.inc" include "gui.inc"
include "users.inc"
START: START:
@ -154,7 +155,6 @@ START:
rep stosd rep stosd
; allocate window data block ; allocate window data block
call window_create call window_create
mov ebx, windows mov ebx, windows
mov [ebx + window.data_ptr], eax mov [ebx + window.data_ptr], eax
@ -343,8 +343,8 @@ str_welcome db 10
db 10 db 10
db 'Type /help for help',10,0 db 'Type /help for help',10,0
str_nickchange db 10,'Nickname is now ',0 str_nickchange db 'Nickname is now ',0
str_realchange db 10,'Real name is now ',0 str_realchange db 'Real name is now ',0
str_dotnewline db '.',10, 0 str_dotnewline db '.',10, 0
str_newline db 10, 0 str_newline db 10, 0
str_connecting db 10,'* Connecting to ',0 str_connecting db 10,'* Connecting to ',0

View File

@ -303,6 +303,7 @@ end if
ret ret
.action: .action:
add esi, 8
push esi push esi
if TIMESTAMP if TIMESTAMP
call print_timestamp call print_timestamp
@ -319,7 +320,6 @@ end if
call print_character call print_character
pop esi pop esi
add esi, 8
call print_text2 call print_text2
mov bl, 10 mov bl, 10
@ -513,8 +513,9 @@ cmd_part:
mov esi, str_newline mov esi, str_newline
call print_text2 call print_text2
;;; TODO: dec [window.users], remove username from the userlist mov ebx, [window_print]
mov esi, servercommand+1
call user_remove
ret ret
@ -595,7 +596,9 @@ cmd_join:
mov esi, str_newline mov esi, str_newline
call print_text2 call print_text2
;;; TODO: inc [window.users], add username to the userlist mov ebx, [window_print]
mov esi, servercommand+1
call user_add
ret ret
@ -606,10 +609,27 @@ cmd_nick:
; NOTE: This command applies to a user, and thus has no specific channel ; NOTE: This command applies to a user, and thus has no specific channel
add esi, 5 ; skip 'NICK ' add esi, 5 ; skip 'NICK '
cmp byte[esi], ':' ; TODO: skip all spaces and semicolons?
jne @f
inc esi
@@:
; Change the nick in the current userlist. TODO: check other channels too!
push esi push esi
mov ebx, [window_print]
mov esi, servercommand+1
call user_remove
mov esi, [esp]
call user_add
call redraw_channel_list
; Is it me who changed nick? ; Is it me who changed nick?
mov edi, servercommand+1 mov edi, servercommand+1
call compare_to_nick call compare_to_nick
pop esi
jne .not_me jne .not_me
mov ecx, MAX_NICK_LEN-1 mov ecx, MAX_NICK_LEN-1
@ -627,11 +647,9 @@ cmd_nick:
xor al, al xor al, al
stosb stosb
pop esi pop esi
.not_me: .not_me:
; TODO: if we reach here: change nick in userlist(s) ; Now print a message on the current channel
push esi push esi
mov esi, action_header_short mov esi, action_header_short
call print_text2 call print_text2
@ -685,7 +703,9 @@ cmd_kick:
mov esi, str_newline mov esi, str_newline
call print_text2 call print_text2
;;; TODO: dec [window.users], remove username from the userlist mov ebx, [window_print]
mov esi, servercommand+1
call user_remove
ret ret
@ -704,7 +724,10 @@ cmd_quit:
mov esi, has_quit_irc mov esi, has_quit_irc
call print_text2 call print_text2
;;; TODO: dec [window.users], remove username from the userlist ; TODO: check other channels on same server too!
mov ebx, [window_print]
mov esi, servercommand+1
call user_remove
ret ret
@ -747,47 +770,24 @@ cmd_353: ; channel usernames reply
; now find window ptr and check if this is the first 353 message ; now find window ptr and check if this is the first 353 message
mov ebx, [window_print] mov ebx, [window_print]
test [ebx + window.flags], FLAG_RECEIVING_NAMES test [ebx + window.flags], FLAG_RECEIVING_NAMES
jnz .start jnz .add
or [ebx + window.flags], FLAG_RECEIVING_NAMES or [ebx + window.flags], FLAG_RECEIVING_NAMES
mov [ebx + window.users], 0 ; mov [ebx + window.users], 0
; TODO: remove all users?
.start: .add:
mov eax, [ebx + window.users] push esi
xor edx, edx call user_add
mov ecx, MAX_NICK_LEN pop esi
mul ecx
; eax is now offset
add eax, [ebx + window.data_ptr]
lea edi, [eax + window_data.names]
mov edx, edi
lea ecx, [eax + window_data.names]
add ecx, MAX_NICK_LEN + MAX_USERS
.newname:
cmp edi, ecx ; check buffer overflow
jae .done
inc [ebx + window.users]
.namesloop: .namesloop:
lodsb lodsb
test al, al test al, al
jz .done jz .done
cmp al, ' ' ; names list is separated with spaces cmp al, ' ' ; names list is separated with spaces
je .next jne .namesloop
stosb jmp .add
jmp .namesloop
.next:
add edx, MAX_NICK_LEN
mov edi, edx
.loop3:
lodsb
test al, al
jz .done
cmp al, ' '
je .loop3
stosb
jmp .newname
.done: .done:
call redraw_channel_list call redraw_channel_list
@ -807,10 +807,11 @@ cmd_366: ; channel usernames end
mov ebx, [window_print] mov ebx, [window_print]
and [ebx + window.flags], not FLAG_RECEIVING_NAMES and [ebx + window.flags], not FLAG_RECEIVING_NAMES
ret ret
cmd_topic: cmd_topic:
add esi, 4 ; skip '332 ' add esi, 4 ; skip '332 '
@ -830,7 +831,6 @@ cmd_topic:
mov esi, str_newline mov esi, str_newline
call print_text2 call print_text2
.fail:
ret ret
@ -857,8 +857,12 @@ cmd_333:
mov esi, str_setby mov esi, str_setby
call print_text2 call print_text2
pop esi ; pop esi
call print_text2 ; call print_text2
pop eax
mov dl, '!'
call print_text
mov esi, str_newline mov esi, str_newline
call print_text2 call print_text2

View File

@ -0,0 +1,164 @@
; esi is ptr to nick
; ebx is ptr to window
align 4
user_add:
cmp [ebx + window.users], MAX_USERS
jae fail
mov edi, [ebx + window.data_ptr]
add edi, window_data.names
mov ebp, [ebx + window.users]
inc ebp ; CHECKME
push esi edi
.restart:
mov ecx, MAX_NICK_LEN
.loop1:
lodsb
cmp al, '@'
jne @f
mov al, ' ' ; give @ highest priority
@@:
cmp al, 'A'
jb @f
cmp al, 'Z'
ja @f
add al, 'a' - 'A' ; convert to lowercase
@@:
dec ecx
jz .got_it
.loop2:
mov dl, [edi]
cmp dl, 0
je .got_it
cmp dl, '@'
jne @f
mov dl, ' ' ; give @ highest priority
@@:
cmp dl, 'A'
jb @f
cmp dl, 'Z'
ja @f
add dl, 'a' - 'A' ; convert to lowercase
@@:
cmp al, dl
jb .got_it
je .check_next
pop edi esi
add edi, MAX_NICK_LEN
push esi edi
dec ebp
jnz .restart
.check_next:
inc edi
jmp .loop1
.got_it:
pop edi esi
; OK, insert it here..
; mov all trailing usernames by MAX_NICK_LEN bytes
push esi edi
mov esi, [ebx + window.data_ptr]
add esi, window_data.names + MAX_NICK_LEN * (MAX_USERS - 1)
mov ecx, esi
sub ecx, edi
add ecx, MAX_NICK_LEN
shr ecx, 2
lea edi, [esi + MAX_NICK_LEN]
std
rep movsd
cld
pop edi esi
; Now insert our new username
mov ecx, MAX_NICK_LEN-1
.fill:
lodsb
cmp al, ' '
je .done
cmp al, '!'
je .done
stosb
loop .fill
.done:
xor al, al
stosb
inc [ebx + window.users]
ret
; esi is ptr to nick
; ebx is ptr to window
align 4
user_remove:
call user_find
jz fail
lea esi, [edi + MAX_NICK_LEN]
mov ecx, [ebx + window.data_ptr]
add ecx, window_data.names + MAX_NICK_LEN * MAX_USERS
sub ecx, esi
shr ecx, 2
rep movsd
dec [ebx + window.users]
xor eax, eax
ret
; IN:
; esi is ptr to nick
; ebx is ptr to window
; OUT:
; edi is ptr to nick in userlist
align 4
user_find:
mov eax, [ebx + window.users]
test eax, eax
jz fail
mov edi, [ebx + window.data_ptr]
add edi, window_data.names
.loop:
push esi edi
mov ecx, MAX_NICK_LEN
repe cmpsb
cmp byte[edi-1], 0
je .got_it
; TODO: check byte[esi] too!
pop edi esi
add edi, MAX_NICK_LEN
dec eax
jnz .loop
jmp fail
.got_it:
pop edi esi
test edi, edi ; to clear zero flag
ret
fail:
xor edi, edi
ret