void HandleBlockchange(byte[] buffer, int offset) { try { if (!loggedIn || spamChecker.CheckBlockSpam()) { return; } ushort x = NetUtils.ReadU16(buffer, offset + 1); ushort y = NetUtils.ReadU16(buffer, offset + 3); ushort z = NetUtils.ReadU16(buffer, offset + 5); byte action = buffer[offset + 7]; if (action > 1) { const string msg = "Unknown block action!"; Leave(msg, msg, true); return; } LastAction = DateTime.UtcNow; if (IsAfk) { CmdAfk.ToggleAfk(this, ""); } BlockID held = ReadBlock(buffer, offset + 8); RawHeldBlock = held; if ((action == 0 || held == Block.Air) && !level.Config.Deletable) { Message("Deleting blocks is disabled in this level."); RevertBlock(x, y, z); return; } else if (action == 1 && !level.Config.Buildable) { Message("Placing blocks is disabled in this level."); RevertBlock(x, y, z); return; } if (held >= Block.Extended) { if (!hasBlockDefs || level.CustomBlockDefs[held] == null) { Message("Invalid block type: " + Block.ToRaw(held)); RevertBlock(x, y, z); return; } } HandleManualChange(x, y, z, action != 0, held, true); } catch (Exception e) { // Don't ya just love it when the server tattles? Chat.MessageOps(DisplayName + " has triggered a block change error"); Chat.MessageOps(e.GetType().ToString() + ": " + e.Message); Logger.LogError(e); } }
void CheckTimerElapsed(object sender, ElapsedEventArgs e) { if (name == "") { return; } SendRaw(Opcode.Ping); if (Server.afkminutes <= 0) { return; } if (DateTime.UtcNow < AFKCooldown) { return; } if (IsAfk) { int time = Server.afkkick; if (AutoAfk) { time += Server.afkminutes; } if (Server.afkkick > 0 && group.Permission < Server.afkkickperm) { if (LastAction.AddMinutes(time) < DateTime.UtcNow) { Leave("Auto-kick, AFK for " + Server.afkkick + " minutes"); } } if (Moved()) { CmdAfk.ToggleAfk(this, ""); } } else { if (Moved()) { LastAction = DateTime.UtcNow; } DateTime lastAction = LastAction; if (LastAction.AddMinutes(Server.afkminutes) < DateTime.UtcNow && !String.IsNullOrEmpty(name)) { CmdAfk.ToggleAfk(this, "auto: Not moved for " + Server.afkminutes + " minutes"); AutoAfk = true; LastAction = lastAction; } } }
internal static void CheckState(SchedulerTask task) { Player[] players = PlayerInfo.Online.Items; foreach (Player p in players) { if (p.hasTwoWayPing) { p.Send(Packet.TwoWayPing(true, p.Ping.NextTwoWayPingData())); } else { p.Send(Packet.Ping()); } if (ServerConfig.AutoAfkTime.Ticks <= 0) { return; } if (DateTime.UtcNow < p.AFKCooldown) { return; } if (p.IsAfk) { TimeSpan time = p.group.AfkKickTime; if (p.AutoAfk) { time += ServerConfig.AutoAfkTime; } if (p.group.AfkKicked && p.LastAction.Add(time) < DateTime.UtcNow) { string afkTime = p.group.AfkKickTime.Shorten(true, true); p.Leave("Auto-kick, AFK for " + afkTime); } } else { DateTime lastAction = p.LastAction; if (lastAction.Add(ServerConfig.AutoAfkTime) < DateTime.UtcNow) { string afkTime = ServerConfig.AutoAfkTime.Shorten(true, true); CmdAfk.ToggleAfk(p, "auto: Not moved for " + afkTime); p.AutoAfk = true; p.LastAction = lastAction; } } } }
internal void ProcessBlockchange(ushort x, ushort y, ushort z, byte action, BlockID held) { try { if (spamChecker.CheckBlockSpam()) { return; } LastAction = DateTime.UtcNow; if (IsAfk) { CmdAfk.ToggleAfk(this, ""); } ClientHeldBlock = held; if ((action == 0 || held == Block.Air) && !level.Config.Deletable) { // otherwise if you're holding air and try to place a block, this message would show if (!level.IsAirAt(x, y, z)) { Message("Deleting blocks is disabled in this level."); } RevertBlock(x, y, z); return; } else if (action == 1 && !level.Config.Buildable) { Message("Placing blocks is disabled in this level."); RevertBlock(x, y, z); return; } if (held >= Block.Extended) { if (!hasBlockDefs || level.CustomBlockDefs[held] == null) { Message("Invalid block type: " + Block.ToRaw(held)); RevertBlock(x, y, z); return; } } HandleManualChange(x, y, z, action != 0, held, true); } catch (Exception e) { // Don't ya just love it when the server tattles? Chat.MessageOps(DisplayName + " has triggered a block change error"); Chat.MessageOps(e.GetType().ToString() + ": " + e.Message); Logger.LogError(e); } }
public void ProcessMovement(int x, int y, int z, byte yaw, byte pitch, int held) { if (held >= 0) { ClientHeldBlock = (BlockID)held; } if (trainGrab || following.Length > 0) { CheckBlocks(Pos, Pos); return; } Position next = new Position(x, y, z); CheckBlocks(Pos, next); bool cancel = false; OnPlayerMoveEvent.Call(this, next, yaw, pitch, ref cancel); if (cancel) { cancel = false; return; } Pos = next; SetYawPitch(yaw, pitch); CheckZones(next); if (!Moved() || Loading) { return; } if (DateTime.UtcNow < AFKCooldown) { return; } LastAction = DateTime.UtcNow; if (IsAfk) { CmdAfk.ToggleAfk(this, ""); } }
void HandleChat(byte[] buffer, int offset) { if (!loggedIn) { return; } byte continued = buffer[offset + 1]; string text = NetUtils.ReadString(buffer, offset + 2); LastAction = DateTime.UtcNow; if (FilterChat(ref text, continued)) { return; } if (text != "/afk" && IsAfk) { CmdAfk.ToggleAfk(this, ""); } // Typing //Command appears in chat as /command // Suggested by McMrCat if (text.StartsWith("//")) { text = text.Remove(0, 1); } else if (DoCommand(text)) { return; } // People who are muted can't speak or vote if (muted) { SendMessage("You are muted."); return; } //Muted: Only allow commands // Lava Survival map vote recorder if (Server.lava.HasPlayer(this) && Server.lava.HasVote(text.ToLower())) { if (Server.lava.AddVote(this, text.ToLower())) { SendMessage("Your vote for &5" + text.ToLower().Capitalize() + " %Shas been placed. Thanks!"); Server.lava.map.ChatLevelOps(name + " voted for &5" + text.ToLower().Capitalize() + "%S."); return; } else { SendMessage("&cYou already voted!"); return; } } // Filter out bad words if (ServerConfig.ProfanityFiltering) { text = ProfanityFilter.Parse(text); } if (IsHandledMessage(text)) { return; } // Put this after vote collection so that people can vote even when chat is moderated if (Server.chatmod && !voice) { SendMessage("Chat moderation is on, you cannot speak."); return; } if (ChatModes.Handle(this, text)) { return; } if (text[0] == ':' && PlayingTntWars) { string newtext = text.Remove(0, 1).Trim(); TntWarsGame it = TntWarsGame.GameIn(this); if (it.GameMode == TntWarsGame.TntWarsGameMode.TDM) { TntWarsGame.player pl = it.FindPlayer(this); foreach (TntWarsGame.player p in it.Players) { if (pl.Red && p.Red) { SendMessage(p.p, "To Team " + Colors.red + "-" + color + name + Colors.red + "- %S" + newtext); } if (pl.Blue && p.Blue) { SendMessage(p.p, "To Team " + Colors.blue + "-" + color + name + Colors.blue + "- %S" + newtext); } } Logger.Log(LogType.GameActivity, "[TNT Wars] [TeamChat (" + (pl.Red ? "Red" : "Blue") + ") " + name + " " + newtext); return; } } text = HandleJoker(text); if (Chatroom != null) { Chat.MessageChatRoom(this, text, true, Chatroom); return; } bool levelOnly = !level.SeesServerWideChat; string format = levelOnly ? "<{0}>[level] {1}" : "<{0}> {1}"; Logger.Log(LogType.PlayerChat, format, name, text); OnPlayerChatEvent.Call(this, text); if (cancelchat) { cancelchat = false; return; } if (levelOnly) { Chat.MessageLevel(this, text, true, level); } else { SendChatFrom(this, text); } CheckForMessageSpam(); }
void HandleChat(byte[] buffer, int offset) { if (!loggedIn) { return; } byte continued = buffer[offset + 1]; string text = NetUtils.ReadString(buffer, offset + 2); LastAction = DateTime.UtcNow; if (FilterChat(ref text, continued)) { return; } if (text != "/afk" && IsAfk) { CmdAfk.ToggleAfk(this, ""); } // Typing //Command appears in chat as /command // Suggested by McMrCat if (text.StartsWith("//")) { text = text.Remove(0, 1); } else if (DoCommand(text)) { return; } // People who are muted can't speak or vote if (muted) { Message("You are muted."); return; } //Muted: Only allow commands if (Server.voting) { if (CheckVote(text, this, "y", "yes", ref Server.YesVotes) || CheckVote(text, this, "n", "no", ref Server.NoVotes)) { return; } } if (LSGame.Instance.HandlesChatMessage(this, text)) { return; } if (ZSGame.Instance.HandlesChatMessage(this, text)) { return; } // Put this after vote collection so that people can vote even when chat is moderated if (Server.chatmod && !voice) { Message("Chat moderation is on, you cannot speak."); return; } // Filter out bad words if (ServerConfig.ProfanityFiltering) { text = ProfanityFilter.Parse(text); } if (ChatModes.Handle(this, text)) { return; } text = HandleJoker(text); OnPlayerChatEvent.Call(this, text); if (cancelchat) { cancelchat = false; return; } if (Chatroom != null) { string roomPrefix = "<ChatRoom: " + Chatroom + "> λNICK: &f"; Chat.MessageChat(ChatScope.Chatroom, this, roomPrefix + text, Chatroom, null); } else { Chat.MessageChat(this, "λFULL: &f" + text, null, true); } }
void HandleMovement(byte[] buffer, int offset) { if (!loggedIn || trainGrab || following.Length > 0) { CheckBlocks(Pos); return; } if (Supports(CpeExt.HeldBlock)) { RawHeldBlock = ReadBlock(buffer, offset + 1); if (hasExtBlocks) { offset++; // corret offset for position later } } int x, y, z; if (hasExtPositions) { x = NetUtils.ReadI32(buffer, offset + 2); y = NetUtils.ReadI32(buffer, offset + 6); z = NetUtils.ReadI32(buffer, offset + 10); offset += 6; // for yaw/pitch offset below } else { x = NetUtils.ReadI16(buffer, offset + 2); y = NetUtils.ReadI16(buffer, offset + 4); z = NetUtils.ReadI16(buffer, offset + 6); } byte yaw = buffer[offset + 8], pitch = buffer[offset + 9]; Position next = new Position(x, y, z); CheckBlocks(next); OnPlayerMoveEvent.Call(this, next, yaw, pitch); if (cancelmove) { cancelmove = false; return; } Pos = next; SetYawPitch(yaw, pitch); CheckZones(next); if (!Moved() || Loading) { return; } if (DateTime.UtcNow < AFKCooldown) { return; } LastAction = DateTime.UtcNow; if (IsAfk) { CmdAfk.ToggleAfk(this, ""); } }
internal void ProcessChat(string text, bool continued) { LastAction = DateTime.UtcNow; if (FilterChat(ref text, continued)) { return; } if (text != "/afk" && IsAfk) { CmdAfk.ToggleAfk(this, ""); } bool isCommand; text = Chat.ParseInput(text, out isCommand); if (isCommand) { DoCommand(text); return; } // People who are muted can't speak or vote if (muted) { Message("You are muted."); return; } //Muted: Only allow commands if (Server.voting) { if (CheckVote(text, this, "y", "yes", ref Server.YesVotes) || CheckVote(text, this, "n", "no", ref Server.NoVotes)) { return; } } IGame game = IGame.GameOn(level); if (game != null && game.HandlesChatMessage(this, text)) { return; } // Put this after vote collection so that people can vote even when chat is moderated if (!CheckCanSpeak("speak")) { return; } if (ChatModes.Handle(this, text)) { return; } text = HandleJoker(text); OnPlayerChatEvent.Call(this, text); if (cancelchat) { cancelchat = false; return; } Chat.MessageChat(this, "λFULL: &f" + text, null, true); }
void HandleChat(byte[] buffer, int offset) { if (!loggedIn) { return; } byte continued = buffer[offset + 1]; string text = NetUtils.ReadString(buffer, offset + 2); LastAction = DateTime.UtcNow; if (FilterChat(ref text, continued)) { return; } if (text != "/afk" && IsAfk) { CmdAfk.ToggleAfk(this, ""); } bool isCommand; text = Chat.ParseInput(text, out isCommand); if (isCommand) { DoCommand(text); return; } // People who are muted can't speak or vote if (muted) { Message("You are muted."); return; } //Muted: Only allow commands if (Server.voting) { if (CheckVote(text, this, "y", "yes", ref Server.YesVotes) || CheckVote(text, this, "n", "no", ref Server.NoVotes)) { return; } } if (LSGame.Instance.HandlesChatMessage(this, text)) { return; } if (ZSGame.Instance.HandlesChatMessage(this, text)) { return; } // Put this after vote collection so that people can vote even when chat is moderated if (!CheckCanSpeak("speak")) { return; } // Filter out bad words if (Server.Config.ProfanityFiltering) { text = ProfanityFilter.Parse(text); } if (ChatModes.Handle(this, text)) { return; } text = HandleJoker(text); OnPlayerChatEvent.Call(this, text); if (cancelchat) { cancelchat = false; return; } Chat.MessageChat(this, "λFULL: &f" + text, null, true); }
void HandleMovement(byte[] packet) { if (!loggedIn || trainGrab || following != "") { return; } byte heldBlock = packet[1]; if (HasCpeExt(CpeExt.HeldBlock)) { RawHeldBlock = heldBlock; } ushort x = NetUtils.ReadU16(packet, 2); ushort y = NetUtils.ReadU16(packet, 4); ushort z = NetUtils.ReadU16(packet, 6); byte rotx = packet[8], roty = packet[9]; if (frozen) { bool movedX = Math.Abs((short)x - (short)pos[0]) > 4; // moved more than 0.125 blocks horizontally bool movedY = Math.Abs((short)y - (short)pos[1]) > 40; // moved more than 1.25 blocks vertically bool movedZ = Math.Abs((short)z - (short)pos[2]) > 4; // moved more than 0.125 blocks horizontally if (movedX || movedY || movedZ) { SendPos(Entities.SelfID, pos[0], pos[1], pos[2], rotx, roty); } return; } if (Server.Countdown.HandlesMovement(this, x, y, z, rotx, roty)) { return; } if (Server.zombie.Running && Server.zombie.HandlesMovement(this, x, y, z, rotx, roty)) { return; } if (OnMove != null) { OnMove(this, x, y, z); } if (PlayerMove != null) { PlayerMove(this, x, y, z); } PlayerMoveEvent.Call(this, x, y, z); if (OnRotate != null) { OnRotate(this, rot); } if (PlayerRotate != null) { PlayerRotate(this, rot); } PlayerRotateEvent.Call(this, rot); if (cancelmove) { SendPos(Entities.SelfID, pos[0], pos[1], pos[2], rot[0], rot[1]); return; } pos = new ushort[3] { x, y, z }; rot = new byte[2] { rotx, roty }; if (!Moved() || Loading) { return; } if (DateTime.UtcNow < AFKCooldown) { return; } LastAction = DateTime.UtcNow; if (IsAfk) { CmdAfk.ToggleAfk(this, ""); } /*if (!CheckIfInsideBlock()) { clippos = pos; cliprot = rot; }*/ }