Compare commits

...

4 Commits

Author SHA1 Message Date
ed ffd5555439 v1.6.1 2024-04-27 23:04:56 +00:00
ed d83d39c244 add CTRL-U/D for scrolling on win311 2024-04-27 21:21:49 +00:00
ed f13f578179 fix client crash on untimely naws;
if a client tries to send a msg before sending its terminal size,
and before the handshake_sz timeout has hit (1sec), just ignore it
instead of killing the thread

mainly an issue with bots / synthetic clients
2024-04-27 19:18:57 +00:00
ed bef51dfa98 tell client when they send bad naws 2024-04-27 18:17:20 +00:00
6 changed files with 67 additions and 22 deletions

View File

@ -17,7 +17,7 @@ retr0chat is the lightweight, no-dependencies, runs-anywhere solution for when l
* tries to be irssi
* zero dependencies on python 2.6, 2.7, 3.x
* supports telnet, netcat, /dev/tcp, TLS clients
* is not an irc server, but can bridge to/from irc servers
* is not an irc server, but can [bridge to/from irc servers](#irc)
* [modem-aware](https://ocv.me/r0c-2400.webm); comfortable at 1200 bps
* fallbacks for inhumane conditions
* linemode
@ -31,6 +31,7 @@ retr0chat is the lightweight, no-dependencies, runs-anywhere solution for when l
* 1980: [TVI 920C](https://a.ocv.me/pub/g/nerd-stuff/r0c-tvi-920c.jpg)
* 1987: [IBM 3151](https://a.ocv.me/pub/g/nerd-stuff/r0c-ibm-3151.jpg) (also [video](https://a.ocv.me/pub/g/nerd-stuff/r0c-ibm-3151.webm)), using gnu-screen to translate VT100 sequences
* 1993: [windows 3.11](https://a.ocv.me/pub/g/nerd-stuff/r0c-for-workgroups.png)
## features
@ -48,7 +49,7 @@ technical:
* history of sent messages (arrow-up/down)
* bandwidth-conservative (push/pop lines instead of full redraws; scroll-regions)
* fast enough; 600 clients @ 750 msgs/sec, or 1'000 cli @ 350 msg/s
* bridge several irc channels from several networks into one r0c channel
* [bridge](#irc) several irc channels from several networks into one r0c channel
## windows clients
@ -108,6 +109,22 @@ you can run it as a service so it autostarts on boot:
* on alpine / gentoo: [openrc service](docs/openrc/r0c)
* on windows: [nssm](https://nssm.cc/) probably
## irc
if you want to connect your r0c instance to an irc network and bridge channels between them, you can do that:
![screenshot of a r0c channel being bridged to an irc channel](docs/r0c-irc.png)
```bash
python3 r0c.py --ircn a,127.0.0.1,6667,r0c --ircb a,chat,g
```
run that command to start r0c with irc bridging enabled; r0c will then connect to an irc server (which we nicknamed `a`) on `127.0.0.1:6667` with the irc-nick `r0c` and bridge the irc-channel `#chat` with the r0c-channel `#g`
if you then start an irc server locally, for example [miniircd](https://github.com/jrosdahl/miniircd/blob/master/miniircd) by running `python3 miniircd --verbose` then you're all set, people can now join r0c by connecting via irc
to bridge additional channels on the same network, add more `--ircb` args, for example `--ircb a,tech,tech` like in the screenshot, and optionally add more networks with `--ircn`
## firewall rules
skip this section if:

BIN
docs/r0c-irc.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -1,5 +1,5 @@
VERSION = (1, 6, 0)
BUILD_DT = (2024, 4, 4)
VERSION = (1, 6, 1)
BUILD_DT = (2024, 4, 27)
S_VERSION = u".".join(map(str, VERSION))
S_BUILD_DT = u"{0:04d}-{1:02d}-{2:02d}".format(*BUILD_DT)

View File

@ -327,6 +327,7 @@ class VT100_Client(object):
self.uee_offset = -uee.start
# outgoing data
self.info_q = []
self.outbox = []
self.replies = []
self.last_tx = None
@ -373,6 +374,7 @@ class VT100_Client(object):
self.show_hilight_tutorial = True
self.need_full_redraw = False
self.too_small = False
self.bad_naws = False
self.screen = []
self.w = 80
self.h = 24
@ -441,6 +443,8 @@ class VT100_Client(object):
self.add_esc(u"\x0c", "redraw") # ^L (readline-compat)
self.add_esc(u"\x12", "redraw") # ^R
self.add_esc(u"\x0e", "view") # ^N
self.add_esc(u"\x15", "pgup") # ^U
self.add_esc(u"\x04", "pgdn") # ^D
self.add_esc(u"\x01", "prev-chan") # ^A
self.add_esc(u"\x18", "next-chan") # ^X
self.add_esc(u"\x05", "alt-tab") # ^E
@ -618,23 +622,32 @@ class VT100_Client(object):
return len(nonl)
def set_term_size(self, w, h):
wh = (w, h)
nick = self.user.nick
if self.ar.dbg:
print("terminal sz: %dx%d @%s" % (w, h, nick))
if w >= 512 or not w: # always 0 on win3.11
w = 80
if h >= 512 or not h: # never seen 0 but hey
h = 24
self.w = w
self.h = h
if self.ar.dbg:
print("terminal sz: {0}x{1}".format(self.w, self.h))
if self.w >= 512 or not self.w: # always 0 on win3.11
print("screen width {0} reduced to 80".format(self.w))
self.w = 80
if self.h >= 512 or not self.h: # never seen 0 but hey
print("screen height {0} reduced to 24".format(self.h))
self.h = 24
self.user.nick_len = len(self.user.nick)
if self.user.nick_len > self.w * 0.25:
self.user.nick_len = int(self.w * 0.25)
self.handshake_sz = True
self.user.nick_len = min(len(nick), int(w * 0.25))
if wh != (w, h) and not self.bad_naws:
self.bad_naws = True
t = u"%dx%d; will assume %dx%d" % (wh[0], wh[1], w, h)
print(u" bad naws: %s @%s" % (t, self.user.nick))
t = u"your client reported windowsize " + t
if self.user.chans:
self.world.send_chan_msg(u"-nfo-", self.user.chans[0].nchan, t, False)
else:
self.info_q.append(t)
def handshake_timeout(self):
if self.ar.dbg:
@ -2609,6 +2622,10 @@ class VT100_Client(object):
if not self.slowmo_tx:
self.world.cserial += 1
while self.info_q:
t = self.info_q.pop(0)
self.world.send_chan_msg(u"-nfo-", self.user.chans[0].nchan, t, False)
def check_correct_iface(self, next_stage):
self.wizard_stage = next_stage
@ -2834,6 +2851,14 @@ class VT100_Client(object):
self.last_beep = time.time() - 0.9
if self.echo_on:
self.need_full_redraw = True
if not self.user.active_chan:
t = "XXX sendmsg without %s <%s> %r" % (
"active chan??" if self.handshake_sz else "termsz",
self.user.nick,
self.linebuf,
)
print(t)
self.linebuf = u""
if self.linebuf:
# add this to the message/command ("input") history
if not self.msg_hist or self.msg_hist[-1] != self.linebuf:

View File

@ -59,8 +59,8 @@ Keybinds:
\033[36mHome\033[0m / \033[36mEnd\033[0m input field jump
\033[36mPgUp\033[0m / \033[36mPgDown\033[0m chatlog scrolling... \033[1mtry it :-)\033[0m
if you are using a mac, PgUp is fn-Shift-PgUp
if your terminal is tiny, try \033[36m/mn\033[0m and \033[36m/cy\033[0m
* if your terminal is tiny, try commands \033[36m/mn\033[0m and \033[36m/cy\033[0m
* Cannot scroll? try these: \033[36mCTRL-U\033[0m \033[36mCTRL-D\033[0m \033[36m/u\033[0m \033[36m/d\033[0m
"""
@ -149,7 +149,7 @@ class User(object):
# the messy version
text = u"""
`1;30m______ `37m_`30m ______
`1;30m\\\\\\\\\\\\\\ `37m/ \\ `30m/////// `0mret`1mr0c`22mhat r0c_ver `36m-----
`1;30m\\\\\\\\\\\\\\ `37m/ \\ `30m/////// `0mret`1mr0c`22mhat r0c_ver `36m---
`1;30m\\\\ `36m/`37m^^ | | `36m/^`0;36m^`1;30m // `0mgithub.com/9001/r0c
`1;30m\\ `0;36m| `1m\\_/ `0;36m\\__ `1;30m/ `0;36m------b. r0c_build `0m
"""

View File

@ -4,7 +4,6 @@ from __future__ import print_function
import builtins
import multiprocessing
import threading
import socket
import struct
import signal
@ -179,6 +178,10 @@ class Client(object):
util.Daemon(self.rx_loop)
util.Daemon(self.tx_loop)
def close(self):
self.stopping = True
self.sck.close()
def send_status(self, txt):
if False:
print(txt)