Exemplo n.º 1
0
        public static void ReloadMap(Player p, Player who, bool showMessage)
        {
            who.Loading = true;
            Entities.DespawnEntities(who);
            who.SendMap(who.level);
            Entities.SpawnEntities(who);
            who.Loading = false;
            if (!showMessage)
            {
                return;
            }

            if (p == null || !Entities.CanSee(who, p))
            {
                who.SendMessage("&bMap reloaded");
            }
            else
            {
                who.SendMessage("&bMap reloaded by " + p.ColoredName);
            }
            if (Entities.CanSee(p, who))
            {
                Player.Message(p, "&4Finished reloading for " + who.ColoredName);
            }
        }
Exemplo n.º 2
0
        public static Player FindNick(Player p, string nick)
        {
            nick = Colors.StripColors(nick);
            Player[] players = PlayerInfo.Online.Items;
            Player   match = null; int matches = 0;

            foreach (Player pl in players)
            {
                if (!Entities.CanSee(p, pl))
                {
                    continue;
                }
                string name = Colors.StripColors(pl.DisplayName);

                if (name.CaselessEq(nick))
                {
                    return(pl);
                }
                if (name.CaselessContains(nick))
                {
                    match = pl; matches++;
                }
            }
            return(matches == 1 ? match : null);
        }
Exemplo n.º 3
0
        /// <summary> Sends a message to all players who in the player's level,
        /// and are not ignoring source player or in a chatroom. </summary>
        /// <remarks> Optionally prefixes message by &lt;Level&gt; [source name]: </remarks>
        public static void MessageLevel(Player source, string message, bool showPrefix,
                                        Level lvl, bool visibleOnly = false)
        {
            if (showPrefix)
            {
                message = "<Level>" + source.FullName + ": &f" + message;
            }

            Player[] players = PlayerInfo.Online.Items;
            foreach (Player p in players)
            {
                if (!NotIgnoring(p, source))
                {
                    continue;
                }
                if (visibleOnly && !Entities.CanSee(p, source))
                {
                    continue;
                }

                if (p.level == lvl && p.Chatroom == null)
                {
                    Player.Message(p, message);
                }
            }
        }
Exemplo n.º 4
0
        static void ShowAltsTask(SchedulerTask task)
        {
            string name = (string)task.State;
            Player p    = PlayerInfo.FindExact(name);

            if (p == null || p.ip == "127.0.0.1" || p.Socket.Disconnected)
            {
                return;
            }

            List <string> alts = PlayerInfo.FindAccounts(p.ip);

            // in older versions it was possible for your name to appear multiple times in DB
            while (alts.CaselessRemove(p.name))
            {
            }
            if (alts.Count == 0)
            {
                return;
            }

            ItemPerms opchat  = Chat.OpchatPerms;
            string    altsMsg = "λNICK %Sis lately known as: " + alts.Join();

            Chat.MessageFrom(p, altsMsg,
                             (pl, obj) => Entities.CanSee(pl, p) && opchat.UsableBy(pl.Rank));

            //IRCBot.Say(temp, true); //Tells people in op channel on IRC
            altsMsg = altsMsg.Replace("λNICK", name);
            Logger.Log(LogType.UserActivity, altsMsg);
        }
Exemplo n.º 5
0
        public static void ReloadFor(Player src, Player p, bool announce)
        {
            p.Loading = true;
            Entities.DespawnEntities(p);
            p.SendMap(p.level);
            Entities.SpawnEntities(p);
            p.Loading = false;
            if (!announce)
            {
                return;
            }

            if (src == null || !Entities.CanSee(p, src))
            {
                p.Message("&bMap reloaded");
            }
            else
            {
                p.Message("&bMap reloaded by " + src.ColoredName);
            }
            if (Entities.CanSee(src, p))
            {
                src.Message("&4Finished reloading for " + p.ColoredName);
            }
        }
