Merge fix

This commit is contained in:
UnknownShadow200 2016-09-09 11:04:45 +10:00
commit f62fefc977
20 changed files with 333 additions and 255 deletions

View File

@ -80,7 +80,7 @@ namespace MCGalaxy.Commands {
Player[] players = PlayerInfo.Online.Items; Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) { foreach (Player pl in players) {
if (pl.level == p.level && pl.name != p.name) if (pl.level == p.level && pl.name != p.name)
PlayerActions.ChangeMap(pl, Server.mainLevel.name); PlayerActions.ChangeMap(pl, Server.mainLevel);
} }
} else if (cmd == "KICK") { } else if (cmd == "KICK") {
if (arg == "") { p.SendMessage("You must specify a player to kick."); return; } if (arg == "") { p.SendMessage("You must specify a player to kick."); return; }
@ -88,7 +88,7 @@ namespace MCGalaxy.Commands {
Player pl = PlayerInfo.FindMatches(p, arg); Player pl = PlayerInfo.FindMatches(p, arg);
if (pl != null) { if (pl != null) {
if (pl.level.name == p.level.name) if (pl.level.name == p.level.name)
PlayerActions.ChangeMap(pl, Server.mainLevel.name); PlayerActions.ChangeMap(pl, Server.mainLevel);
else else
p.SendMessage("Player is not on your level!"); p.SendMessage("Player is not on your level!");
} }
@ -257,7 +257,7 @@ namespace MCGalaxy.Commands {
} }
Player.Message(p, blocked.name + " has been blacklisted from your map."); Player.Message(p, blocked.name + " has been blacklisted from your map.");
if (blocked.level.name == p.level.name) { if (blocked.level.name == p.level.name) {
PlayerActions.ChangeMap(blocked, Server.mainLevel.name); return; PlayerActions.ChangeMap(blocked, Server.mainLevel); return;
} }
} else if (cmd == "UNBLOCK") { } else if (cmd == "UNBLOCK") {
if (value == "") { if (value == "") {

View File

@ -75,9 +75,11 @@ namespace MCGalaxy.Commands {
Player.Message(p, " BlockDB (Used for /b) is {0}", data.blockDB ? "&aEnabled" : "&cDisabled"); Player.Message(p, " BlockDB (Used for /b) is {0}", data.blockDB ? "&aEnabled" : "&cDisabled");
ShowPermissions(p, data); ShowPermissions(p, data);
Player.Message(p, "Use %T/mi env {0} %Sto see environment settings.", data.Name); Player.Message(p, "Use %T/mi env {0} %Sto see environment settings.", data.Name);
if (!Server.zombie.IsZombieMap(data.Name)) return; if (!Server.zombie.IsZombieMap(data.Name)) return;
Player.Message(p, "Map authors: " + data.Authors);
string[] authors = data.Authors.Replace(" ", "").Split(',');
Player.Message(p, "Map authors: {0}",
authors.Join(n => PlayerInfo.GetColoredName(p, n)));
int winChance = data.TotalRounds == 0 ? 100 : (data.HumanRounds * 100) / data.TotalRounds; int winChance = data.TotalRounds == 0 ? 100 : (data.HumanRounds * 100) / data.TotalRounds;
Player.Message(p, "&a{0} %Srounds played total, &a{1}% %Swin chance for humans.", Player.Message(p, "&a{0} %Srounds played total, &a{1}% %Swin chance for humans.",
data.TotalRounds, winChance); data.TotalRounds, winChance);

View File

@ -65,7 +65,7 @@ namespace MCGalaxy.Commands {
if (who.muted) mute.Use(p, message); if (who.muted) mute.Use(p, message);
if (who.frozen) freeze.Use(p, message); if (who.frozen) freeze.Use(p, message);
PlayerActions.ChangeMap(who, Server.mainLevel.name); PlayerActions.ChangeMap(who, Server.mainLevel);
who.BlockUntilLoad(10); who.BlockUntilLoad(10);
jail.Use(p, message); jail.Use(p, message);

View File

@ -16,9 +16,6 @@
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
using System; using System;
using System.Collections.Generic;
using System.IO;
using MCGalaxy.Games;
namespace MCGalaxy.Commands.World { namespace MCGalaxy.Commands.World {
public sealed class CmdGoto : Command { public sealed class CmdGoto : Command {
@ -35,112 +32,12 @@ namespace MCGalaxy.Commands.World {
public override void Use(Player p, string message) { public override void Use(Player p, string message) {
if (p == null) { MessageInGameOnly(p); return; } if (p == null) { MessageInGameOnly(p); return; }
if (message == "") { Help(p); return; } if (message == "") { Help(p); return; }
if (p.usingGoto) { Player.Message(p, "Cannot use /goto, already loading a map."); return; } if (!Formatter.ValidName(p, message, "level")) return;
PlayerActions.ChangeMap(p, message);
Level oldLevel = p.level;
p.usingGoto = true;
bool didJoin = false;
try {
didJoin = HandleGoto(p, message);
} finally {
p.usingGoto = false;
GC.Collect();
GC.WaitForPendingFinalizers();
}
if (!didJoin) return;
bool unloadOld = true;
if (oldLevel.unload && !oldLevel.IsMuseum) {
Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players)
if (pl.level == oldLevel) { unloadOld = false; break; }
if (unloadOld && Server.AutoLoad) oldLevel.Unload(true);
}
}
bool HandleGoto(Player p, string message) {
Level lvl = LevelInfo.FindExact(message);
if (lvl != null) {
return GoToLevel(p, lvl, message);
} 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);
string map = LevelInfo.FindMapMatches(p, message);
if (map == null) return false;
return GotoOfflineLevel(p, map);
} else {
lvl = LevelInfo.Find(message);
if (lvl == null) {
Player.Message(p, "There is no level \"{0}\" loaded. Did you mean..", message);
Command.all.Find("search").Use(p, "levels " + message);
return false;
}
return GoToLevel(p, lvl, message);
}
}
static bool GotoOfflineLevel(Player p, string message) {
if (Level.CheckLoadOnGoto(message)) {
CmdLoad.LoadLevel(p, message, "0", true);
Level lvl = LevelInfo.Find(message);
if (lvl != null) {
return GoToLevel(p, lvl, message);
} else {
Player.Message(p, "Level \"{0}\" failed to be auto-loaded.", message);
return false;
}
}
Player.Message(p, "Level \"{0}\" cannot be loaded using /goto.", message);
return false;
}
static bool GoToLevel(Player p, Level lvl, string message) {
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;
p.Loading = true;
Entities.DespawnEntities(p);
Level oldLevel = p.level;
p.level = lvl; p.SendUserMOTD(); p.SendMap(oldLevel);
ushort x = (ushort)(lvl.spawnx * 32 + 16);
ushort y = (ushort)(lvl.spawny * 32 + 32);
ushort z = (ushort)(lvl.spawnz * 32 + 16);
Entities.SpawnEntities(p, x, y, z, lvl.rotx, lvl.roty);
p.Loading = false;
CheckGamesJoin(p, oldLevel);
p.prevMsg = "";
if (!p.hidden && p.level.ShouldShowJoinMessage(oldLevel)) {
Player.SendChatFrom(p, p.color + "*" + p.DisplayName + " %Swent to &b" + lvl.name, false);
Player.RaisePlayerAction(p, PlayerAction.JoinWorld, lvl.name);
}
return true;
}
internal static void CheckGamesJoin(Player p, Level oldLvl) {
Server.lava.PlayerJoinedLevel(p, p.level, oldLvl);
Server.zombie.PlayerJoinedLevel(p, p.level, oldLvl);
if (p.inTNTwarsMap) p.canBuild = true;
TntWarsGame game = TntWarsGame.Find(p.level);
if (game == null) return;
if (game.GameStatus != TntWarsGame.TntWarsGameStatus.Finished &&
game.GameStatus != TntWarsGame.TntWarsGameStatus.WaitingForPlayers) {
p.canBuild = false;
Player.Message(p, "TNT Wars: Disabled your building because you are in a TNT Wars map!");
}
p.inTNTwarsMap = true;
} }
public override void Help(Player p) { public override void Help(Player p) {
Player.Message(p, "%T/goto <mapname>"); Player.Message(p, "%T/goto [map name]");
Player.Message(p, "%HTeleports yourself to a different level."); Player.Message(p, "%HTeleports yourself to a different level.");
} }
} }

View File

@ -61,7 +61,7 @@ namespace MCGalaxy.Commands {
} }
if (p != null && who.level != p.level) { if (p != null && who.level != p.level) {
Player.Message(p, "Moving player to your map..."); Player.Message(p, "Moving player to your map...");
PlayerActions.ChangeMap(who, p.level.name); PlayerActions.ChangeMap(who, p.level);
who.BlockUntilLoad(500); who.BlockUntilLoad(500);
} }
Chat.MessageAll("{0} %Shas been locked down!", who.ColoredName); Chat.MessageAll("{0} %Shas been locked down!", who.ColoredName);

View File

@ -33,7 +33,7 @@ namespace MCGalaxy.Commands.World {
if (p.level.name == Server.mainLevel.name) { if (p.level.name == Server.mainLevel.name) {
Player.Message(p, "You are already on the server's main level."); return; Player.Message(p, "You are already on the server's main level."); return;
} }
PlayerActions.ChangeMap(p, Server.mainLevel.name); PlayerActions.ChangeMap(p, Server.mainLevel);
} else { } else {
if (!CheckExtraPerm(p)) { MessageNeedExtra(p, "change the main level"); return; } if (!CheckExtraPerm(p)) { MessageNeedExtra(p, "change the main level"); return; }
if (!Formatter.ValidName(p, message, "level")) return; if (!Formatter.ValidName(p, message, "level")) return;

View File

@ -74,7 +74,7 @@ namespace MCGalaxy.Commands.World {
} }
public override void Help(Player p) { public override void Help(Player p) {
Player.Message(p, "%T/museum <map> <restore>"); Player.Message(p, "%T/museum [map] [restore]");
Player.Message(p, "%HAllows you to access a restore of the map entered. Works on unloaded maps"); Player.Message(p, "%HAllows you to access a restore of the map entered. Works on unloaded maps");
} }
} }

View File

@ -54,7 +54,7 @@ namespace MCGalaxy.Commands {
if (p.level != who.level) { if (p.level != who.level) {
Player.Message(p, who.ColoredName + " %Sis in a different Level. Forcefetching has started!"); Player.Message(p, who.ColoredName + " %Sis in a different Level. Forcefetching has started!");
PlayerActions.ChangeMap(who, p.level.name); PlayerActions.ChangeMap(who, p.level);
Thread.Sleep(1000); Thread.Sleep(1000);
// Sleep for a bit while they load // Sleep for a bit while they load
} }

View File

@ -85,8 +85,7 @@ namespace MCGalaxy.Commands {
sender.currentTpa = ""; sender.currentTpa = "";
Thread.Sleep(1000); Thread.Sleep(1000);
if (p.level != sender.level) { if (p.level != sender.level) {
Level where = p.level; PlayerActions.ChangeMap(sender, p.level);
PlayerActions.ChangeMap(sender, where.name);
Thread.Sleep(1000); Thread.Sleep(1000);
} }

View File

@ -297,9 +297,9 @@ namespace MCGalaxy.Games
if (pl.level == oldMap) if (pl.level == oldMap)
{ {
if (sendAfkMain && pl.IsAfk) if (sendAfkMain && pl.IsAfk)
PlayerActions.ChangeMap(pl, Server.mainLevel.name); PlayerActions.ChangeMap(pl, Server.mainLevel);
else else
PlayerActions.ChangeMap(pl, map.name); PlayerActions.ChangeMap(pl, map);
} }
} }
if (OnMapChange != null) if (OnMapChange != null)

View File

@ -157,7 +157,7 @@ namespace MCGalaxy.Games
{ {
foreach (player p in Players.Where(p => p.p.level != lvl)) foreach (player p in Players.Where(p => p.p.level != lvl))
{ {
PlayerActions.ChangeMap(p.p, lvl.name); PlayerActions.ChangeMap(p.p, lvl);
p.p.inTNTwarsMap = true; p.p.inTNTwarsMap = true;
} }
if (GameMode == TntWarsGameMode.TDM) { Command.all.Find("reveal").Use(null, "all " + lvl.name); }//So peoples names apear above their heads in the right color! if (GameMode == TntWarsGameMode.TDM) { Command.all.Find("reveal").Use(null, "all " + lvl.name); }//So peoples names apear above their heads in the right color!

View File

@ -83,10 +83,14 @@ namespace MCGalaxy.Games {
if (Server.votingforlevel && HandleVote(p, message)) return true; if (Server.votingforlevel && HandleVote(p, message)) return true;
if (message[0] == '~' && message.Length > 1) { if (message[0] == '~' && message.Length > 1) {
Player[] players = p.Game.Infected ? Infected.Items : Alive.Items; Player[] players = PlayerInfo.Online.Items;
string type = p.Game.Infected ? " &cto zombies%S: " : " &ato humans%S: "; string type = p.Game.Infected ? " &cto zombies%S: " : " &ato humans%S: ";
foreach (Player pl in players)
foreach (Player pl in players) {
if (!pl.level.name.CaselessEq(CurLevelName)) continue;
if (pl.Game.Referee || pl.Game.Infected == p.Game.Infected)
pl.SendMessage(p.ColoredName + type + message.Substring(1)); pl.SendMessage(p.ColoredName + type + message.Substring(1));
}
return true; return true;
} else if (message[0] == '`' && message.Length > 1) { } else if (message[0] == '`' && message.Length > 1) {
if (p.Game.Team == null) { if (p.Game.Team == null) {
@ -142,8 +146,11 @@ namespace MCGalaxy.Games {
"%SPillaring " + (CurLevel.Pillaring ? "&aYes" : "&cNo") + "%SPillaring " + (CurLevel.Pillaring ? "&aYes" : "&cNo") +
"%S, Type is &a" + CurLevel.BuildType); "%S, Type is &a" + CurLevel.BuildType);
if (CurLevel.Authors != "") if (CurLevel.Authors != "") {
p.SendMessage("It was created by " + CurLevel.Authors); string[] authors = CurLevel.Authors.Replace(" ", "").Split(',');
Player.Message(p, "It was created by {0}",
authors.Join(n => PlayerInfo.GetColoredName(p, n)));
}
PlayerMoneyChanged(p); PlayerMoneyChanged(p);
UpdatePlayerStatus(p); UpdatePlayerStatus(p);

View File

@ -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,

View File

@ -208,7 +208,7 @@ namespace MCGalaxy {
foreach (Player p in players) { foreach (Player p in players) {
if (p.level == this) { if (p.level == this) {
Player.Message(p, "You were moved to the main level as " + name + " was unloaded."); Player.Message(p, "You were moved to the main level as " + name + " was unloaded.");
PlayerActions.ChangeMap(p, Server.mainLevel.name); PlayerActions.ChangeMap(p, Server.mainLevel);
} }
} }
} }

View File

@ -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,
}
} }

View File

@ -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) {
@ -356,7 +359,7 @@ namespace MCGalaxy {
} }
} catch (Exception ex) { } catch (Exception ex) {
success = false; success = false;
PlayerActions.ChangeMap(this, Server.mainLevel.name); PlayerActions.ChangeMap(this, Server.mainLevel);
SendMessage("There was an error sending the map data, you have been sent to the main level."); SendMessage("There was an error sending the map data, you have been sent to the main level.");
Server.ErrorLog(ex); Server.ErrorLog(ex);
} finally { } finally {

View File

@ -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

View File

@ -25,9 +25,9 @@ namespace MCGalaxy {
void HandleLogin(byte[] packet) { void HandleLogin(byte[] packet) {
LastAction = DateTime.UtcNow; LastAction = DateTime.UtcNow;
try {
if (loggedIn) return; if (loggedIn) return;
<<<<<<< HEAD
byte version = packet[1]; byte version = packet[1];
name = enc.GetString(packet, 2, 64).Trim(); name = enc.GetString(packet, 2, 64).Trim();
if (name.Length > 16) { if (name.Length > 16) {
@ -47,6 +47,27 @@ namespace MCGalaxy {
} }
if (altsCount > 0) { if (altsCount > 0) {
Leave("Already logged in!", true); return; Leave("Already logged in!", true); return;
=======
byte version = packet[1];
name = enc.GetString(packet, 2, 64).Trim();
if (name.Length > 16) {
Leave("Usernames must be 16 characters or less", true); return;
}
truename = name;
skinName = name;
int altsCount = 0;
lock (pendingLock) {
DateTime now = DateTime.UtcNow;
foreach (PendingItem item in pendingNames) {
if (item.Name == truename && (now - item.Connected).TotalSeconds <= 60)
altsCount++;
>>>>>>> 22ce3355275dac2590aae6a9ecc600706f28e377
}
pendingNames.Add(new PendingItem(name));
}
if (altsCount > 0) {
Leave("Already logged in!", true); return;
} }
string verify = enc.GetString(packet, 66, 32).Trim(); string verify = enc.GetString(packet, 66, 32).Trim();
@ -97,8 +118,14 @@ namespace MCGalaxy {
} else { } else {
Kick(Server.defaultBanMessage, true); Kick(Server.defaultBanMessage, true);
} }
<<<<<<< HEAD
byte type = packet[130];
if (type == 0x42) { hasCpe = true; SendCpeExtensions(); }
=======
return; return;
} }
>>>>>>> 22ce3355275dac2590aae6a9ecc600706f28e377
// maxplayer check // maxplayer check
if (!CheckPlayersCount(foundGrp)) return; if (!CheckPlayersCount(foundGrp)) return;
@ -116,9 +143,13 @@ namespace MCGalaxy {
} }
} }
LoadIgnores();
byte type = packet[130]; byte type = packet[130];
if (type == 0x42) { hasCpe = true; SendCpeExtensions(); } if (type == 0x42) { hasCpe = true; SendCpeExtensions(); }
try { left.Remove(name.ToLower()); }
catch { }
group = foundGrp; group = foundGrp;
Loading = true; Loading = true;
if (disconnected) return; if (disconnected) return;
@ -126,10 +157,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) {
@ -194,7 +221,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;
@ -204,10 +230,6 @@ namespace MCGalaxy {
connections.Remove(this); connections.Remove(this);
RemoveFromPending(); RemoveFromPending();
Server.s.PlayerListUpdate(); Server.s.PlayerListUpdate();
} 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);
@ -275,17 +297,15 @@ 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) { PlayerActions.CheckGamesJoin(this, null);
Server.ErrorLog(e);
Server.s.Log("Error spawning player \"" + name + "\"");
}
CmdGoto.CheckGamesJoin(this, null);
Loading = false; Loading = false;
} }
@ -340,6 +360,7 @@ namespace MCGalaxy {
} }
if (alts.Count == 0) return; if (alts.Count == 0) return;
<<<<<<< HEAD
LevelPermission adminChatRank = CommandOtherPerms.FindPerm("adminchat", LevelPermission.Admin); LevelPermission adminChatRank = CommandOtherPerms.FindPerm("adminchat", LevelPermission.Admin);
string altsMsg = p.ColoredName + " %Sis lately known as: " + alts.Join(); string altsMsg = p.ColoredName + " %Sis lately known as: " + alts.Join();
if (p.group.Permission < adminChatRank || !Server.adminsjoinsilent) { if (p.group.Permission < adminChatRank || !Server.adminsjoinsilent) {
@ -347,6 +368,13 @@ namespace MCGalaxy {
//IRCBot.Say(temp, true); //Tells people in op channel on IRC //IRCBot.Say(temp, true); //Tells people in op channel on IRC
} }
Server.s.Log(altsMsg); Server.s.Log(altsMsg);
=======
short reachDist;
if (!short.TryParse(reach, out reachDist)) return;
ReachDistance = reachDist / 32f;
if (HasCpeExt(CpeExt.ClickDistance))
Send(Packet.MakeClickDistance(reachDist));
>>>>>>> 22ce3355275dac2590aae6a9ecc600706f28e377
} }
} }
} }

