input_skip buggy

This commit is contained in:
y4my4my4m 2023-04-30 19:32:01 +09:00
parent 50eda1dcd1
commit 8ad6968dec

View file

@ -3,6 +3,25 @@
#define TELNET_PORT 23 #define TELNET_PORT 23
#define BUF_SIZE 512 #define BUF_SIZE 512
#define TIMEOUT_DURATION 5000
Bool skip_input = FALSE;
Bool WaitForInputOrTimeout(I64 timeout_duration) {
I64 start_jiffies = counts.jiffies;
I64 elapsed_jiffies;
U8 ch;
while (TRUE) {
elapsed_jiffies = counts.jiffies - start_jiffies;
if (elapsed_jiffies >= timeout_duration) {
return TRUE; // Timeout
}
ch = CharGet(, FALSE);
if (ch != CH_SHIFT_ESC) {
return FALSE; // needed?
}
}
}
I64 TelnetOpen(U8 *host, U16 port) { I64 TelnetOpen(U8 *host, U16 port) {
I64 sock; I64 sock;
@ -17,7 +36,7 @@ I64 TelnetOpen(U8 *host, U16 port) {
return sock; return sock;
} }
sock(CTCPSocket *)->timeout = TCP_TIMEOUT; // sock(CTCPSocket *)->timeout = TCP_TIMEOUT;
return sock; return sock;
} }
@ -96,7 +115,8 @@ U0 HandleControlCodes(U8 ch) {
DocClear; DocClear;
break; break;
case 13: // CR (Carriage Return) case 13: // CR (Carriage Return)
"\r"; "\r\n\0";
skip_input = TRUE;
break; break;
case 14: // SO (Shift Out) case 14: // SO (Shift Out)
// Switch to an alternate character set // Switch to an alternate character set
@ -104,7 +124,6 @@ U0 HandleControlCodes(U8 ch) {
case 15: // SI (Shift In) case 15: // SI (Shift In)
// Switch back to the default character set // Switch back to the default character set
break; break;
// Add cases for other control codes as needed
default: default:
break; break;
} }
@ -118,7 +137,6 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
I64 sock, bytes_received, input_len; I64 sock, bytes_received, input_len;
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 negotiate = FALSE;
sock = TelnetOpen(host, port); sock = TelnetOpen(host, port);
if (sock <= 0) { if (sock <= 0) {
@ -130,7 +148,7 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
while (!force_disconnect) { while (!force_disconnect) {
bytes_received = TCPSocketReceive(sock, buffer, BUF_SIZE - 1); bytes_received = TCPSocketReceive(sock, buffer, BUF_SIZE - 1);
if (bytes_received > 0) { if (bytes_received > 0) {
buffer[bytes_received] = '\0'; buffer[bytes_received] = '\0';
// Basic Telnet protocol parser // Basic Telnet protocol parser
ptr = buffer; ptr = buffer;
@ -239,12 +257,15 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
ptr++; ptr++;
} }
} }
skip_input = WaitForInputOrTimeout(TIMEOUT_DURATION);
if (!skip_input)
{
// should have a timer that checks if data is being received // should have a timer that checks if data is being received
// look at the Clocks graphics demo (count.jiffies) maybe // look at the Clocks graphics demo (count.jiffies) maybe
Sleep(1000); Sleep(200);
// Prompt user for input and send it to the remote host // Prompt user for input and send it to the remote host
"\nEnter your choice: "; "\n$$RED$$$BK,1$Input$BK,0$$$BLACK$$: ";
U8 *line = input_buffer; U8 *line = input_buffer;
while (1) { while (1) {
@ -277,6 +298,8 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
"Force disconnecting...\n"; "Force disconnecting...\n";
break; break;
} }
}
skip_input = FALSE;
} else { } else {
"Error: Connection closed by the remote host.\n"; "Error: Connection closed by the remote host.\n";
break; break;
@ -305,6 +328,6 @@ U0 TelnetPrompt() {
// Dev auto-connect to test server // Dev auto-connect to test server
// Telnet("mbrserver.com"); // Telnet("mbrserver.com");
// Telnet("freechess.org"); Telnet("freechess.org");
Telnet("dura-bbs.net", 6359); //Telnet("dura-bbs.net", 6359);
//Telnet("darkrealms.ca"); //Telnet("darkrealms.ca");