It's rough, but it works. I made a new thread apart from my chat server thread because though they are somewhat related with similar goals, the two projects are intended for different implementations.
I tested this with a random server on mIRC. It will not work with ALL servers as not all commands have been implemented. But it should be ok for any server allowing public access without passwords. I have yet to try SSL, that'll be after I've cleaned up this code and built a framework. This is my dirty rough draft.
For the server address you'll need the IP, AppGameKit sockets don't seem to like host names as I learned when creating the FTP library. Once connected, press "1" to send the initial registration request for your user/nickname. (felix in my test) After seeing the response you can press "2" to join a channel (which is called canada in my test) You can then send/receive messages to the channel. Press ENTER to begin typing your message and again to send it. Press ESC to properly end your session and disconnect the socket. Be careful not to spam or abuse when testing as this is NOT my server in the demo. You can set up your own server to test with if you wish, Unreal is considered the most popular choice today.
+ Code Snippet// Project: irc
// Created: 2025-01-07
SetErrorMode(2)
SetWindowTitle( "irc client" )
SetWindowSize( 800, 600, 0 )
SetVirtualResolution( 800,600)
SetSyncRate(0, 0 )
UseNewDefaultFonts( 1 )
setPrintSize(14)
#constant MAXLINES = 20
lineOffset = 0
text as integer[MAXLINES]
for i = 1 to MAXLINES
text[i] = createText("")
setTextSize(text[i], 14)
setTextPosition(text[i], 4, 50+i*14)
next i
// Connect to the server
connection = connectSocket("188.166.52.166", 6667, 6000)
msg = createMemblock(512)
msgPointer = 0
messages as string[]
logIndex = 0
` CR = 13(0x0d), LF = 10(0x0a)
f = opentowrite("raw:d:\irc.log")
readlines = 0
doText = 0
msg$ = ""
repeat
if getSocketConnected(connection)
while getSocketBytesAvailable(connection) > 0 and msgPointer < 512
b = getSocketByte(connection)
writeByte(f, b)
setMemblockByte(msg, msgPointer, b)
inc msgPointer
if msgPointer > 1
// Each message ends with CRLF
if b = 10 and getMemblockByte(msg, msgPointer-2) = 13
s$ = getMemblockString(msg, 0, msgPointer-2)
messages.insert(s$)
msgPointer = 0
inc readLines
lineOffset = messages.length - MAXLINES
if lineOffset < 0 then lineOffset = 0
endif
endif
endwhile
endif
for i = logIndex to messages.length
cmd$ = mid(messages[i], 1, 4)
if cmd$ = "PING"
t$ = "PONG "+mid(messages[i], 7, len(messages[i])-6)
sendSocketStringRaw(connection, t$)
flushSocket(connection)
messages.insert(t$)
endif
next i
logIndex = messages.length + 1
if getRawKeyPressed(49) // 1
if getSocketConnected(connection)
`sendSocketStringRaw(connection, "PASS none") // optional
`flushSocket(connection)
sendSocketStringRaw(connection, "NICK felix")
`flushSocket(connection)
sendSocketStringRaw(connection, "USER felix 0 * felix")
flushSocket(connection)
endif
endif
if doText = 1
test$ = test$ + getCharBuffer()
print("> "+test$)
else
print("| ")
endif
if getRawKeyState(38) // up
if lineOffset > 0 then dec lineOffset
endif
if getRawKeyState(40) // down
if lineOffset < messages.length - MAXLINES then inc lineOffset
endif
if getRawKeyPressed(50) // 2
sendSocketStringRaw(connection, "JOIN #canada")
flushSocket(connection)
endif
if getRawKeyPressed(51) // 3
endif
if getRawKeyPressed(13) = 1 // enter
if doText = 0
dotext = 1
test$ = ""
getCharBuffer()
else
dotext = 0
sendSocketStringRaw(connection, "PRIVMSG #canada :"+test$)
flushSocket(connection)
messages.insert("PRIVMSG #canada :"+test$)
endif
endif
print("Connected: " + str(getSocketConnected(connection)))
`for i = lineOffset to lineOffset+(MAXLINES-1)
for i = 1 to MAXLINES
j = lineOffset + (i)
if j <= messages.length
setTextString(text[i], pad$(str(j))+": "+messages[j])
else
setTextString(text[i], "Line "+str(j))
endif
next i
`if messages.length > -1 then print(messages[messages.length])
`print(messages.length)
Sync()
until getRawKeyPressed(27)
sendSocketStringRaw(connection, "QUIT")
flushSocket(connection)
deleteSocket(connection)
closeFile(f)
end
function sendSocketStringRaw(socketId as integer, s as string)
for i = 1 to len(s)
sendSocketByte(socketId, asc(mid(s, i, 1)))
next i
sendSocketByte(socketId, 13)
sendSocketByte(socketId, 10)
endfunction
function pad$(s$)
if len(s$) = 0 then exitfunction "000"
if len(s$) = 1 then exitfunction "00"+s$
if len(s$) = 2 then exitfunction "0"+s$
endfunction s$