Пример #1
0
        public virtual void Message(byte id, string message)
        {
            // Message should start with server color if no initial color
            if (message.Length > 0 && !(message[0] == '&' || message[0] == '%'))
            {
                message = Server.Config.DefaultColor + message;
            }
            message = Chat.Format(message, this);
            OnMessageRecievedEvent.Call(this, message);
            if (cancelmessage)
            {
                cancelmessage = false; return;
            }

            try {
                foreach (string raw in LineWrapper.Wordwrap(message))
                {
                    string line = raw;
                    if (!Supports(CpeExt.EmoteFix) && LineEndsInEmote(line))
                    {
                        line += '\'';
                    }

                    Send(Packet.Message(line, (CpeMessageType)id, hasCP437));
                }
            } catch (Exception e) {
                Logger.LogError(e);
            }
        }
Пример #2
0
        public virtual void Message(byte id, string message)
        {
            // Message should start with server color if no initial color
            if (message.Length > 0 && !(message[0] == '&' || message[0] == '%'))
            {
                message = Server.Config.DefaultColor + message;
            }
            message = Chat.Format(message, this);
            OnMessageRecievedEvent.Call(this, message);
            if (cancelmessage)
            {
                cancelmessage = false; return;
            }

            try {
                List <string> lines  = LineWrapper.Wordwrap(message);
                byte[]        packet = new byte[lines.Count * 66];

                for (int i = 0; i < lines.Count; i++)
                {
                    string line = lines[i];
                    if (!Supports(CpeExt.EmoteFix) && LineEndsInEmote(line))
                    {
                        line += '\'';
                    }
                    Packet.WriteMessage(line, id, hasCP437, packet, i * 66);
                }
                // So multi-line messages from multiple threads don't interleave
                Send(packet);
            } catch (Exception e) {
                Logger.LogError(e);
            }
        }
Пример #3
0
        static string ToIRCColors(string input)
        {
            input = Colors.Escape(input);
            input = LineWrapper.CleanupColors(input, true, false);

            StringBuilder sb = new StringBuilder(input);

            for (int i = 0; i < ircColors.Length; i++)
            {
                sb.Replace(ircReplacements[i], ircColors[i]);
            }
            return(sb.ToString());
        }
Пример #4
0
        public void SendMessage(byte id, string message, bool colorParse = true)
        {
            message = Chat.Format(message, this, colorParse);
            int totalTries = 0;

            if (MessageRecieve != null)
            {
                MessageRecieve(this, message);
            }
            if (OnMessageRecieve != null)
            {
                OnMessageRecieve(this, message);
            }
            OnMessageRecieveEvent.Call(this, message);
            if (cancelmessage)
            {
                cancelmessage = false; return;
            }

            retryTag : try {
                foreach (string raw in LineWrapper.Wordwrap(message))
                {
                    string line = raw;
                    if (!HasCpeExt(CpeExt.EmoteFix) && line.TrimEnd(' ')[line.TrimEnd(' ').Length - 1] < '!')
                    {
                        line += '\'';
                    }

                    byte[] buffer = new byte[66];
                    buffer[0] = Opcode.Message;
                    buffer[1] = (byte)id;
                    NetUtils.Write(line, buffer, 2, HasCpeExt(CpeExt.FullCP437));
                    Send(buffer);
                }
            } catch (Exception e) {
                message = "&f" + message;
                totalTries++;
                if (totalTries < 10)
                {
                    goto retryTag;
                }
                else
                {
                    Server.ErrorLog(e);
                }
            }
        }
Пример #5
0
        public static string ConvertMCToIRC(string input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            input = Escape(input);
            input = LineWrapper.CleanupColors(input, true, false);

            StringBuilder sb = new StringBuilder(input);

            for (int i = 0; i < ircColors.Length; i++)
            {
                sb.Replace(ircReplacements[i], ircColors[i]);
            }
            return(sb.ToString());
        }
Пример #6
0
        public void SendCpeMessage(CpeMessageType type, string message)
        {
            if (type != CpeMessageType.Normal && !Supports(CpeExt.MessageTypes))
            {
                if (type == CpeMessageType.Announcement)
                {
                    type = CpeMessageType.Normal;
                }
                else
                {
                    return;
                }
            }

            message = Chat.Format(message, this);
            message = LineWrapper.CleanupColors(message, this);
            Send(Packet.Message(message, type, hasCP437));
        }
