From 197a8f0f23a82e5fa873bed51d66aa323ecb4602 Mon Sep 17 00:00:00 2001
From: Rob Swindell <rob@synchro.net>
Date: Sun, 6 Feb 2022 02:13:54 -0800
Subject: [PATCH] Fix access-control by terminal cap issue introduced a week
 ago

In commit 9a9c26f4, I was addressing the issue reported by Nelgin via IRC:
<nelgin> If you login using a term that doesn't support ansi, it changes your settings - can you set 'em back when done?
<DigitalMan> if you have auto-term enabled, it doesn't actually change your settings, just what's in use during that session
<nelgin> I logged in using my BBC emulator which doesn't do ansi, then when I logged in through syncterm, I got the display like it was on the BBC. All my characters replaced with #'s and stuff.
<nelgin> I had to go back into the user menu to fix it. That is going to confuse users.

However, the chk_ar() function in userdat.c which is used to populate JS objects (e.g. xtrn_area.sec_list[].prog_list[]) uses the user.misc value (cannot call term_supports()), so the current user terminal flags need to be reflected in user.misc always. So the real fix for the originally reported problem is to clear the charset-related terminal settings when logging in with auto-terminal settings enabled (and before the auto-detected charset flags are OR'd in).

I toyed with the idea of storing a copy of the term_supports() result in client_t, which is passed to chk_ar() when appropriate, but decided that was a bit overkill and there were issues with servers that don't have term_supports (e.g. the web server) and properly populating access-controlled areas in the JS object model (e.g. door games that require ANSI). Better to use the last-auto-detected terminal caps than assuming "no" terminal capabilities in that scenario.
---
 src/sbbs3/logon.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/sbbs3/logon.cpp b/src/sbbs3/logon.cpp
index 17991b9107..5ddc5add8a 100644
--- a/src/sbbs3/logon.cpp
+++ b/src/sbbs3/logon.cpp
@@ -162,10 +162,11 @@ bool sbbs_t::logon()
 		} 
 	}
 
-	if(((useron.misc & (AUTOTERM | PETSCII)) == PETSCII) && (autoterm & ANSI)) {
+	if((useron.misc & AUTOTERM)
 		// User manually-enabled PETSCII, but they're logging in with an ANSI (auto-detected) terminal
-		useron.misc &= ~PETSCII;
-		useron.misc |= AUTOTERM;
+		|| ((useron.misc & PETSCII) && (autoterm & ANSI))) {
+		useron.misc &= ~(ANSI|RIP|CHARSET_FLAGS);
+		useron.misc |= (AUTOTERM | autoterm);
 	}
 
 	if(!chk_ar(cfg.shell[useron.shell]->ar,&useron,&client)) {
-- 
GitLab