Exemplo n.º 6
0
        public static void ReloadAll(Level lvl, Player src, bool announce)
        {
            Player[] players = PlayerInfo.Online.Items;
            foreach (Player p in players)
            {
                if (p.level != lvl)
                {
                    continue;
                }
                PlayerActions.ReloadMap(p);
                if (!announce)
                {
                    continue;
                }

                if (src == null || !Entities.CanSee(p, src))
                {
                    p.Message("&bMap reloaded");
                }
                else
                {
                    p.Message("&bMap reloaded by " + src.ColoredName);
                }
                if (Entities.CanSee(src, p))
                {
                    src.Message("&4Finished reloading for " + p.ColoredName);
                }
            }
        }
Exemplo n.º 7
0
        public static string GetColoredName(Player p, string name)
        {
            Player target = FindExact(name);

            return(target != null && Entities.CanSee(p, target) ?
                   target.ColoredName : GetColor(name) + name.RemoveLastPlus()); // TODO: select color from database?
        }
Exemplo n.º 8
0
 static ChatMessageFilter FilterGoto(Player source, Level prev, Level lvl)
 {
     return((pl, obj) =>
            (Chat.FilterGlobal(pl, obj) ||
             Chat.FilterLevel(pl, prev) ||
             Chat.FilterLevel(pl, lvl)) &&
            Entities.CanSee(pl, source) &&
            !pl.Ignores.WorldChanges);
 }
Exemplo n.º 9
0
        void ExtraTimerElapsed(object sender, ElapsedEventArgs e)
        {
            DisposeTimer(extraTimer, ExtraTimerElapsed);

            try {
                if (group.commands.Contains("inbox") && Database.TableExists("Inbox" + name))
                {
                    using (DataTable table = Database.Backend.GetRows("Inbox" + name, "*")) {
                        if (table.Rows.Count > 0)
                        {
                            SendMessage("You have &a" + table.Rows.Count + " %Smessages in /inbox");
                        }
                    }
                }
            } catch {
            }

            if (Server.updateTimer.Interval > 1000)
            {
                SendMessage("Lowlag mode is currently &aON.");
            }
            if (Economy.Enabled)
            {
                SendMessage("You currently have &a" + money + " %S" + Server.moneys);
            }

            try {
                Group nobody = Group.findPerm(LevelPermission.Nobody);
                if (!nobody.commands.Contains("award") && !nobody.commands.Contains("awards") && !nobody.commands.Contains("awardmod"))
                {
                    SendMessage("You have " + Awards.AwardAmount(name) + " awards.");
                }
            } catch {
            }

            Player[] players = PlayerInfo.Online.Items;
            int      visible = 0;

            foreach (Player pl in players)
            {
                if (pl == this || Entities.CanSee(this, pl))
                {
                    visible++;
                }
            }

            string prefix = visible == 1 ? "There is" : "There are";
            string suffix = visible == 1 ? " player online" : " players online";

            SendMessage(prefix + " currently &a" + visible + suffix);

            if (Server.lava.active)
            {
                SendMessage("There is a &aLava Survival %Sgame active! Join it by typing /ls go");
            }
        }
Exemplo n.º 10
0
        public static Player FindMatches(Player pl, string name,
                                         out int matches, bool onlyCanSee = true)
        {
            matches = 0;
            if (!Formatter.ValidName(pl, name, "player"))
            {
                return(null);
            }

            return(Matcher.Find(pl, name, out matches, Online.Items,
                                p => Entities.CanSee(pl, p) || !onlyCanSee,
                                p => p.name, "online players"));
        }
Exemplo n.º 11
0
        public static Player FindMatches(Player pl, string name,
                                         out int matches, bool onlyCanSee = true)
        {
            matches = 0;
            if (!Player.ValidName(name))
            {
                Player.Message(pl, "\"{0}\" is not a valid player name.", name); return(null);
            }

            return(Utils.FindMatches <Player>(pl, name, out matches, Online.Items,
                                              p => Entities.CanSee(pl, p) || !onlyCanSee,
                                              p => p.name, "online players"));
        }