Пример #7
0
        public virtual void Message(byte type, string message)
        {
            // Message should start with server color if no initial color
            if (message.Length > 0 && !(message[0] == '&' || message[0] == '%'))
            {
                message = Server.Config.DefaultColor + message;
            }
            message = Chat.Format(message, this);
            OnMessageRecievedEvent.Call(this, message);
            if (cancelmessage)
            {
                cancelmessage = false; return;
            }

            try {
                SendLines(LineWrapper.Wordwrap(message), type);
            } catch (Exception e) {
                Logger.LogError(e);
            }
        }
Пример #8
0
        static void SpawnRaw(Player dst, byte id, Entity e, Position pos, Orientation rot,
                             string skin, string name, string model)
        {
            // NOTE: Fix for standard clients
            if (id == Entities.SelfID)
            {
                pos.Y -= 22;
            }
            name = LineWrapper.CleanupColors(name, dst);

            if (dst.Supports(CpeExt.ExtPlayerList, 2))
            {
                dst.Send(Packet.ExtAddEntity2(id, skin, name, pos, rot, dst.hasCP437, dst.hasExtPositions));
            }
            else if (dst.hasExtList)
            {
                dst.Send(Packet.ExtAddEntity(id, skin, name, dst.hasCP437));
                dst.Send(Packet.Teleport(id, pos, rot, dst.hasExtPositions));
            }
            else
            {
                dst.Send(Packet.AddEntity(id, name, pos, rot, dst.hasCP437, dst.hasExtPositions));
            }

            if (dst.hasChangeModel)
            {
                OnSendingModelEvent.Call(e, ref model, dst);
                if (!model.CaselessEq("humanoid"))
                {
                    SendModel(dst, id, model);
                }
            }

            if (dst.Supports(CpeExt.EntityProperty))
            {
                dst.Send(Packet.EntityProperty(id, EntityProp.RotX, Orientation.PackedToDegrees(rot.RotX)));
                dst.Send(Packet.EntityProperty(id, EntityProp.RotZ, Orientation.PackedToDegrees(rot.RotZ)));
                SendModelScales(dst, id, e);
            }
        }
Пример #9
0
        /// <summary> Adds the given player to that player's tab list (if their client supports it). </summary>
        public static void Add(Player dst, Player p, byte id)
        {
            if (!dst.hasExtList)
            {
                return;
            }
            byte grpPerm = (byte)(offset - p.Rank);

            if (!Server.Config.TablistRankSorted)
            {
                grpPerm = 0;
            }

            string name, group;

            GetEntry(p, dst, out name, out group);

            name  = Colors.Escape(name); // for nicks
            name  = LineWrapper.CleanupColors(name, dst);
            group = LineWrapper.CleanupColors(group, dst);
            dst.Send(Packet.ExtAddPlayerName(id, p.truename, name, group, grpPerm, dst.hasCP437));
        }
Пример #10
0
        static void SpawnRaw(Player dst, byte id, Entity e, Position pos, Orientation rot,
                             string skin, string name, string model)
        {
            name = LineWrapper.CleanupColors(name, dst);
            dst.Session.SendSpawnEntity(id, name, skin, pos, rot);

            if (dst.hasChangeModel)
            {
                OnSendingModelEvent.Call(e, ref model, dst);
                if (!model.CaselessEq("humanoid"))
                {
                    dst.Session.SendChangeModel(id, model);
                }
            }

            if (dst.Supports(CpeExt.EntityProperty))
            {
                dst.Send(Packet.EntityProperty(id, EntityProp.RotX, Orientation.PackedToDegrees(rot.RotX)));
                dst.Send(Packet.EntityProperty(id, EntityProp.RotZ, Orientation.PackedToDegrees(rot.RotZ)));
                SendModelScales(dst, id, e);
            }
        }
Пример #11
0
        public virtual void Message(byte type, string message)
        {
            // Message should start with server color if no initial color
            if (message.Length > 0 && !(message[0] == '&' || message[0] == '%'))
            {
                message = "&S" + message;
            }
            message = Chat.Format(message, this);

            bool cancel = false;

            OnMessageRecievedEvent.Call(this, ref message, ref cancel);
            if (cancel)
            {
                return;
            }

            try {
                message = LineWrapper.CleanupColors(message, this);
                SendLines(LineWrapper.Wordwrap(message, hasEmoteFix), type);
            } catch (Exception e) {
                Logger.LogError(e);
            }
        }