From 9e9d3ef1a7f601289653db215aac6a67a6853c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Mon, 16 Dec 2024 22:42:18 +0500 Subject: [PATCH] Initial commit. --- LICENSE | 5 ++++ README.md | 2 ++ dobroho_vechora.bash | 61 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100755 dobroho_vechora.bash diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..50bb52d --- /dev/null +++ b/LICENSE @@ -0,0 +1,5 @@ +Copyright (C) 2024 by bedohswe bedohswe@firemail.cc + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e91d6f3 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +Client for the [Sugoma's RAC protocol](https://bedohswe.eu.org/text/rac/protocol.md.html). +There's no help, figure everythin out by yourself. diff --git a/dobroho_vechora.bash b/dobroho_vechora.bash new file mode 100755 index 0000000..a303ffc --- /dev/null +++ b/dobroho_vechora.bash @@ -0,0 +1,61 @@ +#!/bin/bash +set -e +ip="${1}" +port="${2}" +[ -z "${ip}" ] && print_usage 'No IP given.' +[ -z "${port}" ] && print_usage 'No port given.' +[ -z "${3}" ] || print_usage 'Too many arguments.' +get_termsize() { + echo "`expr $(stty -a < $(tty) | grep -Po '(?<=rows )\d+') - 1`" +} +print_usage() { + echo "${1}" + echo "${0} " + exit +} + +send_message() { + exec 3<> "/dev/tcp/${ip}/${port}" + echo "${1}" >&3 + exec 3>&- +} + +get_message() { + exec 3<> "/dev/tcp/${ip}/${port}" + echo "${1}" >&3 + timeout 1s cat <&3 || true + exec 3>&- +} + +while :; do + read cmd + case "${cmd}" in + i) + b="" + while :; do + read c + [[ "${c}" != "." ]] || break + if [ -z ${b} ]; then + b="${c}" + else + b="${b}"$'\n'"${c}" + fi + done + send_message 0"${b}" + ;; + I) + read a + send_message 0"${a}" + ;; + p) + send_message 1 + get_message 2 + ;; + q) + exit + ;; + *) + echo ? + ;; + esac +done