Author Topic: Single Channel IRC client QB64  (Read 4634 times)

0 Members and 1 Guest are viewing this topic.

Offline amigojapan

  • Newbie
  • Posts: 5
    • View Profile
Single Channel IRC client QB64
« 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.  
« Last Edit: January 01, 2020, 09:00:18 am by amigojapan »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Single Channel IRC client QB64
« Reply #1 on: December 29, 2019, 05:27:38 pm »
Pretty cool! But backspace didn't work for some reason. But good job!

Offline amigojapan

  • Newbie
  • Posts: 5
    • View Profile
Re: Single Channel IRC client QB64
« Reply #2 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

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Single Channel IRC client QB64
« Reply #3 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
...
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline amigojapan

  • Newbie
  • Posts: 5
    • View Profile
Re: Single Channel IRC client QB64
« Reply #4 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

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
Re: Single Channel IRC client QB64
« Reply #5 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.

Offline amigojapan

  • Newbie
  • Posts: 5
    • View Profile
Re: Single Channel IRC client QB64
« Reply #6 on: January 01, 2020, 07:45:54 am »
thanks