Exemplo n.º 12
0
        /// <summary> Sends a message to all players, who are not in a chatroom, are not ignoring all chat,
        /// are not on a level that does not have isolated/level only chat, and are not ignoring source. </summary>
        public static void MessageGlobal(Player source, string message, bool showPrefix,
                                         bool visibleOnly = false)
        {
            string msg_NT = message, msg_NN = message, msg_NNNT = message;

            if (showPrefix)
            {
                string msg = ": &f" + message;
                string pre = source.color + source.prefix;
                message = pre + source.DisplayName + msg; // Titles + Nickname
                msg_NN  = pre + source.truename + msg;    // Titles + Account name

                pre      = source.group.Prefix.Length == 0 ? "" : "&f" + source.group.Prefix;
                msg_NT   = pre + source.color + source.DisplayName + msg; // Nickname
                msg_NNNT = pre + source.color + source.truename + msg;    // Account name
            }

            Player[] players = PlayerInfo.Online.Items;
            foreach (Player pl in players)
            {
                if (!NotIgnoring(pl, source))
                {
                    continue;
                }
                if (visibleOnly && !Entities.CanSee(pl, source))
                {
                    continue;
                }
                if (!pl.level.SeesServerWideChat || pl.Chatroom != null)
                {
                    continue;
                }

                if (pl.Ignores.Nicks && pl.Ignores.Titles)
                {
                    Player.Message(pl, msg_NNNT);
                }
                else if (pl.Ignores.Nicks)
                {
                    Player.Message(pl, msg_NN);
                }
                else if (pl.Ignores.Titles)
                {
                    Player.Message(pl, msg_NT);
                }
                else
                {
                    Player.Message(pl, message);
                }
            }
        }
Exemplo n.º 13
0
        static string TokenOnline(Player p)
        {
            Player[] players = PlayerInfo.Online.Items;
            int      count   = 0;

            foreach (Player pl in players)
            {
                if (p == pl || Entities.CanSee(p, pl))
                {
                    count++;
                }
            }
            return(count.ToString());
        }
Exemplo n.º 14
0
        public static Player FindOrShowMatches(Player pl, string name, out int matches, bool onlyCanSee = true)
        {
            Player[] players = PlayerInfo.Online.Items;
            Player   match   = null; matches = 0;

            name = name.ToLower();
            StringBuilder matchNames = new StringBuilder();

            foreach (Player p in players)
            {
                if (onlyCanSee && !Entities.CanSee(pl, p))
                {
                    continue;
                }
                if (p.name.Equals(name, comp))
                {
                    return(p);
                }
                if (p.name.IndexOf(name, comp) >= 0)
                {
                    match = p; matches++;
                    if (matches <= 5)
                    {
                        matchNames.Append(p.name).Append(", ");
                    }
                    else if (matches == 6)
                    {
                        matchNames.Append("(and more)").Append(", ");
                    }
                }
            }
            if (matches == 0)
            {
                Player.SendMessage(pl, "No online players found matching \"" + name + "\"."); return(null);
            }
            else if (matches == 1)
            {
                return(match);
            }
            else
            {
                string names = matchNames.ToString(0, matchNames.Length - 2);
                Player.SendMessage(pl, "Multiple players found matching \"" + name + "\":");
                Player.SendMessage(pl, names); return(null);
            }
        }
