mirror of
https://github.com/TotalFreedomMC/BukkitTelnet.git
synced 2025-08-06 04:23:17 +00:00
Changed output to use whole lines (no more partial lines that start with ":").
Fixed glitch that caused mainLoop to stop blocking and run-away loop (possible cause of high CPU errors).
This commit is contained in:
parent
c5aa5f813d
commit
f7bccca400
3 changed files with 32 additions and 45 deletions
|
@ -79,7 +79,7 @@ public class TelnetLogAppender extends AbstractAppender
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
session.printRawln(formatMessage(message, event));
|
session.printRawLine(formatMessage(message, event));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,12 +70,11 @@ public final class ClientSession extends Thread
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
printRaw(":");
|
writeLine("Session Started.");
|
||||||
println("Session Started.");
|
|
||||||
|
|
||||||
if (!authenticate())
|
if (!authenticate())
|
||||||
{
|
{
|
||||||
println("Authentication failed.");
|
writeLine("Authentication failed.");
|
||||||
syncTerminateSession();
|
syncTerminateSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +109,7 @@ public final class ClientSession extends Thread
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
println("Closing connection...");
|
writeLine("Closing connection...");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
clientSocket.close();
|
clientSocket.close();
|
||||||
|
@ -142,7 +141,7 @@ public final class ClientSession extends Thread
|
||||||
this.filterMode = filterMode;
|
this.filterMode = filterMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printRaw(String message)
|
public void printRawLine(String message)
|
||||||
{
|
{
|
||||||
if (writer == null || !syncIsConnected())
|
if (writer == null || !syncIsConnected())
|
||||||
{
|
{
|
||||||
|
@ -151,7 +150,7 @@ public final class ClientSession extends Thread
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
writer.write(ChatColor.stripColor(message));
|
writer.write(":" + ChatColor.stripColor(message) + "\r\n");
|
||||||
writer.flush();
|
writer.flush();
|
||||||
}
|
}
|
||||||
catch (IOException ex)
|
catch (IOException ex)
|
||||||
|
@ -159,19 +158,9 @@ public final class ClientSession extends Thread
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printRawln(String message)
|
public void writeLine(String message)
|
||||||
{
|
{
|
||||||
printRaw(message + "\r\n:");
|
printRawLine("[" + (username.isEmpty() ? "" : username + "@") + "BukkitTelnet]$ " + message);
|
||||||
}
|
|
||||||
|
|
||||||
public void print(String message)
|
|
||||||
{
|
|
||||||
printRaw("[" + (username.isEmpty() ? "" : username + "@") + "BukkitTelnet]$ " + message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void println(String message)
|
|
||||||
{
|
|
||||||
print(message + "\r\n:");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flush()
|
public void flush()
|
||||||
|
@ -274,7 +263,7 @@ public final class ClientSession extends Thread
|
||||||
int tries = 0;
|
int tries = 0;
|
||||||
while (tries++ < 3)
|
while (tries++ < 3)
|
||||||
{
|
{
|
||||||
print("Username: ");
|
writeLine("Username: ");
|
||||||
|
|
||||||
String input;
|
String input;
|
||||||
try
|
try
|
||||||
|
@ -286,8 +275,6 @@ public final class ClientSession extends Thread
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
printRaw(":");
|
|
||||||
|
|
||||||
if (input == null || input.isEmpty()) // End of stream
|
if (input == null || input.isEmpty()) // End of stream
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
@ -297,7 +284,7 @@ public final class ClientSession extends Thread
|
||||||
|
|
||||||
if (input.isEmpty())
|
if (input.isEmpty())
|
||||||
{
|
{
|
||||||
println("Invalid username.");
|
writeLine("Invalid username.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,7 +309,7 @@ public final class ClientSession extends Thread
|
||||||
tries = 0;
|
tries = 0;
|
||||||
while (tries++ < 3)
|
while (tries++ < 3)
|
||||||
{
|
{
|
||||||
print("Password: ");
|
writeLine("Password: ");
|
||||||
|
|
||||||
String input;
|
String input;
|
||||||
|
|
||||||
|
@ -335,8 +322,6 @@ public final class ClientSession extends Thread
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
printRaw(":");
|
|
||||||
|
|
||||||
if (input == null || input.isEmpty()) // End of stream
|
if (input == null || input.isEmpty()) // End of stream
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
@ -349,7 +334,7 @@ public final class ClientSession extends Thread
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
println("Invalid password.");
|
writeLine("Invalid password.");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
|
@ -369,7 +354,7 @@ public final class ClientSession extends Thread
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
println("Logged in as " + username + ".");
|
writeLine("Logged in as " + username + ".");
|
||||||
TelnetLogger.info(clientAddress + " logged in as \"" + username + "\".");
|
TelnetLogger.info(clientAddress + " logged in as \"" + username + "\".");
|
||||||
|
|
||||||
// Start feeding data to the client.
|
// Start feeding data to the client.
|
||||||
|
@ -389,9 +374,11 @@ public final class ClientSession extends Thread
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
printRaw(":");
|
if (command == null)
|
||||||
|
{
|
||||||
if (command == null || command.isEmpty()) // End of stream
|
break;
|
||||||
|
}
|
||||||
|
else if (command.isEmpty())
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -416,15 +403,15 @@ public final class ClientSession extends Thread
|
||||||
{
|
{
|
||||||
if ("telnet.help".equalsIgnoreCase(command))
|
if ("telnet.help".equalsIgnoreCase(command))
|
||||||
{
|
{
|
||||||
println("--- Telnet commands ---");
|
writeLine("--- Telnet commands ---");
|
||||||
println("telnet.help - See all of the telnet commands.");
|
writeLine("telnet.help - See all of the telnet commands.");
|
||||||
println("telnet.stop - Shut the server down.");
|
writeLine("telnet.stop - Shut the server down.");
|
||||||
println("telnet.log - Change your logging settings.");
|
writeLine("telnet.log - Change your logging settings.");
|
||||||
println("telnet.exit - Quit the telnet session.");
|
writeLine("telnet.exit - Quit the telnet session.");
|
||||||
}
|
}
|
||||||
else if ("telnet.stop".equalsIgnoreCase(command))
|
else if ("telnet.stop".equalsIgnoreCase(command))
|
||||||
{
|
{
|
||||||
println("Shutting down the server...");
|
writeLine("Shutting down the server...");
|
||||||
TelnetLogger.warning(username + ": Shutting down the server...");
|
TelnetLogger.warning(username + ": Shutting down the server...");
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
@ -435,32 +422,32 @@ public final class ClientSession extends Thread
|
||||||
case FULL:
|
case FULL:
|
||||||
{
|
{
|
||||||
filterMode = FilterMode.CHAT_ONLY;
|
filterMode = FilterMode.CHAT_ONLY;
|
||||||
println("Showing only chat logs.");
|
writeLine("Showing only chat logs.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CHAT_ONLY:
|
case CHAT_ONLY:
|
||||||
{
|
{
|
||||||
filterMode = FilterMode.NONCHAT_ONLY;
|
filterMode = FilterMode.NONCHAT_ONLY;
|
||||||
println("Showing only non-chat logs.");
|
writeLine("Showing only non-chat logs.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NONCHAT_ONLY:
|
case NONCHAT_ONLY:
|
||||||
{
|
{
|
||||||
filterMode = FilterMode.FULL;
|
filterMode = FilterMode.FULL;
|
||||||
println("Showing all logs.");
|
writeLine("Showing all logs.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ("telnet.exit".equalsIgnoreCase(command))
|
else if ("telnet.exit".equalsIgnoreCase(command))
|
||||||
{
|
{
|
||||||
println("Goodbye.");
|
writeLine("Goodbye.");
|
||||||
syncTerminateSession();
|
syncTerminateSession();
|
||||||
}
|
}
|
||||||
else if ("telnet.enhanced".equalsIgnoreCase(command))
|
else if ("telnet.enhanced".equalsIgnoreCase(command))
|
||||||
{
|
{
|
||||||
enhancedMode = !enhancedMode;
|
enhancedMode = !enhancedMode;
|
||||||
println((enhancedMode ? "A" : "Dea") + "ctivated enhanced mode.");
|
writeLine((enhancedMode ? "A" : "Dea") + "ctivated enhanced mode.");
|
||||||
if (enhancedMode)
|
if (enhancedMode)
|
||||||
{
|
{
|
||||||
PlayerEventListener.triggerPlayerListUpdates();
|
PlayerEventListener.triggerPlayerListUpdates();
|
||||||
|
@ -468,7 +455,7 @@ public final class ClientSession extends Thread
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
println("Invalid telnet command, use \"telnet.help\" to view help.");
|
writeLine("Invalid telnet command, use \"telnet.help\" to view help.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -486,7 +473,7 @@ public final class ClientSession extends Thread
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
println("playerList~" + playerListData);
|
writeLine("playerList~" + playerListData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class SessionCommandSender implements CommandSender
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(String message)
|
public void sendMessage(String message)
|
||||||
{
|
{
|
||||||
session.printRaw(message + "\r\n:");
|
session.printRawLine(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue