Author Topic: TCP/IP Image Board/Chat program (Now hosted on QLOUD!)  (Read 4007 times)

DSMan195276

  • Hero Member
  • *****
  • Posts: 1978
  • Yes
    • Email
TCP/IP Image Board/Chat program (Now hosted on QLOUD!)
« on: April 18, 2011, 05:29:03 PM »
I've always loved playing around with the TCP/IP capabilities of QB64, since it's commands make it easy(None of the socket whatever is needed) And it opens a whole wide world of possibilities. Anyway, on with the program:

This program is a chat program over TCP/IP. It's different from your normal chat as it has a 'image board' on the top that allows you to draw and have everyone else connected to the program see it. There are dedicated Server and Client programs here. To use the Client program you have to connect to a running Server(You can run a Server on your own computer, in that case use 'localhost' for your IP).

The server routes all the messages/Board drawing to everybody connected using a very simple 'Broadcast' sub. Another nice thing is that all the client managing is done in one simple sub (It checks for new connections, and SWAP's out disconnections. It also informs when someone leaves.). The display messages are actually colored (A 4 byte long color is sent before the message). Messages are in a very simple protocol. One Byte identifies the info to come, and from there, it's just integers/strings. It's all done using PRINT #client.

As for the actual drawing, You can change the color of your 'paintbrush' at any time by typing '/COLOR' as a message (The message routes similar to IRC, where '/' means a command. There are three of these commands, explained below...). And the up and down arrows change the size of your paint brush.

Controls(Client):
PageUp-PageDown: Paint brush size(Shown on the bottom as 'S=')
UP-Down: Scroll through history.
Mouse clicking on top: Draws in your paint brush color, and your size
Right-click: Eraser
typing: Adds to your message. Special messages:
     Any message that starts with a '/' will not be sent
     /COLOR: Allows you to change your paint brush color. Everyone will be notified of the change.
     /PASTE: Replaces your message with whatever is in the clipboard at the time(Text)
    /ONLINE: Returns the names of everybody online, or the message 'Nobody else is online'
     /EXIT: Exits the client program (Same as clicking the 'X')
     /HELP: Displays help text
    /REGISTER: Registers your name with a password so somebody can't copy your name
    /PRIVATE: Private messages a user
     /CLEAR: Clears image (Faster then erasing. Only works for Mods/Owners)
    /KICK: Removes a users (Only works for Mods or Owners)
    /MUTE: Mutes a user (Only works for Mods or Owners)
    /MOD: Makes someone a mod (Only works for Owners)

     /OWNER: Makes someone a owner (Server only command)
Default color is White

Anyway, on with the programs:

Client:
Code: [Select]
'QB64 Internet Board

TYPE histline
    c AS LONG
    msg AS STRING * 80
END TYPE

CONST default$ = "50.62.13.232" 'Set to "" for a prompt for a IP address

COMMON SHARED drawcolor&, board&, nam$, client&, ip$
COMMON SHARED paintbrush&
COMMON SHARED size AS INTEGER
COMMON SHARED message$, row ', col
COMMON SHARED History() AS histline '1000 lines
COMMON SHARED HistCont, loca, first_pass_flag

REDIM History(50) AS histline
loca = 1

'messages
'first Character defines data:
'For sending:
'1 -- Sending Name
'2 -- Sending Color
'3 -- message
'4 -- Pset (LONG color,INTEGER size, LONG x, LONG y, LONG x, LONG y ...)
'5 -- Request online list
'6 -- MOD
'7 -- password
'8 -- MUTE
'9 -- Register

'For recieving:
'1 -- Message (Format: Color(as long), Message to display)
'2 -- newpantbrush color (long)
'3 -- PSET cords (integer size, long, long, long, long....)

row = 20
size = 1

SCREEN _NEWIMAGE(640, 480, 32)
board& = _NEWIMAGE(640, 304)

_DEST board&
PAINT (0, 0), _RGB32(10, 10, 10)
_DEST 0
_TITLE "Client"
IF default$ = "" THEN
    INPUT "What IP should we connect to"; ip$
ELSE
    PRINT "Client Configured to connect to "; CHR$(34); default$; CHR$(34)
    ip$ = default$
END IF
_TITLE ip$ + " -- Client"
PRINT "Please select your draw color:"
PRINT "Controls:"
PRINT "Clicking inside the big box on the left of the color selector will change what  color you have selected"
PRINT "You can changed the 'hue' of the color by clicking on the slider on the right of the big box"
PRINT "The current color you have selected is in the box to the right of the 'select'  button. Click the select button or press enter to select the color"

LINE (170, 144)-(491, 475), _RGB32(0, 255, 255), B
drawcolor& = colselector&(171, 145, &HFF2F2F2F)
_DEST 0
CLS
PRINT "Connecting...";
client& = _OPENCLIENT("TCP/IP:20014:" + ip$)
IF client& = 0 THEN PRINT "Error connecting to "; CHR$(34); ip$; CHR$(34); ", exiting...": END
PRINT "Connection Successfull!"
DO
    INPUT "What name do you want"; nam$
    nam$ = RTRIM$(LTRIM$(nam$))
    IF nam$ > SPACE$(LEN(nam$)) THEN
        PRINT #client&, CHR$(1) + nam$
        DO: _LIMIT 100
            INPUT #client&, ts$
        LOOP UNTIL ts$ > ""
        IF ts$ = CHR$(1) THEN PRINT "NickName already in use..."
        IF ts$ = CHR$(3) THEN
            PRINT "NickName is registered and requires a password"
            INPUT "What is the password"; pass$
            PRINT #client&, CHR$(7); pass$
            DO: _LIMIT 100
                INPUT #client&, ts$
            LOOP UNTIL ts$ > ""
        END IF
    ELSE
        PRINT "Not a vaild name"
    END IF
LOOP UNTIL ts$ = CHR$(2)
updateboard (MKL$(_RGB32(255, 255, 255)) + "Type '/HELP' for help")
PRINT #client&, CHR$(5)
first_pass_flag = -1
DO: _LIMIT 100
    _PUTIMAGE (0, 0), board&
    mk = (mk + 1) MOD 10
    IF mk = 0 THEN
        INPUT #client&, msg$
        IF msg$ > "" THEN
            SELECT CASE ASC(LEFT$(msg$, 1))
                CASE 1
                    updateboard (MID$(msg$, 2))
                CASE 2
                    paintbrush& = CVL(MID$(msg$, 2))
                CASE 3
                    si = CVI(MID$(msg$, 2, 2))
                    msg$ = MID$(msg$, 4)
                    _DEST board&
                    FOR x = 0 TO LEN(msg$) \ 8 - 1
                        'PSET (x&, y&), paintbrush&
                        x& = CVL(MID$(msg$, x * 8 + 1, 4))
                        y& = CVL(MID$(msg$, x * 8 + 5, 4))
                        LINE (x& - si, y& - si)-(x& + si, y& + si), paintbrush&, BF
                    NEXT x
                    _DEST 0
                CASE 4
                    updateboard MID$(msg$, 2)
            END SELECT
        END IF
    END IF
    DO WHILE _MOUSEINPUT
        x = _MOUSEX
        y = _MOUSEY
        b = _MOUSEBUTTON(1)
        b2 = _MOUSEBUTTON(2)
    LOOP
    IF b OR b2 THEN 'paint
        IF y <= 300 THEN

            IF b THEN c& = drawcolor&
            IF b2 THEN c& = _RGB32(10, 10, 10)

            _DEST board&
            IF buf$ = "" THEN
                buf$ = buf$ + CHR$(4) + MKL$(c&) + MKI$(size) + MKL$(CLNG(x)) + MKL$(CLNG(y))
                LINE (x - size, y - size)-(x + size, y + size), c&, BF
            ELSE
                IF (x <> xsav OR y <> ysav) THEN
                    buf$ = buf$ + MKL$(CLNG(x)) + MKL$(CLNG(y))
                    LINE (x - size, y - size)-(x + size, y + size), c&, BF
                END IF
            END IF
            _DEST 0
            xsav = x: ysav = y
        END IF
    ELSEIF buf$ > "" THEN
        PRINT #client&, buf$
        buf$ = ""
        xsav = 500: ysav = 500
    END IF
    changemessage
LOOP
SYSTEM



SUB changemessage
a$ = INKEY$
IF a$ > "" THEN
    Update = -1
    SELECT CASE a$
        CASE " " TO "~"
            'message$ = MID$(message$, 1, position - 1) + a$ + MID$(message$, position) 'message$ + a$
            'position = position + 1
            message$ = message$ + a$
        CASE CHR$(8)
            message$ = LEFT$(message$, LEN(message$) - 1)
        CASE CHR$(13)
            IF message$ > "" THEN
                IF LEFT$(LTRIM$(message$), 1) <> "/" THEN
                    PRINT #client&, CHR$(3) + MKL$(drawcolor&) + message$
                    message$ = ""
                ELSE
                    message$ = LTRIM$(message$)
                    IF LEFT$(UCASE$(message$), 6) = "/COLOR" THEN
                        drawcolor& = colselector&(20, 20, &HFFFFFFFF)
                        _DEST 0
                        PRINT #client&, CHR$(2) + MKL$(drawcolor&)
                        message$ = ""
                    ELSEIF RTRIM$(UCASE$(message$)) = "/EXIT" THEN
                        SYSTEM
                    ELSEIF RTRIM$(UCASE$(message$)) = "/PASTE" THEN
                        message$ = _CLIPBOARD$
                    ELSEIF RTRIM$(UCASE$(message$)) = "/ONLINE" THEN
                        PRINT #client&, CHR$(5)
                        message$ = ""
                    ELSEIF LEFT$(UCASE$(message$), 4) = "/MOD" THEN
                        PRINT #client&, CHR$(6) + MID$(UCASE$(message$), 5)
                        message$ = ""
                    ELSEIF LEFT$(UCASE$(message$), 5) = "/MUTE" THEN
                        PRINT #client&, CHR$(8) + MID$(UCASE$(message$), 6)
                        message$ = ""
                    ELSEIF LEFT$(UCASE$(message$), 9) = "/REGISTER" THEN
                        PRINT #client&, CHR$(9) + RTRIM$(LTRIM$(MID$(message$, 10)))
                        message$ = ""
                    ELSEIF LEFT$(UCASE$(message$), 6) = "/CLEAR" THEN
                        PRINT #client&, CHR$(10)
                        message$ = ""
                    ELSEIF LEFT$(UCASE$(message$), 5) = "/KICK" THEN
                        PRINT #client&, CHR$(11) + MID$(message$, 6)
                        message$ = ""
                    ELSEIF LEFT$(UCASE$(message$), 8) = "/PRIVATE" THEN
                        PRINT #client&, CHR$(12) + MKL$(drawcolor&) + RTRIM$(MID$(message$, 9))
                        message$ = ""
                    ELSEIF RTRIM$(UCASE$(message$)) = "/HELP" THEN
                        message$ = ""
                        CLS
                        LOCATE 1, 1
                        updateb (MKL$(_RGB32(255, 255, 0)) + "Help:")
                        updateb (MKL$(_RGB32(255, 255, 0)) + "Commands are preceded by a '/'. Any message starting with '/' will not be sent")
                        updateb (MKL$(_RGB32(255, 255, 0)) + "Commands:")
                        updateb (MKL$(_RGB32(255, 100, 0)) + " COLOR ----------- Displays the color picking dialog in top left corner")
                        updateb (MKL$(_RGB32(255, 100, 0)) + " PASTE ----------- Replaces your message with whatever text is in the clipboard")
                        updateb (MKL$(_RGB32(255, 100, 0)) + " ONLINE ---------- Gets a list of the users onl")
                        updateb (MKL$(_RGB32(255, 100, 0)) + " EXIT ------------ Exits the client")
                        updateb (MKL$(_RGB32(255, 100, 0)) + " HELP ------------ Displays this dialog")
                        updateb (MKL$(_RGB32(255, 100, 0)) + " REGISTER (pass) - Registers your name with a password or Changes password")
                        updateb (MKL$(_RGB32(255, 100, 0)) + " PRIVATE (name),(message) - Private messages 'name'")
                        updateb (MKL$(_RGB32(255, 255, 0)) + "MOD ONLY:")
                        updateb (MKL$(_RGB32(255, 100, 0)) + " MUTE (name) ----- Mutes/UnMutes someone")
                        updateb (MKL$(_RGB32(255, 100, 0)) + " KICK (name) ----- Disconnects someone")
                        updateb (MKL$(_RGB32(255, 100, 0)) + " CLEAR ----------- Clears the image board")
                        updateb (MKL$(_RGB32(255, 255, 0)) + "OWNER ONLY:")
                        updateb (MKL$(_RGB32(255, 100, 0)) + " MOD (name) ------ Mods/UnMods someone")
                        updateb (MKL$(_RGB32(255, 255, 0)) + "UP/DOWN - Scroll through message history")
                        PRINT "PGUP/PGDN - Change Brush Size"
                        updateb (MKL$(_RGB32(255, 255, 0)) + "Left Click on top image - Draw in your color")
                        PRINT "Right Click - Eraser"
                        PRINT "Press any key to continue..."
                        SLEEP
                        updateboard ""
                    END IF
                END IF
            END IF
    END SELECT
    IF LEN(a$) = 2 THEN
        SELECT CASE ASC(RIGHT$(a$, 1))
            CASE 81
                IF size > 0 THEN size = size - 1
            CASE 73
                IF size < 80 THEN size = size + 1
            CASE 80
                IF loca <= HistCont - 1 THEN loca = loca + 1
            CASE 72
                IF loca > 1 THEN loca = loca - 1
        END SELECT
        updateboard ""
    END IF
END IF
IF Update OR first_pass_flag THEN
    Update = 0
    COLOR _RGB32(255, 255, 255) 'drawcolor&
    'LOCATE 30, 1, 0
    'PRINT SPACE$(80);
    LOCATE 30, 1, 1
    PRINT USING "S=## Msg:\                                                                  \ "; size; RIGHT$(message$, 68);
    'LINE (8 * (position - cut_spot) + 8 * 9, 479)-(8 * (position - cut_spot) + 8 * 9 - 9, 479), _RGB32(255, 255, 255)
    'PRINT "S="; RIGHT$(STR$(size), 2); " Msg: "; RIGHT$(message$, 70);
    first_pass_flag = 0
END IF
END SUB

SUB updateboard (msg$)
crlf$ = CHR$(10) + CHR$(13)
col1 = POS(0)
row1 = CSRLIN
IF msg$ > "" AND NOT INSTR(msg$, CHR$(13)) AND NOT INSTR(msg$, CHR$(10)) THEN
    GOSUB disp_line
ELSEIF msg$ > "" THEN
    lmsg$ = msg$
    DO
        IF INSTR(lmsg$, crlf$) THEN
            msg$ = MID$(lmsg$, 1, INSTR(lmsg$, crlf$) - 1)
            lmsg$ = MID$(lmsg$, INSTR(lmsg$, crlf$) + 2)
        ELSEIF INSTR(lmsg$, CHR$(13)) THEN
            msg$ = MID$(lmsg$, 1, INSTR(lmsg$, CHR$(13)) - 1)
            lmsg$ = MID$(lmsg$, INSTR(lmsg$, CHR$(13)) + 1)
        ELSEIF INSTR(lmsg$, CHR$(10)) THEN
            msg$ = MID$(lmsg$, 1, INSTR(lmsg$, CHR$(10)) - 1)
            lmsg$ = MID$(lmsg$, INSTR(lmsg$, CHR$(10)) + 1)
        ELSE
            msg$ = lmsg$
            lmsg$ = ""
        END IF
        GOSUB disp_line
    LOOP UNTIL lmsg$ = ""
END IF
VIEW PRINT 20 TO 29

FOR x = 20 TO 29
    LOCATE x, 1, 0
    IF UBOUND(history) >= loca + x - 20 THEN
        COLOR History(loca + x - 20).c
        PRINT History(loca + x - 20).msg;
    ELSE
        PRINT SPACE$(80);
    END IF
NEXT x
VIEW PRINT 1 TO 30
LOCATE row1, col1, 1
EXIT SUB

disp_line:
IF LEN(msg$) - 4 <= 80 THEN
    HistCont = HistCont + 1
    IF HistCont >= UBOUND(history) THEN
        REDIM _PRESERVE History(UBOUND(history) * 1.5) AS histline
    END IF
    History(HistCont).c = CVL(MID$(msg$, 1, 4))
    History(HistCont).msg = MID$(msg$, 5)
    loca = loca + 1
    IF HistCont < 9 + loca THEN loca = loca - 1
ELSE
    cl& = CVL(MID$(msg$, 1, 4))
    FOR x = 1 TO (LEN(msg$) - 4) \ 80 + 1
        HistCont = HistCont + 1
        IF HistCont >= UBOUND(history) THEN
            REDIM _PRESERVE History(UBOUND(history) * 1.5) AS histline
        END IF

        loca = loca + 1
        History(HistCont).c = cl&
        History(HistCont).msg = MID$(msg$, 5 + (x - 1) * 80, 80)
        IF HistCont < 9 + loca THEN loca = loca - 1
    NEXT x
END IF
RETURN
END SUB

FUNCTION colselector& (x1, y1, back&)
CONST xoff = 15
CONST yoff = 15
CONST xlen = 255
CONST ylen = 255
hue = 0: sat = 0: value = 1
scrnsav& = _COPYIMAGE(0) 'save screen image
destsav& = _DEST
'printsav& = _PRINTMODE
colsel& = _NEWIMAGE(320, 330, 32)
_PRINTMODE _KEEPBACKGROUND , colsel&
_DEST colsel&
_PUTIMAGE (x1, y1), colsel&, 0
PAINT (0, 0), back& 'paint screen white
FOR x = .0001 TO xlen
    FOR y = .0001 TO ylen
        CALL HSVtoRGB(hue, x / xlen, y / ylen, r, g, b)
        PSET (x + xoff, y + yoff), _RGB32(r, g, b)
    NEXT y
NEXT x
LINE (xlen + 14 + xoff, yoff - 1)-(xlen + 26 + xoff, ylen + yoff + 1), _RGB32(255, 255, 255), BF

FOR x = 0 TO ylen
    CALL HSVtoRGB(x / ylen * 359, 1, 1, rcol, gcol, bcol)
    LINE (xlen + 15 + xoff, x + yoff)-(xlen + 25 + xoff, x + yoff), _RGB(rcol, gcol, bcol)
NEXT x
selected = 1
update = -1
LOCATE 20, 14
COLOR _RGB32(0, 0, 0), _RGB32(0, 140, 140)

bx1 = 100
by1 = 293
bx2 = 107 + _PRINTWIDTH("Select")
by2 = 300 + _FONTHEIGHT(_FONT)

LINE (bx1, by1)-(bx2, by2), _RGB32(0, 0, 0), BF
LINE (bx1 + 1, by1 + 1)-(bx2 - 1, by2 - 1), _RGBA32(9, 207, 239, 128), BF

_PRINTSTRING (bx1 + 4, by1 + 4), "Select"

_PUTIMAGE (x1, y1), colsel&, 0
DO: _LIMIT 5000
    DO WHILE _MOUSEINPUT
        mx = _MOUSEX - x1
        my = _MOUSEY - y1
        but = -_MOUSEBUTTON(1) - _MOUSEBUTTON(2) * 2
    LOOP
    IF but > 0 THEN
        IF mx >= bx1 AND mx <= bx2 AND my >= by1 AND my <= by2 THEN
            entered = -1
        END IF
        IF mx >= xoff AND mx <= xoff + xlen AND my >= yoff AND my <= yoff + ylen THEN
            sat = (mx - xoff) / xlen
            value = (my - yoff) / ylen
            update = -1
            selected = 1
        END IF
        IF mx >= xoff + xlen AND mx <= xoff + xlen + 10 THEN
            IF my >= yoff AND my <= yoff + ylen THEN
                value = (my - yoff) / ylen
                update = -1
            END IF
        END IF
        IF my >= yoff + ylen AND my <= yoff + ylen + 10 THEN
            IF mx >= xoff AND mx <= xoff + xlen THEN
                sat = (mx - xoff) / xlen
                update = -1
            END IF
        END IF
        IF mx >= xoff + xlen + 15 AND mx < xoff + xlen + 35 AND my >= yoff AND my <= yoff + ylen THEN
            hue = (my - yoff) / ylen * 359
            update = -1
            selected = 2
        END IF
    END IF
    a$ = INKEY$
    IF a$ > "" THEN
        SELECT CASE a$
            CASE CHR$(0) + CHR$(80) ' up
                IF selected = 1 THEN
                    IF value < 1 THEN
                        value = value + (5 / xlen)
                        update = -1
                    END IF
                ELSEIF selected = 2 THEN
                    IF hue < 359 THEN
                        hue = hue + (5 / xlen) * 359
                        update = -1
                    END IF
                END IF
            CASE CHR$(0) + CHR$(72) ' down
                IF selected = 1 THEN
                    IF value > 0 THEN
                        value = value - (5 / xlen)
                        update = -1
                    END IF
                ELSEIF selected = 2 THEN
                    IF hue > 2 THEN
                        hue = hue - (5 / xlen) * 359
                        update = -1
                    END IF
                END IF
            CASE CHR$(0) + CHR$(75) ' left
                IF selected = 1 THEN
                    IF sat > 0 THEN
                        sat = sat - (5 / ylen)
                        update = -1
                    END IF
                END IF
            CASE CHR$(0) + CHR$(77) ' right
                IF selected = 1 THEN
                    IF sat < 1 THEN
                        sat = sat + (5 / ylen)
                        update = -1
                    END IF
                END IF
            CASE CHR$(9)
                selected = (selected MOD 2) + 1
            CASE CHR$(13)
                entered = -1
        END SELECT
    END IF
    IF sav > 1 THEN sat = 1
    IF sat < 0 THEN sat = 0
    IF hue > 359 THEN hue = 359
    IF hue < 0 THEN hue = 0
    IF value > 1 THEN value = 1
    IF value < 0 THEN value = 0

    IF update THEN 'redraw screem to a extent
        LINE (xoff - 1, yoff - 1)-(xoff + xlen + 2, yoff + ylen + 2), _RGB32(255, 255, 255), BF
        FOR x = .0001 TO xlen
            FOR y = .0001 TO ylen
                CALL HSVtoRGB(hue, x / xlen, y / ylen, r, g, b)
                PSET (x + xoff, y + yoff), _RGB32(r, g, b)
            NEXT y
        NEXT x

        LINE (xoff + xlen + 1, yoff - 6)-(xoff + xlen + 6, yoff + ylen + 6), back&, BF
        CALL drawarrow(xoff + xlen + 1, yoff + value * ylen, 1, _RGB32(0, 0, 0))

        LINE (xoff - 6, yoff + ylen + 1)-(xoff + xlen, yoff + ylen + 6), back&, BF
        CALL drawarrow(xoff + sat * xlen, yoff + ylen + 1, 2, _RGB32(0, 0, 0))

        LINE (xoff + xlen + 26, yoff - 5)-(xoff + xlen + 31, yoff + ylen + 5), back&, BF
        CALL drawarrow(xoff + xlen + 26, yoff + (hue / 360) * ylen, 1, _RGB32(0, 0, 0))

        CALL HSVtoRGB(hue, sat, value, r, g, b)

        LINE (xoff - 1, yoff + ylen + 9)-(xoff + 71, yoff + ylen + 51), _RGB32(0, 0, 0), B
        LINE (xoff, yoff + ylen + 10)-(xoff + 70, yoff + ylen + 50), _RGB32(r, g, b), BF

        LINE (170, 285)-(300, 320), back&, BF
        LINE (170, 285)-(300, 320), _RGBA32(26, 189, 92, 128), BF
        LINE (169, 284)-(301, 321), _RGB32(0, 0, 0), B

        LOCATE 19, 23
        COLOR _RGB32(0, 0, 0), back& ' _RGB32(255, 255, 255)
        PRINT "Hue   Sat   Val";
        LOCATE 20, 23
        PRINT USING "###"; hue;
        LOCATE 20, 28
        PRINT USING "###%"; sat * 100;
        LOCATE 20, 34
        PRINT USING "###%"; value * 100;
        _PUTIMAGE (x1, y1), colsel&, 0
        update = 0
    END IF
LOOP UNTIL entered
CALL HSVtoRGB(hue, sat, value, r, g, b)
SCREEN scrnsav&
_DEST destsav&
colselector& = _RGB32(r, g, b)
END FUNCTION



SUB drawarrow (x, y, dir, col&)
SELECT CASE dir
    CASE 1 'left
        FOR k = 0 TO 5
            LINE (x + k, y - k)-(x + k, y + k), col&
        NEXT k
    CASE 2 'up
        FOR k = 0 TO 5
            LINE (x - k, y + k)-(x + k, y + k), col&
        NEXT k
    CASE 3 'right
        FOR k = 0 TO 5
            LINE (x - k, y - k)-(x - k, y + k), col&
        NEXT k
    CASE 4 'down
        FOR k = 0 TO 5
            LINE (x - k, y - k)-(x + k, y - k), col&
        NEXT k
END SELECT
END SUB

SUB HSVtoRGB (h, s, v, r, g, b)
r = 0: g = 0: b = 0
hi = (h / 60): c = v * s
x = c * (1 - ABS(hi - (2 * INT(hi / 2)) - 1))
SELECT CASE INT(hi)
    CASE 0: r = c: g = x
    CASE 1: r = x: g = c
    CASE 2: g = c: b = x
    CASE 3: g = x: b = c
    CASE 4: r = x: b = c
    CASE 5: r = c: b = x
END SELECT
M = v - c
r = r + M: r = r * 255
g = g + M: g = g * 255
b = b + M: b = b * 255
END SUB

SUB updateb (strn$)
COLOR CVL(MID$(strn$, 1, 4))
PRINT MID$(strn$, 5)
END SUB


Server:
Download .BAS file

The client by default will connect to the 'unofficial' QB64 chat which is hosted off my house. You can however host a server from your house, or really from anywhere that will run the program, and the client can be modified to connect to it.

Matt

UPDATE:Now that Galleon has started up QLOUD I'm hoping this on there. Recompile the client, as I changed the port number and IP address.
« Last Edit: June 17, 2012, 07:05:38 PM by DSMan195276 »
"Cast your cares on the Lord and he will sustain you; he will never let the righteous be shaken" -- Psalm 55:22
QB64 Linux Installer

Cyperium

  • Hero Member
  • *****
  • Posts: 3285
  • Knowledge is good, but understanding is better
    • Cyperium
    • Email
Re: TCP/IP Image Board/Chat program (Server and Client programs)
« Reply #1 on: April 18, 2011, 06:00:10 PM »
I'm on right now! I have two questions, does everyone use the same image to paint on? How to erase what you painted?
Venture - New Prototype, QB64 Editor v1.95b (linux compatible, if you compile the source).

Galleon

  • Administrator
  • Hero Member
  • *****
  • Posts: 4664
  • QB Forever
    • Email
Re: TCP/IP Image Board/Chat program (Server and Client programs)
« Reply #2 on: April 18, 2011, 07:32:06 PM »
Matt, Cyperium & I just spent half and hour 'image chatting'. Hope to see you all there later on! Matt's going to change it so you can quickly see who is only and so it keeps a chat-log. After that, I intend to leave this baby running whenever my computer is running. It's pretty early on development wise, but Matt's trying to host it round the clock and even at this stage it's already useable and fun.
Something old... Something new... Something borrowed... Something blue...

GarryRicketson

  • Guest
Re: TCP/IP Image Board/Chat program (Server and Client programs)
« Reply #3 on: April 18, 2011, 07:34:08 PM »
I just tried, but could not connect,..? Maybe the server is not running ?
Or I am not inserting the IP: 107.9.250.37 in the correct place.
 I am a little confused as to which one (program I should use) I sure would like to try it, if you have the patience to explain a little more,
thanks from Garry
Edit: I did connect, and chatted with cyberium, pretty neat program,...
I have some questions, as to How dose one determine what the IP: adress is for theyer computer ? Dose the computer need to be connected to any other browser, such as google, at the time ? Or can 2 computers connect, we are useing USB wireless devices, the 2 computers I have in mind ? with a modem it would be simple, as just dialing the number, but I am not sure about the USB wide band things....
Anyway great program, Matt, Galleon, it works cool!,..
« Last Edit: April 18, 2011, 08:28:30 PM by GarryRicketson »

Galleon

  • Administrator
  • Hero Member
  • *****
  • Posts: 4664
  • QB Forever
    • Email
Re: TCP/IP Image Board/Chat program (Server and Client programs)
« Reply #4 on: April 18, 2011, 07:38:46 PM »
It's online right now. Check your firewall settings?
Something old... Something new... Something borrowed... Something blue...

Cyperium

  • Hero Member
  • *****
  • Posts: 3285
  • Knowledge is good, but understanding is better
    • Cyperium
    • Email
Re: TCP/IP Image Board/Chat program (Server and Client programs)
« Reply #5 on: April 18, 2011, 07:41:39 PM »
Try using the client program. I noticed 2 " Has left" messages in the chat. Matt has left by now but he says he will keep it open for the night and tomorrow.


Garry successfully logged in, but his messages are displayed in black and so is the paintbrush. I don't know if he intentionally chose black as the color.

<edit> he managed to change colors and I've chatted with him for a while, it seemed to work fine! Perhaps black shouldn't be selectable?
« Last Edit: April 18, 2011, 08:13:50 PM by Cyperium »
Venture - New Prototype, QB64 Editor v1.95b (linux compatible, if you compile the source).

GarryRicketson

  • Guest
Re: TCP/IP Image Board/Chat program (Server and Client programs)
« Reply #6 on: April 18, 2011, 08:32:29 PM »
If some one has a "blue screen", black would work, but  not the computer!
That was pretty neat, I enjoyed it. I am hopeing to figure out how to use this so I can chat with my wife,...
from Garry
Quote
How to erase what you painted?
Useing black one can "erase" what they drew, but it might be nice if the default color was something that showed up on the black,..that is what had me thinking it was not running, but then when CY logged in and I saw his ,messages,..I found I had not changed the color, it was black.
 I am still on, if anyone wants to try it,..
« Last Edit: April 18, 2011, 09:40:18 PM by GarryRicketson »

DSMan195276

  • Hero Member
  • *****
  • Posts: 1978
  • Yes
    • Email
Re: TCP/IP Image Board/Chat program (Server and Client programs)
« Reply #7 on: April 19, 2011, 03:57:54 AM »


Quote from: Cyperium on April 18, 2011, 07:41:39 PM
Try using the client program. I noticed 2 " Has left" messages in the chat. Matt has left by now but he says he will keep it open for the night and tomorrow.


Garry successfully logged in, but his messages are displayed in black and so is the paintbrush. I don't know if he intentionally chose black as the color.

<edit> he managed to change colors and I've chatted with him for a while, it seemed to work fine! Perhaps black shouldn't be selectable?

The Has Left messages would be from a client disconnecting before it even set it's name. The message is 'name' " Has Left" But without name you just get " Has Left" like you said. (I think Garry might have caused it ;) ). My best guess: He was trying to connect, and it got though but before Garry's program sent it's name in to let us know who it is, Garry clicked the 'X' and closed it. Resulting in a connection failure

Thanks, Noted Cyperium. I don't want to just restrict Black, because a color like _rgb32(1, 1, 1) won't show up either, but it's hard to say for how long to restrict these colors.

Quote from: GarryRicketson on April 18, 2011, 08:32:29 PM
If some one has a "blue screen", black would work, but  not the computer!
That was pretty neat, I enjoyed it. I am hopeing to figure out how to use this so I can chat with my wife,...
from Garry
 Useing black one can "erase" what they drew, but it might be nice if the default color was something that showed up on the black,..that is what had me thinking it was not running, but then when CY logged in and I saw his ,messages,..I found I had not changed the color, it was black.
 I am still on, if anyone wants to try it,..

I could help you set it up to chat with your Wife, it's very simple. Just start-up the server program (Probably on your size) And Email your wife the IP address that it displays in the title. Then, open a client on your side (On the same computer as the server) And use 'localhost' as the IP address. That will connect you to the server on your computer. You're Wife will need a copy of the Client program, and she would run it, and use the IP address you Emailed in the program. After that, Everything should work as expected. The entire system isn't amazingly complicated as long as you know that you connect to the Global IP address in the title of the server if you're outside the LAN, you use the local IP inside the LAN, and use 'localhost' on the computer with the server running to connect.

Actually, I forgot to write it down XD. You can very easily erase by right clicking ;) I don't recommend using Dark colors since it's hard to see them in the area below (I won't stop you from using them, specifically because I don't know how to determine if a color is 'light' or 'dark')

