IRC-Client: first working version
This commit is contained in:
parent
65615dddc9
commit
8e4f23cf7c
|
@ -1123,7 +1123,7 @@ PUB lan_rxtime(handleidx, timeout): rxbyte
|
||||||
|
|
||||||
PUB lan_rxdata(handleidx, filename, len): error | fnr
|
PUB lan_rxdata(handleidx, filename, len): error | fnr
|
||||||
''funktionsgruppe : lan
|
''funktionsgruppe : lan
|
||||||
''funktion : bei bestehender Verbindung die angegebene Datenmenge empfangen
|
''funktion : bei bestehender Verbindung die angegebene Datenmenge in File der RAM-Disk schreiben
|
||||||
''eingabe : -
|
''eingabe : -
|
||||||
''ausgabe : -
|
''ausgabe : -
|
||||||
''busprotokoll : [078][put.handleidx][sub_putlong.len][get.byte1][get.byte<len>][get.error]
|
''busprotokoll : [078][put.handleidx][sub_putlong.len][get.byte1][get.byte<len>][get.error]
|
||||||
|
|
|
@ -58,12 +58,23 @@ LEN_USER = 32
|
||||||
LEN_CHAN = 32
|
LEN_CHAN = 32
|
||||||
LEN_IRCLINE = 512
|
LEN_IRCLINE = 512
|
||||||
|
|
||||||
|
CON 'NVRAM Konstanten --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#4, NVRAM_IPADDR
|
||||||
|
#8, NVRAM_IPMASK
|
||||||
|
#12, NVRAM_IPGW
|
||||||
|
#16, NVRAM_IPDNS
|
||||||
|
#20, NVRAM_IPBOOT
|
||||||
|
#24, NVRAM_HIVE ' 4 Bytes
|
||||||
|
|
||||||
VAR
|
VAR
|
||||||
|
|
||||||
long t1char 'Zeit, wann 1. Zeichen einer Zeile empfangen
|
long t1char 'Empfangs-Zeitpunkt des 1. Zeichen einer Zeile
|
||||||
long ip_addr
|
long ip_addr
|
||||||
|
long hiveid
|
||||||
word ip_port
|
word ip_port
|
||||||
word readpos
|
word readpos
|
||||||
|
word sendpos
|
||||||
byte handleidx 'Handle-Nummer IRC Verbindung
|
byte handleidx 'Handle-Nummer IRC Verbindung
|
||||||
byte rows,cols,vidmod
|
byte rows,cols,vidmod
|
||||||
byte x0[4],y0[4],xn[4],yn[4],hy[4],focus
|
byte x0[4],y0[4],xn[4],yn[4],hy[4],focus
|
||||||
|
@ -82,6 +93,8 @@ PUB main | key
|
||||||
key := ios.key
|
key := ios.key
|
||||||
case key
|
case key
|
||||||
gc#KEY_TAB: f_focus
|
gc#KEY_TAB: f_focus
|
||||||
|
gc#KEY_CURUP: f_scrollup
|
||||||
|
gc#KEY_CURDOWN: f_scrolldown
|
||||||
gc#KEY_F02: f_setconf
|
gc#KEY_F02: f_setconf
|
||||||
gc#KEY_F03: f_connect
|
gc#KEY_F03: f_connect
|
||||||
gc#KEY_F09: f_close
|
gc#KEY_F09: f_close
|
||||||
|
@ -92,10 +105,11 @@ PUB main | key
|
||||||
|
|
||||||
PRI init
|
PRI init
|
||||||
|
|
||||||
long[ip_addr] := 0
|
ip_addr := 0
|
||||||
word[ip_port] := 0
|
ip_port := 0
|
||||||
word[readpos] := 0
|
readpos := 0
|
||||||
byte[handleidx] := $FF
|
sendpos := 0
|
||||||
|
handleidx := $FF
|
||||||
password[0] := 0
|
password[0] := 0
|
||||||
nickname[0] := 0
|
nickname[0] := 0
|
||||||
username[0] := 0
|
username[0] := 0
|
||||||
|
@ -138,6 +152,12 @@ PRI conf_load | i
|
||||||
|
|
||||||
ios.sddmact(ios#DM_USER) 'u-marker aktivieren
|
ios.sddmact(ios#DM_USER) 'u-marker aktivieren
|
||||||
|
|
||||||
|
hiveid := ios.getNVSRAM(NVRAM_HIVE)
|
||||||
|
hiveid += ios.getNVSRAM(NVRAM_HIVE+1) << 8
|
||||||
|
hiveid += ios.getNVSRAM(NVRAM_HIVE+2) << 16
|
||||||
|
hiveid += ios.getNVSRAM(NVRAM_HIVE+3) << 24
|
||||||
|
|
||||||
|
|
||||||
PRI conf_save | i
|
PRI conf_save | i
|
||||||
|
|
||||||
ios.sddmset(ios#DM_USER) 'u-marker setzen
|
ios.sddmset(ios#DM_USER) 'u-marker setzen
|
||||||
|
@ -173,11 +193,20 @@ PRI f_focus
|
||||||
if ++focus == 4
|
if ++focus == 4
|
||||||
focus := 1
|
focus := 1
|
||||||
win_redraw
|
win_redraw
|
||||||
|
PRI f_scrollup
|
||||||
|
|
||||||
|
ios.winset(focus)
|
||||||
|
ios.scrollup
|
||||||
|
|
||||||
|
PRI f_scrolldown
|
||||||
|
|
||||||
|
ios.winset(focus)
|
||||||
|
ios.scrolldown
|
||||||
|
|
||||||
PRI f_setconf | i,n
|
PRI f_setconf | i,n
|
||||||
|
|
||||||
if ip_addr == 0
|
if ip_addr == 0
|
||||||
byte[temp_str][0] := 0
|
temp_str[0] := 0
|
||||||
else
|
else
|
||||||
IpPortToStr(ip_addr, ip_port)
|
IpPortToStr(ip_addr, ip_port)
|
||||||
input(string("IRC-Server angeben (IP:Port):"),@temp_str ,21)
|
input(string("IRC-Server angeben (IP:Port):"),@temp_str ,21)
|
||||||
|
@ -189,37 +218,37 @@ PRI f_setconf | i,n
|
||||||
n := 1
|
n := 1
|
||||||
repeat i from 0 to LEN_PASS
|
repeat i from 0 to LEN_PASS
|
||||||
if n == 0
|
if n == 0
|
||||||
byte[@password][i] := 0
|
password[i] := 0
|
||||||
else
|
else
|
||||||
n := byte[@input_str][i]
|
n := input_str[i]
|
||||||
byte[@password][i] := n
|
password[i] := n
|
||||||
|
|
||||||
input(string("Nickname eingeben:"),@nickname,LEN_NICK)
|
input(string("Nickname eingeben:"),@nickname,LEN_NICK)
|
||||||
n := 1
|
n := 1
|
||||||
repeat i from 0 to LEN_NICK
|
repeat i from 0 to LEN_NICK
|
||||||
if n == 0
|
if n == 0
|
||||||
byte[@nickname][i] := 0
|
nickname[i] := 0
|
||||||
else
|
else
|
||||||
n := byte[@input_str][i]
|
n := input_str[i]
|
||||||
byte[@nickname][i] := n
|
nickname[i] := n
|
||||||
|
|
||||||
input(string("Username eingeben:"),@username,LEN_USER)
|
input(string("Username eingeben:"),@username,LEN_USER)
|
||||||
n := 1
|
n := 1
|
||||||
repeat i from 0 to LEN_USER
|
repeat i from 0 to LEN_USER
|
||||||
if n == 0
|
if n == 0
|
||||||
byte[@username][i] := 0
|
username[i] := 0
|
||||||
else
|
else
|
||||||
n := byte[@input_str][i]
|
n := input_str[i]
|
||||||
byte[@username][i] := n
|
username[i] := n
|
||||||
|
|
||||||
input(string("Channel eingeben:"),@channel,LEN_CHAN)
|
input(string("Channel eingeben:"),@channel,LEN_CHAN)
|
||||||
n := 1
|
n := 1
|
||||||
repeat i from 0 to LEN_CHAN
|
repeat i from 0 to LEN_CHAN
|
||||||
if n == 0
|
if n == 0
|
||||||
byte[@channel][i] := 0
|
channel[i] := 0
|
||||||
else
|
else
|
||||||
n := byte[@input_str][i]
|
n := input_str[i]
|
||||||
byte[@channel][i] := n
|
channel[i] := n
|
||||||
|
|
||||||
win_redraw
|
win_redraw
|
||||||
|
|
||||||
|
@ -230,7 +259,7 @@ PRI f_connect | t
|
||||||
ios.winset(2)
|
ios.winset(2)
|
||||||
ios.print(string(10,"Starte LAN..."))
|
ios.print(string(10,"Starte LAN..."))
|
||||||
ios.lanstart
|
ios.lanstart
|
||||||
delay_ms(800) 'nach ios.lanstart dauert es, bis der Stack funktioniert
|
waitcnt(cnt + clkfreq) '1sek warten (nach ios.lanstart dauert es, bis der Stack funktioniert)
|
||||||
ios.print(string(10,"Verbinde mit IRC-Server..."))
|
ios.print(string(10,"Verbinde mit IRC-Server..."))
|
||||||
if (handleidx := ios.lan_connect(ip_addr, ip_port)) == $FF
|
if (handleidx := ios.lan_connect(ip_addr, ip_port)) == $FF
|
||||||
ios.print(string(10,"Kein Socket frei!"))
|
ios.print(string(10,"Kein Socket frei!"))
|
||||||
|
@ -241,9 +270,9 @@ PRI f_connect | t
|
||||||
return(-1)
|
return(-1)
|
||||||
ios.print(string(10,"Verbunden, warte auf Bereitschaft..."))
|
ios.print(string(10,"Verbunden, warte auf Bereitschaft..."))
|
||||||
|
|
||||||
' t := cnt
|
t := cnt
|
||||||
' repeat until (cnt - t) / (clkfreq / 1000) > 5000
|
repeat until (cnt - t) / clkfreq > 1 '1s lang Meldungen des Servers entgegennehmen
|
||||||
' irc_getline
|
irc_getline
|
||||||
|
|
||||||
irc_pass
|
irc_pass
|
||||||
irc_join
|
irc_join
|
||||||
|
@ -261,32 +290,32 @@ PRI f_quit
|
||||||
ios.screeninit
|
ios.screeninit
|
||||||
ios.stop
|
ios.stop
|
||||||
|
|
||||||
PRI f_input(key)| i
|
PRI f_input(key)
|
||||||
|
|
||||||
i := strsize(@send_str)
|
case key
|
||||||
|
$0d: if strsize(@send_str) > 0 'Zeilenende, absenden
|
||||||
|
irc_putLine
|
||||||
|
ios.winset(3)
|
||||||
|
ios.printnl
|
||||||
|
sendpos := 0
|
||||||
|
send_str[0] := 0
|
||||||
|
ios#CHAR_BS: if sendpos > 0 'backspace
|
||||||
ios.winset(3)
|
ios.winset(3)
|
||||||
if key == $0d
|
|
||||||
if sendStr(@send_str) || sendStr(string(13,10))
|
|
||||||
ios.printcls
|
|
||||||
ios.winset(1)
|
|
||||||
ios.printchar(10)
|
|
||||||
ios.print(@send_str)
|
|
||||||
byte[@send_str][0] := 0
|
|
||||||
if (key == ios#CHAR_BS)&(i>0) 'backspace
|
|
||||||
ios.printbs
|
ios.printbs
|
||||||
i--
|
sendpos--
|
||||||
byte[@send_str][i] := 0
|
send_str[sendpos] := 0
|
||||||
elseif i < LEN_IRCLINE-2 'normales zeichen
|
9 .. 13, 32 .. 255: if sendpos < LEN_IRCLINE-2 'normales zeichen
|
||||||
|
ios.winset(3)
|
||||||
ios.printchar(key)
|
ios.printchar(key)
|
||||||
byte[@send_str][i] := key
|
send_str[sendpos] := key
|
||||||
i++
|
sendpos++
|
||||||
byte[@send_str][i] := 0
|
send_str[sendpos] := 0
|
||||||
|
|
||||||
PRI irc_pass
|
PRI irc_pass
|
||||||
|
|
||||||
ios.winset(2)
|
ios.winset(2)
|
||||||
ios.print(string(10,"Sende Paßwort..."))
|
ios.print(string(10,"Sende Paßwort..."))
|
||||||
if sendStr(string("PASS ")) || sendStr(@password) || sendStr(string(13,10))
|
if sendStr(string("PASS ")) or sendStr(@password) or sendStr(string(13,10))
|
||||||
ios.print(string(10,"Fehler beim Senden des Paßwortes"))
|
ios.print(string(10,"Fehler beim Senden des Paßwortes"))
|
||||||
return(-1)
|
return(-1)
|
||||||
|
|
||||||
|
@ -294,37 +323,70 @@ PRI irc_join
|
||||||
|
|
||||||
ios.winset(2)
|
ios.winset(2)
|
||||||
ios.print(string(10,"Sende Nickname"))
|
ios.print(string(10,"Sende Nickname"))
|
||||||
if sendStr(string("NICK ")) || sendStr(@nickname) || sendStr(string(13,10))
|
if sendStr(string("NICK ")) or sendStr(@nickname) or sendStr(string(13,10))
|
||||||
ios.print(string(10,"Fehler beim Senden des Nicknamens"))
|
ios.print(string(10,"Fehler beim Senden des Nicknamens"))
|
||||||
return(-1)
|
return(-1)
|
||||||
|
|
||||||
ios.print(string(", Benutzerinformationen"))
|
ios.print(string(", Benutzerinformationen"))
|
||||||
if sendStr(string("USER ")) || sendStr(@username) || sendStr(string(" 0 * :Hive #",13,10))
|
if sendStr(string("USER ")) or sendStr(@username) or sendStr(string(" 8 * :Hive #")) or sendStr(str.trimCharacters(num.ToStr(hiveid, num#DEC))) or sendStr(string(13,10))
|
||||||
ios.print(string(10,"Fehler beim Senden des Nicknamens"))
|
ios.print(string(10,"Fehler beim Senden des Nicknamens"))
|
||||||
return(-1)
|
return(-1)
|
||||||
|
|
||||||
ifnot strsize(@channel) == 0
|
ifnot strsize(@channel) == 0
|
||||||
ios.winset(2)
|
ios.winset(2)
|
||||||
ios.print(string(" und verbinde mit Channel"))
|
ios.print(string(" und verbinde mit Channel"))
|
||||||
if sendStr(string("JOIN ")) || sendStr(@channel) || sendStr(string(13,10))
|
if sendStr(string("JOIN ")) or sendStr(@channel) or sendStr(string(13,10))
|
||||||
ios.print(string(10,"Fehler beim Verbinden mit dem Channel"))
|
ios.print(string(10,"Fehler beim Verbinden mit dem Channel"))
|
||||||
return(-1)
|
return(-1)
|
||||||
|
|
||||||
PRI irc_getLine
|
PRI irc_getLine | i, nickstr, chanstr, msgstr
|
||||||
|
|
||||||
if readLine(2000) 'vollständige Zeile empfangen
|
if readLine(2000) 'vollständige Zeile empfangen
|
||||||
|
|
||||||
if str.findCharacters(@receive_str, string("PING :")) == @receive_str
|
if (i := str.findCharacters(@receive_str, string("PRIVMSG "))) 'Chat Message
|
||||||
|
chanstr := i + 8
|
||||||
|
if (msgstr := str.replaceCharacter(chanstr, " ", 0))
|
||||||
|
msgstr++
|
||||||
|
nickstr := @receive_str[1]
|
||||||
|
if str.replaceCharacter(nickstr, "!", 0)
|
||||||
|
printChatStr(chanstr, nickstr, msgstr)
|
||||||
|
elseif str.findCharacters(@receive_str, string("PING :")) == @receive_str 'PING
|
||||||
ios.winset(2)
|
ios.winset(2)
|
||||||
ios.print(string(10,"PING erhalten, sende PONG"))
|
ios.print(string(10,"PING erhalten, sende PONG"))
|
||||||
receive_str[1] := "O"
|
receive_str[1] := "O"
|
||||||
sendStr(@receive_str)
|
sendStr(@receive_str)
|
||||||
sendStr(string(13,10))
|
sendStr(string(13,10))
|
||||||
else
|
else
|
||||||
ios.winset(1)
|
ios.winset(2)
|
||||||
ios.printchar(10)
|
ios.printchar(10)
|
||||||
ios.print(@receive_str)
|
ios.print(@receive_str)
|
||||||
|
|
||||||
|
PRI irc_putLine | i
|
||||||
|
|
||||||
|
if str.startsWithCharacters(@send_str, string("/set")) 'Einstellungen
|
||||||
|
f_setconf
|
||||||
|
elseif str.startsWithCharacters(@send_str, string("/msg")) 'Message an Nickname
|
||||||
|
sendStr(string("PRIVMSG "))
|
||||||
|
if (i := str.replaceCharacter(@send_str[5], " ", 0))
|
||||||
|
sendStr(@send_str[5])
|
||||||
|
sendStr(string(" :"))
|
||||||
|
sendStr(i)
|
||||||
|
sendStr(string(13,10))
|
||||||
|
printChatStr(@send_str[5], @nickname, i)
|
||||||
|
elseif send_str[0] == "/" 'anderes IRC-Kommando an Server
|
||||||
|
sendStr(@send_str[1])
|
||||||
|
sendStr(string(13,10))
|
||||||
|
ios.winset(1)
|
||||||
|
ios.printnl
|
||||||
|
ios.print(@send_str[1])
|
||||||
|
else 'Message an Channel
|
||||||
|
sendStr(string("PRIVMSG "))
|
||||||
|
sendStr(@channel)
|
||||||
|
sendStr(string(" :"))
|
||||||
|
sendStr(@send_str)
|
||||||
|
sendStr(string(13,10))
|
||||||
|
printChatStr(@channel, @nickname, @send_str)
|
||||||
|
|
||||||
PRI frame_draw
|
PRI frame_draw
|
||||||
|
|
||||||
ios.winset(0)
|
ios.winset(0)
|
||||||
|
@ -427,6 +489,25 @@ PRI setscreen
|
||||||
'Eingabe-Fenster (Nr. 4)
|
'Eingabe-Fenster (Nr. 4)
|
||||||
ios.windefine(4,13,10,47,13)
|
ios.windefine(4,13,10,47,13)
|
||||||
|
|
||||||
|
PRI printTime
|
||||||
|
|
||||||
|
ios.printchar("[")
|
||||||
|
ios.print(str.trimCharacters(str.numberToDecimal(ios.getHours, 2)))
|
||||||
|
ios.printchar(":")
|
||||||
|
ios.print(str.trimCharacters(str.numberToDecimal(ios.getMinutes, 2)))
|
||||||
|
ios.printchar("]")
|
||||||
|
|
||||||
|
PRI printChatStr(chanstr, nickstr, msgstr)
|
||||||
|
|
||||||
|
ios.winset(1)
|
||||||
|
ios.printnl
|
||||||
|
printTime
|
||||||
|
ios.print(nickstr)
|
||||||
|
ios.printchar(">")
|
||||||
|
ios.print(chanstr)
|
||||||
|
ios.print(string(": "))
|
||||||
|
ios.print(msgstr)
|
||||||
|
|
||||||
PRI strToIpPort(ipstr, ip, port) | octet
|
PRI strToIpPort(ipstr, ip, port) | octet
|
||||||
' extracts the IP and PORT from a string
|
' extracts the IP and PORT from a string
|
||||||
|
|
||||||
|
@ -515,27 +596,27 @@ PUB input(strdesc, strdef, input_len) | i,n
|
||||||
byte[@input_str][i] := 0
|
byte[@input_str][i] := 0
|
||||||
ios.curoff
|
ios.curoff
|
||||||
|
|
||||||
PRI readLine(timeout) : complete | ch
|
PRI readLine(timeout) : ch
|
||||||
|
|
||||||
complete := FALSE
|
|
||||||
ifnot (ch := ios.lan_rxbyte(handleidx)) == -1
|
ifnot (ch := ios.lan_rxbyte(handleidx)) == -1
|
||||||
if readpos == 0 '1. Zeichen einer Zeile empfangen
|
if readpos == 0 '1. Zeichen einer Zeile empfangen
|
||||||
t1char := cnt
|
t1char := cnt
|
||||||
if (ch == 10) and receive_str[readpos-1] == 13 'Zeilenende
|
if (ch == 10) and receive_str[readpos-1] == 13 'Zeilenende
|
||||||
receive_str[readpos-1] := 0
|
receive_str[readpos-1] := 0
|
||||||
readpos := 0
|
readpos := 0
|
||||||
complete := TRUE
|
return(TRUE)
|
||||||
return(complete)
|
|
||||||
receive_str[readpos++] := ch
|
receive_str[readpos++] := ch
|
||||||
if readpos == LEN_IRCLINE-1 'max. Zeilenlänge
|
if readpos == LEN_IRCLINE-1 'max. Zeilenlänge erreicht
|
||||||
receive_str[readpos] := 0
|
receive_str[readpos] := 0
|
||||||
readpos := 0
|
readpos := 0
|
||||||
complete := TRUE
|
return(TRUE)
|
||||||
return(complete)
|
|
||||||
if (readpos <> 0) and ((cnt - t1char) / (clkfreq / 1000) > timeout) 'Timeout seit Empfang 1. Zeichen
|
if (readpos <> 0) and ((cnt - t1char) / (clkfreq / 1000) > timeout) 'Timeout seit Empfang 1. Zeichen
|
||||||
receive_str[readpos] := 0
|
receive_str[readpos] := 0
|
||||||
readpos := 0
|
readpos := 0
|
||||||
complete := TRUE
|
return(TRUE)
|
||||||
|
|
||||||
|
return(FALSE)
|
||||||
|
|
||||||
PRI sendStr (strSend) : error
|
PRI sendStr (strSend) : error
|
||||||
|
|
||||||
|
@ -544,10 +625,6 @@ PRI sendStr (strSend) : error
|
||||||
' ios.printnl
|
' ios.printnl
|
||||||
error := ios.lan_txdata(handleidx, strSend, strsize(strSend))
|
error := ios.lan_txdata(handleidx, strSend, strsize(strSend))
|
||||||
|
|
||||||
PRI delay_ms(Duration)
|
|
||||||
waitcnt(clkfreq/1000*Duration + cnt)
|
|
||||||
|
|
||||||
|
|
||||||
DAT
|
DAT
|
||||||
|
|
||||||
strWin1 byte "Chat",0
|
strWin1 byte "Chat",0
|
||||||
|
|
Loading…
Reference in New Issue