Tidy up leaving server code a little bit

This commit is contained in:
UnknownShadow200 2020-05-09 15:43:46 +10:00
parent e3ef369c38
commit 7eeb3d6c53
3 changed files with 9 additions and 17 deletions

View File

@ -62,8 +62,7 @@ namespace MCGalaxy {
case Opcode.CpeTwoWayPing: return 1 + 1 + 2;
default:
string msg = "Unhandled message id \"" + opcode + "\"!";
Leave(msg, msg, true);
Leave("Unhandled opcode \"" + opcode + "\"!", true);
return -1;
}
}

View File

@ -188,8 +188,7 @@ namespace MCGalaxy {
byte action = buffer[offset + 7];
if (action > 1) {
const string msg = "Unknown block action!";
Leave(msg, msg, true); return;
Leave("Unknown block action!", true); return;
}
LastAction = DateTime.UtcNow;
@ -496,8 +495,7 @@ namespace MCGalaxy {
text = Regex.Replace(text, " +", " ");
if (text.IndexOf('&') >= 0) {
const string msg = "Illegal character in chat message!";
Leave(msg, msg, true); return true;
Leave("Illegal character in chat message!", true); return true;
}
return text.Length == 0;
}

View File

@ -191,25 +191,20 @@ namespace MCGalaxy {
}
/// <summary> Disconnects the players from the server,
/// with the given message shown in both chat and in the disconnect packet. </summary>
/// with the given messages shown in chat and in the disconnect packet. </summary>
public void Leave(string chatMsg, string discMsg, bool sync = false) {
LeaveServer(chatMsg, discMsg, false, sync);
}
/// <summary> Disconnects the players from the server,
/// with the given messages shown in chat and in the disconnect packet. </summary>
public void Leave(string discMsg) { Leave(discMsg, false); }
public void Leave(string discMsg, bool sync = false) {
LeaveServer(discMsg, discMsg, false, sync);
/// with the same message shown in chat and in the disconnect packet. </summary>
public void Leave(string msg) { Leave(msg, false); }
public void Leave(string msg, bool sync = false) {
LeaveServer(msg, msg, false, sync);
}
[Obsolete("Use Leave() or Kick() instead")]
public void leftGame(string discMsg = "") {
string chatMsg = discMsg;
if (chatMsg.Length > 0) chatMsg = "(" + chatMsg + ")"; // old format
LeaveServer(chatMsg, discMsg, true);
}
public void leftGame(string discMsg = "") { Kick(discMsg); }
bool leftServer = false;
void LeaveServer(string chatMsg, string discMsg, bool isKick, bool sync = false) {