mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Remove unnecessary try{} catch{}
This commit is contained in:
parent
de79a0e3e4
commit
d8b6240a52
@ -61,13 +61,13 @@ namespace MCGalaxy.Commands.World {
|
||||
bool HandleGoto(Player p, string message) {
|
||||
Level lvl = LevelInfo.FindExact(message);
|
||||
if (lvl != null) {
|
||||
return GoToLevel(p, lvl, message);
|
||||
return GoToLevel(p, lvl);
|
||||
} else if (Server.AutoLoad) {
|
||||
// First try exactly matching unloaded levels
|
||||
if (LevelInfo.ExistsOffline(message))
|
||||
return GotoOfflineLevel(p, message);
|
||||
lvl = LevelInfo.Find(message);
|
||||
if (lvl != null) return GoToLevel(p, lvl, message);
|
||||
if (lvl != null) return GoToLevel(p, lvl);
|
||||
|
||||
string map = LevelInfo.FindMapMatches(p, message);
|
||||
if (map == null) return false;
|
||||
@ -79,7 +79,7 @@ namespace MCGalaxy.Commands.World {
|
||||
Command.all.Find("search").Use(p, "levels " + message);
|
||||
return false;
|
||||
}
|
||||
return GoToLevel(p, lvl, message);
|
||||
return GoToLevel(p, lvl);
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ namespace MCGalaxy.Commands.World {
|
||||
CmdLoad.LoadLevel(p, message, "0", true);
|
||||
Level lvl = LevelInfo.Find(message);
|
||||
if (lvl != null) {
|
||||
return GoToLevel(p, lvl, message);
|
||||
return GoToLevel(p, lvl);
|
||||
} else {
|
||||
Player.Message(p, "Level \"{0}\" failed to be auto-loaded.", message);
|
||||
return false;
|
||||
@ -98,7 +98,7 @@ namespace MCGalaxy.Commands.World {
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool GoToLevel(Player p, Level lvl, string message) {
|
||||
static bool GoToLevel(Player p, Level lvl) {
|
||||
if (p.level == lvl) { Player.Message(p, "You are already in \"" + lvl.name + "\"."); return false; }
|
||||
if (!lvl.CanJoin(p)) return false;
|
||||
if (!Server.zombie.PlayerCanJoinLevel(p, lvl, p.level)) return false;
|
||||
|
@ -230,9 +230,11 @@ namespace MCGalaxy {
|
||||
BuildAccess.CheckDetailed(p, false);
|
||||
p.ZoneSpam = DateTime.UtcNow.AddSeconds(2);
|
||||
}
|
||||
if (p.level == this) return p.AllowBuild;
|
||||
|
||||
return p.level == this
|
||||
? p.AllowBuild : BuildAccess.Check(p, false);
|
||||
LevelAccessResult access = BuildAccess.Check(p, false);
|
||||
return access == LevelAccessResult.Whitelisted
|
||||
|| access == LevelAccessResult.Allowed;
|
||||
}
|
||||
|
||||
public bool CheckAffectPermissions(Player p, ushort x, ushort y, ushort z,
|
||||
|
@ -62,15 +62,21 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
|
||||
/// <summary> Returns whether the given player is allowed by these access permissions. </summary>
|
||||
public bool Check(Player p, bool ignoreRankPerm = false) {
|
||||
if (Blacklisted.CaselessContains(p.name)) return false;
|
||||
if (Whitelisted.CaselessContains(p.name) || ignoreRankPerm) return true;
|
||||
/// <summary> Returns the allowed state for the given player. </summary>
|
||||
public LevelAccessResult Check(Player p, bool ignoreRankPerm = false) {
|
||||
if (Blacklisted.CaselessContains(p.name))
|
||||
return LevelAccessResult.Blacklisted;
|
||||
if (Whitelisted.CaselessContains(p.name))
|
||||
return LevelAccessResult.Whitelisted;
|
||||
if (ignoreRankPerm)
|
||||
return LevelAccessResult.Allowed;
|
||||
|
||||
if (p.Rank < Min) return false;
|
||||
if (p.Rank < Min)
|
||||
return LevelAccessResult.BelowMinRank;
|
||||
string maxCmd = IsVisit ? "pervisitmax" : "perbuildmax";
|
||||
if (p.Rank > Max && !p.group.CanExecute(maxCmd)) return false;
|
||||
return true;
|
||||
if (p.Rank > Max && !p.group.CanExecute(maxCmd))
|
||||
return LevelAccessResult.AboveMaxRank;
|
||||
return LevelAccessResult.Allowed;
|
||||
}
|
||||
|
||||
/// <summary> Returns whether the given player is allowed for these access permissions. </summary>
|
||||
@ -153,8 +159,29 @@ namespace MCGalaxy {
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
foreach (Player p in players) {
|
||||
if (p.level != lvl) continue;
|
||||
p.AllowBuild = lvl.BuildAccess.Check(p, false);
|
||||
|
||||
LevelAccessResult access = lvl.BuildAccess.Check(p, false);
|
||||
p.AllowBuild = access == LevelAccessResult.Whitelisted
|
||||
|| access == LevelAccessResult.Allowed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum LevelAccessResult {
|
||||
|
||||
/// <summary> The player is whitelisted and always allowed. </summary>
|
||||
Whitelisted,
|
||||
|
||||
/// <summary> The player is blacklisted and never allowed. </summary>
|
||||
Blacklisted,
|
||||
|
||||
/// <summary> The player is allowed (by their rank) </summary>
|
||||
Allowed,
|
||||
|
||||
/// <summary> The player's rank is below the minimum rank allowed. </summary>
|
||||
BelowMinRank,
|
||||
|
||||
/// <summary> The player's rank is above the maximum rank allowed. </summary>
|
||||
AboveMaxRank,
|
||||
}
|
||||
}
|
@ -319,7 +319,10 @@ namespace MCGalaxy {
|
||||
bool success = true;
|
||||
useCheckpointSpawn = false;
|
||||
lastCheckpointIndex = -1;
|
||||
AllowBuild = level.BuildAccess.Check(this, false);
|
||||
|
||||
LevelAccessResult access = level.BuildAccess.Check(this, false);
|
||||
AllowBuild = access == LevelAccessResult.Whitelisted
|
||||
|| access == LevelAccessResult.Allowed;
|
||||
|
||||
try {
|
||||
if (hasBlockDefs) {
|
||||
|
@ -187,8 +187,8 @@ namespace MCGalaxy {
|
||||
byte[] remaining = new byte[buffer.Length - size];
|
||||
Buffer.BlockCopy(buffer, size, remaining, 0, remaining.Length);
|
||||
return ProcessReceived(remaining);
|
||||
} catch (Exception e) {
|
||||
Server.ErrorLog(e);
|
||||
} catch (Exception ex) {
|
||||
Server.ErrorLog(ex);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
@ -441,7 +441,6 @@ return;
|
||||
}
|
||||
|
||||
void HandleChat(byte[] packet) {
|
||||
try {
|
||||
if (!loggedIn) return;
|
||||
byte continued = packet[1];
|
||||
string text = GetString(packet, 2);
|
||||
@ -519,8 +518,6 @@ return;
|
||||
}
|
||||
CheckForMessageSpam();
|
||||
}
|
||||
catch ( Exception e ) { Server.ErrorLog(e); Chat.MessageAll("An error occurred: {0}", e.Message); }
|
||||
}
|
||||
|
||||
bool FilterChat(ref string text, byte continued) {
|
||||
// handles the /womid client message, which displays the WoM vrersion
|
||||
|
@ -25,7 +25,6 @@ namespace MCGalaxy {
|
||||
|
||||
void HandleLogin(byte[] packet) {
|
||||
LastAction = DateTime.UtcNow;
|
||||
try {
|
||||
if (loggedIn) return;
|
||||
|
||||
byte version = packet[1];
|
||||
@ -130,10 +129,6 @@ namespace MCGalaxy {
|
||||
|
||||
if (type != 0x42)
|
||||
CompleteLoginProcess();
|
||||
} catch (Exception e) {
|
||||
Server.ErrorLog(e);
|
||||
Chat.MessageAll("An error occurred: {0}", e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
bool CheckPlayersCount(Group foundGrp) {
|
||||
@ -198,7 +193,6 @@ namespace MCGalaxy {
|
||||
void CompleteLoginProcess() {
|
||||
LevelPermission adminChatRank = CommandOtherPerms.FindPerm("adminchat", LevelPermission.Admin);
|
||||
|
||||
try {
|
||||
SendUserMOTD();
|
||||
SendMap(null);
|
||||
if (disconnected) return;
|
||||
@ -229,10 +223,6 @@ namespace MCGalaxy {
|
||||
}
|
||||
}
|
||||
CheckOutdatedClient();
|
||||
} catch (Exception e) {
|
||||
Server.ErrorLog(e);
|
||||
Chat.MessageAll("An error occurred: {0}", e.Message);
|
||||
}
|
||||
|
||||
//OpenClassic Client Check
|
||||
SendBlockchange(0, 0, 0, 0);
|
||||
@ -310,16 +300,14 @@ namespace MCGalaxy {
|
||||
Server.s.Log(name + " [" + ip + "] has joined the server.");
|
||||
Game.InfectMessages = PlayerDB.GetInfectMessages(this);
|
||||
Server.zombie.PlayerJoinedServer(this);
|
||||
try {
|
||||
|
||||
ushort x = (ushort)((0.5 + level.spawnx) * 32);
|
||||
ushort y = (ushort)((1 + level.spawny) * 32);
|
||||
ushort z = (ushort)((0.5 + level.spawnz) * 32);
|
||||
pos = new ushort[3] { x, y, z }; rot = new byte[2] { level.rotx, level.roty };
|
||||
pos = new ushort[3] { x, y, z };
|
||||
rot = new byte[2] { level.rotx, level.roty };
|
||||
|
||||
Entities.SpawnEntities(this, x, y, z, rot[0], rot[1]);
|
||||
} catch (Exception e) {
|
||||
Server.ErrorLog(e);
|
||||
Server.s.Log("Error spawning player \"" + name + "\"");
|
||||
}
|
||||
CmdGoto.CheckGamesJoin(this, null);
|
||||
Loading = false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user