IRC-Client: connect to server
This commit is contained in:
parent
e6a093acf4
commit
65615dddc9
|
@ -172,7 +172,8 @@ A_AYS = %00000000_00000000_00000010_00000000
|
|||
a_lanClose 'TCP-Verbindung schließen
|
||||
a_lanRXTime 'bestimmte Zeit warten auf Byte aus Empfangspuffer
|
||||
a_lanRXData 'Daten aus Empfangspuffer lesen
|
||||
a_lanTXData '79 'Daten senden
|
||||
a_lanTXData 'Daten senden
|
||||
a_lanRXByte '80 'wenn vorhanden, Byte aus Empfangspuffer lesen
|
||||
|
||||
' ---------------------------------------------- CHIP-MANAGMENT
|
||||
#92, a_mgrSetSound 'soundsubsysteme verwalten
|
||||
|
|
|
@ -1166,6 +1166,22 @@ PUB lan_txdata(handleidx, ptr, len): error
|
|||
error := bus_getchar1
|
||||
error := ~error
|
||||
|
||||
PUB lan_rxbyte(handleidx): rxbyte
|
||||
''funktionsgruppe : lan
|
||||
''funktion : wenn vorhanden, ein empfangenes Byte lesen
|
||||
'' : nicht verwenden, wenn auch $FF empfangen werden kann
|
||||
''eingabe : -
|
||||
''ausgabe : -
|
||||
''busprotokoll : [080][sub_putlong.handleidx]][get.rxbyte]
|
||||
'' : handleidx - lfd. Nr. der Verbindung
|
||||
'' : rxbyte - empfangenes Zeichen oder
|
||||
'' : sock#RETBUFFEREMPTY (-1) wenn Empfangspuffer leer
|
||||
|
||||
bus_putchar1(gc#a_lanRXByte)
|
||||
bus_putchar1(handleidx)
|
||||
rxbyte := bus_getchar1
|
||||
rxbyte := ~rxbyte
|
||||
|
||||
CON ''------------------------------------------------- Hydra Sound System
|
||||
|
||||
PUB hss_playfile(stradr) | status 'hss: spielt übergebene hss-datei von sd-card
|
||||
|
|
|
@ -299,6 +299,7 @@ PUB main | cmd,err 'chip: kommandointerpret
|
|||
gc#a_lanRXTime: lan_rxtime 'bestimmte Zeit warten auf Byte aus Empfangspuffer
|
||||
gc#a_lanRXData: lan_rxdata 'Daten aus Empfangspuffer lesen
|
||||
gc#a_lanTXData: lan_txdata 'Daten senden
|
||||
gc#a_lanRXByte: lan_rxbyte 'wenn vorhanden, Byte aus Empfangspuffer lesen
|
||||
|
||||
' ---------------------------------------------- CHIP-MANAGMENT
|
||||
gc#a_mgrGetSpec: mgr_getspec 'spezifikation abfragen
|
||||
|
@ -1334,6 +1335,19 @@ PRI lan_txdata | handleidx, len, txbyte, error
|
|||
|
||||
bus_putchar(error)
|
||||
|
||||
PRI lan_rxbyte
|
||||
''funktionsgruppe : lan
|
||||
''funktion : wenn vorhanden, ein empfangenes Byte lesen
|
||||
'' : nicht verwenden, wenn auch $FF empfangen werden kann
|
||||
''eingabe : -
|
||||
''ausgabe : -
|
||||
''busprotokoll : [080][get.handleidx][put.rxbyte]
|
||||
'' : handleidx - lfd. Nr. der Verbindung
|
||||
'' : rxbyte - empfangenes Zeichen oder
|
||||
'' : sock#RETBUFFEREMPTY (-1) wenn kein Zeichen vorhanden
|
||||
|
||||
bus_putchar(sock.readByteNonBlocking(sockhandle[bus_getchar]))
|
||||
|
||||
DAT
|
||||
long ' long alignment for addresses
|
||||
ip_addr byte 10, 1, 1, 1 'ip
|
||||
|
|
|
@ -40,6 +40,8 @@ CON
|
|||
_CLKMODE = XTAL1 + PLL16X
|
||||
_XINFREQ = 5_000_000
|
||||
|
||||
LANMASK = %00000000_00000000_00000000_00100000
|
||||
|
||||
VAR
|
||||
|
||||
long ip_addr
|
||||
|
@ -57,7 +59,10 @@ PUB main
|
|||
remdir[0] := 0
|
||||
filename[0] := 0
|
||||
|
||||
ios.start 'ios initialisieren
|
||||
ios.start
|
||||
ifnot (ios.admgetspec & LANMASK)
|
||||
ios.print(string(10,"Administra stellt keine Netzwerk-Funktionen zur Verfügung!",10,"Bitte admnet laden.",10))
|
||||
ios.stop
|
||||
ios.printnl
|
||||
ios.parastart 'parameterübergabe starten
|
||||
repeat while ios.paranext(@parastr) 'parameter einlesen
|
||||
|
@ -112,12 +117,12 @@ PRI ftpconnect
|
|||
|
||||
PRI ftpclose
|
||||
|
||||
if handleidx_control
|
||||
ifnot handleidx_control == $FF
|
||||
ios.lan_close(handleidx_control)
|
||||
handleidx_control := 0
|
||||
if handleidx_data
|
||||
handleidx_control := $FF
|
||||
ifnot handleidx_data == $FF
|
||||
ios.lan_close(handleidx_data)
|
||||
handleidx_data := 0
|
||||
handleidx_data := $FF
|
||||
|
||||
PRI ftplogin(username, password) | pwreq, respOK
|
||||
|
||||
|
|
|
@ -43,6 +43,8 @@ _XINFREQ = 5_000_000
|
|||
|
||||
CON
|
||||
|
||||
LANMASK = %00000000_00000000_00000000_00100000
|
||||
|
||||
W0X_MENU = 8
|
||||
W0Y_MENU = 0
|
||||
|
||||
|
@ -54,42 +56,57 @@ LEN_PASS =32
|
|||
LEN_NICK = 32
|
||||
LEN_USER = 32
|
||||
LEN_CHAN = 32
|
||||
LEN_IRCLINE = 512
|
||||
|
||||
VAR
|
||||
|
||||
long t1char 'Zeit, wann 1. Zeichen einer Zeile empfangen
|
||||
long ip_addr
|
||||
word ip_port
|
||||
word readpos
|
||||
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]
|
||||
byte send_str[LEN_IRCLINE]
|
||||
byte receive_str[LEN_IRCLINE]
|
||||
|
||||
PUB main | key
|
||||
|
||||
init
|
||||
|
||||
repeat
|
||||
key := ios.keywait
|
||||
if ios.keystat > 0
|
||||
key := ios.key
|
||||
case key
|
||||
gc#KEY_TAB: f_focus
|
||||
gc#KEY_F02: f_setconf
|
||||
gc#KEY_F03: f_connect
|
||||
gc#KEY_F09: f_close
|
||||
gc#KEY_F10: f_quit
|
||||
|
||||
other: f_input(key)
|
||||
ifnot handleidx == $FF
|
||||
irc_getLine
|
||||
|
||||
PRI init
|
||||
|
||||
long[ip_addr] := 0
|
||||
word[ip_port] := 0
|
||||
word[readpos] := 0
|
||||
byte[handleidx] := $FF
|
||||
password[0] := 0
|
||||
nickname[0] := 0
|
||||
username[0] := 0
|
||||
channel[0] := 0
|
||||
send_str[0] := 0
|
||||
focus := 3
|
||||
|
||||
ios.start 'ios initialisieren
|
||||
ifnot (ios.admgetspec & LANMASK)
|
||||
ios.print(string(10,"Administra stellt keine Netzwerk-Funktionen zur Verfügung!",10,"Bitte admnet laden.",10))
|
||||
ios.stop
|
||||
setscreen
|
||||
conf_load
|
||||
if ip_addr == 0
|
||||
|
@ -208,26 +225,106 @@ PRI f_setconf | i,n
|
|||
|
||||
conf_save
|
||||
|
||||
PRI f_connect
|
||||
PRI f_connect | t
|
||||
|
||||
ios.winset(2)
|
||||
ios.print(string(10,"Starte LAN..."))
|
||||
ios.lanstart
|
||||
delay_ms(800) 'nach ios.lanstart dauert es, bis der Stack funktioniert
|
||||
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."))
|
||||
f_close
|
||||
return(-1)
|
||||
ios.print(string(10,"Verbindung mit IRC-Server hergestellt"))
|
||||
ios.print(string(10,"Verbunden, warte auf Bereitschaft..."))
|
||||
|
||||
' t := cnt
|
||||
' repeat until (cnt - t) / (clkfreq / 1000) > 5000
|
||||
' irc_getline
|
||||
|
||||
irc_pass
|
||||
irc_join
|
||||
|
||||
PRI f_close
|
||||
|
||||
ifnot handleidx == $FF
|
||||
ios.lan_close(handleidx)
|
||||
handleidx := $FF
|
||||
|
||||
PRI f_quit
|
||||
|
||||
f_close
|
||||
ios.winset(0)
|
||||
ios.screeninit
|
||||
ios.stop
|
||||
|
||||
PRI f_input(key)| i
|
||||
|
||||
i := strsize(@send_str)
|
||||
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
|
||||
i--
|
||||
byte[@send_str][i] := 0
|
||||
elseif i < LEN_IRCLINE-2 'normales zeichen
|
||||
ios.printchar(key)
|
||||
byte[@send_str][i] := key
|
||||
i++
|
||||
byte[@send_str][i] := 0
|
||||
|
||||
PRI irc_pass
|
||||
|
||||
ios.winset(2)
|
||||
ios.print(string(10,"Sende Paßwort..."))
|
||||
if sendStr(string("PASS ")) || sendStr(@password) || sendStr(string(13,10))
|
||||
ios.print(string(10,"Fehler beim Senden des Paßwortes"))
|
||||
return(-1)
|
||||
|
||||
PRI irc_join
|
||||
|
||||
ios.winset(2)
|
||||
ios.print(string(10,"Sende Nickname"))
|
||||
if sendStr(string("NICK ")) || sendStr(@nickname) || sendStr(string(13,10))
|
||||
ios.print(string(10,"Fehler beim Senden des Nicknamens"))
|
||||
return(-1)
|
||||
|
||||
ios.print(string(", Benutzerinformationen"))
|
||||
if sendStr(string("USER ")) || sendStr(@username) || sendStr(string(" 0 * :Hive #",13,10))
|
||||
ios.print(string(10,"Fehler beim Senden des Nicknamens"))
|
||||
return(-1)
|
||||
|
||||
ifnot strsize(@channel) == 0
|
||||
ios.winset(2)
|
||||
ios.print(string(" und verbinde mit Channel"))
|
||||
if sendStr(string("JOIN ")) || sendStr(@channel) || sendStr(string(13,10))
|
||||
ios.print(string(10,"Fehler beim Verbinden mit dem Channel"))
|
||||
return(-1)
|
||||
|
||||
PRI irc_getLine
|
||||
|
||||
if readLine(2000) 'vollständige Zeile empfangen
|
||||
|
||||
if str.findCharacters(@receive_str, string("PING :")) == @receive_str
|
||||
ios.winset(2)
|
||||
ios.print(string(10,"PING erhalten, sende PONG"))
|
||||
receive_str[1] := "O"
|
||||
sendStr(@receive_str)
|
||||
sendStr(string(13,10))
|
||||
else
|
||||
ios.winset(1)
|
||||
ios.printchar(10)
|
||||
ios.print(@receive_str)
|
||||
|
||||
PRI frame_draw
|
||||
|
||||
ios.winset(0)
|
||||
|
@ -254,6 +351,8 @@ PRI win_draw | i
|
|||
ios.winoframe
|
||||
if i == focus
|
||||
ios.setcolor(COL_DEFAULT)
|
||||
if i == 3
|
||||
ios.curon
|
||||
ios.winset(0)
|
||||
ios.cursetx(2)
|
||||
ios.cursety(hy[i])
|
||||
|
@ -275,6 +374,8 @@ PRI win_redraw | i
|
|||
ios.winoframe
|
||||
if i == focus
|
||||
ios.setcolor(COL_DEFAULT)
|
||||
if i == 3
|
||||
ios.curon
|
||||
ios.winset(0)
|
||||
ios.cursetx(2)
|
||||
ios.cursety(hy[i])
|
||||
|
@ -414,8 +515,38 @@ PUB input(strdesc, strdef, input_len) | i,n
|
|||
byte[@input_str][i] := 0
|
||||
ios.curoff
|
||||
|
||||
PRI readLine(timeout) : complete | ch
|
||||
|
||||
complete := FALSE
|
||||
ifnot (ch := ios.lan_rxbyte(handleidx)) == -1
|
||||
if readpos == 0 '1. Zeichen einer Zeile empfangen
|
||||
t1char := cnt
|
||||
if (ch == 10) and receive_str[readpos-1] == 13 'Zeilenende
|
||||
receive_str[readpos-1] := 0
|
||||
readpos := 0
|
||||
complete := TRUE
|
||||
return(complete)
|
||||
receive_str[readpos++] := ch
|
||||
if readpos == LEN_IRCLINE-1 'max. Zeilenlänge
|
||||
receive_str[readpos] := 0
|
||||
readpos := 0
|
||||
complete := TRUE
|
||||
return(complete)
|
||||
if (readpos <> 0) and ((cnt - t1char) / (clkfreq / 1000) > timeout) 'Timeout seit Empfang 1. Zeichen
|
||||
receive_str[readpos] := 0
|
||||
readpos := 0
|
||||
complete := TRUE
|
||||
|
||||
PRI sendStr (strSend) : error
|
||||
|
||||
' ios.print(string(" > "))
|
||||
' ios.print(strSend)
|
||||
' ios.printnl
|
||||
error := ios.lan_txdata(handleidx, strSend, strsize(strSend))
|
||||
|
||||
PRI delay_ms(Duration)
|
||||
waitcnt(((clkfreq / 1_000 * Duration - 3932)) + cnt)
|
||||
waitcnt(clkfreq/1000*Duration + cnt)
|
||||
|
||||
|
||||
DAT
|
||||
|
||||
|
|
Loading…
Reference in New Issue