Exemplo n.º 15
0
        void CompleteLoginProcess()
        {
            LevelPermission adminChatRank = CommandOtherPerms.FindPerm("adminchat", LevelPermission.Admin);

            SendUserMOTD();
            SendMap(null);
            if (disconnected)
            {
                return;
            }
            loggedIn = true;

            PlayerInfo.Online.Add(this);
            connections.Remove(this);
            RemoveFromPending();
            Server.s.PlayerListUpdate();

            //OpenClassic Client Check
            SendBlockchange(0, 0, 0, 0);
            timeLogged = DateTime.Now;
            lastLogin  = DateTime.Now;
            time       = new TimeSpan(0, 0, 0, 1);
            DataTable playerDb = Database.Backend.GetRows("Players", "*", "WHERE Name=@0", name);

            if (playerDb.Rows.Count == 0)
            {
                InitPlayerStats(playerDb);
            }
            else
            {
                LoadPlayerStats(playerDb);
            }

            Server.Background.QueueOnce(ShowAltsTask, name, TimeSpan.Zero);
            CheckState();
            ZombieStats stats = Server.zombie.LoadZombieStats(name);

            Game.MaxInfected       = stats.MaxInfected; Game.TotalInfected = stats.TotalInfected;
            Game.MaxRoundsSurvived = stats.MaxRounds; Game.TotalRoundsSurvived = stats.TotalRounds;

            if (!Directory.Exists("players"))
            {
                Directory.CreateDirectory("players");
            }
            PlayerDB.Load(this);
            Game.Team = Team.FindTeam(this);
            SetPrefix();
            playerDb.Dispose();
            LoadCpeData();

            if (Server.verifyadmins && group.Permission >= Server.verifyadminsrank)
            {
                adminpen = true;
            }
            if (Server.noEmotes.Contains(name))
            {
                parseEmotes = !Server.parseSmiley;
            }

            hidden = group.CanExecute("hide") && Server.hidden.Contains(name);
            if (hidden)
            {
                SendMessage("&8Reminder: You are still hidden.");
            }
            if (group.Permission >= adminChatRank && Server.adminsjoinsilent)
            {
                hidden = true; adminchat = true;
            }

            if (PlayerConnect != null)
            {
                PlayerConnect(this);
            }
            OnPlayerConnectEvent.Call(this);
            if (cancellogin)
            {
                cancellogin = false; return;
            }


            string joinm = "&a+ " + FullName + " %S" + PlayerDB.GetLoginMessage(this);

            if (hidden)
            {
                joinm = "&8(hidden)" + joinm;
            }
            const LevelPermission perm = LevelPermission.Guest;

            if (group.Permission > perm || (Server.guestJoinNotify && group.Permission <= perm))
            {
                Player[] players = PlayerInfo.Online.Items;
                foreach (Player pl in players)
                {
                    if (Entities.CanSee(pl, this))
                    {
                        Player.Message(pl, joinm);
                    }
                }
            }

            if (Server.agreetorulesonentry && group.Permission == LevelPermission.Guest && !Server.agreed.Contains(name))
            {
                SendMessage("&9You must read the &c/rules&9 and &c/agree&9 to them before you can build and use commands!");
                agreed = false;
            }

            if (Server.verifyadmins && group.Permission >= Server.verifyadminsrank)
            {
                if (!Directory.Exists("extra/passwords") || !File.Exists("extra/passwords/" + name + ".dat"))
                {
                    SendMessage("&cPlease set your admin verification password with &a/setpass [Password]!");
                }
                else
                {
                    SendMessage("&cPlease complete admin verification with &a/pass [Password]!");
                }
            }

            Server.s.Log(name + " [" + ip + "] has joined the server.");
            Game.InfectMessages = PlayerDB.GetInfectMessages(this);
            Server.zombie.PlayerJoinedServer(this);

            ushort x = (ushort)(level.spawnx * 32 + 16);
            ushort y = (ushort)(level.spawny * 32 + 32);
            ushort z = (ushort)(level.spawnz * 32 + 16);

            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]);
            PlayerActions.CheckGamesJoin(this, null);
            Loading = false;
        }
Exemplo n.º 16
0
 static ChatMessageFilter FilterGoto(Player source)
 {
     return((pl, obj) => Entities.CanSee(pl, source) && !pl.Ignores.WorldChanges);
 }
Exemplo n.º 17
0
 public static ChatMessageFilter FilterVisible(Player source)
 {
     return((pl, obj) => Entities.CanSee(pl, source));
 }