I'm working on the next update right now, I'll probably be done tonight. And the server is still running, I got to see a nice picture of a monorail from Galleon's son  :)

Matt
"Cast your cares on the Lord and he will sustain you; he will never let the righteous be shaken" -- Psalm 55:22
QB64 Linux Installer

Galleon

  • Administrator
  • Hero Member
  • *****
  • Posts: 4664
  • QB Forever
    • Email
Re: TCP/IP Image Board/Chat program (Server and Client programs)
« Reply #8 on: April 19, 2011, 04:26:18 AM »
Quote
I got to see a nice picture of a monorail from Galleon's son
He used the drawing tablet for that. Actually he likes to test a lot of stuff at QB64. He even knows the QB64 song, but you'll only find out what that is over my dead body.
Something old... Something new... Something borrowed... Something blue...

GarryRicketson

  • Guest
Re: TCP/IP Image Board/Chat program (Server and Client programs)
« Reply #9 on: April 19, 2011, 05:22:26 AM »
Quote
I could help you set it up to chat with your Wife, it's very simple. Just start-up the server program (Probably on your size) And Email your wife the IP address that it displays in the title. Then, open a client on your side (On the same computer as the server)
Thanks Matt,
Last night ,after I logged off, from yours, I did do some more "tests", on my computer, and that is what I did, I started the server, then I used localhost to connect, and I started another instance of a client and did the same, and it works good, I did notice,when the server is started, it shows what the IP address is,..so I got that, also, on the firewall, that was a problem, but now I have it as an exception, so it (windows) allows the connection., I will have to do the same, on the other computer, It is basicly pretty simple, and that is a big plus for the program. It sound like it was me, the "has left", message
,because The first 2 times, I disconnected, when I had first tried.
 Ok on the right clicking to erase,..
