13 Commits
Author SHA1 Message Date
observer 6ec2d360a0 README 2026-11-17 11:54:07 +00:00
observer 4f762aa8f8 Bump wrapper to 9.8.2
Signed-off-by: shrapnelnet <shrapnelnet@protonmail.com>
2026-11-09 16:21:42 +00:00
observer 521d17046f Bump version 2026-11-08 22:31:59 +00:00
observer fe9a00110d Add testing sandbox 2026-11-08 22:31:41 +00:00
observer feded91e72 Add Part, YoureOper 2026-11-08 22:31:21 +00:00
observer 6e880e0a20 Make user fields nullable 2026-11-08 22:30:53 +00:00
observer c23b85712a Add Part, youreoper 2026-11-08 22:30:36 +00:00
observer 00a4fd3a93 Add clear error message when timing out expecting a message 2026-11-08 22:30:20 +00:00
observer 7e7361799a Change log severity background colour codes 2026-11-08 22:27:26 +00:00
observer 066b380a98 Use IRCClient.quit() instead of raw queueing 2026-11-08 22:26:57 +00:00
observer e09f391bff Add new client messages to API 2026-11-08 22:25:41 +00:00
observer 2db2daa897 make connection socket, reader, writer, private set 2026-11-08 22:24:55 +00:00
observer 1bb8ccb798 Add Part, Quit, Stats Client Msg 2026-11-08 22:24:27 +00:00
16 changed files with 196 additions and 98 deletions
+19
View File
@@ -0,0 +1,19 @@
# FerretIRC - Client Library
ferretirc-client v0.1.2
[Maven Repo](https://central.sonatype.com/artifact/com.shr4pnel/libferretirc)
An asynchronous, Kotlin based library for communication with IRC servers.
FerretIRC is actively in development, so some features have not yet been implemented. I am aiming for [RFC 2812](https://www.rfc-editor.org/info/rfc2812/) compliance, whilst also adopting modern standards created by server vendors as defined in [ircdocs](https://modern.ircdocs.horse/).
When these are compatible, IRCv3 features will follow, e.g. SASL authentication, tag support, multiprefix etc.
## Dependencies
- ngircd (this is inflexible as it has no windows builds, will add more IRCDs for testing later)
- sed
- ts (from moreutils)
+1 -1
View File
@@ -6,7 +6,7 @@ plugins {
} }
group = "com.shr4pnel" group = "com.shr4pnel"
version = "0.1.0" version = "0.1.1"
val ktorVersion = "3.5.2" val ktorVersion = "3.5.2"
repositories { repositories {
Binary file not shown.
+5 -2
View File
@@ -1,6 +1,9 @@
#Tue Aug 04 23:49:39 BST 2026
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.7.1-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.2-bin.zip
networkTimeout=10000
retries=0
retryBackOffMs=500
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
Vendored
+34 -20
View File
@@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# #
# Copyright © 2015-2021 the original authors. # Copyright © 2015 the original authors.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
@@ -15,10 +15,12 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
# SPDX-License-Identifier: Apache-2.0
#
############################################################################## ##############################################################################
# #
# Gradle start up script for POSIX generated by Gradle. # gradlew start up script for POSIX generated by Gradle.
# #
# Important for running: # Important for running:
# #
@@ -27,7 +29,7 @@
# bash, then to run this script, type that shell name before the whole # bash, then to run this script, type that shell name before the whole
# command line, like: # command line, like:
# #
# ksh Gradle # ksh gradlew
# #
# Busybox and similar reduced shells will NOT work, because this script # Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features: # requires all of these POSIX shell features:
@@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop. # Darwin, MinGW, and NonStop.
# #
# (3) This script is generated from the Groovy template # (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project. # within the Gradle project.
# #
# You can find Gradle at https://github.com/gradle/gradle/. # You can find Gradle at https://github.com/gradle/gradle/.
@@ -80,13 +82,11 @@ do
esac esac
done done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # This is normally unused
# shellcheck disable=SC2034
APP_NAME="Gradle"
APP_BASE_NAME=${0##*/} APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value. # Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum MAX_FD=maximum
@@ -114,7 +114,6 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;; NONSTOP* ) nonstop=true ;;
esac esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM. # Determine the Java command to use to start the JVM.
@@ -133,22 +132,29 @@ location of your Java installation."
fi fi
else else
JAVACMD=java JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the Please set the JAVA_HOME variable in your environment to match the
location of your Java installation." location of your Java installation."
fi
fi fi
# Increase the maximum file descriptors if we can. # Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #( case $MAX_FD in #(
max*) max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) || MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit" warn "Could not query maximum file descriptor limit"
esac esac
case $MAX_FD in #( case $MAX_FD in #(
'' | soft) :;; #( '' | soft) :;; #(
*) *)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" || ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD" warn "Could not set maximum file descriptor limit to $MAX_FD"
esac esac
@@ -165,7 +171,6 @@ fi
# For Cygwin or MSYS, switch paths to Windows format before running java # For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" ) JAVACMD=$( cygpath --unix "$JAVACMD" )
@@ -193,18 +198,27 @@ if "$cygwin" || "$msys" ; then
done done
fi fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
# shell script including quotes and variable substitutions, so put them in DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded. # Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \ set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \ "-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \ -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
org.gradle.wrapper.GradleWrapperMain \
"$@" "$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args. # Use "xargs" to parse quoted args.
# #
# With -n1 it outputs one arg per line, with the quotes and backslashes removed. # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Vendored
+58 -35
View File
@@ -13,19 +13,49 @@
@rem See the License for the specific language governing permissions and @rem See the License for the specific language governing permissions and
@rem limitations under the License. @rem limitations under the License.
@rem @rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%" == "" @echo off @if "%DEBUG%"=="" @echo off
@rem ########################################################################## @rem ##########################################################################
@rem @rem
@rem Gradle startup script for Windows @rem gradlew startup script for Windows
@rem @rem
@rem ########################################################################## @rem ##########################################################################
@rem Set local scope for the variables with windows NT shell @rem Set local scope for the variables, and ensure extensions are enabled
if "%OS%"=="Windows_NT" setlocal setlocal EnableExtensions
@rem Catch executions from older scripts and ensure they exit cleanly.
@rem This can be removed once we can be reasonably confident that few people
@rem will be migrating directly to this new wrapper.
goto afterSafetyNet
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
goto exitWithErrorLevel
:afterSafetyNet
set DIRNAME=%~dp0 set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=. if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0 set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME% set APP_HOME=%DIRNAME%
@@ -40,15 +70,16 @@ if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1 %JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2 echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo. 1>&2 echo.
echo Please set the JAVA_HOME variable in your environment to match the 1>&2 echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation. 1>&2 echo location of your Java installation.
goto fail "%COMSPEC%" /c exit 1
goto exitWithErrorLevel
:findJavaFromJavaHome :findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=% set JAVA_HOME=%JAVA_HOME:"=%
@@ -56,34 +87,26 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute if exist "%JAVA_EXE%" goto execute
echo. 1>&2 echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo. 1>&2 echo.
echo Please set the JAVA_HOME variable in your environment to match the 1>&2 echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation. 1>&2 echo location of your Java installation.
goto fail "%COMSPEC%" /c exit 1
goto exitWithErrorLevel
:execute :execute
@rem Setup the command line @rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle @rem Execute gradlew
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* @rem endlocal doesn't take effect until after the line is parsed and variables are expanded
@rem which allows us to clear the local environment before executing the java command
endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel & goto exitWithErrorLevel
:end @rem This label must not be changed. We rely on old scripts being able to jump to this point.
@rem End local scope for the variables with windows NT shell :exitWithErrorLevel
if "%ERRORLEVEL%"=="0" goto mainEnd @rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
"%COMSPEC%" /c exit %ERRORLEVEL%
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
@@ -6,14 +6,11 @@ import com.shr4pnel.ferretirc.irc.User
import com.shr4pnel.ferretirc.net.Connection import com.shr4pnel.ferretirc.net.Connection
import com.shr4pnel.ferretirc.net.messages.ClientMessage import com.shr4pnel.ferretirc.net.messages.ClientMessage
import com.shr4pnel.ferretirc.net.messages.ServerMessage import com.shr4pnel.ferretirc.net.messages.ServerMessage
import io.github.oshai.kotlinlogging.KotlinLogging
import io.github.oshai.kotlinlogging.KotlinLoggingConfiguration import io.github.oshai.kotlinlogging.KotlinLoggingConfiguration
import io.github.oshai.kotlinlogging.slf4j.logger
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel import kotlinx.coroutines.cancel
import org.slf4j.helpers.NOPLogger
class IrcClient( class IrcClient(
hostname: String, hostname: String,
@@ -30,8 +27,7 @@ class IrcClient(
lateinit var server: Server lateinit var server: Server
private set private set
lateinit var currentUser: User val user = User()
private set
@PublishedApi @PublishedApi
internal val connection = Connection(hostname, port, scope, enableLogging) internal val connection = Connection(hostname, port, scope, enableLogging)
@@ -52,6 +48,9 @@ class IrcClient(
} }
suspend fun join(channel: IRCChannel) = queueMessage(ClientMessage.Join(channel)) suspend fun join(channel: IRCChannel) = queueMessage(ClientMessage.Join(channel))
suspend fun quit(reason: String) = queueMessage(ClientMessage.Quit(reason))
suspend fun part(channels: List<String>) = queueMessage(ClientMessage.Part(channels))
suspend fun part(channel: String) = queueMessage(ClientMessage.Part(listOf(channel)))
/** /**
* Send a message to the IRC server writer * Send a message to the IRC server writer
@@ -108,19 +107,17 @@ class IrcClient(
realName: String? = null, realName: String? = null,
password: String? = null, password: String? = null,
) { ) {
currentUser = User(nick, "") // TODO TEMP USER ASSIGNMENT user.nick = nick // TODO TEMP USER ASSIGNMENT
val messages = val messages =
buildList { buildList {
if (!password.isNullOrEmpty()) add(ClientMessage.Pass(password)) if (!password.isNullOrEmpty()) add(ClientMessage.Pass(password))
add(ClientMessage.Cap.LS()) add(ClientMessage.Cap.LS())
add(ClientMessage.Nick(nick)) add(ClientMessage.Nick(nick))
if (!realName.isNullOrEmpty()) { if (!realName.isNullOrEmpty()) add(ClientMessage.User(nick, realName))
add(ClientMessage.User(nick, realName)) else add(ClientMessage.User(nick, nick))
} else {
add(ClientMessage.User(nick, nick))
}
add(ClientMessage.Cap.END()) add(ClientMessage.Cap.END())
}.toTypedArray() }.toTypedArray()
waitForNextMessageAfterAction<ServerMessage.Numeric.RPL_WELCOME> { queueMessages(*messages) } waitForNextMessageAfterAction<ServerMessage.Numeric.RPL_WELCOME> { queueMessages(*messages) }
} }
} }
@@ -6,6 +6,7 @@ import com.shr4pnel.ferretirc.net.messages.ServerMessage.Numeric
import io.github.oshai.kotlinlogging.KotlinLogging import io.github.oshai.kotlinlogging.KotlinLogging
import io.github.oshai.kotlinlogging.slf4j.logger import io.github.oshai.kotlinlogging.slf4j.logger
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.SharedFlow
@@ -114,20 +115,20 @@ class Server(
* @param T The type of ServerMessage to fetch * @param T The type of ServerMessage to fetch
* @return A set of messages of type T in the buffer that arrive before untilMessage appears * @return A set of messages of type T in the buffer that arrive before untilMessage appears
*/ */
suspend inline fun <reified T : ServerMessage, reified U : ServerMessage> fetchMessagesOfType( // suspend inline fun <reified T : ServerMessage, reified U : ServerMessage> fetchMessagesOfType(
timeoutMillis: Long = 5000, // timeoutMillis: Long = 5000,
noinline subscriptionMessage: suspend () -> Unit = {}, // noinline subscriptionMessage: suspend () -> Unit = {},
): List<T> { // ): List<T> {
val buffer = mutableListOf<T>() // val buffer = mutableListOf<T>()
withTimeoutOrNull(timeoutMillis) { // withTimeoutOrNull(timeoutMillis) {
msgBuffer // msgBuffer
.onSubscription { subscriptionMessage() } // .onSubscription { subscriptionMessage() }
.takeWhile { it !is U } // .takeWhile { it !is U }
.filterIsInstance<T>() // .filterIsInstance<T>()
.collect { buffer.add(it) } // .collect { buffer.add(it) }
} ?: logger.error { "Timed out while waiting to receive ${U::class}" } // } ?: logger.error { "Timed out while waiting to receive ${U::class}" }
return buffer.toList() // return buffer.toList()
} // }
fun fetchFeatures() { fun fetchFeatures() {
} }
@@ -137,12 +138,18 @@ class Server(
predicate: (T) -> Boolean = { true }, predicate: (T) -> Boolean = { true },
timeoutMillis: Long = 5000, timeoutMillis: Long = 5000,
onSubscribedLambda: suspend () -> Unit = {}, onSubscribedLambda: suspend () -> Unit = {},
): T = ): T {
withTimeout(timeoutMillis) { try {
msgBuffer return withTimeout(timeoutMillis) {
.onSubscription { onSubscribedLambda() } msgBuffer
.filter { kClass.isInstance(it) } .onSubscription { onSubscribedLambda() }
.map { kClass.cast(it) } .filter { kClass.isInstance(it) }
.first(predicate) .map { kClass.cast(it) }
.first(predicate)
}
} catch (e: TimeoutCancellationException) {
logger.error {"Timed out while waiting to receive ${kClass.simpleName} message"}
throw e
} }
}
} }
@@ -1,3 +1,5 @@
package com.shr4pnel.ferretirc.irc package com.shr4pnel.ferretirc.irc
class User(val nick: String, var mask: String?) class User(var nick: String? = null, var mask: String? = null) {
}
@@ -15,9 +15,9 @@ class Connection(
) { ) {
private val selectorManager = SelectorManager(Dispatchers.IO) private val selectorManager = SelectorManager(Dispatchers.IO)
private val socketBuilder = aSocket(selectorManager).tcp() private val socketBuilder = aSocket(selectorManager).tcp()
lateinit var socket: Socket lateinit var socket: Socket private set
lateinit var reader: MessageReader lateinit var reader: MessageReader private set
lateinit var writer: MessageWriter lateinit var writer: MessageWriter private set
suspend fun connect(): Server { suspend fun connect(): Server {
socket = socketBuilder.connect(hostname, port) socket = socketBuilder.connect(hostname, port)
@@ -61,6 +61,7 @@ class MessageParser(val incoming: Channel<String>, enableLogging: Boolean = fals
"CAP" -> Cap(getTrailingParameterString()) "CAP" -> Cap(getTrailingParameterString())
"PING" -> Ping(getTrailingParameterString()) "PING" -> Ping(getTrailingParameterString())
"ERROR" -> Error(getTrailingParameterString()) "ERROR" -> Error(getTrailingParameterString())
"PART" -> Part(getNonTrailingParameters())
else -> UNIMPLEMENTED("$command ${getTrailingParameterString()}") else -> UNIMPLEMENTED("$command ${getTrailingParameterString()}")
} }
} }
@@ -82,6 +83,7 @@ class MessageParser(val incoming: Channel<String>, enableLogging: Boolean = fals
TOPICWHOTIME(333), TOPICWHOTIME(333),
NAMREPLY(353), NAMREPLY(353),
ENDOFNAMES(366), ENDOFNAMES(366),
YOUREOPER(381),
NONE(0xbeef), ; NONE(0xbeef), ;
companion object { companion object {
@@ -112,6 +114,7 @@ class MessageParser(val incoming: Channel<String>, enableLogging: Boolean = fals
RPL.TOPICWHOTIME -> UNIMPLEMENTED(parameters.toString()) RPL.TOPICWHOTIME -> UNIMPLEMENTED(parameters.toString())
RPL.NAMREPLY -> UNIMPLEMENTED(parameters.toString()) RPL.NAMREPLY -> UNIMPLEMENTED(parameters.toString())
RPL.ENDOFNAMES -> RPL_ENDOFNAMES RPL.ENDOFNAMES -> RPL_ENDOFNAMES
RPL.YOUREOPER -> RPL_YOUREOPER
RPL.NONE -> UNIMPLEMENTED(parameters.toString()) RPL.NONE -> UNIMPLEMENTED(parameters.toString())
} }
} }
@@ -115,4 +115,21 @@ sealed class ClientMessage(val strName: String) {
override val trailing: String override val trailing: String
get() = token get() = token
} }
class Quit(val reason: String) : ClientMessage("QUIT") {
override val trailing: String
get() = reason
}
class Part(channels: kotlin.collections.List<String>) : ClientMessage("PART") {
val strChannels = listOf(channels.joinToString(","))
override val params: kotlin.collections.List<String>
get() = strChannels
}
class Stats(val query: Char) : ClientMessage("STATS") {
override val params: kotlin.collections.List<String>
get() = listOf(query.toString())
}
} }
@@ -13,6 +13,7 @@ sealed class ServerMessage {
data class Join(val target: String) : ServerMessage() data class Join(val target: String) : ServerMessage()
data class Ping(val token: String) : ServerMessage() data class Ping(val token: String) : ServerMessage()
data class Error(val message: String) : ServerMessage() data class Error(val message: String) : ServerMessage()
data class Part(val channels: List<String>) : ServerMessage()
sealed class Numeric(val number: Short) : ServerMessage() { sealed class Numeric(val number: Short) : ServerMessage() {
data class RPL_WELCOME(val message: String) : Numeric(1) data class RPL_WELCOME(val message: String) : Numeric(1)
@@ -27,5 +28,6 @@ sealed class ServerMessage {
data class RPL_TOPIC(val topic: String) : Numeric(332) data class RPL_TOPIC(val topic: String) : Numeric(332)
data class RPL_NAMREPLY(val message: String) : Numeric(353) data class RPL_NAMREPLY(val message: String) : Numeric(353)
data object RPL_ENDOFNAMES : Numeric(366) data object RPL_ENDOFNAMES : Numeric(366)
data object RPL_YOUREOPER : Numeric(381)
} }
} }
@@ -24,11 +24,11 @@ object Codes {
const val FG_START = ANSI.ESC_START + "38;5;" const val FG_START = ANSI.ESC_START + "38;5;"
const val FG_BOLD_START = ANSI.ESC_START + ANSI.BOLD + "38;5;" const val FG_BOLD_START = ANSI.ESC_START + ANSI.BOLD + "38;5;"
const val BG_START = ANSI.ESC_START + "48;5;" const val BG_START = ANSI.ESC_START + "48;5;"
const val RED = "9" const val RED = "196"
const val BLACK = "16" const val BLACK = "16"
const val BLUE = "26" const val BLUE = "26"
const val GREEN = "28" const val GREEN = "34"
const val ORANGE = "202" const val ORANGE = "208"
const val DIMMED_WHITE = "250" const val DIMMED_WHITE = "250"
const val WHITE = "255" const val WHITE = "255"
const val UNSET = "" const val UNSET = ""
@@ -52,7 +52,7 @@ class IrcClientTest {
fun shutdown() = fun shutdown() =
runBlocking { runBlocking {
logger.info { "Closing server." } logger.info { "Closing server." }
client.queueMessage(Message.Die()) client.quit("")
client.waitForNext<ServerMessage.Notice>() client.waitForNext<ServerMessage.Notice>()
processes.forEach { it.destroy() } processes.forEach { it.destroy() }
} }
@@ -0,0 +1,11 @@
package com.shr4pnel.ferretirc
import com.shr4pnel.ferretirc.net.messages.ClientMessage
import org.junit.jupiter.api.Test
class Sandbox {
@Test
fun doesPartUnderstandMultiChannel() {
val part = ClientMessage.Part(listOf("#Default", "#Secondary"))
}
}