This commit is contained in:
y4my4my4m 2023-05-08 19:40:44 +09:00
parent 38a21812a3
commit 3eafc9a034

View file

@ -2,7 +2,7 @@
// Public Domain // Public Domain
#define TELNET_PORT 23 #define TELNET_PORT 23
#define BUF_SIZE 4096 // way too big? #define BUF_SIZE 40960 // way too big?
#define TIMEOUT_DURATION 5000 #define TIMEOUT_DURATION 5000
#define NEGOTIATE 0xFF #define NEGOTIATE 0xFF
@ -26,6 +26,15 @@ U8 IsDigit(U8 ch) {
return '0' <= ch <= '9'; return '0' <= ch <= '9';
} }
Bool CursorInWin(CTask *task, I64 x, I64 y)
{
if ( 0 <= x + task->scroll_x < task->pix_width &&
0 <= y + task->scroll_y < task->pix_height)
return TRUE;
else
return FALSE;
}
I64 TelnetOpen(U8 *host, U16 port) { I64 TelnetOpen(U8 *host, U16 port) {
I64 sock; I64 sock;
@ -133,10 +142,10 @@ U0 HandleControlCodes(U8 ch) {
} }
U0 Telnet(U8 *host, U16 port=TELNET_PORT) { U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
I64 sock, bytes_received, input_len, sc = 0; I64 sock, bytes_received, input_len, sc;
U8 buffer[BUF_SIZE], input_buffer[BUF_SIZE], *ptr, ch; U8 buffer[BUF_SIZE], input_buffer[BUF_SIZE], *ptr, ch;
Bool force_disconnect = FALSE; Bool force_disconnect = FALSE;
Bool request_input = FALSE; Bool input_request = FALSE;
I64 window_width = 80; I64 window_width = 80;
I64 window_height = 25; I64 window_height = 25;
@ -293,14 +302,10 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
ptr++; ptr++;
break; break;
} else if (*ptr == 'A') { } else if (*ptr == 'A') {
// TODO: Cursor Up CursorInWin(Fs, 0, -1); // Cursor Up
// arg = isNaN(args[0]) ? 1 : args[0];
// self.moveCursor(0, -arg);
ptr++; ptr++;
} else if (*ptr == 'B') { } else if (*ptr == 'B') {
// TODO: Cursor Down CursorInWin(Fs, 0, 1); // Cursor Down
// arg = isNaN(args[0]) ? 1 : args[0];
// self.moveCursor(0, arg);
ptr++; ptr++;
} else if (*ptr == 'C') { } else if (*ptr == 'C') {
// Cursor Right // Cursor Right
@ -314,28 +319,23 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
move_count = 1; // Default value if no number is provided move_count = 1; // Default value if no number is provided
} }
for (i = 0; i < move_count; i++) { // for (i = 0; i < move_count; i++) {
Print(" "); // Print(" ");
} // }
// arg = isNaN(args[0]) ? 1 : args[0]; CursorInWin(Fs, move_count, 0); // Cursor Right
// self.moveCursor(arg, 0);
ptr++; ptr++;
} else if (*ptr == 'D') { } else if (*ptr == 'D') {
// TODO: Cursor Left CursorInWin(Fs, -1, 0); // Cursor Left
// arg = isNaN(args[0]) ? 1 : args[0];
// self.moveCursor(-arg, 0);
ptr++; ptr++;
} else if (*ptr == 'E') { } else if (*ptr == 'E') {
"\n"; "\n";
ptr++; ptr++;
} else if (*ptr == 'H' || *ptr == 'f') { } else if (*ptr == 'H' || *ptr == 'f') {
// TODO: Cursor Position // TODO: Cursor Position
// self.row = isNaN(args[0]) ? 1 : args[0]; // CursorInWin(Fs, arg1, arg2);
// self.column = isNaN(args[1]) ? 1 : args[1];
// self.positionUpdated();
ptr++; ptr++;
} else if (*ptr == 'J') { } else if (*ptr == 'J') {
// TODO: Erase in Display // Erase in Display
DocClear; DocClear;
ptr++; ptr++;
} else if (*ptr == 'K') { } else if (*ptr == 'K') {
@ -399,37 +399,47 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
// related refs // related refs
// https://github.com/NuSkooler/enigma-bbs/blob/97cd0c3063b0c9f93a0fa4a44a85318ca81aef43/core/connect.js#L137 // https://github.com/NuSkooler/enigma-bbs/blob/97cd0c3063b0c9f93a0fa4a44a85318ca81aef43/core/connect.js#L137
if (request_input) { if (!input_request) {
// Prompt user for input and send it to the remote host // Prompt user for input and send it to the remote host
"\n$$RED$$$BK,1$Input$BK,0$$$BLACK$$: "; "\n$$RED$$$BK,1$Input$BK,0$$$BLACK$$: ";
U8 *temp;
U8 *line = input_buffer; U8 *line = input_buffer;
input_len = 0; input_len = 0;
while (1) { while (1) {
ch = CharGet(, FALSE); ch = CharGet(, FALSE);
if (ch == '\r' || ch == '\n') { if (ch == '\r' || ch == '\n') {
input_buffer[input_len++] = '\r';
input_buffer[input_len++] = '\n';
break; break;
} }
else if (ch == CH_SHIFT_ESC) { // ESC key else if (ch == CH_SHIFT_ESC) {
force_disconnect = TRUE; force_disconnect = TRUE;
break; break;
} }
else if (ch == CH_ESC) {
input_buffer[input_len++] = 0x1B;
break;
}
else {
input_buffer[input_len++] = ch; input_buffer[input_len++] = ch;
"%c", ch; "%c", ch;
} }
// input_buffer[input_len] = '\0'; }
input_buffer[input_len++] = '\0';
if (!force_disconnect) { if (!force_disconnect) {
// input_buffer[input_len++] = '\r'; // SysLog(input_buffer);
// input_buffer[input_len++] = '\n'; temp = MStrPrint("%s\r\n", input_buffer);
TCPSocketSend(sock, input_buffer, input_len); TCPSocketSendString(sock, temp);
// TCPSocketSend(sock, "\x0D\x0A", 2); // CR followed by LF Free(temp);
MemSet(input_buffer, 0, BUF_SIZE);
// TCPSocketSend(sock, input_buffer, input_len);
} else { } else {
"Force disconnecting...\n"; "Force disconnecting...\n";
goto disconnect; goto disconnect;
break; break;
} }
request_input = FALSE;
} }
} else { } else {
// SysLog("Error: %0x%02X\n", ch); // SysLog("Error: %0x%02X\n", ch);
@ -437,6 +447,9 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
break; break;
} }
} }
// Free(input_buffer);
// Free(buffer);
disconnect: disconnect:
TCPSocketClose(sock); TCPSocketClose(sock);
"Telnet connection closed.\n"; "Telnet connection closed.\n";
@ -467,5 +480,36 @@ U0 TelnetPrompt() {
// good to test refresh, line feed, etc // good to test refresh, line feed, etc
// Telnet("20forbeers.com", 1337); // Telnet("20forbeers.com", 1337);
// view public IP
// Telnet("telnetmyip.com")
// time
// Telnet("india.colorado.edu", 13);
// telehack
// Telnet("telehack.com");
// star trek game
// Telnet("mtrek.com", 1701);
// Telnet("xmltrek.com", 1701);
// Telnet("bbs.archaicbinary.net"); // Archaic Binary
// Telnet("ateraan.com", 4002); // New Worlds - Ateraan
// Telnet("avalon-rpg.com"); // Avalon: The Legend Lives
// Telnet("aardmud.org", 4000); // Aardwolf MUD
// Telnet("TextMMOde.com"); // Sands of Time / Deep Space MMO
// Telnet("legendofthereddragon.ca"); // Legend of the Red Dragon (Canada)
// Telnet("lord.stabs.org"); // Legend of the Red Dragon
// Telnet("thehatshop.mudhosting.net", 3000); // Hallowed Halls
// Telnet("eclipse.cs.pdx.edi", 7680); // New Moon
// Telnet("batmud.bat.org"); // BatMUD
// Telnet("forgottenkingdoms.org", 4000); // Forgotten Kingdoms
// Telnet("mush.shelteringcolorado.com"), 2601; // Sheltering Sky: Colorado by Night
Telnet("igormud.org", 1701);// Igor MUD
// Telnet("achaea.com"); // Achaea, Dreams of Divine Lands
// Telnet("gcomm.com"); // Galacticomm BBS
// Telnet("1984.ws"); // 1984
// ZealBBS dev server // ZealBBS dev server
Telnet("localhost", 8888); // Telnet("localhost", 8888);