from garry

Clippy

  • Hero Member
  • *****
  • Posts: 16431
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: TCP/IP Image Board/Chat program (Server and Client programs)
« Reply #10 on: April 19, 2011, 09:16:50 AM »
Quote
He even knows the QB64 song, but you'll only find out what that is over my dead body.

How would that be possible?  ;D
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

GarryRicketson

  • Guest
Re: TCP/IP Image Board/Chat program (Server and Client programs)
« Reply #11 on: April 19, 2011, 04:51:37 PM »
I did some tests using localhost and it appears to work fine, How ever, and I hope it is ok, in the same thread, I would like to see if anyone can connect, this is the IP,    IP: 201.144.130.21  I will leave it running a few hours.
Thanks from Garry
Note edit: It seems safe enough, and I have pretty good antivirus, but I do wonder, could someone connect, and cause any kind of damage ?...or is it safe to go take a nap ?....

DSMan195276

  • Hero Member
  • *****
  • Posts: 1978
  • Yes
    • Email
Re: TCP/IP Image Board/Chat program (Server and Client programs)
« Reply #12 on: April 19, 2011, 05:29:54 PM »
Quote from: GarryRicketson on April 19, 2011, 04:51:37 PM
I did some tests using localhost and it appears to work fine, How ever, and I hope it is ok, in the same thread, I would like to see if anyone can connect, this is the IP,    IP: 201.144.130.21  I will leave it running a few hours.
Thanks from Garry
Note edit: It seems safe enough, and I have pretty good antivirus, but I do wonder, could someone connect, and cause any kind of damage ?...or is it safe to go take a nap ?....

