public bool HandleDeath(BlockID block, string customMsg = "", bool explode = false, bool immediate = false) { if (!immediate && lastDeath.AddSeconds(2) > DateTime.UtcNow) { return(false); } if (invincible) { return(false); } cancelDeath = false; OnPlayerDeathEvent.Call(this, block); if (cancelDeath) { cancelDeath = false; return(false); } onTrain = false; trainInvincible = false; trainGrab = false; ushort x = (ushort)Pos.BlockX, y = (ushort)Pos.BlockY, z = (ushort)Pos.BlockZ; string deathMsg = level.Props[block].DeathMessage; if (deathMsg != null) { AnnounceDeath(deathMsg); } if (block == Block.RocketHead) { level.MakeExplosion(x, y, z, 0); } if (block == Block.Creeper) { level.MakeExplosion(x, y, z, 1); } if (block == Block.Stone || block == Block.Cobblestone) { if (explode) { level.MakeExplosion(x, y, z, 1); } if (block == Block.Stone) { Chat.MessageFrom(this, customMsg.Replace("@p", "λNICK")); } else { AnnounceDeath(customMsg); } } PlayerActions.Respawn(this); TimesDied++; // NOTE: If deaths column is ever increased past 16 bits, remove this clamp if (TimesDied > short.MaxValue) { TimesDied = short.MaxValue; } if (Server.Config.AnnounceDeathCount && (TimesDied > 0 && TimesDied % 10 == 0)) { AnnounceDeath("@p &Shas died &3" + TimesDied + " times"); } lastDeath = DateTime.UtcNow; return(true); }
bool SendRawMapCore(Level prev, Level level) { if (level.blocks == null) { return(false); } bool success = true; useCheckpointSpawn = false; lastCheckpointIndex = -1; AFKCooldown = DateTime.UtcNow.AddSeconds(2); ZoneIn = null; SendMapMotd(); AllowBuild = level.BuildAccess.CheckAllowed(this); try { int volume = level.blocks.Length; if (Supports(CpeExt.FastMap)) { Send(Packet.LevelInitaliseExt(volume)); } else { Send(Packet.LevelInitalise()); } if (hasBlockDefs) { if (prev != null && prev != level) { RemoveOldLevelCustomBlocks(prev); } BlockDefinition.SendLevelCustomBlocks(this); if (Supports(CpeExt.InventoryOrder)) { BlockDefinition.SendLevelInventoryOrder(this); } } using (LevelChunkStream dst = new LevelChunkStream(this)) using (Stream stream = LevelChunkStream.CompressMapHeader(this, volume, dst)) { if (level.MightHaveCustomBlocks()) { LevelChunkStream.CompressMap(this, stream, dst); } else { LevelChunkStream.CompressMapSimple(this, stream, dst); } } // Force players to read the MOTD (clamped to 3 seconds at most) if (level.Config.LoadDelay > 0) { System.Threading.Thread.Sleep(level.Config.LoadDelay); } byte[] buffer = Packet.LevelFinalise(level.Width, level.Height, level.Length); Send(buffer); Loading = false; OnSentMapEvent.Call(this, prev, level); } catch (Exception ex) { success = false; PlayerActions.ChangeMap(this, Server.mainLevel); Message("&WThere was an error sending the map, you have been sent to the main level."); Logger.LogError(ex); } finally { Server.DoGC(); } return(success); }
void CompleteLoginProcess() { Player clone = null; OnPlayerFinishConnectingEvent.Call(this); if (cancelconnecting) { cancelconnecting = false; return; } lock (PlayerInfo.Online.locker) { // Check if any players online have same name Player[] players = PlayerInfo.Online.Items; foreach (Player pl in players) { if (pl.truename == truename) { clone = pl; break; } } // Remove clone from list (hold lock for as short time as possible) if (clone != null && ServerConfig.VerifyNames) { PlayerInfo.Online.Remove(clone); } id = NextFreeId(); PlayerInfo.Online.Add(this); } if (clone != null && ServerConfig.VerifyNames) { string reason = ip == clone.ip ? "(Reconnecting)" : "(Reconnecting from a different IP)"; clone.Leave(reason); } else if (clone != null) { Leave(null, "Already logged in!", true); return; } SendMap(null); if (disconnected) { return; } loggedIn = true; pending.Remove(this); SessionStartTime = DateTime.UtcNow; LastLogin = DateTime.Now; TotalTime = TimeSpan.FromSeconds(1); GetPlayerStats(); ShowWelcome(); Server.Background.QueueOnce(ShowAltsTask, name, TimeSpan.Zero); CheckState(); if (!Directory.Exists("players")) { Directory.CreateDirectory("players"); } PlayerDB.Load(this); Game.Team = Team.TeamIn(this); SetPrefix(); LoadCpeData(); if (ServerConfig.verifyadmins && Rank >= ServerConfig.VerifyAdminsRank) { adminpen = true; } if (Server.noEmotes.Contains(name)) { parseEmotes = !ServerConfig.ParseEmotes; } hideRank = Rank; hidden = group.CanExecute("Hide") && Server.hidden.Contains(name); if (hidden) { Message("&8Reminder: You are still hidden."); } if (Chat.AdminchatPerms.UsableBy(Rank) && ServerConfig.AdminsJoinSilently) { hidden = true; adminchat = true; } OnPlayerConnectEvent.Call(this); if (cancellogin) { cancellogin = false; return; } string joinm = "&a+ λFULL %S" + PlayerDB.GetLoginMessage(this); if (hidden) { joinm = "&8(hidden)" + joinm; } if (ServerConfig.GuestJoinsNotify || Rank > LevelPermission.Guest) { Chat.MessageFrom(this, joinm, Chat.FilterVisible(this), !hidden); } if (ServerConfig.AgreeToRulesOnEntry && Rank == LevelPermission.Guest && !Server.agreed.Contains(name)) { Message("&9You must read the &c/Rules &9and &c/Agree &9to them before you can build and use commands!"); agreed = false; } if (ServerConfig.verifyadmins && Rank >= ServerConfig.VerifyAdminsRank) { if (!Directory.Exists("extra/passwords") || !File.Exists("extra/passwords/" + name + ".dat")) { Message("%WPlease set your admin verification password with %T/SetPass [password]!"); } else { Message("%WPlease complete admin verification with %T/Pass [password]!"); } } if (group.CanExecute("Inbox") && Database.TableExists("Inbox" + name)) { int count = Database.CountRows("Inbox" + name); if (count > 0) { Message("You have &a" + count + " %Smessages in %T/Inbox"); } } if (ServerConfig.PositionUpdateInterval > 1000) { Message("Lowlag mode is currently &aON."); } if (String.IsNullOrEmpty(appName)) { Logger.Log(LogType.UserActivity, "{0} [{1}] connected.", name, ip); } else { Logger.Log(LogType.UserActivity, "{0} [{1}] connected using {2}.", name, ip, appName); } PlayerActions.PostSentMap(this, null, level, false); Loading = false; }
internal void CompleteLoginProcess() { Player clone = null; OnPlayerFinishConnectingEvent.Call(this); if (cancelconnecting) { cancelconnecting = false; return; } lock (PlayerInfo.Online.locker) { // Check if any players online have same name clone = FindClone(truename); // Remove clone from list (hold lock for as short time as possible) if (clone != null && clone != this && Server.Config.VerifyNames) { PlayerInfo.Online.Remove(clone); } id = NextFreeId(); PlayerInfo.Online.Add(this); } if (clone != null && Server.Config.VerifyNames) { string reason = ip == clone.ip ? "(Reconnecting)" : "(Reconnecting from a different IP)"; clone.Leave(reason); } else if (clone != null) { Leave(null, "Already logged in!", true); return; } SendRawMap(null, level); if (Socket.Disconnected) { return; } loggedIn = true; SessionStartTime = DateTime.UtcNow; LastLogin = DateTime.Now; TotalTime = TimeSpan.FromSeconds(1); GetPlayerStats(); ShowWelcome(); Server.Background.QueueOnce(ShowAltsTask, name, TimeSpan.Zero); CheckState(); PlayerDB.LoadNick(this); Game.Team = Team.TeamIn(this); SetPrefix(); LoadCpeData(); if (Server.noEmotes.Contains(name)) { parseEmotes = !Server.Config.ParseEmotes; } hideRank = Rank; hidden = CanUse("Hide") && Server.hidden.Contains(name); if (hidden) { Message("&8Reminder: You are still hidden."); } if (Chat.AdminchatPerms.UsableBy(Rank) && Server.Config.AdminsJoinSilently) { hidden = true; adminchat = true; } OnPlayerConnectEvent.Call(this); if (cancellogin) { cancellogin = false; return; } string joinMsg = "&a+ λFULL &S" + PlayerDB.GetLoginMessage(this); if (hidden) { joinMsg = "&8(hidden)" + joinMsg; } if (Server.Config.GuestJoinsNotify || Rank > LevelPermission.Guest) { Chat.MessageFrom(ChatScope.All, this, joinMsg, null, Chat.FilterVisible(this), !hidden); } if (Server.Config.AgreeToRulesOnEntry && Rank == LevelPermission.Guest && !Server.agreed.Contains(name)) { Message("&9You must read the &c/Rules &9and &c/Agree &9to them before you can build and use commands!"); agreed = false; } CheckIsUnverified(); if (CanUse("Inbox") && Database.TableExists("Inbox" + name)) { int count = Database.CountRows("Inbox" + name); if (count > 0) { Message("You have &a" + count + " &Smessages in &T/Inbox"); } } if (Server.Config.PositionUpdateInterval > 1000) { Message("Lowlag mode is currently &aON."); } if (String.IsNullOrEmpty(appName)) { Logger.Log(LogType.UserActivity, "{0} [{1}] connected.", truename, IP); } else { Logger.Log(LogType.UserActivity, "{0} [{1}] connected using {2}.", truename, IP, appName); } PlayerActions.PostSentMap(this, null, level, false); Loading = false; }