View File

@ -16,6 +16,9 @@
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
using System; using System;
using MCGalaxy.Games;
using MCGalaxy.Commands.World;
namespace MCGalaxy { namespace MCGalaxy {
public static class PlayerActions { public static class PlayerActions {
@ -34,8 +37,121 @@ namespace MCGalaxy {
} }
/// <summary> Moves the player to the specified map. </summary> /// <summary> Moves the player to the specified map. </summary>
public static void ChangeMap(Player p, string name) { public static bool ChangeMap(Player p, string name) { return ChangeMap(p, null, name); }
Command.all.Find("goto").Use(p, name);
/// <summary> Moves the player to the specified map. </summary>
public static bool ChangeMap(Player p, Level lvl) { return ChangeMap(p, lvl, null); }
static bool ChangeMap(Player p, Level lvl, string name) {
if (p.usingGoto) { Player.Message(p, "Cannot use /goto, already loading a map."); return false; }
Level oldLevel = p.level;
p.usingGoto = true;
bool didJoin = false;
try {
didJoin = name == null ?
GotoLevel(p, lvl) : GotoMap(p, name);
} finally {
p.usingGoto = false;
GC.Collect();
GC.WaitForPendingFinalizers();
}
if (!didJoin) return false;
Unload(oldLevel);
return true;
}
static bool GotoMap(Player p, string name) {
Level lvl = LevelInfo.FindExact(name);
if (lvl != null) return GotoLevel(p, lvl);
if (Server.AutoLoad) {
// First try exactly matching unloaded levels
if (LevelInfo.ExistsOffline(name))
return LoadOfflineLevel(p, name);
lvl = LevelInfo.Find(name);
if (lvl != null) return GotoLevel(p, lvl);
string matches = LevelInfo.FindMapMatches(p, name);
if (matches == null) return false;
return LoadOfflineLevel(p, matches);
} else {
lvl = LevelInfo.Find(name);
if (lvl == null) {
Player.Message(p, "There is no level \"{0}\" loaded. Did you mean..", name);
Command.all.Find("search").Use(p, "levels " + name);
return false;
}
return GotoLevel(p, lvl);
}
}
static bool LoadOfflineLevel(Player p, string name) {
if (!Level.CheckLoadOnGoto(name)) {
Player.Message(p, "Level \"{0}\" cannot be loaded using /goto.", name);
return false;
}
CmdLoad.LoadLevel(p, name, "0", true);
Level lvl = LevelInfo.FindExact(name);
if (lvl != null) return GotoLevel(p, lvl);
Player.Message(p, "Level \"{0}\" failed to be auto-loaded.", name);
return false;
}
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;
p.Loading = true;
Entities.DespawnEntities(p);
Level oldLevel = p.level;
p.level = lvl; p.SendUserMOTD(); p.SendMap(oldLevel);
ushort x = (ushort)(lvl.spawnx * 32 + 16);
ushort y = (ushort)(lvl.spawny * 32 + 32);
ushort z = (ushort)(lvl.spawnz * 32 + 16);
Entities.SpawnEntities(p, x, y, z, lvl.rotx, lvl.roty);
p.Loading = false;
CheckGamesJoin(p, oldLevel);
p.prevMsg = "";
if (!p.hidden && p.level.ShouldShowJoinMessage(oldLevel)) {
Player.SendChatFrom(p, p.color + "*" + p.DisplayName + " %Swent to &b" + lvl.name, false);
Player.RaisePlayerAction(p, PlayerAction.JoinWorld, lvl.name);
}
return true;
}
internal static void CheckGamesJoin(Player p, Level oldLvl) {
Server.lava.PlayerJoinedLevel(p, p.level, oldLvl);
Server.zombie.PlayerJoinedLevel(p, p.level, oldLvl);
if (p.inTNTwarsMap) p.canBuild = true;
TntWarsGame game = TntWarsGame.Find(p.level);
if (game == null) return;
if (game.GameStatus != TntWarsGame.TntWarsGameStatus.Finished &&
game.GameStatus != TntWarsGame.TntWarsGameStatus.WaitingForPlayers) {
p.canBuild = false;
Player.Message(p, "TNT Wars: Disabled your building because you are in a TNT Wars map!");
}
p.inTNTwarsMap = true;
}
static void Unload(Level lvl) {
bool unloadOld = true;
if (lvl.IsMuseum || !lvl.unload) return;
Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) {
if (pl.level == lvl) { unloadOld = false; break; }
}
if (unloadOld && Server.AutoLoad) lvl.Unload(true);
} }
} }
} }

View File

@ -48,7 +48,7 @@ namespace MCGalaxy {
Level lvl = LevelInfo.FindExact(wp.lvlname); Level lvl = LevelInfo.FindExact(wp.lvlname);
if (p.level != lvl) if (p.level != lvl)
PlayerActions.ChangeMap(p, wp.lvlname); PlayerActions.ChangeMap(p, lvl);
if (p.level.name.CaselessEq(wp.lvlname)) { if (p.level.name.CaselessEq(wp.lvlname)) {
p.SendPos(0xFF, wp.x, wp.y, wp.z, wp.rotx, wp.roty); p.SendPos(0xFF, wp.x, wp.y, wp.z, wp.rotx, wp.roty);