I couldn't connect, you might have to forward port 300 on your router to your computers Local IP (If you need help, feel free to email me, It'd be a little off topic to explain how in this thread).

The thing as a whole is safe, someone can't connect to this program and cause any damage to your computer. However, Someone could PING your IP address and possibly try to launch a attack on your network. But I would say that's highly unlikely considering I don't see why anybody would. If you are worried, when you're done testing just turn your router off and on, that will give you a new IP address.

In other news, I updated again. This update includes chat history, being able to view who's online, and improved drawing (The drawing data is gathered into a buffer like Cy and Galleon suggested, and it won't double-up cords)

Matt
"Cast your cares on the Lord and he will sustain you; he will never let the righteous be shaken" -- Psalm 55:22
QB64 Linux Installer

GarryRicketson

  • Guest
Re: TCP/IP Image Board/Chat program (Server and Client programs)
« Reply #13 on: April 19, 2011, 06:02:59 PM »
Quote
I couldn't connect, you might have to forward port 300 on your router to your computers Local IP (If you need help, feel free to email me, It'd be a little off topic to explain how in this thread).  
Ok Matt, thanks, I guess I will need a little help, I don't know much on the port stuff,
I tried, the Icon, below your name, but did not get any e-mail, adreess, just your website ?
from Garry
My e-mail is in the little envelope thing,...If it is not to much trouble...
thanks from Garry
Ok thanks, on that , I just read your reply.
« Last Edit: April 19, 2011, 06:17:27 PM by GarryRicketson »

DSMan195276

  • Hero Member
  • *****
  • Posts: 1978
  • Yes
    • Email
Re: TCP/IP Image Board/Chat program (Server and Client programs)
« Reply #14 on: April 19, 2011, 06:08:49 PM »
Quote from: GarryRicketson on April 19, 2011, 06:02:59 PM
Ok Matt, thanks, I guess I will need a little help, I don't know much on the port stuff,
I tried, the Icon, below your name, but did not get any e-mail, adreess, just your website ?
from Garry

It didn't work? It works for me, odd. I'll email you then.

Matt
"Cast your cares on the Lord and he will sustain you; he will never let the righteous be shaken" -- Psalm 55:22
QB64 Linux Installer