Merge pull request #20 from Hagb/develop

Fix UTF-8 and something about color code
This commit is contained in:
Tero Korpela
2019-04-15 08:37:27 +03:00
committed by GitHub

View File

@ -481,17 +481,18 @@ void print_color(int color)
"\033[0;35m", /* 05 PURPLE 0x35 */ "\033[0;35m", /* 05 PURPLE 0x35 */
"\033[0;33m", /* 06 GOLD 0x36 */ "\033[0;33m", /* 06 GOLD 0x36 */
"\033[0;37m", /* 07 GREY 0x37 */ "\033[0;37m", /* 07 GREY 0x37 */
"\033[1;30m", /* 08 DGREY 0x38 */ "\033[0;1;30m", /* 08 DGREY 0x38 */
"\033[1;34m", /* 09 LBLUE 0x39 */ "\033[0;1;34m", /* 09 LBLUE 0x39 */
"\033[1;32m", /* 10 LGREEN 0x61 */ "\033[0;1;32m", /* 10 LGREEN 0x61 */
"\033[1;36m", /* 11 LCYAN 0x62 */ "\033[0:1;36m", /* 11 LCYAN 0x62 */
"\033[1;31m", /* 12 LRED 0x63 */ "\033[0;1;31m", /* 12 LRED 0x63 */
"\033[1;35m", /* 13 LPURPLE 0x64 */ "\033[0;1;35m", /* 13 LPURPLE 0x64 */
"\033[1;33m", /* 14 YELLOW 0x65 */ "\033[0;1;33m", /* 14 YELLOW 0x65 */
"\033[1;37m", /* 15 WHITE 0x66 */ "\033[0;1;37m", /* 15 WHITE 0x66 */
"\033[4m" /* 16 UNDERLINE 0x6e */
}; };
if(color == 0) if(color == 0 || color == 0x72) /* 0x72: 'r' */
{ {
fputs("\033[0m", stdout); /* CANCEL COLOR */ fputs("\033[0m", stdout); /* CANCEL COLOR */
} }
@ -500,6 +501,7 @@ void print_color(int color)
{ {
if(color >= 0x61 && color <= 0x66) color -= 0x57; if(color >= 0x61 && color <= 0x66) color -= 0x57;
else if(color >= 0x30 && color <= 0x39) color -= 0x30; else if(color >= 0x30 && color <= 0x39) color -= 0x30;
else if(color == 0x6e) color=16; /* 0x6e: 'n' */
else return; else return;
#ifndef _WIN32 #ifndef _WIN32
@ -534,20 +536,13 @@ void packet_print(rc_packet *packet)
// colors enabled so try to handle the bukkit colors for terminal // colors enabled so try to handle the bukkit colors for terminal
if (print_colors == 1) if (print_colors == 1)
{ {
for (i = 0; (unsigned char) packet->data[i] != 0; ++i) for (i = 0; (unsigned char) packet->data[i] != 0; ++i)
{ {
if ((unsigned char) packet->data[i] == 0xc2) if (packet->data[i] == 0x0A) print_color(def_color);
continue; else if((unsigned char) packet->data[i] == 0xc2 && (unsigned char) packet->data[i+1] == 0xa7){
print_color(packet->data[i+=2]);
if ((unsigned char) packet->data[i] == 0xa7)
{
++i;
print_color(packet->data[i]);
continue; continue;
} }
if (packet->data[i] == 0x0A) print_color(def_color);
putchar(packet->data[i]); putchar(packet->data[i]);
} }
print_color(def_color); // cancel coloring print_color(def_color); // cancel coloring
@ -557,15 +552,10 @@ void packet_print(rc_packet *packet)
{ {
for (i = 0; (unsigned char) packet->data[i] != 0; ++i) for (i = 0; (unsigned char) packet->data[i] != 0; ++i)
{ {
if ((unsigned char) packet->data[i] == 0xc2) if ((unsigned char) packet->data[i] == 0xc2 && (unsigned char) packet->data[i+1] == 0xa7){
continue; i+=2;
if ((unsigned char) packet->data[i] == 0xa7)
{
++i;
continue; continue;
} }
putchar(packet->data[i]); putchar(packet->data[i]);
} }
} }