From e6a093acf4ce06ddd5da1ce23f5439bbf957d828 Mon Sep 17 00:00:00 2001 From: Joerg Deckert Date: Sun, 29 Dec 2013 20:05:15 +0100 Subject: [PATCH] IRC-Client: GUI enhancement --- system/regnatix/irc.spin | 206 +++++++++++++++++++++++++++++++++++---- 1 file changed, 185 insertions(+), 21 deletions(-) diff --git a/system/regnatix/irc.spin b/system/regnatix/irc.spin index a19cb42..d47aeca 100644 --- a/system/regnatix/irc.spin +++ b/system/regnatix/irc.spin @@ -50,13 +50,21 @@ COL_DEFAULT = 0 COL_MENU = 8 COL_FOCUS = 3 +LEN_PASS =32 +LEN_NICK =32 +LEN_USER =32 +LEN_CHAN =32 + VAR long ip_addr word ip_port + byte handleidx 'Handle-Nummer IRC Verbindung byte rows,cols,vidmod byte x0[4],y0[4],xn[4],yn[4],hy[4],focus + byte password[LEN_PASS+1],nickname[LEN_NICK+1],username[LEN_USER+1],channel[LEN_CHAN+1] byte input_str[64] + byte temp_str[64] PUB main | key @@ -66,16 +74,82 @@ PUB main | key key := ios.keywait case key gc#KEY_TAB: f_focus - gc#KEY_F02: f_setserver + gc#KEY_F02: f_setconf + gc#KEY_F03: f_connect gc#KEY_F10: f_quit PRI init + long[ip_addr] := 0 + word[ip_port] := 0 + password[0] := 0 + nickname[0] := 0 + username[0] := 0 + channel[0] := 0 focus := 3 ios.start 'ios initialisieren setscreen + conf_load + if ip_addr == 0 + f_setconf + +PRI conf_load | i + + ios.sddmset(ios#DM_USER) 'u-marker setzen + ios.sddmact(ios#DM_SYSTEM) 's-marker aktivieren + + ifnot ios.sdopen("R",@strConfFile) + ip_addr := ios.sdgetc << 24 + ip_addr += ios.sdgetc << 16 + ip_addr += ios.sdgetc << 8 + ip_addr += ios.sdgetc + ip_port := ios.sdgetc << 8 + ip_port += ios.sdgetc + + repeat i from 0 to LEN_PASS + password[i] := ios.sdgetc + repeat i from 0 to LEN_NICK + nickname[i] := ios.sdgetc + repeat i from 0 to LEN_USER + username[i] := ios.sdgetc + repeat i from 0 to LEN_CHAN + channel[i] := ios.sdgetc + + ios.sdclose + + ios.sddmact(ios#DM_USER) 'u-marker aktivieren + +PRI conf_save | i + + ios.sddmset(ios#DM_USER) 'u-marker setzen + ios.sddmact(ios#DM_SYSTEM) 's-marker aktivieren + + ios.sdnewfile(@strConfFile) + ifnot ios.sdopen("W",@strConfFile) + ios.sdputc(ip_addr >> 24) + ios.sdputc(ip_addr >> 16) + ios.sdputc(ip_addr >> 8) + ios.sdputc(ip_addr ) + ios.sdputc(ip_port >> 8) + ios.sdputc(ip_port ) + + repeat i from 0 to LEN_PASS + ios.sdputc(password[i]) + repeat i from 0 to LEN_NICK + ios.sdputc(nickname[i]) + repeat i from 0 to LEN_USER + ios.sdputc(username[i]) + repeat i from 0 to LEN_CHAN + ios.sdputc(channel[i]) + + ios.sdclose + + ios.sddmact(ios#DM_USER) 'u-marker aktivieren + + ios.winset(2) + ios.print(string(10,"Konfiguration gespeichert.")) PRI f_focus @@ -83,20 +157,70 @@ PRI f_focus focus := 1 win_redraw -PRI f_setserver +PRI f_setconf | i,n - input(string("IRC-Server angeben (IP:Port):"),21) - win_redraw - ios.winset(2) - ios.print(string("Verbinde mit ")) - ios.print(@input_str) - ios.print(string("...",10)) - - if strToIpPort(@input_str, ip_addr, ip_port) - ios.print(string("Wandlung erfolgreich",10)) + if ip_addr == 0 + byte[temp_str][0] := 0 else - ios.print(string("Wandlung fehlgeschlagen",10)) + IpPortToStr(ip_addr, ip_port) + input(string("IRC-Server angeben (IP:Port):"),@temp_str ,21) + ifnot strToIpPort(@input_str, @ip_addr, @ip_port) + ios.winset(2) + ios.print(string(10,"Fehlerhafte Eingabe von IP-Adresse und Port des IRC-Servers.")) + input(string("Paßwort eingeben:"),@password,LEN_PASS) + n := 1 + repeat i from 0 to LEN_PASS + if n == 0 + byte[@password][i] := 0 + else + n := byte[@input_str][i] + byte[@password][i] := n + + input(string("Nickname eingeben:"),@nickname,LEN_NICK) + n := 1 + repeat i from 0 to LEN_NICK + if n == 0 + byte[@nickname][i] := 0 + else + n := byte[@input_str][i] + byte[@nickname][i] := n + + input(string("Username eingeben:"),@username,LEN_USER) + n := 1 + repeat i from 0 to LEN_USER + if n == 0 + byte[@username][i] := 0 + else + n := byte[@input_str][i] + byte[@username][i] := n + + input(string("Channel eingeben:"),@channel,LEN_CHAN) + n := 1 + repeat i from 0 to LEN_CHAN + if n == 0 + byte[@channel][i] := 0 + else + n := byte[@input_str][i] + byte[@channel][i] := n + + win_redraw + + conf_save + +PRI f_connect + + ios.winset(2) + ios.print(string(10,"Starte LAN...")) + ios.lanstart + ios.print(string(10,"Verbinde mit IRC-Server...")) + if (handleidx := ios.lan_connect(ip_addr, ip_port)) == $FF + ios.print(string(10,"Kein Socket frei!")) + return(-1) + ifnot (ios.lan_waitconntimeout(handleidx, 2000)) + ios.print(string(10,"Verbindung mit IRC-Server konnte nicht aufgebaut werden.")) + return(-1) + ios.print(string(10,"Verbindung mit IRC-Server hergestellt")) PRI f_quit @@ -112,8 +236,9 @@ PRI frame_draw ios.cursetx(W0X_MENU) ios.cursety(W0Y_MENU) ios.setcolor(COL_MENU) -' ios.print(string(" ")) - ios.print(string(" IRC Client ")) + ios.print(string(" IRC Client")) + repeat cols-W0X_MENU-11 + ios.printchar(" ") ios.printlogo(0,0) ios.setcolor(COL_DEFAULT) @@ -199,7 +324,7 @@ PRI setscreen win_draw 'Eingabe-Fenster (Nr. 4) - ios.windefine(4,15,10,45,13) + ios.windefine(4,13,10,47,13) PRI strToIpPort(ipstr, ip, port) | octet ' extracts the IP and PORT from a string @@ -230,7 +355,25 @@ PRI strToIpPort(ipstr, ip, port) | octet return true -PUB input(stradr, input_len) | key,bnr +PRI IpPortToStr(ip, port) | i,n,x,stradr + ' IP-Adresse und Port stehen dann in temp_str + + n := 0 + repeat i from 3 to 0 + stradr := str.trimCharacters(num.ToStr(byte[@ip][i], num#DEC)) + x := 0 + repeat strsize(stradr) + byte[@temp_str][n++] := byte[stradr][x++] + if(i) + byte[@temp_str][n++] := "." + byte[@temp_str][n++] := ":" + stradr := str.trimCharacters(num.ToStr(port, num#DEC)) + x := 0 + repeat strsize(stradr) + byte[@temp_str][n++] := byte[stradr][x++] + byte[@temp_str][n] := 0 + +PUB input(strdesc, strdef, input_len) | i,n input_str[0] := 0 ios.winset(4) @@ -240,7 +383,7 @@ PUB input(stradr, input_len) | key,bnr ios.curoff ios.setcolor(COL_DEFAULT) ios.printchar(" ") - ios.print(stradr) + ios.print(strdesc) ios.printnl ios.printnl ios.printchar(" ") @@ -248,8 +391,27 @@ PUB input(stradr, input_len) | key,bnr ios.printchar("_") ios.curpos1 ios.printchar(" ") + i := 0 + repeat strsize(strdef) 'Vorgabewert in strdef eintragen + n := byte[strdef+i] + ios.printchar(n) + byte[@input_str][i] := n + i++ + byte[@input_str][i] := 0 ios.curon - ios.input(@input_str,input_len) + repeat 'entspricht ab hier ios.input + n := ios.keywait 'auf taste warten + if n == $0d + quit + if (n == ios#CHAR_BS)&(i>0) 'backspace + ios.printbs + i-- + byte[@input_str][i] := 0 + elseif i < input_len 'normales zeichen + ios.printchar(n) + byte[@input_str][i] := n + i++ + byte[@input_str][i] := 0 ios.curoff PRI delay_ms(Duration) @@ -257,9 +419,11 @@ PRI delay_ms(Duration) DAT -strWin1 byte "Chat",0 -strWin2 byte "Status",0 -strWin3 byte "Eingabe",0 +strWin1 byte "Chat",0 +strWin2 byte "Status",0 +strWin3 byte "Eingabe",0 + +strConfFile byte "irc.cfg",0 DAT 'lizenz