コード例 #1
0
        public void SendMessage(byte id, string message, bool colorParse = true)
        {
            message = ConvertMessage(message, 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 line in Wordwrap(message))
                {
                    string newLine = line;
                    if (newLine.TrimEnd(' ')[newLine.TrimEnd(' ').Length - 1] < '!')
                    {
                        if (!HasCpeExt(CpeExt.EmoteFix))
                        {
                            newLine += '\'';
                        }
                    }

                    byte[] buffer = new byte[66];
                    buffer[0] = Opcode.Message;
                    buffer[1] = (byte)id;
                    if (HasCpeExt(CpeExt.FullCP437))
                    {
                        NetUtils.WriteCP437(newLine, buffer, 2);
                    }
                    else
                    {
                        NetUtils.WriteAscii(newLine, buffer, 2);
                    }
                    SendRaw(buffer);
                }
            } catch (Exception e) {
                message = "&f" + message;
                totalTries++;
                if (totalTries < 10)
                {
                    goto retryTag;
                }
                else
                {
                    Server.ErrorLog(e);
                }
            }
        }
コード例 #2
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);
                }
            }
        }