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