mirror of
https://github.com/Zeal-Operating-System/ZealOS.git
synced 2024-12-25 23:10:32 +00:00
Colors
This commit is contained in:
parent
acd9d71f6d
commit
938ea9a441
1 changed files with 106 additions and 81 deletions
|
@ -2,7 +2,7 @@
|
||||||
// Public Domain
|
// Public Domain
|
||||||
|
|
||||||
#define TELNET_PORT 23
|
#define TELNET_PORT 23
|
||||||
#define BUF_SIZE 512
|
#define BUF_SIZE 51200
|
||||||
#define TIMEOUT_DURATION 5000
|
#define TIMEOUT_DURATION 5000
|
||||||
|
|
||||||
Bool skip_input = FALSE;
|
Bool skip_input = FALSE;
|
||||||
|
@ -43,7 +43,7 @@ I64 TelnetOpen(U8 *host, U16 port) {
|
||||||
return sock;
|
return sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
U0 AppendColorString(I64 color_code, U8 *buf) {
|
U0 AppendColorString(I64 color_code) {
|
||||||
U8 *color;
|
U8 *color;
|
||||||
switch (color_code) {
|
switch (color_code) {
|
||||||
case 0: color = "$$BLACK$$"; break;
|
case 0: color = "$$BLACK$$"; break;
|
||||||
|
@ -51,12 +51,12 @@ U0 AppendColorString(I64 color_code, U8 *buf) {
|
||||||
case 2: color = "$$GREEN$$"; break;
|
case 2: color = "$$GREEN$$"; break;
|
||||||
case 3: color = "$$YELLOW$$"; break;
|
case 3: color = "$$YELLOW$$"; break;
|
||||||
case 4: color = "$$BLUE$$"; break;
|
case 4: color = "$$BLUE$$"; break;
|
||||||
case 5: color = "$$MAGENTA$$"; break;
|
case 5: color = "$$BROWN$$"; break;
|
||||||
case 6: color = "$$CYAN$$"; break;
|
case 6: color = "$$CYAN$$"; break;
|
||||||
case 7: color = "$$WHITE$$"; break;
|
case 7: color = "$$WHITE$$"; break;
|
||||||
default: color = ""; break;
|
default: color = ""; break;
|
||||||
}
|
}
|
||||||
"%s%s$$FG$$", color, buf;
|
"%s", color;
|
||||||
}
|
}
|
||||||
|
|
||||||
U0 SendWindowSize(I64 sock, U16 rows, U16 cols) {
|
U0 SendWindowSize(I64 sock, U16 rows, U16 cols) {
|
||||||
|
@ -135,6 +135,17 @@ U0 HandleControlCodes(U8 ch) {
|
||||||
// skip_input = TRUE;
|
// skip_input = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
U0 HandleMCICode(U8 *ptr, I64 *index) {
|
||||||
|
U8 code[4];
|
||||||
|
MemCopy(code, ptr + *index, 3);
|
||||||
|
*index += 3;
|
||||||
|
|
||||||
|
if (StrCompare(code, "ET1") == 0) {
|
||||||
|
// Handle ET1 MCI code here
|
||||||
|
}
|
||||||
|
SysLog("MCI code: %s\n", code);
|
||||||
|
// Add support for other MCI codes if needed
|
||||||
|
}
|
||||||
|
|
||||||
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 = 0;
|
||||||
|
@ -156,7 +167,7 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
"$$BG,RED$$$$WHITE$$Connected$$FG$$$$BG$$\n"
|
"$$BG,RED$$$$WHITE$$Connected$$FG$$$$BG$$\n";
|
||||||
|
|
||||||
while (!force_disconnect) {
|
while (!force_disconnect) {
|
||||||
bytes_received = TCPSocketReceive(sock, buffer, BUF_SIZE - 1);
|
bytes_received = TCPSocketReceive(sock, buffer, BUF_SIZE - 1);
|
||||||
|
@ -166,7 +177,7 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
|
||||||
// Basic Telnet protocol parser
|
// Basic Telnet protocol parser
|
||||||
ptr = buffer;
|
ptr = buffer;
|
||||||
while (*ptr) {
|
while (*ptr) {
|
||||||
SysLog("BUF: 0x%02X\n", *ptr);
|
// SysLog("BUF: 0x%02X\n", *ptr);
|
||||||
if (*ptr == 0xFF) { // Telnet negotiation sequence
|
if (*ptr == 0xFF) { // Telnet negotiation sequence
|
||||||
U8 negotiation_code = *(ptr + 1);
|
U8 negotiation_code = *(ptr + 1);
|
||||||
U8 option_code = *(ptr + 2);
|
U8 option_code = *(ptr + 2);
|
||||||
|
@ -194,6 +205,7 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
|
||||||
response[2] = option_code;
|
response[2] = option_code;
|
||||||
response[3] = '\0';
|
response[3] = '\0';
|
||||||
TCPSocketSendString(sock, response);
|
TCPSocketSendString(sock, response);
|
||||||
|
Sleep(2000);
|
||||||
SendTerminalType(sock, "ANSI");
|
SendTerminalType(sock, "ANSI");
|
||||||
// SendWindowSize(sock, 25, 80);
|
// SendWindowSize(sock, 25, 80);
|
||||||
ptr += 3;
|
ptr += 3;
|
||||||
|
@ -231,10 +243,13 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
|
||||||
ptr++;
|
ptr++;
|
||||||
if (ansi_code >= 30 && ansi_code <= 37) {
|
if (ansi_code >= 30 && ansi_code <= 37) {
|
||||||
//Set foreground color
|
//Set foreground color
|
||||||
Print("%s", AppendColorString(ansi_code - 30, *ptr));
|
"%s", AppendColorString(ansi_code - 30);
|
||||||
} else if (ansi_code >= 40 && ansi_code <= 47) {
|
} else if (ansi_code >= 40 && ansi_code <= 47) {
|
||||||
// Set background color
|
// Set background color
|
||||||
Print("%s", AppendColorString(ansi_code - 40, *ptr));
|
"%s", AppendColorString(ansi_code - 40);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
"$$BG$$$$FG$$";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} else if (*ptr == 'H') {
|
} else if (*ptr == 'H') {
|
||||||
|
@ -267,6 +282,15 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (*ptr == ';') {
|
||||||
|
SysLog("; event\n");
|
||||||
|
ptr++;
|
||||||
|
}
|
||||||
|
} else if (*ptr == '%' || *ptr == '|') {
|
||||||
|
// MCI code detected
|
||||||
|
ptr++;
|
||||||
|
HandleMCICode(ptr, &ptr);
|
||||||
|
ptr++;
|
||||||
} else {
|
} else {
|
||||||
// Print the received character
|
// Print the received character
|
||||||
HandleControlCodes(*ptr);
|
HandleControlCodes(*ptr);
|
||||||
|
@ -275,9 +299,9 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// skip_input = WaitForInputOrTimeout(TIMEOUT_DURATION);
|
// skip_input = WaitForInputOrTimeout(TIMEOUT_DURATION);
|
||||||
if (!skip_input)
|
// if (!skip_input)
|
||||||
{
|
// {
|
||||||
Sleep(200);
|
// Sleep(200);
|
||||||
// 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$$: ";
|
||||||
|
|
||||||
|
@ -332,26 +356,27 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
|
||||||
// "%c%c%c", 8, ' ', 8; // Move the cursor back, erase the character, and move the cursor back again
|
// "%c%c%c", 8, ' ', 8; // Move the cursor back, erase the character, and move the cursor back again
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
else {
|
// *line++ = ch;
|
||||||
*line++ = ch;
|
|
||||||
"%c", ch;
|
"%c", ch;
|
||||||
}
|
}
|
||||||
}
|
// *line++ = '\r';
|
||||||
*line++ = '\r';
|
// *line++ = '\n';
|
||||||
*line++ = '\n';
|
// *line = '\0';
|
||||||
*line = '\0';
|
|
||||||
|
|
||||||
if (!force_disconnect) {
|
if (!force_disconnect) {
|
||||||
TCPSocketSendString(sock, line);
|
// SysLog("Sending: %s\n", input_buffer);
|
||||||
// TCPSocketSend(sock, input_buffer, BUF_SIZE);
|
TCPSocketSendString(sock, input_buffer);
|
||||||
|
// input_buffer[BUF_SIZE] = 0;
|
||||||
|
// cant send line? its not a string but input_buffer is?
|
||||||
|
// TCPSocketSendString(sock, line);
|
||||||
|
// TCPSocketSend(sock, line, 16);
|
||||||
} else {
|
} else {
|
||||||
"Force disconnecting...\n";
|
"Force disconnecting...\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// skip_input = FALSE;
|
// skip_input = FALSE;
|
||||||
} else {
|
} else {
|
||||||
SysLog("Error: %0x%02X\n", ch);
|
// SysLog("Error: %0x%02X\n", ch);
|
||||||
"Error: Connection closed by the remote host.\n";
|
"Error: Connection closed by the remote host.\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -379,9 +404,9 @@ 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");
|
||||||
|
|
||||||
// ZealBBS dev server
|
// ZealBBS dev server
|
||||||
// Telnet("localhost", 8888);
|
Telnet("localhost", 8888);
|
Loading…
Reference in a new issue