mirror of
https://github.com/Zeal-Operating-System/ZealOS.git
synced 2024-12-25 15:10:28 +00:00
input_skip buggy
This commit is contained in:
parent
50eda1dcd1
commit
8ad6968dec
1 changed files with 64 additions and 41 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +94,7 @@ U0 HandleControlCodes(U8 ch) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 0: // NUL (Null)
|
case 0: // NUL (Null)
|
||||||
// Typically ignored
|
// Typically ignored
|
||||||
break;
|
break;
|
||||||
case 7: // BEL (Bell)
|
case 7: // BEL (Bell)
|
||||||
// Make a beep sound or flash the screen
|
// Make a beep sound or flash the screen
|
||||||
Beep;
|
Beep;
|
||||||
|
@ -96,15 +115,15 @@ U0 HandleControlCodes(U8 ch) {
|
||||||
DocClear;
|
DocClear;
|
||||||
break;
|
break;
|
||||||
case 13: // CR (Carriage Return)
|
case 13: // CR (Carriage Return)
|
||||||
"\r";
|
"\r\n\0";
|
||||||
break;
|
skip_input = TRUE;
|
||||||
|
break;
|
||||||
case 14: // SO (Shift Out)
|
case 14: // SO (Shift Out)
|
||||||
// Switch to an alternate character set
|
// Switch to an alternate character set
|
||||||
break;
|
break;
|
||||||
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,44 +257,49 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
skip_input = WaitForInputOrTimeout(TIMEOUT_DURATION);
|
||||||
|
|
||||||
// should have a timer that checks if data is being received
|
if (!skip_input)
|
||||||
// look at the Clocks graphics demo (count.jiffies) maybe
|
{
|
||||||
Sleep(1000);
|
// should have a timer that checks if data is being received
|
||||||
// Prompt user for input and send it to the remote host
|
// look at the Clocks graphics demo (count.jiffies) maybe
|
||||||
"\nEnter your choice: ";
|
Sleep(200);
|
||||||
|
// Prompt user for input and send it to the remote host
|
||||||
|
"\n$$RED$$$BK,1$Input$BK,0$$$BLACK$$: ";
|
||||||
|
|
||||||
U8 *line = input_buffer;
|
U8 *line = input_buffer;
|
||||||
while (1) {
|
while (1) {
|
||||||
ch = CharGet(, FALSE);
|
ch = CharGet(, FALSE);
|
||||||
if (ch == '\r' || ch == '\n') {
|
if (ch == '\r' || ch == '\n') {
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
if (ch == CH_SHIFT_ESC) { // ESC key
|
|
||||||
force_disconnect = TRUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (ch == CH_BACKSPACE || ch == 127) { // Backspace or Delete key
|
|
||||||
if (line != input_buffer) {
|
|
||||||
line--; // Move the pointer back
|
|
||||||
"%c%c%c", 8, ' ', 8; // Move the cursor back, erase the character, and move the cursor back again
|
|
||||||
}
|
}
|
||||||
|
if (ch == CH_SHIFT_ESC) { // ESC key
|
||||||
|
force_disconnect = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (ch == CH_BACKSPACE || ch == 127) { // Backspace or Delete key
|
||||||
|
if (line != input_buffer) {
|
||||||
|
line--; // Move the pointer back
|
||||||
|
"%c%c%c", 8, ' ', 8; // Move the cursor back, erase the character, and move the cursor back again
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
*line++ = ch;
|
||||||
|
HandleControlCodes(ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*line++ = '\r';
|
||||||
|
*line++ = '\n';
|
||||||
|
*line = '\0';
|
||||||
|
|
||||||
|
if (!force_disconnect) {
|
||||||
|
// SysLog("Sending: %s\n", input_buffer); // Debugging line
|
||||||
|
TCPSocketSendString(sock, line);
|
||||||
} else {
|
} else {
|
||||||
*line++ = ch;
|
"Force disconnecting...\n";
|
||||||
HandleControlCodes(ch);
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*line++ = '\r';
|
skip_input = FALSE;
|
||||||
*line++ = '\n';
|
|
||||||
*line = '\0';
|
|
||||||
|
|
||||||
if (!force_disconnect) {
|
|
||||||
// SysLog("Sending: %s\n", input_buffer); // Debugging line
|
|
||||||
TCPSocketSendString(sock, line);
|
|
||||||
} else {
|
|
||||||
"Force disconnecting...\n";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} 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");
|
Loading…
Reference in a new issue