Compare commits
37
Commits
becc871f52
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ec2d360a0 | ||
|
|
4f762aa8f8 | ||
|
|
521d17046f | ||
|
|
fe9a00110d | ||
|
|
feded91e72 | ||
|
|
6e880e0a20 | ||
|
|
c23b85712a | ||
|
|
00a4fd3a93 | ||
|
|
7e7361799a | ||
|
|
066b380a98 | ||
|
|
e09f391bff | ||
|
|
2db2daa897 | ||
|
|
1bb8ccb798 | ||
|
|
357405aba5
|
||
|
|
96d0c084b1
|
||
|
|
736b7b37df
|
||
|
|
0c3e3013cd
|
||
|
|
281b8fff2a
|
||
|
|
5575d96f93
|
||
|
|
06e0ff92de
|
||
|
|
d3deed36db
|
||
|
|
81efc6dcc3
|
||
|
|
4602af4e44
|
||
|
|
0bf6b0dae0
|
||
|
|
97fc15c7b2
|
||
|
|
6c13b6ecc6
|
||
|
|
796bd814e1
|
||
|
|
c728a612bb
|
||
|
|
5df0d734dc
|
||
|
|
101761bade
|
||
|
|
521dc00757
|
||
|
|
cc0719a061
|
||
|
|
7c65309d99
|
||
|
|
95b27aa0af
|
||
|
|
1599a20583
|
||
|
|
4368315657
|
||
|
|
8611ebb1ea
|
+7
-2
@@ -1,7 +1,12 @@
|
|||||||
[*.{kt,kts}]
|
[*.{kt,kts}]
|
||||||
ktlint_class_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = 4 # don't force multiline constructors unless they're big
|
|
||||||
ktlint_standard_class-naming = disabled # don't enforce capitalisation of classes
|
ktlint_standard_class-naming = disabled # don't enforce capitalisation of classes
|
||||||
ktlint_standard_when-entry-bracing = disabled
|
ktlint_standard_when-entry-bracing = disabled
|
||||||
ktlint_standard_blank-line-between-when-conditions = disabled
|
ktlint_standard_blank-line-between-when-conditions = disabled
|
||||||
ktlint_standard_blank-line-before-declaration = disabled
|
ktlint_standard_blank-line-before-declaration = disabled
|
||||||
ktlint_standard_multiline-expression-wrapping = disabled
|
ktlint_standard_multiline-expression-wrapping = disabled
|
||||||
|
ktlint_standard_multiline-loop = disabled
|
||||||
|
ktlint_function_signature_body_expression_wrapping = default
|
||||||
|
ktlint_standard_property-naming = disabled
|
||||||
|
ktlint_standard_function-signature = disabled
|
||||||
|
ktlint_standard_class-signature = disabled
|
||||||
|
ktlint_standard_multiline-if-else = disabled
|
||||||
+2
-1
@@ -44,6 +44,7 @@ bin/
|
|||||||
### Mac OS ###
|
### Mac OS ###
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
src/test/resources/logs/ngircd.log
|
src/test/resources/logs/*.log
|
||||||
!src/test/resources/logs/.gitkeep
|
!src/test/resources/logs/.gitkeep
|
||||||
.idea
|
.idea
|
||||||
|
todo.md
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|
||||||
|
|
||||||
+7
-2
@@ -2,10 +2,11 @@ plugins {
|
|||||||
kotlin("jvm") version "2.4.0"
|
kotlin("jvm") version "2.4.0"
|
||||||
id("org.jlleitschuh.gradle.ktlint") version "12.3.0"
|
id("org.jlleitschuh.gradle.ktlint") version "12.3.0"
|
||||||
id("dev.detekt") version "2.0.0-alpha.6"
|
id("dev.detekt") version "2.0.0-alpha.6"
|
||||||
|
id("org.jetbrains.dokka") version "2.2.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "com.shr4pnel"
|
group = "com.shr4pnel"
|
||||||
version = "1.0-SNAPSHOT"
|
version = "0.1.1"
|
||||||
val ktorVersion = "3.5.2"
|
val ktorVersion = "3.5.2"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
@@ -14,12 +15,14 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
testImplementation(kotlin("test"))
|
testImplementation(kotlin("test"))
|
||||||
|
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.11.0")
|
||||||
implementation("io.ktor:ktor-client-core:$ktorVersion")
|
implementation("io.ktor:ktor-client-core:$ktorVersion")
|
||||||
implementation("io.ktor:ktor-client-cio:$ktorVersion")
|
implementation("io.ktor:ktor-client-cio:$ktorVersion")
|
||||||
implementation("io.ktor:ktor-network:$ktorVersion")
|
implementation("io.ktor:ktor-network:$ktorVersion")
|
||||||
implementation("io.ktor:ktor-network-tls:$ktorVersion")
|
implementation("io.ktor:ktor-network-tls:$ktorVersion")
|
||||||
implementation("io.github.oshai:kotlin-logging-jvm:8.0.4")
|
implementation("io.github.oshai:kotlin-logging-jvm:8.0.4")
|
||||||
implementation("ch.qos.logback:logback-classic:1.6.1")
|
implementation("ch.qos.logback:logback-classic:1.6.3")
|
||||||
|
testImplementation("org.jline:jansi-core:4.4.3")
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
@@ -28,4 +31,6 @@ kotlin {
|
|||||||
|
|
||||||
tasks.test {
|
tasks.test {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
val logDir = layout.projectDirectory.dir("src/test/resources/logs").toString()
|
||||||
|
systemProperty("TEST_LOG_DIR", logDir)
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
BIN
Binary file not shown.
+5
-2
@@ -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
|
||||||
|
|||||||
@@ -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
@@ -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
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package com.shr4pnel.ferretirc
|
package com.shr4pnel.ferretirc
|
||||||
|
|
||||||
|
import com.shr4pnel.ferretirc.irc.IRCChannel
|
||||||
import com.shr4pnel.ferretirc.irc.Server
|
import com.shr4pnel.ferretirc.irc.Server
|
||||||
import com.shr4pnel.ferretirc.util.Helpers
|
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
|
||||||
@@ -11,17 +12,25 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
|
|
||||||
class IrcClient(hostname: String, port: Int, enableLogging: Boolean = true) {
|
class IrcClient(
|
||||||
|
hostname: String,
|
||||||
|
port: Int,
|
||||||
|
val enableLogging: Boolean = false,
|
||||||
|
) {
|
||||||
init {
|
init {
|
||||||
KotlinLoggingConfiguration.logStartupMessage = false
|
KotlinLoggingConfiguration.logStartupMessage = false
|
||||||
Helpers.enableLogging = enableLogging
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// private val logger = if (enableLogging) KotlinLogging.logger {} else KotlinLogging.logger(NOPLogger.NOP_LOGGER)
|
||||||
val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||||
|
|
||||||
lateinit var server: Server
|
lateinit var server: Server
|
||||||
|
private set
|
||||||
|
|
||||||
|
val user = User()
|
||||||
|
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
internal val connection = Connection(hostname, port, scope)
|
internal val connection = Connection(hostname, port, scope, enableLogging)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to the socket
|
* Connect to the socket
|
||||||
@@ -31,14 +40,18 @@ class IrcClient(hostname: String, port: Int, enableLogging: Boolean = true) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a message to the IRC server writer
|
* Send a message to the IRC server message writer
|
||||||
* This is asynchronous and ordered
|
|
||||||
* @param message The client message to send to the server
|
* @param message The client message to send to the server
|
||||||
*/
|
*/
|
||||||
suspend fun queueMessage(message: ClientMessage) {
|
suspend fun queueMessage(message: ClientMessage) {
|
||||||
connection.writer.outgoingMessages.send(message)
|
connection.writer.outgoingMessages.send(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
* This is asynchronous and ordered
|
* This is asynchronous and ordered
|
||||||
@@ -58,29 +71,53 @@ class IrcClient(hostname: String, port: Int, enableLogging: Boolean = true) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the next Server Message meeting condition
|
* Return the next Server Message meeting given condition "predicate"
|
||||||
* @param predicate A function to filter a message based on its parameters
|
* @param predicate A function to filter a message based on its parameters
|
||||||
|
* @param T A ServerMessage inheritor
|
||||||
|
* @return An instance of ServerMessage
|
||||||
|
* @see com.shr4pnel.ferretirc.irc.Server.waitForNext
|
||||||
|
* @see com.shr4pnel.ferretirc.net.messages.ServerMessage
|
||||||
*/
|
*/
|
||||||
suspend inline fun <reified T : ServerMessage> waitForNext(noinline predicate: (T) -> Boolean = { true }): T =
|
suspend inline fun <reified T : ServerMessage> waitForNext(noinline predicate: (T) -> Boolean = { true }): T =
|
||||||
connection.reader.waitForNext(T::class, predicate)
|
server.waitForNext(T::class, predicate)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queue a client message, and wait for the next server message meeting condition (predicate)
|
||||||
|
* @param predicate A function to filter a message based on its parameters
|
||||||
|
* @see com.shr4pnel.ferretirc.IrcClient.waitForNext
|
||||||
|
*/
|
||||||
|
suspend inline fun <reified T : ServerMessage> queueMessageAndWaitForNext(
|
||||||
|
message: ClientMessage,
|
||||||
|
noinline predicate: (T) -> Boolean = { true },
|
||||||
|
): T = server.waitForNext(T::class, predicate) { queueMessage(message) }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a subscription to the server message buffer, after performing an action
|
||||||
|
* @param predicate A function to filter the message buffer flow
|
||||||
|
* @param action A function to execute after message buffer flow collection has begun
|
||||||
|
* @see com.shr4pnel.ferretirc.IrcClient.waitForNext
|
||||||
|
*/
|
||||||
|
suspend inline fun <reified T : ServerMessage> waitForNextMessageAfterAction(
|
||||||
|
noinline predicate: (T) -> Boolean = { true },
|
||||||
|
noinline action: suspend () -> Unit,
|
||||||
|
): T = server.waitForNext(T::class, predicate) { action() }
|
||||||
|
|
||||||
suspend fun register(
|
suspend fun register(
|
||||||
nick: String,
|
nick: String,
|
||||||
realName: String? = null,
|
realName: String? = null,
|
||||||
password: String? = null,
|
password: String? = null,
|
||||||
) {
|
) {
|
||||||
|
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()
|
||||||
queueMessages(*messages.toTypedArray())
|
|
||||||
|
waitForNextMessageAfterAction<ServerMessage.Numeric.RPL_WELCOME> { queueMessages(*messages) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
package com.shr4pnel.ferretirc.irc
|
package com.shr4pnel.ferretirc.irc
|
||||||
|
|
||||||
class IRCChannel(val chanName: String, val clientCount: Int, val topic: String)
|
data class IRCChannel(val chanName: String, val clientCount: Int, val topic: String)
|
||||||
|
|||||||
+11
-10
@@ -1,23 +1,24 @@
|
|||||||
package com.shr4pnel.ferretirc.irc
|
package com.shr4pnel.ferretirc.irc
|
||||||
|
|
||||||
data class ISupportFeatures(val capabilities: List<Feature>)
|
sealed class ISupportFeature(key: String) {
|
||||||
|
|
||||||
sealed class Feature(key: String) {
|
|
||||||
// Indicates the maximum number of online nicknames a user may have in their accept list. First introduced in ircd-ratbox-3.0.9(r28737).
|
// Indicates the maximum number of online nicknames a user may have in their accept list. First introduced in ircd-ratbox-3.0.9(r28737).
|
||||||
data class ACCEPT(val max: Int) : Feature("ACCEPT")
|
data class ACCEPT(val max: Int) : ISupportFeature("ACCEPT")
|
||||||
|
|
||||||
// Indicates the maximum length of an away message. If "number" is not defined, there is no limit.
|
// Indicates the maximum length of an away message. If "number" is not defined, there is no limit.
|
||||||
data class AWAYLEN(val max: Int) : Feature("AWAYLEN")
|
data class AWAYLEN(val max: Int) : ISupportFeature("AWAYLEN")
|
||||||
|
|
||||||
// Indicates the character to be used as a user mode to let clients mark themselves as bots by setting it
|
// Indicates the character to be used as a user mode to let clients mark themselves as bots by setting it
|
||||||
data class BOT(val letter: Char) : Feature("BOT")
|
data class BOT(val letter: Char) : ISupportFeature("BOT")
|
||||||
|
|
||||||
// Indicates that the "caller-id" user mode is supported, which rejects messages from unauthorized users. "letter" defines the mode character, which is used for this feature. If the value is not given, it defaults to the mode "g".
|
// Indicates that the "caller-id" user mode is supported, which rejects messages from unauthorized users. "letter" defines the mode character, which is used for this feature. If the value is not given, it defaults to the mode "g".
|
||||||
data class CALLERID(val letter: Char) : Feature("CALLERID")
|
data class CALLERID(val letter: Char) : ISupportFeature("CALLERID")
|
||||||
|
|
||||||
// Indicates the method that’s used to compare equality of case-insensitive strings (such as nick/channel names). Typical values include "ascii" and "rfc1459". "rfc3454" is a proposed value that refers to the stringprep method described in RFC3454 (typically used for UTF-8 casefolding).
|
// Indicates the method that’s used to compare equality of case-insensitive strings (such as nick/channel names). Typical values include "ascii" and "rfc1459". "rfc3454" is a proposed value that refers to the stringprep method described in RFC3454 (typically used for UTF-8 casefolding).
|
||||||
data class CASEMAPPING(val method: String) : Feature("CASEMAPPING")
|
data class CASEMAPPING(val method: String) : ISupportFeature("CASEMAPPING")
|
||||||
|
|
||||||
// Indicates the maximum length of a nickname that a client may use. Other clients on the network may have nicknames longer than this.
|
/** Indicates the maximum length of a nickname that a client may use. Other clients on the network may have nicknames longer than this. */
|
||||||
data class MAXNICKLEN(val max: Int) : Feature("MAXNICKLEN")
|
data class MAXNICKLEN(val max: Int) : ISupportFeature("MAXNICKLEN")
|
||||||
|
|
||||||
|
/** deprecated but still commonly sent by IRCDs */
|
||||||
|
data class CHARSET(val charset: String) : ISupportFeature("CHARSET")
|
||||||
}
|
}
|
||||||
@@ -2,38 +2,154 @@ package com.shr4pnel.ferretirc.irc
|
|||||||
|
|
||||||
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 com.shr4pnel.ferretirc.net.messages.ServerMessage.Numeric
|
||||||
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||||
|
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.SharedFlow
|
import kotlinx.coroutines.flow.SharedFlow
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
import kotlinx.coroutines.flow.filter
|
||||||
import kotlinx.coroutines.flow.filterIsInstance
|
import kotlinx.coroutines.flow.filterIsInstance
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.onSubscription
|
import kotlinx.coroutines.flow.onSubscription
|
||||||
import kotlinx.coroutines.flow.takeWhile
|
import kotlinx.coroutines.flow.takeWhile
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withTimeout
|
||||||
|
import kotlinx.coroutines.withTimeoutOrNull
|
||||||
|
import org.slf4j.helpers.NOPLogger
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
import kotlin.reflect.cast
|
||||||
|
|
||||||
class Server(
|
class Server(
|
||||||
private val msgBuffer: SharedFlow<ServerMessage>,
|
@PublishedApi internal val msgBuffer: SharedFlow<ServerMessage>,
|
||||||
private val outgoingMessages: Channel<ClientMessage>,
|
@PublishedApi internal val outgoingMessages: Channel<ClientMessage>,
|
||||||
private val scope: CoroutineScope,
|
private val scope: CoroutineScope,
|
||||||
|
enableLogging: Boolean = false,
|
||||||
) {
|
) {
|
||||||
lateinit var features: ISupportFeatures
|
@PublishedApi
|
||||||
private set
|
internal val logger = if (enableLogging) KotlinLogging.logger {} else KotlinLogging.logger(NOPLogger.NOP_LOGGER)
|
||||||
|
|
||||||
var channels: Set<IRCChannel> = setOf()
|
private val _features = MutableStateFlow<List<ISupportFeature>>(emptyList())
|
||||||
private set
|
val features: StateFlow<List<ISupportFeature>> = _features.asStateFlow()
|
||||||
|
|
||||||
suspend fun fetchChannels(): Set<IRCChannel> {
|
/** Backing field for channels storing the current state of visible channels */
|
||||||
val buffer = mutableSetOf<IRCChannel>()
|
private val _channels = MutableStateFlow<List<IRCChannel>>(emptyList())
|
||||||
|
val channels: StateFlow<List<IRCChannel>> = _channels.asStateFlow()
|
||||||
|
|
||||||
|
private val _users = MutableStateFlow<List<User>>(emptyList())
|
||||||
|
val users: StateFlow<List<User>> = _users.asStateFlow()
|
||||||
|
|
||||||
|
init {
|
||||||
|
listen()
|
||||||
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
fun parseISupportFeature(msg: Numeric.RPL_ISUPPORT): List<ISupportFeature> {
|
||||||
|
val mutableFeatures = mutableListOf<ISupportFeature>()
|
||||||
|
msg.keypairs.forEach {
|
||||||
|
if (it.contains("=")) {
|
||||||
|
val split = it.split("=")
|
||||||
|
val key = split.first().uppercase()
|
||||||
|
val value = split.last()
|
||||||
|
|
||||||
|
val feature = when (key) {
|
||||||
|
"ACCEPT" -> ISupportFeature.ACCEPT(value.toInt())
|
||||||
|
"AWAYLEN" -> ISupportFeature.AWAYLEN(value.toInt())
|
||||||
|
"BOT" -> ISupportFeature.BOT(value.single())
|
||||||
|
"CALLERID" -> ISupportFeature.CALLERID(value.single())
|
||||||
|
"CASEMAPPING" -> ISupportFeature.CASEMAPPING(value)
|
||||||
|
"MAXNICKLEN" -> ISupportFeature.MAXNICKLEN(value.toInt())
|
||||||
|
"CHARSET" -> ISupportFeature.CHARSET(value)
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (feature != null)
|
||||||
|
mutableFeatures.add(feature)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mutableFeatures.toList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun fetchChannels(timeoutMillis: Long = 5000): List<IRCChannel> {
|
||||||
|
logger.debug { "Fetching IRC channels" }
|
||||||
|
val buffer = mutableListOf<IRCChannel>()
|
||||||
msgBuffer
|
msgBuffer
|
||||||
.onSubscription { outgoingMessages.send(ClientMessage.List()) }
|
.onSubscription { outgoingMessages.send(ClientMessage.List()) }
|
||||||
.filterIsInstance<ServerMessage.Numeric>()
|
.filterIsInstance<Numeric>()
|
||||||
.takeWhile { it !is ServerMessage.Numeric.RPL_LISTEND }
|
.takeWhile { it !is Numeric.RPL_LISTEND }
|
||||||
.filterIsInstance<ServerMessage.Numeric.RPL_LIST>()
|
.filterIsInstance<Numeric.RPL_LIST>()
|
||||||
.collect { buffer.add(IRCChannel(it.chanName, it.clientCount, it.topic)) }
|
.collect { buffer.add(IRCChannel(it.chanName, it.clientCount, it.topic)) }
|
||||||
|
val sortedChannels = buffer.sortedBy { it.chanName }
|
||||||
channels = buffer.toSortedSet(compareBy { it.chanName })
|
_channels.value = sortedChannels
|
||||||
return channels
|
return sortedChannels
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun listen() = scope.launch {
|
||||||
|
msgBuffer.collect { msg ->
|
||||||
|
when (msg) {
|
||||||
|
is Numeric.RPL_ISUPPORT -> {
|
||||||
|
val feats = parseISupportFeature(msg)
|
||||||
|
_features.value += feats
|
||||||
|
feats.forEach { logger.debug { "Parsed ISUPPORT: $it" } }
|
||||||
|
}
|
||||||
|
is ServerMessage.Ping -> {
|
||||||
|
val pong = ClientMessage.Pong(msg.token)
|
||||||
|
logger.debug { "[C->S]: Responding to server $msg with $pong" }
|
||||||
|
scope.launch { outgoingMessages.send(pong) }
|
||||||
|
}
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch messages of type T until untilMessage appears in buffer
|
||||||
|
* @param subscriptionMessage A lambda to execute before waiting for U
|
||||||
|
* @param U The server message to wait for before returning the Set of messages
|
||||||
|
* @param T The type of ServerMessage to fetch
|
||||||
|
* @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(
|
||||||
|
// timeoutMillis: Long = 5000,
|
||||||
|
// noinline subscriptionMessage: suspend () -> Unit = {},
|
||||||
|
// ): List<T> {
|
||||||
|
// val buffer = mutableListOf<T>()
|
||||||
|
// withTimeoutOrNull(timeoutMillis) {
|
||||||
|
// msgBuffer
|
||||||
|
// .onSubscription { subscriptionMessage() }
|
||||||
|
// .takeWhile { it !is U }
|
||||||
|
// .filterIsInstance<T>()
|
||||||
|
// .collect { buffer.add(it) }
|
||||||
|
// } ?: logger.error { "Timed out while waiting to receive ${U::class}" }
|
||||||
|
// return buffer.toList()
|
||||||
|
// }
|
||||||
|
|
||||||
fun fetchFeatures() {
|
fun fetchFeatures() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun <T : ServerMessage> waitForNext(
|
||||||
|
kClass: KClass<T>,
|
||||||
|
predicate: (T) -> Boolean = { true },
|
||||||
|
timeoutMillis: Long = 5000,
|
||||||
|
onSubscribedLambda: suspend () -> Unit = {},
|
||||||
|
): T {
|
||||||
|
try {
|
||||||
|
return withTimeout(timeoutMillis) {
|
||||||
|
msgBuffer
|
||||||
|
.onSubscription { onSubscribedLambda() }
|
||||||
|
.filter { kClass.isInstance(it) }
|
||||||
|
.map { kClass.cast(it) }
|
||||||
|
.first(predicate)
|
||||||
|
}
|
||||||
|
} catch (e: TimeoutCancellationException) {
|
||||||
|
logger.error {"Timed out while waiting to receive ${kClass.simpleName} message"}
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.shr4pnel.ferretirc.irc
|
||||||
|
|
||||||
|
class User(var nick: String? = null, var mask: String? = null) {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -7,19 +7,24 @@ import io.ktor.network.sockets.aSocket
|
|||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
|
||||||
class Connection(val hostname: String, val port: Int, val scope: CoroutineScope) {
|
class Connection(
|
||||||
|
val hostname: String,
|
||||||
|
val port: Int,
|
||||||
|
val scope: CoroutineScope,
|
||||||
|
val enableLogging: Boolean = false,
|
||||||
|
) {
|
||||||
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)
|
||||||
reader = MessageReader(socket, scope)
|
reader = MessageReader(socket, scope, enableLogging)
|
||||||
writer = MessageWriter(socket, scope)
|
writer = MessageWriter(socket, scope, enableLogging)
|
||||||
reader.start()
|
reader.start()
|
||||||
writer.start()
|
writer.start()
|
||||||
return Server(reader.sharedMessageBuffer, writer.outgoingMessages, scope)
|
return Server(reader.sharedMessageBuffer, writer.outgoingMessages, scope, enableLogging)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
package com.shr4pnel.ferretirc.net
|
package com.shr4pnel.ferretirc.net
|
||||||
|
|
||||||
import com.shr4pnel.ferretirc.net.messages.ServerMessage
|
import com.shr4pnel.ferretirc.net.messages.ServerMessage
|
||||||
import com.shr4pnel.ferretirc.util.Helpers
|
import com.shr4pnel.ferretirc.net.messages.ServerMessage.*
|
||||||
|
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.channels.Channel
|
import kotlinx.coroutines.channels.Channel
|
||||||
import org.slf4j.helpers.NOPLogger
|
import org.slf4j.helpers.NOPLogger
|
||||||
|
|
||||||
class MessageParser(val incoming: Channel<String>) {
|
class MessageParser(val incoming: Channel<String>, enableLogging: Boolean = false) {
|
||||||
val incomingParsedMessages = Channel<ServerMessage>()
|
val incomingParsedMessages = Channel<ServerMessage>()
|
||||||
private val logger = if (Helpers.enableLogging) KotlinLogging.logger {} else KotlinLogging.logger(NOPLogger.NOP_LOGGER)
|
private val logger = if (enableLogging) KotlinLogging.logger {} else KotlinLogging.logger(NOPLogger.NOP_LOGGER)
|
||||||
|
|
||||||
class MessageBuilder {
|
class MessageBuilder {
|
||||||
private var tags: String? = null
|
private var tags: String? = null
|
||||||
@@ -19,7 +20,10 @@ class MessageParser(val incoming: Channel<String>) {
|
|||||||
abstract class Command(open val command: String, open val parameters: List<String>) {
|
abstract class Command(open val command: String, open val parameters: List<String>) {
|
||||||
abstract fun toServerMessage(): ServerMessage
|
abstract fun toServerMessage(): ServerMessage
|
||||||
|
|
||||||
fun getTrailingParameterIndex() = parameters.indexOfFirst { it.startsWith(":") }
|
fun getTrailingParameterIndex(): Int {
|
||||||
|
val index = parameters.indexOfFirst { it.startsWith(":") }
|
||||||
|
return if (index != -1) index else 0
|
||||||
|
}
|
||||||
|
|
||||||
fun getTrailingParameterString() =
|
fun getTrailingParameterString() =
|
||||||
parameters
|
parameters
|
||||||
@@ -27,48 +31,59 @@ class MessageParser(val incoming: Channel<String>) {
|
|||||||
.joinToString(" ")
|
.joinToString(" ")
|
||||||
.removePrefix(":")
|
.removePrefix(":")
|
||||||
|
|
||||||
fun getNonTrailingParameterString() =
|
fun getNonTrailingParameterString(startIndex: Int = 0) =
|
||||||
parameters
|
parameters
|
||||||
.subList(0, getTrailingParameterIndex())
|
.subList(startIndex, getTrailingParameterIndex())
|
||||||
.joinToString(" ")
|
.joinToString(" ")
|
||||||
.removePrefix(":")
|
.removePrefix(":")
|
||||||
|
|
||||||
fun getNonTrailingParameters() = getNonTrailingParameterString().split(" ")
|
fun getNonTrailingParameters() =
|
||||||
|
getNonTrailingParameterString()
|
||||||
|
.split(" ")
|
||||||
|
|
||||||
class NamedCommand(override val command: String, override val parameters: List<String>) : Command(command, parameters) {
|
class NamedCommand(override val command: String, override val parameters: List<String>) : Command(command, parameters) {
|
||||||
override fun toServerMessage() =
|
override fun toServerMessage() =
|
||||||
when (command.uppercase()) {
|
when (command.uppercase()) {
|
||||||
"PONG" -> ServerMessage.Pong(getTrailingParameterString().removePrefix(":"))
|
"PONG" -> Pong(getTrailingParameterString().removePrefix(":"))
|
||||||
|
"MODE" -> Mode(
|
||||||
// TODO MODE, CHANMODE, LOCALMODE
|
parameters.first(), // TODO MODE, CHANMODE, LOCALMODE
|
||||||
"MODE" ->
|
parameters.last().removePrefix(":"),
|
||||||
ServerMessage.Mode(
|
)
|
||||||
parameters.first(),
|
"NOTICE" -> Notice(
|
||||||
parameters.last().removePrefix(":"),
|
getNonTrailingParameters(),
|
||||||
)
|
getTrailingParameterString(),
|
||||||
|
)
|
||||||
"NOTICE" ->
|
"PRIVMSG" -> PrivMsg(
|
||||||
ServerMessage.Notice(
|
getNonTrailingParameters(),
|
||||||
getNonTrailingParameters(),
|
getTrailingParameterString(),
|
||||||
getTrailingParameterString(),
|
)
|
||||||
)
|
"JOIN" -> Join(getTrailingParameterString())
|
||||||
|
"CAP" -> Cap(getTrailingParameterString())
|
||||||
"PRIVMSG" ->
|
"PING" -> Ping(getTrailingParameterString())
|
||||||
ServerMessage.PrivMsg(
|
"ERROR" -> Error(getTrailingParameterString())
|
||||||
getNonTrailingParameters(),
|
"PART" -> Part(getNonTrailingParameters())
|
||||||
getTrailingParameterString(),
|
else -> UNIMPLEMENTED("$command ${getTrailingParameterString()}")
|
||||||
)
|
|
||||||
|
|
||||||
else -> ServerMessage.UNIMPLEMENTED("$command ${parameters.joinToString(" ")}")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class NumericCommand(override val command: String, override val parameters: List<String>) : Command(command, parameters) {
|
class NumericCommand(override val command: String, override val parameters: List<String>) : Command(command, parameters) {
|
||||||
private enum class RPL(val underlying: Int) {
|
private enum class RPL(val underlying: Int) {
|
||||||
|
WELCOME(1),
|
||||||
|
YOURHOST(2),
|
||||||
|
CREATED(3),
|
||||||
|
MYINFO(4),
|
||||||
ISUPPORT(5),
|
ISUPPORT(5),
|
||||||
|
BOUNCE(10),
|
||||||
|
STATSCOMMANDS(212),
|
||||||
|
ENDOFSTATS(219),
|
||||||
LISTSTART(321),
|
LISTSTART(321),
|
||||||
LIST(322),
|
LIST(322),
|
||||||
LISTEND(323),
|
LISTEND(323),
|
||||||
|
TOPIC(332),
|
||||||
|
TOPICWHOTIME(333),
|
||||||
|
NAMREPLY(353),
|
||||||
|
ENDOFNAMES(366),
|
||||||
|
YOUREOPER(381),
|
||||||
NONE(0xbeef), ;
|
NONE(0xbeef), ;
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -80,38 +95,32 @@ class MessageParser(val incoming: Channel<String>) {
|
|||||||
|
|
||||||
override fun toServerMessage() =
|
override fun toServerMessage() =
|
||||||
when (RPL from command) {
|
when (RPL from command) {
|
||||||
RPL.ISUPPORT -> ServerMessage.Numeric.RPL_ISUPPORT(getNonTrailingParameterString())
|
RPL.WELCOME -> RPL_WELCOME(getTrailingParameterString())
|
||||||
RPL.LISTSTART -> ServerMessage.Numeric.RPL_LISTSTART()
|
RPL.YOURHOST -> RPL_YOURHOST(getTrailingParameterString())
|
||||||
RPL.LIST -> ServerMessage.Numeric.RPL_LIST(
|
RPL.CREATED -> RPL_CREATED(getTrailingParameterString())
|
||||||
|
RPL.MYINFO -> RPL_MYINFO(getTrailingParameterString())
|
||||||
|
RPL.BOUNCE -> UNIMPLEMENTED(parameters.toString())
|
||||||
|
RPL.ISUPPORT -> RPL_ISUPPORT(getNonTrailingParameterString(1).split(" "))
|
||||||
|
RPL.LISTSTART -> RPL_LISTSTART
|
||||||
|
RPL.LIST -> RPL_LIST(
|
||||||
parameters[1],
|
parameters[1],
|
||||||
parameters[2].toInt(),
|
parameters[2].toInt(),
|
||||||
getTrailingParameterString(),
|
getTrailingParameterString(),
|
||||||
)
|
)
|
||||||
RPL.LISTEND -> ServerMessage.Numeric.RPL_LISTEND()
|
RPL.LISTEND -> RPL_LISTEND
|
||||||
RPL.NONE -> ServerMessage.UNIMPLEMENTED(parameters.toString())
|
RPL.STATSCOMMANDS -> UNIMPLEMENTED(parameters.toString())
|
||||||
|
RPL.ENDOFSTATS -> UNIMPLEMENTED(parameters.toString())
|
||||||
|
RPL.TOPIC -> RPL_TOPIC(getTrailingParameterString())
|
||||||
|
RPL.TOPICWHOTIME -> UNIMPLEMENTED(parameters.toString())
|
||||||
|
RPL.NAMREPLY -> UNIMPLEMENTED(parameters.toString())
|
||||||
|
RPL.ENDOFNAMES -> RPL_ENDOFNAMES
|
||||||
|
RPL.YOUREOPER -> RPL_YOUREOPER
|
||||||
|
RPL.NONE -> UNIMPLEMENTED(parameters.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Messages have this format, as rough ABNF:
|
|
||||||
*
|
|
||||||
* message ::= ['@' <tags> SPACE] [':' <source> SPACE] <command> <parameters> <crlf>
|
|
||||||
* SPACE ::= %x20 *( %x20 ) ; space character(s)
|
|
||||||
* crlf ::= %x0D %x0A ; "carriage return" "linefeed"
|
|
||||||
*
|
|
||||||
* The specific parts of an IRC message are:
|
|
||||||
*
|
|
||||||
* tags: Optional metadata on a message, starting with ('@', 0x40).
|
|
||||||
*
|
|
||||||
* source: Optional note of where the message came from, starting with (':', 0x3A).
|
|
||||||
*
|
|
||||||
* command: The specific command this message represents.
|
|
||||||
*
|
|
||||||
* parameters: If it exists, data relevant to this specific command.
|
|
||||||
*
|
|
||||||
* ===================
|
|
||||||
*
|
|
||||||
* Convert line from server into tokens split on strings and remove elements that belong
|
* Convert line from server into tokens split on strings and remove elements that belong
|
||||||
* to different segments of the IRC message e.g. tags, prefixes etc
|
* to different segments of the IRC message e.g. tags, prefixes etc
|
||||||
*/
|
*/
|
||||||
@@ -119,31 +128,28 @@ class MessageParser(val incoming: Channel<String>) {
|
|||||||
val tokens = commandList.toMutableList()
|
val tokens = commandList.toMutableList()
|
||||||
|
|
||||||
// remove tags from strlist if present
|
// remove tags from strlist if present
|
||||||
tags =
|
tags = if (tokens.first().startsWith("@")) {
|
||||||
if (tokens.first().startsWith("@")) {
|
tokens.removeFirst()
|
||||||
tokens.removeFirst()
|
} else {
|
||||||
} else {
|
null
|
||||||
null
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// remove client prefix (nick&opt hostname) if present
|
// remove client prefix (nick&opt hostname) if present
|
||||||
prefix =
|
prefix = if (tokens.first().startsWith(":")) {
|
||||||
if (tokens.first().startsWith(":")) {
|
tokens.removeFirst()
|
||||||
tokens.removeFirst()
|
} else {
|
||||||
} else {
|
null
|
||||||
null
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// get command e.g. PING
|
// get command e.g. PING, 005
|
||||||
val commandStr = tokens.removeFirst()
|
val commandStr = tokens.removeFirst()
|
||||||
|
|
||||||
// Check if command is a numeric (RPL/ERR) or named
|
// Check if command is a numeric (RPL/ERR) or named
|
||||||
command =
|
command = if (commandStr.toIntOrNull() == null) {
|
||||||
if (commandStr.toIntOrNull() == null) {
|
Command.NamedCommand(commandStr, tokens)
|
||||||
Command.NamedCommand(commandStr, tokens)
|
} else {
|
||||||
} else {
|
Command.NumericCommand(commandStr, tokens)
|
||||||
Command.NumericCommand(commandStr, tokens)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return command.toServerMessage()
|
return command.toServerMessage()
|
||||||
}
|
}
|
||||||
@@ -155,7 +161,13 @@ class MessageParser(val incoming: Channel<String>) {
|
|||||||
val builder = MessageBuilder()
|
val builder = MessageBuilder()
|
||||||
for (msg in incoming) {
|
for (msg in incoming) {
|
||||||
logger.trace { "Receiving: $msg" }
|
logger.trace { "Receiving: $msg" }
|
||||||
incomingParsedMessages.send(builder.build(msg))
|
val parsed = builder.build(msg)
|
||||||
|
if (parsed is UNIMPLEMENTED) {
|
||||||
|
logger.warn { "[S->C]: Left unparsed: $msg" }
|
||||||
|
} else {
|
||||||
|
logger.debug { "[S->C]: Got $parsed" }
|
||||||
|
}
|
||||||
|
incomingParsedMessages.send(parsed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package com.shr4pnel.ferretirc.net
|
package com.shr4pnel.ferretirc.net
|
||||||
|
|
||||||
import com.shr4pnel.ferretirc.net.messages.MessageIO
|
|
||||||
import com.shr4pnel.ferretirc.net.messages.ServerMessage
|
import com.shr4pnel.ferretirc.net.messages.ServerMessage
|
||||||
import com.shr4pnel.ferretirc.util.Helpers
|
|
||||||
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 io.ktor.network.sockets.Socket
|
import io.ktor.network.sockets.Socket
|
||||||
@@ -10,53 +8,37 @@ import io.ktor.network.sockets.openReadChannel
|
|||||||
import io.ktor.utils.io.ByteReadChannel
|
import io.ktor.utils.io.ByteReadChannel
|
||||||
import io.ktor.utils.io.readLineStrict
|
import io.ktor.utils.io.readLineStrict
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.channels.Channel
|
||||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
import kotlinx.coroutines.flow.asSharedFlow
|
import kotlinx.coroutines.flow.asSharedFlow
|
||||||
import kotlinx.coroutines.flow.filter
|
|
||||||
import kotlinx.coroutines.flow.first
|
|
||||||
import kotlinx.coroutines.flow.map
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.slf4j.helpers.NOPLogger
|
import org.slf4j.helpers.NOPLogger
|
||||||
import kotlin.reflect.KClass
|
|
||||||
import kotlin.reflect.cast
|
|
||||||
|
|
||||||
class MessageReader(socket: Socket, scope: CoroutineScope) : MessageIO(socket, scope) {
|
class MessageReader(val socket: Socket, val scope: CoroutineScope, enableLogging: Boolean = false) {
|
||||||
private lateinit var receive: ByteReadChannel
|
private lateinit var receive: ByteReadChannel
|
||||||
private val messageBuffer = MutableSharedFlow<ServerMessage>(16, 64)
|
val incomingMessages = Channel<String>(Channel.BUFFERED)
|
||||||
|
private val messageBuffer = MutableSharedFlow<ServerMessage>(0, 64)
|
||||||
val sharedMessageBuffer = messageBuffer.asSharedFlow()
|
val sharedMessageBuffer = messageBuffer.asSharedFlow()
|
||||||
val parser = MessageParser(incomingMessages)
|
val parser = MessageParser(incomingMessages, enableLogging)
|
||||||
private val logger = if (Helpers.enableLogging) KotlinLogging.logger {} else KotlinLogging.logger(NOPLogger.NOP_LOGGER)
|
private val logger = if (enableLogging) KotlinLogging.logger {} else KotlinLogging.logger(NOPLogger.NOP_LOGGER)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
parser.start()
|
parser.start()
|
||||||
}
|
}
|
||||||
scope.launch {
|
scope.launch {
|
||||||
for (msg in parser.incomingParsedMessages)
|
for (msg in parser.incomingParsedMessages) // receive parsed messages
|
||||||
messageBuffer.emit(msg)
|
messageBuffer.emit(msg) // send messages down shared flow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun start() {
|
fun start() {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
receive = socket.openReadChannel()
|
receive = socket.openReadChannel()
|
||||||
while (true) {
|
while (true) {
|
||||||
val line = receive.readLineStrict() ?: break // >:( no LineEnding option for just CRLF? charlatans...
|
val line = receive.readLineStrict() ?: break // >:( no LineEnding option for just CRLF? charlatans...
|
||||||
logger.debug { "Receive: $line" }
|
incomingMessages.send(line) // send raw messages to parser
|
||||||
incomingMessages.send(line)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun <T : ServerMessage> waitForNext(
|
|
||||||
kClass: KClass<T>,
|
|
||||||
predicate: (T) -> Boolean = { true },
|
|
||||||
): T {
|
|
||||||
return messageBuffer
|
|
||||||
.filter {
|
|
||||||
kClass.isInstance(it)
|
|
||||||
}.map {
|
|
||||||
kClass.cast(it)
|
|
||||||
}.first(predicate)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.shr4pnel.ferretirc.net
|
package com.shr4pnel.ferretirc.net
|
||||||
|
|
||||||
import com.shr4pnel.ferretirc.net.messages.MessageIO
|
import com.shr4pnel.ferretirc.net.messages.ClientMessage
|
||||||
import com.shr4pnel.ferretirc.util.Helpers
|
|
||||||
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 io.ktor.network.sockets.Socket
|
import io.ktor.network.sockets.Socket
|
||||||
@@ -9,19 +8,21 @@ import io.ktor.network.sockets.openWriteChannel
|
|||||||
import io.ktor.utils.io.ByteWriteChannel
|
import io.ktor.utils.io.ByteWriteChannel
|
||||||
import io.ktor.utils.io.writeFully
|
import io.ktor.utils.io.writeFully
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.channels.Channel
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.slf4j.helpers.NOPLogger
|
import org.slf4j.helpers.NOPLogger
|
||||||
|
|
||||||
class MessageWriter(socket: Socket, scope: CoroutineScope) : MessageIO(socket, scope) {
|
class MessageWriter(val socket: Socket, val scope: CoroutineScope, enableLogging: Boolean = false) {
|
||||||
private lateinit var send: ByteWriteChannel
|
private lateinit var send: ByteWriteChannel
|
||||||
private val logger = if (Helpers.enableLogging) KotlinLogging.logger {} else KotlinLogging.logger(NOPLogger.NOP_LOGGER)
|
private val logger = if (enableLogging) KotlinLogging.logger {} else KotlinLogging.logger(NOPLogger.NOP_LOGGER)
|
||||||
|
val outgoingMessages = Channel<ClientMessage>(Channel.BUFFERED)
|
||||||
|
|
||||||
override fun start() =
|
fun start() =
|
||||||
scope.launch {
|
scope.launch {
|
||||||
send = socket.openWriteChannel()
|
send = socket.openWriteChannel()
|
||||||
|
|
||||||
for (msg in outgoingMessages) {
|
for (msg in outgoingMessages) {
|
||||||
logger.debug { "Sending: ${msg.toWireIntermediate()}" }
|
logger.debug { "[C->S]: Sending ${msg.toWireIntermediate()}" }
|
||||||
send.writeFully(msg.toWire())
|
send.writeFully(msg.toWire())
|
||||||
send.flush()
|
send.flush()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ sealed class ClientMessage(val strName: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun toString() = "$strName[params=$params trailing=:$trailing]"
|
||||||
|
|
||||||
class Ping(val token: String? = null) : ClientMessage("PING") {
|
class Ping(val token: String? = null) : ClientMessage("PING") {
|
||||||
init {
|
init {
|
||||||
require(token?.isNotEmpty() ?: true) {
|
require(token?.isNotEmpty() ?: true) {
|
||||||
@@ -97,14 +99,37 @@ sealed class ClientMessage(val strName: String) {
|
|||||||
get() = listOf(channel.chanName)
|
get() = listOf(channel.chanName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO RPL_ISUPPORT REQUIREMENTS IN FUN EG LINELEN STATUSMSG - ALSO ADD FUCKING STUPID STATUSMSG & SUPPORT FOR MASKS. FUCK ME
|
||||||
class PrivMsg(val target: IRCChannel, val message: String) : ClientMessage("PRIVMSG") {
|
class PrivMsg(val target: IRCChannel, val message: String) : ClientMessage("PRIVMSG") {
|
||||||
override val params: kotlin.collections.List<String>
|
override val params: kotlin.collections.List<String>
|
||||||
get() =
|
get() =
|
||||||
listOf(
|
listOf(
|
||||||
target.chanName,
|
target.chanName,
|
||||||
) // TODO RPL_ISUPPORT REQUIREMENTS IN FUN EG LINELEN STATUSMSG - ALSO ADD FUCKING STUPID STATUSMSG & SUPPORT FOR MASKS. FUCK ME
|
)
|
||||||
|
|
||||||
override val trailing: String
|
override val trailing: String
|
||||||
get() = message
|
get() = message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Pong(val token: String) : ClientMessage("PONG") {
|
||||||
|
override val trailing: String
|
||||||
|
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())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.shr4pnel.ferretirc.net.messages
|
|
||||||
|
|
||||||
import io.ktor.network.sockets.Socket
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.channels.Channel
|
|
||||||
|
|
||||||
abstract class MessageIO(val socket: Socket, val scope: CoroutineScope) {
|
|
||||||
val incomingMessages = Channel<String>(Channel.BUFFERED)
|
|
||||||
val outgoingMessages = Channel<ClientMessage>(Channel.BUFFERED)
|
|
||||||
|
|
||||||
abstract fun start(): Any
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -4,25 +4,30 @@ package com.shr4pnel.ferretirc.net.messages
|
|||||||
* Representation of responses from the IRC server
|
* Representation of responses from the IRC server
|
||||||
*/
|
*/
|
||||||
sealed class ServerMessage {
|
sealed class ServerMessage {
|
||||||
data class Cap(val placeholder: String? = null) : ServerMessage()
|
data class Cap(val capabilities: String) : ServerMessage()
|
||||||
|
|
||||||
data class Pong(val token: String? = null) : ServerMessage()
|
data class Pong(val token: String? = null) : ServerMessage()
|
||||||
|
|
||||||
data class Mode(val operatorName: String, val pMask: String) : ServerMessage()
|
data class Mode(val operatorName: String, val pMask: String) : ServerMessage()
|
||||||
|
|
||||||
data class PrivMsg(val targets: List<String>, val message: String) : ServerMessage()
|
data class PrivMsg(val targets: List<String>, val message: String) : ServerMessage()
|
||||||
|
|
||||||
data class Notice(val targets: List<String>, val message: String) : ServerMessage()
|
data class Notice(val targets: List<String>, val message: String) : ServerMessage()
|
||||||
|
|
||||||
data class UNIMPLEMENTED(val msg: String) : ServerMessage()
|
data class UNIMPLEMENTED(val msg: String) : ServerMessage()
|
||||||
|
data class Join(val target: String) : ServerMessage()
|
||||||
|
data class Ping(val token: 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_ISUPPORT(val keypairs: String) : Numeric(5)
|
data class RPL_WELCOME(val message: String) : Numeric(1)
|
||||||
|
data class RPL_YOURHOST(val message: String) : Numeric(2)
|
||||||
class RPL_LISTSTART : Numeric(321)
|
data class RPL_CREATED(val message: String) : Numeric(3)
|
||||||
|
data class RPL_MYINFO(val message: String) : Numeric(4)
|
||||||
|
data class RPL_ISUPPORT(val keypairs: List<String>) : Numeric(5)
|
||||||
|
data class RPL_LUSER(val message: String) : Numeric(251)
|
||||||
|
data object RPL_LISTSTART : Numeric(321)
|
||||||
data class RPL_LIST(val chanName: String, val clientCount: Int, val topic: String) : Numeric(322)
|
data class RPL_LIST(val chanName: String, val clientCount: Int, val topic: String) : Numeric(322)
|
||||||
|
data object RPL_LISTEND : Numeric(323)
|
||||||
class RPL_LISTEND : Numeric(323)
|
data class RPL_TOPIC(val topic: String) : Numeric(332)
|
||||||
|
data class RPL_NAMREPLY(val message: String) : Numeric(353)
|
||||||
|
data object RPL_ENDOFNAMES : Numeric(366)
|
||||||
|
data object RPL_YOUREOPER : Numeric(381)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
package com.shr4pnel.ferretirc.util
|
|
||||||
|
|
||||||
class Helpers {
|
|
||||||
companion object LoggingConfig {
|
|
||||||
var enableLogging = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
package com.shr4pnel.ferretirc.util
|
||||||
|
|
||||||
|
import ch.qos.logback.classic.Level
|
||||||
|
import ch.qos.logback.classic.spi.ILoggingEvent
|
||||||
|
import ch.qos.logback.core.pattern.CompositeConverter
|
||||||
|
import ch.qos.logback.core.pattern.color.BoldWhiteCompositeConverter
|
||||||
|
import ch.qos.logback.core.pattern.color.ForegroundCompositeConverterBase
|
||||||
|
import ch.qos.logback.core.pattern.color.ANSIConstants as ANSI
|
||||||
|
|
||||||
|
private fun center(severity: String, width: Int = 7): String {
|
||||||
|
val pad = width - severity.length
|
||||||
|
if (pad <= 0) return severity
|
||||||
|
val leading = pad / 2
|
||||||
|
return buildString {
|
||||||
|
repeat(leading) { append(" ") }
|
||||||
|
append(severity)
|
||||||
|
repeat(pad - leading) { append(" ") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 8 bit ANSI codes (logback uses 3/4 bit which isn't always equivalent) */
|
||||||
|
object Codes {
|
||||||
|
const val SET_DEFAULT_COLOR = ANSI.ESC_START + ANSI.RESET + ANSI.DEFAULT_FG + ANSI.ESC_END
|
||||||
|
const val FG_START = ANSI.ESC_START + "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 RED = "196"
|
||||||
|
const val BLACK = "16"
|
||||||
|
const val BLUE = "26"
|
||||||
|
const val GREEN = "34"
|
||||||
|
const val ORANGE = "208"
|
||||||
|
const val DIMMED_WHITE = "250"
|
||||||
|
const val WHITE = "255"
|
||||||
|
const val UNSET = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface of HighlightingCompositeConverterExt, used to colour the background and foreground of log messages
|
||||||
|
* depending on their severity.
|
||||||
|
*
|
||||||
|
* Inheritor of ForegroundCompositeConverterBase, the implementation controlling colour-based transformations of
|
||||||
|
* log events
|
||||||
|
*
|
||||||
|
* @see HighlightingCompositeConverterExt
|
||||||
|
* @see CompositeConverter
|
||||||
|
*/
|
||||||
|
abstract class ForegroundBackgroundCompositeConverter<E : ILoggingEvent> : ForegroundCompositeConverterBase<E>() {
|
||||||
|
override fun transform(event: E, `in`: String) = buildString {
|
||||||
|
val fg = getForegroundColorCode(event)
|
||||||
|
val bg = getBackgroundColourCode(event)
|
||||||
|
val severity = center(`in`.trim())
|
||||||
|
if (fg.isNotEmpty()) {
|
||||||
|
append(Codes.FG_BOLD_START)
|
||||||
|
append(fg)
|
||||||
|
append(ANSI.ESC_END)
|
||||||
|
}
|
||||||
|
if (bg.isNotEmpty()) {
|
||||||
|
append(Codes.BG_START)
|
||||||
|
append(getBackgroundColourCode(event))
|
||||||
|
append(ANSI.ESC_END)
|
||||||
|
}
|
||||||
|
append(severity)
|
||||||
|
append(Codes.SET_DEFAULT_COLOR)
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract fun getBackgroundColourCode(event: ILoggingEvent): String
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converter class extension for control over backgrounds and foregrounds<
|
||||||
|
*
|
||||||
|
* Overrides methods of ForegroundBackgroundCompositeConverter to specify the bg/fg colours depending on severity
|
||||||
|
*
|
||||||
|
* Adapted from [shuwada/logback-custom-color](https://github.com/shuwada/logback-custom-color)
|
||||||
|
*/
|
||||||
|
class HighlightingCompositeConverterExt : ForegroundBackgroundCompositeConverter<ILoggingEvent>() {
|
||||||
|
override fun getForegroundColorCode(event: ILoggingEvent) = when (event.level) {
|
||||||
|
Level.TRACE -> Codes.WHITE
|
||||||
|
Level.DEBUG -> Codes.WHITE
|
||||||
|
Level.WARN -> Codes.WHITE
|
||||||
|
Level.INFO -> Codes.WHITE
|
||||||
|
Level.ERROR -> Codes.WHITE
|
||||||
|
else -> Codes.UNSET
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getBackgroundColourCode(event: ILoggingEvent) = when (event.level) {
|
||||||
|
Level.TRACE -> Codes.BLACK
|
||||||
|
Level.DEBUG -> Codes.GREEN
|
||||||
|
Level.WARN -> Codes.ORANGE
|
||||||
|
Level.INFO -> Codes.BLUE
|
||||||
|
Level.ERROR -> Codes.RED
|
||||||
|
else -> Codes.UNSET
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converter rule which pulls out the last string of the thread split by spaces
|
||||||
|
*/
|
||||||
|
class ThreadConverter<E> : CompositeConverter<E>() {
|
||||||
|
override fun transform(event: E, `in`: String) = `in`.split(" ").last()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converter rule which converts text to bold white
|
||||||
|
*/
|
||||||
|
class BoldWhiteCompositeConverterExt<E> : BoldWhiteCompositeConverter<E>() {
|
||||||
|
override fun transform(event: E, `in`: String) =
|
||||||
|
Codes.FG_BOLD_START + Codes.DIMMED_WHITE + ANSI.ESC_END + `in` + Codes.SET_DEFAULT_COLOR
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<included>
|
||||||
|
<import class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"/>
|
||||||
|
<import class="ch.qos.logback.core.ConsoleAppender"/>
|
||||||
|
<import class="ch.qos.logback.classic.filter.ThresholdFilter"/>
|
||||||
|
<import class="ch.qos.logback.core.FileAppender"/>
|
||||||
|
<import class="com.shr4pnel.ferretirc.util.HighlightingCompositeConverterExt"/>
|
||||||
|
<import class="com.shr4pnel.ferretirc.util.ThreadConverter"/>
|
||||||
|
<import class="com.shr4pnel.ferretirc.util.BoldWhiteCompositeConverterExt"/>
|
||||||
|
<!-- https://logback.qos.ch/manual/layouts.html#formatModifiers -->
|
||||||
|
<conversionRule conversionWord="highlightext" class="HighlightingCompositeConverterExt" />
|
||||||
|
<conversionRule conversionWord="boldwhiteext" class="BoldWhiteCompositeConverterExt" />
|
||||||
|
<conversionRule conversionWord="threadconvert" class="ThreadConverter" />
|
||||||
|
<appender name="STDOUT" class="ConsoleAppender">
|
||||||
|
<filter class="ThresholdFilter">
|
||||||
|
<level>${STDOUT_LEVEL:-debug}</level>
|
||||||
|
</filter>
|
||||||
|
<encoder class="PatternLayoutEncoder">
|
||||||
|
<pattern>%d{ss.SSS} %highlightext(%level) %green(%-13.13threadconvert(%t)) %magenta(%-36.36logger) %boldwhiteext(%msg) %n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
<appender name="FILE" class="FileAppender">
|
||||||
|
<file>${TEST_LOG_DIR}/libferretirc.log</file>
|
||||||
|
<immediateFlush>true</immediateFlush>
|
||||||
|
<append>false</append>
|
||||||
|
<encoder class="PatternLayoutEncoder">
|
||||||
|
<pattern>%d{HH:mm:ss.SSS} %-20.20([%threadconvert(%t)/%level]) %logger %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
</included>
|
||||||
@@ -2,14 +2,8 @@
|
|||||||
<!DOCTYPE configuration>
|
<!DOCTYPE configuration>
|
||||||
<!-- From https://logback.qos.ch/manual/configuration.html -->
|
<!-- From https://logback.qos.ch/manual/configuration.html -->
|
||||||
<configuration>
|
<configuration>
|
||||||
<import class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"/>
|
<include resource="logback-base.xml"/>
|
||||||
<import class="ch.qos.logback.core.ConsoleAppender"/>
|
<root level="info">
|
||||||
<appender name="STDOUT" class="ConsoleAppender">
|
|
||||||
<encoder class="PatternLayoutEncoder">
|
|
||||||
<pattern>%d{ISO8601} [%5level] %.36logger %msg%n</pattern>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
<root level="debug">
|
|
||||||
<appender-ref ref="STDOUT"/>
|
<appender-ref ref="STDOUT"/>
|
||||||
</root>
|
</root>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.shr4pnel.ferretirc
|
||||||
|
|
||||||
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import org.junit.jupiter.api.BeforeAll
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
class IRCErrTest {
|
||||||
|
companion object {
|
||||||
|
lateinit var processes: MutableList<Process>
|
||||||
|
val client = IrcClient("localhost", 6667, enableLogging = true)
|
||||||
|
private val logger = KotlinLogging.logger {}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@BeforeAll
|
||||||
|
fun setup(): Unit =
|
||||||
|
runBlocking {
|
||||||
|
val logFile = File("src/test/resources/logs/ngircd.log")
|
||||||
|
val ngircdConfigPath = javaClass.classLoader.getResource("ngircd.conf")!!.path
|
||||||
|
logFile.createNewFile()
|
||||||
|
processes =
|
||||||
|
ProcessBuilder.startPipeline(
|
||||||
|
listOf<ProcessBuilder>(
|
||||||
|
// Run IRC server in [-d] debug log mode, with [-n] no daemon, using config [-f] file at path
|
||||||
|
ProcessBuilder("ngircd", "-dnf", ngircdConfigPath).redirectErrorStream(true),
|
||||||
|
// Remove unhelpful default ngircd info [PID. relative time, GID?]
|
||||||
|
ProcessBuilder("sed", "-ue", "s/\\[[^][]*\\]//g"),
|
||||||
|
// Add relative timestamp
|
||||||
|
ProcessBuilder("ts", "-s", "%H:%M:%.S").redirectOutput(logFile),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
client.connect()
|
||||||
|
client.register("shr4p", "Tyler Fullname", "password")
|
||||||
|
val default = client.server.fetchChannels().first()
|
||||||
|
client.join(default)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,17 +2,13 @@ package com.shr4pnel.ferretirc
|
|||||||
|
|
||||||
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.KotlinLogging
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.withTimeoutOrNull
|
|
||||||
import org.junit.jupiter.api.AfterAll
|
import org.junit.jupiter.api.AfterAll
|
||||||
import org.junit.jupiter.api.BeforeAll
|
import org.junit.jupiter.api.BeforeAll
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.lang.ProcessBuilder
|
import java.lang.ProcessBuilder
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertNotNull
|
|
||||||
import kotlin.time.Duration.Companion.seconds
|
|
||||||
import com.shr4pnel.ferretirc.net.messages.ClientMessage as Message
|
import com.shr4pnel.ferretirc.net.messages.ClientMessage as Message
|
||||||
|
|
||||||
class IrcClientTest {
|
class IrcClientTest {
|
||||||
@@ -20,12 +16,13 @@ class IrcClientTest {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
lateinit var processes: MutableList<Process>
|
lateinit var processes: MutableList<Process>
|
||||||
val client = IrcClient("localhost", 6667)
|
val client = IrcClient("localhost", 6667, enableLogging = true)
|
||||||
private val logger = KotlinLogging.logger {}
|
private val logger = KotlinLogging.logger {}
|
||||||
|
val guestUser = IrcClient("localhost", 6667)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
fun setup() =
|
fun setup(): Unit =
|
||||||
runBlocking {
|
runBlocking {
|
||||||
val logFile = File("src/test/resources/logs/ngircd.log")
|
val logFile = File("src/test/resources/logs/ngircd.log")
|
||||||
val ngircdConfigPath = javaClass.classLoader.getResource("ngircd.conf")!!.path
|
val ngircdConfigPath = javaClass.classLoader.getResource("ngircd.conf")!!.path
|
||||||
@@ -42,7 +39,12 @@ class IrcClientTest {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
client.connect()
|
client.connect()
|
||||||
client.register("shr4p", "Tyler D", "password")
|
client.register("shr4p", "Tyler Fullname", "password")
|
||||||
|
guestUser.connect()
|
||||||
|
guestUser.register("guest", "guest", "pass")
|
||||||
|
val default = client.server.fetchChannels().first()
|
||||||
|
client.join(default)
|
||||||
|
guestUser.join(default)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@@ -50,70 +52,68 @@ 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() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun sample() {
|
|
||||||
client.scope.launch {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun pingGetsPong() =
|
fun pingGetsPong() =
|
||||||
runBlocking {
|
runBlocking {
|
||||||
val token = "ACK"
|
val token = "ACK"
|
||||||
logger.info { "Sending PING $token" }
|
val msg = Message.Ping(token)
|
||||||
client.queueMessage(Message.Ping(token))
|
val pong = client.queueMessageAndWaitForNext<ServerMessage.Pong>(msg)
|
||||||
|
|
||||||
logger.info { "Waiting to receive PONG" }
|
|
||||||
val pong =
|
|
||||||
withTimeoutOrNull(1.seconds) {
|
|
||||||
client.waitForNext<ServerMessage.Pong> { it.token.equals(token) }
|
|
||||||
}
|
|
||||||
assertNotNull(pong, "Reached timeout while waiting for PONG")
|
|
||||||
assertEquals(token, pong.token, "Token in PING did not match PONG")
|
assertEquals(token, pong.token, "Token in PING did not match PONG")
|
||||||
logger.info { "Received PING" }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun oper() =
|
fun oper() =
|
||||||
runBlocking {
|
runBlocking {
|
||||||
client.queueMessage(Message.Oper("shr4p", "password"))
|
val mode = client.queueMessageAndWaitForNext<ServerMessage.Mode>(Message.Oper("shr4p", "password"))
|
||||||
val mode =
|
|
||||||
withTimeoutOrNull(1.seconds) {
|
|
||||||
client.waitForNext<ServerMessage.Mode>()
|
|
||||||
}
|
|
||||||
assertNotNull(mode, "Timed out waiting for OPER MODE response")
|
|
||||||
assertEquals("shr4p", mode.operatorName, "Received incorrect operator name in MODE")
|
assertEquals("shr4p", mode.operatorName, "Received incorrect operator name in MODE")
|
||||||
assertEquals("+o", mode.pMask, "Received unexpected mask in MODE")
|
assertEquals("+o", mode.pMask, "Received unexpected mask in MODE")
|
||||||
logger.info { "Received MODE with mask ${mode.pMask}" }
|
logger.info { "Received MODE with mask ${mode.pMask}" }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun listChannels() =
|
fun listChannels() = runBlocking {
|
||||||
runBlocking {
|
assert(
|
||||||
val channels = client.server.fetchChannels()
|
client.server.channels.value.isNotEmpty(),
|
||||||
assert(channels.isNotEmpty())
|
)
|
||||||
client.queueMessage(Message.Join(channels.first()))
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun messageLands() =
|
fun messageLands() =
|
||||||
runBlocking {
|
runBlocking {
|
||||||
val guestUser = IrcClient("localhost", 6667, false)
|
val channels = client.server.channels.value
|
||||||
guestUser.connect()
|
|
||||||
guestUser.register("guest", "guest", "pass")
|
|
||||||
val channels = client.server.fetchChannels()
|
|
||||||
val message = Message.PrivMsg(channels.first(), "bring me to life")
|
val message = Message.PrivMsg(channels.first(), "bring me to life")
|
||||||
guestUser.queueMessage(message)
|
val receivedMessage = client.waitForNextMessageAfterAction<ServerMessage.PrivMsg> {
|
||||||
val receivedMessage = client.waitForNext<ServerMessage.PrivMsg>()
|
guestUser.queueMessage(message)
|
||||||
|
}
|
||||||
logger.debug { "Message: $message, Received: $receivedMessage" }
|
logger.debug { "Message: $message, Received: $receivedMessage" }
|
||||||
assertEquals(message.message, receivedMessage.message)
|
assertEquals(message.message, receivedMessage.message)
|
||||||
assertEquals(message.target.chanName, receivedMessage.targets.first())
|
assertEquals(message.target.chanName, receivedMessage.targets.first())
|
||||||
guestUser.close()
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun manyMessagesLand() =
|
||||||
|
runBlocking {
|
||||||
|
val channels = client.server.channels.value
|
||||||
|
val channel = channels.first()
|
||||||
|
val max = 100
|
||||||
|
|
||||||
|
val messages = mutableListOf<Message.PrivMsg>()
|
||||||
|
val receivedMessages = mutableListOf<ServerMessage.PrivMsg>()
|
||||||
|
|
||||||
|
for (i in 1..max) messages.add(Message.PrivMsg(channel, "$i: bring me to life"))
|
||||||
|
|
||||||
|
for (i in 0..<max) {
|
||||||
|
val msg = client.waitForNextMessageAfterAction<ServerMessage.PrivMsg> {
|
||||||
|
guestUser.queueMessage(messages[i])
|
||||||
|
}
|
||||||
|
receivedMessages.add(msg)
|
||||||
|
}
|
||||||
|
for (i in 0..<max) assertEquals(messages[i].message, receivedMessages[i].message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE configuration>
|
||||||
|
<!-- From https://logback.qos.ch/manual/configuration.html -->
|
||||||
|
<configuration>
|
||||||
|
<import class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"/>
|
||||||
|
<import class="ch.qos.logback.core.ConsoleAppender"/>
|
||||||
|
<include resource="logback-base.xml"/>
|
||||||
|
<logger name="com.shr4pnel" level="trace" additivity="false">
|
||||||
|
<appender-ref ref="STDOUT"/>
|
||||||
|
<appender-ref ref="FILE"/>
|
||||||
|
</logger>
|
||||||
|
<root level="warn">
|
||||||
|
<appender-ref ref="STDOUT"/>
|
||||||
|
</root>
|
||||||
|
</configuration>
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
PAM = no
|
PAM = no
|
||||||
PAMIsOptional = yes
|
PAMIsOptional = yes
|
||||||
PAMServiceName = ngircd
|
PAMServiceName = ngircd
|
||||||
RequireAuthPing = no
|
RequireAuthPing = yes
|
||||||
ScrubCTCP = no
|
ScrubCTCP = no
|
||||||
SyslogFacility = local5
|
SyslogFacility = local5
|
||||||
WebircPassword =
|
WebircPassword =
|
||||||
|
|||||||
Reference in New Issue
Block a user