-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVSNC.bat
More file actions
195 lines (165 loc) · 5.85 KB
/
Copy pathVSNC.bat
File metadata and controls
195 lines (165 loc) · 5.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
:: ============================================================
:: VSNC v2.2 – Very Simple Network Chat (2026)
:: GitHub: https://github.com/pollhammer/vsnc
:: Author: Manuel Pollhammer
:: ============================================================
@echo off
setlocal EnableDelayedExpansion
:: -------------------- Initialization -----------------------
for /F %%a in ('echo prompt $E ^| cmd') do set "ESC=%%a"
reg add "HKCU\Console" /v VirtualTerminalLevel /t REG_DWORD /d 1 /f >nul 2>&1
chcp 65001 >nul
title VSNC v2.2 - PM Edition
mode con: cols=91 lines=24
:: -------------------- Chat directory ----------------------
set "CHAT=C:\Temp"
set "CHATFILE=%CHAT%\chat.txt"
set "USERCOLORFILE=%CHAT%\usercolors.txt"
if not exist "%CHAT%" mkdir "%CHAT%"
if not exist "%USERCOLORFILE%" echo.>"%USERCOLORFILE%"
:: -------------------- Header -------------------------------
echo.
echo %ESC%[38;5;214m _ __ _____ _ __ ______
echo %ESC%[38;5;208m ^| ^| / // ___/ / ^| / // ____/
echo %ESC%[38;5;202m ^| ^|/ / \__ \ / ^|/ // /
echo %ESC%[38;5;196m ^| / ___/ / /^| // /___
echo %ESC%[38;5;124m ^|__/ /____/_/ ^|_/ \____/
echo %ESC%[0m
echo v2.2
echo Very Simple Network Chat
echo (2026) by Manuel Pollhammer
echo.
:: -------------------- User login --------------------------
set /p USER=Please enter your name:
if "%USER%"=="" set USER=Guest
set "SAFEUSER=%USER: =_%"
set "TMPF=%CHAT%\vsnc_%SAFEUSER%"
:: -------------------- User color handling ------------------
:: Optimized color palette for better readability and variety
set COLORS=10 11 12 13 14 15 39 46 48 51 75 81 118 121 154 159 165 190 196 201 202 208 214 220 226 229
set "USERCOLOR="
if exist "%USERCOLORFILE%" (
for /f "usebackq tokens=1,2 delims=:" %%A in ("%USERCOLORFILE%") do (
if /I "%%A"=="%USER%" set "USERCOLOR=%%B"
)
)
if not defined USERCOLOR (
:: Random selection from the improved palette
set /a IDX=%RANDOM% %% 26
set /a CNT=0
for %%C in (%COLORS%) do (
if !CNT! EQU !IDX! set USERCOLOR=%%C
set /a CNT+=1
)
echo %USER%:!USERCOLOR!>>"%USERCOLORFILE%"
)
:: ====================== MAIN LOOP ==========================
cls
:loop
:: Move cursor to top without clearing screen
echo %ESC%[H
echo ===== CHAT (latest 15) =====
echo %ESC%[38;5;196mSystem:%ESC%[0m Chat started (User: %USER%)
echo.
:: Read and decode messages
set LINECOUNT=0
if exist "%CHATFILE%" (
for /f "usebackq delims=" %%L in ("%CHATFILE%") do (
echo %%L > "%TMPF%.b64"
certutil -decode "%TMPF%.b64" "%TMPF%.bin" >nul 2>&1
if exist "%TMPF%.bin" (
set "DECODED_LINE="
for /f "usebackq delims=" %%D in ("%TMPF%.bin") do set "DECODED_LINE=%%D"
set "SHOW=YES"
:: Privacy filter logic
echo "!DECODED_LINE!" | findstr /C:"[TO:" >nul
if !errorlevel! EQU 0 (
set "SHOW=NO"
:: Show if message is for me
echo "!DECODED_LINE!" | findstr /I /C:"[TO:%USER%]" >nul
if !errorlevel! EQU 0 set "SHOW=YES"
:: Show if message is from me
echo "!DECODED_LINE!" | findstr /I /C:"(%USER%):" >nul
if !errorlevel! EQU 0 set "SHOW=YES"
)
if "!SHOW!"=="YES" (
set /a LINECOUNT+=1
set "LINE[!LINECOUNT!]=!DECODED_LINE!"
)
del "%TMPF%.bin" >nul 2>&1
)
)
)
:: Show only the last 15 filtered messages
set /a START=LINECOUNT-14
if !START! LSS 1 set START=1
for /l %%I in (!START!,1,!LINECOUNT!) do (
if defined LINE[%%I] echo !LINE[%%I]!
)
:: -------------------- Menu -------------------------------
set "MENU=[W] write [Q] quit"
:: Only display menu if it is not already the last line
if "!LINE[!LINECOUNT!]!" neq "!MENU!" echo !MENU!
:: 1-second wait / live update
choice /c WQR /n /t 1 /d R >nul
if errorlevel 3 (
for /l %%I in (1,1,100) do set "LINE[%%I]="
goto loop
)
if errorlevel 2 goto end
if errorlevel 1 goto write
:: Clear message cache
for /l %%I in (1,1,!LINECOUNT!) do set "LINE[%%I]="
goto loop
:: ===================== WRITE MESSAGE ======================
:write
set "TEXT="
echo.
set /p TEXT=%ESC%[38;5;!USERCOLOR!m %USER%:%ESC%[0m
if not defined TEXT goto loop
:: Initialize display variables
set "PREFIX="
set "UTAG="
set "DISPLAY_NAME=%USER%"
:: Process /pm command
echo !TEXT!| findstr /I /C:"/pm " >nul
if !errorlevel! EQU 0 (
for /f "tokens=2,3*" %%A in ("!TEXT!") do (
set "PREFIX=%ESC%[38;5;201m[TO:%%A]%ESC%[0m "
set "UTAG=(%USER%)"
set "DISPLAY_NAME="
set "TEXT=%%B %%C"
)
)
:: Format timestamps and raw message
set "TIMESTAMP=%TIME:~0,5%"
:: Added a space after the colon in the final RAW string
set "RAW=%ESC%[38;5;240m[%DATE% !TIMESTAMP!]%ESC%[0m !PREFIX!%ESC%[38;5;!USERCOLOR!m!DISPLAY_NAME!!UTAG!:%ESC%[0m !TEXT!"
cls
:: Write to file without newline for Base64
<nul set /p="!RAW!" > "%TMPF%.raw"
:: Encode to Base64
certutil -encode "%TMPF%.raw" "%TMPF%.b64_full" >nul 2>&1
:: Extract Base64 data lines
set "B64_DATA="
for /f "usebackq tokens=*" %%B in ("%TMPF%.b64_full") do (
set "ln=%%B"
if "!ln:~0,1!" neq "-" set "B64_DATA=!B64_DATA!!ln!"
)
echo !B64_DATA!>>"%CHATFILE%"
:: Cleanup temporary files
del "%TMPF%.raw" "%TMPF%.b64_full" "%TMPF%.b64" >nul 2>&1
:: Limit chat.txt to 15 messages
set /a C_LINES=0
if exist "%CHATFILE%" (
for /f "usebackq delims=" %%l in ("%CHATFILE%") do set /a C_LINES+=1
)
if !C_LINES! gtr 15 (
more +1 "%CHATFILE%" > "%CHATFILE%.tmp"
move /y "%CHATFILE%.tmp" "%CHATFILE%" >nul
)
goto loop
:end
:: Clean up all user-related temp files on exit
del "%TMPF%*" >nul 2>&1
exit