QB64.org Forum

Active Forums => Programs => Topic started by: amigojapan on December 29, 2019, 02:54:56 am

Title: Single Channel IRC client QB64
Post by: amigojapan on December 29, 2019, 02:54:56 am
Code: QB64: [Select]
  1. server$ = "irc.freenode.net"
  2. nick$ = "your_nick_here"
  3. channel$ = "#QB64"
  4. client = _OPENCLIENT("TCP/IP:6667:" + server$)
  5. line$ = "nick " + nick$ + CHR$(13) + CHR$(10) + "user a a a a" + CHR$(13) + CHR$(10)
  6. PUT #client, , line$: SLEEP 2
  7. line$ = "join " + channel$ + CHR$(13) + CHR$(10)
  8. PUT #client, , line$: SLEEP 2
  9.  
  10.     _DELAY 0.05 ' 50ms delay (20 checks per second)
  11.     GET #client, , buff$
  12.     IF buff$ <> "" THEN
  13.         PRINT buff$
  14.         PRINT ""
  15.         PRINT user_input$;
  16.         IF INSTR(1, buff$, "PING") = 1 THEN 'handle PING
  17.             s$ = MID$(buff$, 5, LEN(buff$)) 'get orwell.freenode.net
  18.             line$ = "PONG" + s$ + CHR$(13) + CHR$(10)
  19.             PRINT "pong reached", line$
  20.             PUT #client, , line$: SLEEP 2
  21.         END IF
  22.     END IF
  23.     k$ = INKEY$
  24.     IF k$ <> "" THEN
  25.         IF k$ = CHR$(8) THEN
  26.             user_input$ = MID$(user_input$, 1, LEN(user_input$) - 1)
  27.             PRINT ""
  28.             PRINT user_input$;
  29.         ELSE IF k$ = CHR$(13) THEN
  30.                 line$ = "privmsg " + channel$ + " :" + user_input$ + CHR$(13) + CHR$(10)
  31.                 PUT #client, , line$: SLEEP 2
  32.                 user_input$ = ""
  33.                 PRINT ""
  34.             ELSE
  35.                 user_input$ = user_input$ + k$
  36.                 PRINT k$; 'echo user input ; eliminates new lines
  37.             END IF
  38.         END IF
  39.     END IF
  40. CLOSE client
  41.  
Title: Re: Single Channel IRC client QB64
Post by: SierraKen on December 29, 2019, 05:27:38 pm
Pretty cool! But backspace didn't work for some reason. But good job!
Title: Re: Single Channel IRC client QB64
Post by: amigojapan on December 29, 2019, 08:00:18 pm
Thanks, yeah backspace would require a bit more work, I guess I will do that, since it is pretty important
Title: Re: Single Channel IRC client QB64
Post by: SMcNeill on December 29, 2019, 09:24:20 pm
Thanks, yeah backspace would require a bit more work, I guess I will do that, since it is pretty important


...
        ELSEIF k$ = CHR$(8) THEN 'backspace key
            user_input$ = LEFT$(user_input$, LEN(user_input$)-1)
            PRINT k$; 'echo user input ; eliminates new lines
        ELSE
            user_input$ = user_input$ + k$
            PRINT k$; 'echo user input ; eliminates new lines
        END IF
...
Title: Re: Single Channel IRC client QB64
Post by: amigojapan on December 31, 2019, 11:03:13 pm
yeah, did pretty much that, also made it easier to see what you are typing after a new commend comes in
Title: Re: Single Channel IRC client QB64
Post by: luke on January 01, 2020, 01:58:54 am
Messages in IRC are properly terminated by CR LF; that is, CHR$(13) + CHR$(10), not the reverse.
Title: Re: Single Channel IRC client QB64
Post by: amigojapan on January 01, 2020, 07:45:54 am
thanks