protected override void ParseBody(ByteBuffer buf)
 {
     #if DEBUG
     Client.LogManager.Log(ToString() + " " + Utils.Util.ToHex(buf.ToByteArray()));
     #endif
     ReplyCode = (ReplyCode)buf.Get();
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="IRC"/> class.
        /// </summary>
        /// <param name="nick">Bot Nickname</param>
        /// <param name="realname">Realname</param>
        /// <param name="username">Username</param>
        /// <param name="server">Irc Host Address</param>
        /// <param name="port">Port</param>
        /// <param name="lastknown">Last known IRC Reply Code</param>
        /// <param name="colour">Console Color</param>
        /// <param name="channel">Starting channel</param>
        /// <param name="key">Starting channel's Key</param>
        /// <param name="owner">Bot Owner</param>
        /// <param name="debug">Debug Channel</param>
        public Irc(string nick, string realname, string username, string nickPass, string server, string serverPassword, int port, ReplyCode lastknown, ConsoleColor colour, string channel, string key = "", string owner = "", string debug = "", string debkey = "")
        {
            settings = new Settings( );

            this.nick     = nick;
            this.realname = realname;
            this.username = username;
            this.host     = server;
            this.port     = port;
            this.code     = lastknown;
            this.colour   = colour;
            this.__nspass = nickPass;
            this._srvPass = serverPassword;
            _owner        = owner;
            _dbgchan      = debug;
            _dbkey        = debkey;
            channelBuffer = new Stack <ChannelData> ( );
            if (!string.IsNullOrEmpty(channel))
            {
                startchan = channel;
            }
            if (!string.IsNullOrEmpty(key))
            {
                startkey = key;
            }

            songman = new LastFMSongManager( );
            //songman.Listen ( );
        }
Exemple #3
0
        void Listener_OnError(ReplyCode code, string message)
        {
            switch (code)
            {
            case ReplyCode.ERR_BANNEDFROMCHAN:
                Server.s.Log("Your server is banned from the Global Chat Channel. Please appeal at mcforge.net");
                break;

            case ReplyCode.ERR_INVITEONLYCHAN:
                Server.s.Log("Cannot join Global Chat. (Channel is invite only (+i))");
                break;

            case ReplyCode.ERR_YOUREBANNEDCREEP:
            {
                if (Server.irc)
                {
                    if (Server.ircServer == server)
                    {
                        return;
                    }
                }
                Server.s.Log(message);
                Server.s.Log("This means your server is banned from the Global Chat server, please contact a SinCraft Staff member for an unban.");
            }
            break;
            }
        }
Exemple #4
0
 public IrcMessageData(
     IrcClient ircclient,
     string from,
     string nick,
     string ident,
     string host,
     string channel,
     string message,
     string rawmessage,
     ReceiveType type,
     ReplyCode replycode)
 {
     this._Irc             = ircclient;
     this._RawMessage      = rawmessage;
     this._RawMessageArray = rawmessage.Split(' ');
     this._Type            = type;
     this._ReplyCode       = replycode;
     this._From            = from;
     this._Nick            = nick;
     this._Ident           = ident;
     this._Host            = host;
     this._Channel         = channel;
     if (message == null)
     {
         return;
     }
     this._Message      = message;
     this._MessageArray = message.Split(' ');
 }
Exemple #5
0
 /// <summary>
 /// Tell listeners that an error has been encountered
 /// </summary>
 internal void Error(ReplyCode code, string message)
 {
     if (OnError != null)
     {
         OnError(code, message);
     }
 }
Exemple #6
0
        public async Task <object> exampleLogin(sysUserInfo sysUserInfo)
        {
            try
            {
                //do transaction
                if (string.IsNullOrEmpty(sysUserInfo.LoginName) || string.IsNullOrEmpty(sysUserInfo.LoginPWD))
                {
                    return(ReplyCode.badRequest(ErrorCode.账号密码错误));
                }
                sysUserInfo.LoginPWD = MD5Helper.MD5Encrypt32(sysUserInfo.LoginPWD);
                var user = await service.LoginAsync(sysUserInfo);

                if (user != null)
                {
                    return(ReplyCode.success(new { token = generatorToken(user, "Admin") }));
                }
                else
                {
                    return(ReplyCode.badRequest(ErrorCode.账号密码错误));
                }
            }
            catch (Exception e)
            {
                // if error,unify to handle
                return(ReplyCode.errorRequest(e).ToJsonResult());
            }
        }
Exemple #7
0
 ///<summary>Sends a reply to the client connection and disposes it afterwards.</summary>
 ///<param name="Value">A byte that contains the reply code to send to the client.</param>
 protected override async Task Dispose(ReplyCode Value)
 {
     byte[] ToSend;
     try
     {
         ToSend = new byte[] { 0, (byte)Value, (byte)(Math.Floor(((IPEndPoint)RemoteConnection.RemoteEndPoint).Port / 256.0)),
                               (byte)(((IPEndPoint)RemoteConnection.RemoteEndPoint).Port % 256),
                               (byte)(Math.Floor((IPHelper.Endpoint2Int(RemoteConnection.RemoteEndPoint) % 256.0))),
                               (byte)(Math.Floor((IPHelper.Endpoint2Int(RemoteConnection.RemoteEndPoint) % 65536) / 256.0)),
                               (byte)(Math.Floor((IPHelper.Endpoint2Int(RemoteConnection.RemoteEndPoint) % 16777216) / 65536.0)),
                               (byte)(Math.Floor(IPHelper.Endpoint2Int(RemoteConnection.RemoteEndPoint) / 16777216.0)) };
     }
     catch
     {
         ToSend = new byte[] { 0, 91, 0, 0, 0, 0, 0, 0 };
     }
     try
     {
         await Connection.SendAsync(ToSend, (ToSend[1] == 90 ? (Action <int>)OnDisposeGood : OnDisposeBad));
     }
     catch
     {
         await Dispose(false);
     }
 }
Exemple #8
0
 private void Listener_OnError(ReplyCode code, string message)
 {
     if (message.Contains("PONG"))
     {
         return; // Silly lib thinks PONG is an error!
     }
     try
     {
         this.Output("ERROR: " + message);
         if (this.Connected)
         {
             this.Connected = false;
             this.Output("Disconnected");
         }
         if (this.Closing == false && this.ReconnectTimer.Enabled == false)
         {
             this.Output("Reconnecting in " + this.ConnectDelay + " seconds");
             this.ReconnectTimer.Enabled = true;
         }
         try
         {
             this.IRC.Disconnect("Error");
             this._IRC = null;
         }
         catch { }
     }
     catch { }
 }
Exemple #9
0
 /// <summary>
 /// Tell listeners that an error has been encountered
 /// </summary>
 internal void Error(ReplyCode code, string message)
 {
     if (OnError != null)
     {
         OnError(this, new ErrorMessageEventArgs(code, message));
     }
 }
Exemple #10
0
 /// <summary>
 /// Constructor to create an instace of IrcMessageData
 /// </summary>
 /// <param name="ircclient">IrcClient the message originated from</param>
 /// <param name="from">combined nickname, identity and host of the user that sent the message (nick!ident@host)</param>
 /// <param name="nick">nickname of the user that sent the message</param>
 /// <param name="ident">identity (username) of the userthat sent the message</param>
 /// <param name="host">hostname of the user that sent the message</param>
 /// <param name="channel">channel the message originated from</param>
 /// <param name="message">message</param>
 /// <param name="rawmessage">raw message sent by the server</param>
 /// <param name="type">message type</param>
 /// <param name="replycode">message reply code</param>
 public IrcMessageData(IrcClient ircclient,
      string from,
      string nick,
      string ident,
      string host,
      string channel,
      string message,
      string rawmessage,
      ReceiveType type,
      ReplyCode replycode)
 {
     _Irc = ircclient;
     _RawMessage = rawmessage;
     _RawMessageArray = rawmessage.Split(new[] {' '});
     _Type = type;
     _ReplyCode = replycode;
     _From = from;
     _Nick = nick;
     _Ident = ident;
     _Host = host;
     _Channel = channel;
     if (message != null)
     {
         // message is optional
         _Message = message;
         _MessageArray = message.Split(new[] {' '});
     }
 }
Exemple #11
0
        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            var responseCodeText = ReplyCode.ToString(CultureInfo.InvariantCulture);
            var statusCodeText   = string.IsNullOrWhiteSpace(EnhancedStatusCode)
                ? string.Empty
                : $" {EnhancedStatusCode.Trim()}";

            if (Content.Count == 0)
            {
                return($"{responseCodeText}{statusCodeText}");
            }

            var builder = new StringBuilder();

            for (var i = 0; i < Content.Count; i++)
            {
                var isLastLine = i == Content.Count - 1;

                builder.Append(isLastLine
                    ? $"{responseCodeText}{statusCodeText} {Content[i]}"
                    : $"{responseCodeText}-{Content[i]}\r\n");
            }

            return(builder.ToString());
        }
Exemple #12
0
        protected override void ParseBody(ByteBuffer buf)
        {
#if DEBUG
            Client.LogManager.Log(ToString() + " " + Utils.Util.ToHex(buf.ToByteArray()));
#endif
            ReplyCode = (ReplyCode)buf.Get();
        }
Exemple #13
0
        void Listener_OnError(ReplyCode code, string message)
        {
            switch (code)
            {
            case ReplyCode.ERR_BANNEDFROMCHAN:
                Server.s.Log("Your server is banned from the Global Chat channel. Contact an MCGalaxy Staff member for an unban.");
                break;

            case ReplyCode.ERR_INVITEONLYCHAN:
                Server.s.Log("Cannot join Global Chat. (Channel is invite only (+i))");
                break;

            case ReplyCode.ERR_YOUREBANNEDCREEP:
            {
                if (Server.irc)
                {
                    if (Server.ircServer == server)
                    {
                        return;
                    }
                }
                Server.s.Log(message);
                Server.s.Log("Your server is banned from the Global Chat channel. Contact an MCGalaxy Staff member for an unban.");
            }
            break;
            }
        }
Exemple #14
0
 public void OnError(ReplyCode code, string message)
 {
     //All anticipated errors have a numeric code. The custom Thresher ones start at 1000 and
     //can be found in the ErrorCodes class. All the others are determined by the IRC spec
     //and can be found in RFC2812Codes.
     Console.WriteLine("An error of type " + code + " due to " + message + " has occurred.");
     this.Invoke(new Action(() => this.chatMessage.Text += "[SYSTEM] An error of type " + code + " due to " + message + " has occurred.\n"));
 }
Exemple #15
0
        internal override void DoWhenFailed(ReplyCode code)
        {
            emailTextBox.SelectAll();
            emailTextBox.Focus();
            signUpButton.Enabled = true;

            base.DoWhenFailed(code);
        }
Exemple #16
0
        private ReplyCode GetReply(ref int nValue, bool bVersion)
        {
            byte[]    RxBuffer = new byte[9];
            byte      uchReplyAddr = 0, ucModuleAdr = 0, uchStatus = 0, ucCmdNumber = 0;
            ReplyCode ret = _Main.GetLoadlockData().Loadlock.GetReply(ref uchReplyAddr, ref ucModuleAdr, ref uchStatus, ref ucCmdNumber, ref nValue, ref RxBuffer, bVersion);

            return(ret);
        }
Exemple #17
0
 public OrderResult(long transId, double orderNumber,
                    ReplyCode replyCode, ResultCode resultCode)
 {
     TransId     = transId;
     OrderNumber = orderNumber;
     ReplyCode   = replyCode;
     ResultCode  = resultCode;
 }
        protected override void ParseBody(ByteBuffer buf)
        {
#if DEBUG
            Client.LogManager.Log(ToString() + " Decoded Data:" + Utils.Util.ToHex(buf.ToByteArray()));
#endif

            buf.GetChar();//length or sth..
            ReplyCode = buf.Get();
            int len = 0;
            switch (ReplyCode)
            {
            case 0x00:                                                          //success!
                Client.LogManager.Log(ToString() + ":0x" + ReplyCode.ToString("X2") + " Login Success!");
                len = buf.GetChar();                                            //0x0020
                Client.QQUser.QQKey.LoginInfo_Token      = buf.GetByteArray(len);
                Client.QQUser.QQKey.LoginInfo_UnknowData = buf.GetByteArray(4); //buf.GetInt()
                Client.ServerTime = buf.GetByteArray(4);

                len = buf.GetChar();
                Client.QQUser.QQKey.LoginInfo_Data_Token = buf.GetByteArray(len);
                len = buf.GetChar();
                Client.QQUser.QQKey.LoginInfo_Magic_Token = buf.GetByteArray(len);
                Client.QQUser.QQKey.LoginInfo_Key1        = buf.GetByteArray(16);
                buf.GetChar();                     //0x00 00
                if (buf.Position + 3 < buf.Length) //判断来的包是否包含LoginInfo_Key3 因为有的版本没这个key 应该说本人用的正式版本没这个
                {
                    Client.QQUser.QQKey.LoginInfo_Key3 = buf.GetByteArray(16);
#if DEBUG
                    Client.LogManager.Log(ToString() + "Client.QQUser.QQKey.LoginInfo_Key3:" + Utils.Util.ToHex(Client.QQUser.QQKey.LoginInfo_Key3));
#endif
                }
                buf.GetChar();    //0x00 00
                return;

            case 0x33:
            case 0x51:    //denied!
                Client.LogManager.Log(ToString() + ":0x" + ReplyCode.ToString("X2") + " Denied!");
                break;

            case 0xBF:
                Client.LogManager.Log(ToString() + ":0x" + ReplyCode.ToString("X2") + " No this QQ number!");
                break;

            case 0x34:
                Client.LogManager.Log(ToString() + ":0x" + ReplyCode.ToString("X2") + " Wrong password!");
                break;

            default:
                Client.LogManager.Log(ToString() + ":0x" + ReplyCode.ToString("X2") + " Unknow ReplyCode!");
                break;
            }
            buf.Position = 11;
            len          = (int)buf.GetChar();
            byte[] data = buf.GetByteArray(len);
            ReplyMessage = Utils.Util.GetString(data);

            Client.LogManager.Log(ToString() + ":0x" + ReplyCode.ToString("X2") + " Message Data(UTF-8): " + Utils.Util.ToHex(data) + "-->" + ReplyMessage);
        }
Exemple #19
0
        public void IrcRemoveHandler(ReplyCode code)
        {
            string scode = code.ToInt32().ToIrcOpcode();

            if (IrcMethodMap.ContainsKey(scode))
            {
                IrcMethodMap.Remove(scode);
            }
        }
 protected override void ParseBody(ByteBuffer buf)
 {
     ReplyCode = (ReplyCode)buf.Get();
     if (ReplyCode == ReplyCode.OK)
     {
         int len = buf.Get() & 0xFF;
         LoginToken = buf.GetByteArray(len);
     }
 }
 protected override void ParseBody(ByteBuffer buf)
 {
     buf.Get();
     ReplyCode = (ReplyCode)buf.Get();
     buf.Get();
     Onlines = new List<uint>();
     while (buf.HasRemaining())
         Onlines.Add(buf.GetUInt());
 }
Exemple #22
0
        private void _SimpleParser(object sender, ReadLineEventArgs args)
        {
            string rawline = args.Line;

            string[] rawlineex   = rawline.Split(new char[] { ' ' });
            string   messagecode = "";

            if (rawline[0] == ':')
            {
                messagecode = rawlineex[1];

                ReplyCode replycode = ReplyCode.Null;
                try {
                    replycode = (ReplyCode)int.Parse(messagecode);
                } catch (FormatException) {
                }

                if (replycode != ReplyCode.Null)
                {
                    switch (replycode)
                    {
                    case ReplyCode.Welcome:
                        _IsRegistered = true;
#if LOG4NET
                        Logger.Connection.Info("logged in");
#endif
                        break;
                    }
                }
                else
                {
                    switch (rawlineex[1])
                    {
                    case "PONG":
                        DateTime now = DateTime.Now;
                        _LastPongReceived = now;
                        _Lag = now - _LastPingSent;

#if LOG4NET
                        Logger.Connection.Debug("PONG received, took: " + _Lag.TotalMilliseconds + " ms");
#endif
                        break;
                    }
                }
            }
            else
            {
                messagecode = rawlineex[0];
                switch (messagecode)
                {
                case "ERROR":
                    // FIXME: handle server errors differently than connection errors!
                    //IsConnectionError = true;
                    break;
                }
            }
        }
        protected override void ParseBody(ByteBuffer buf)
        {
#if DEBUG
            Client.LogManager.Log(ToString() + " " + Utils.Util.ToHex(buf.ToByteArray()));
#endif
            SubCommand =(AddFriendAuthSubCmd) buf.Get();
            To = buf.GetInt();
            ReplyCode = (ReplyCode)buf.Get();
        }
Exemple #24
0
        /// <summary>读取回复信息,接受者是一个QQ号
        ///     <remark>abu 2008-02-26 </remark>
        /// </summary>
        /// <param name="buf">The buf.</param>
        public void ReadQQ(ByteBuffer buf)
        {
            IsQQ      = true;
            QQ        = buf.GetInt();
            ReplyCode = (ReplyCode)buf.Get();
            int len = buf.Get() & 0xFF;

            Message = Utils.Util.GetString(buf, len);
            unknown = buf.Get();
        }
Exemple #25
0
 public void IrcRemoveHandler(ReplyCode code)
 {
     lock (Lock)
     {
         foreach (var nw in _networks)
         {
             nw.Value.IrcRemoveHandler(code);
         }
     }
 }
Exemple #26
0
 public void IrcRemoveHandler(ReplyCode code, IRCDelegate method)
 {
     lock (Lock)
     {
         foreach (var nw in _networks)
         {
             nw.Value.IrcRemoveHandler(code, method);
         }
     }
 }
Exemple #27
0
        /// <summary>读取回复信息,接受者类型是手机号码
        ///     <remark>abu 2008-02-26 </remark>
        /// </summary>
        /// <param name="buf">The buf.</param>
        public void ReadMobile(ByteBuffer buf)
        {
            IsQQ   = false;
            Mobile = Utils.Util.GetString(buf, (byte)0, QQGlobal.QQ_MAX_SMS_MOBILE_LENGTH);
            buf.GetUShort();
            ReplyCode = (ReplyCode)buf.Get();
            int len = buf.Get() & 0xFF;

            Message = Utils.Util.GetString(buf, len);
            unknown = buf.Get();
        }
Exemple #28
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="code"></param>
 /// <param name="tokens"></param>
 private void HandleDefaultReply(ReplyCode code, string[] tokens)
 {
     if (code >= ReplyCode.ERR_NOSUCHNICK && code <= ReplyCode.ERR_USERSDONTMATCH)
     {
         OnError.Fire(this, new ErrorMessageEventArgs(code, CondenseStrings(tokens, 3)));
     }
     else
     {
         OnReply.Fire(this, new ReplyEventArgs(code, CondenseStrings(tokens, 3)));
     }
 }
 void HandleDefaultReply(ReplyCode code, string[] tokens)
 {
     if (code >= ReplyCode.ERR_NOSUCHNICK && code <= ReplyCode.ERR_USERSDONTMATCH)
     {
         OnError(code, GetSuffix(tokens, 3));
     }
     else if (OnReply != null)
     {
         OnReply(code, GetSuffix(tokens, 3));
     }
 }
        private async Task RespondErrorAsync([NotNull] HttpContext ctx, ReplyCode code, string err, int http)
        {
            var output = new Status {
                ErrorCode = code,
                Message   = err
            };

            ctx.Response.Headers["Content-Type"] = "application/json";
            ctx.Response.StatusCode = http;

            await ctx.Response.WriteAsync(JsonConvert.SerializeObject(output, this.m_settings)).AwaitBackground();
        }
Exemple #31
0
        public Task SendReplyAsync(ReplyCode replyCode, bool more, string message, CancellationToken cancellationToken)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(((int)replyCode).ToString("D3"));
            builder.Append(more ? "-" : " ");
            if (message != null)
            {
                builder.Append(message);
            }
            return(Connection.WriteLineAsync(builder.ToString(), Encoding.ASCII, cancellationToken));
        }
 protected override void ParseBody(ByteBuffer buf)
 {
     #if DEBUG
     Client.LogManager.Log(ToString() + " " + Utils.Util.ToHex(buf.ToByteArray()));
     #endif
     FriendQQ = buf.GetInt();
     ReplyCode = (ReplyCode)buf.Get();
     if (ReplyCode == ReplyCode.OK)
     {
         AuthCode = (AuthType)buf.Get();
     }
 }
Exemple #33
0
 public static byte[] GetReplyCode(ReplyCode rc)
 {
     byte[] rply = new byte[2];
     rply[0] |= (byte)(GetBool(!rc.IsQuery) << 7);
     rply[0] |= (byte)((byte)((int)(rc.OpCode)) << 3);
     rply[0] |= (byte)(GetBool(rc.AuthoritativeAnswer) << 2);
     rply[0] |= (byte)(GetBool(rc.Truncation) << 1);
     rply[0] |= (byte)(GetBool(rc.RecursionDesired));
     rply[1] |= (byte)(GetBool(rc.RecursionAvailable) << 7);
     rply[1] |= (byte)(((int)rc.ResponseCode));
     return(rply);
 }
Exemple #34
0
        public void IrcRegisterHandler(ReplyCode code, IRCDelegate method)
        {
            string scode = code.ToInt32().ToIrcOpcode();

            if (IrcMethodMap.ContainsKey(scode))
            {
                IrcMethodMap[scode].Method += method;
            }
            else
            {
                IrcMethodMap.Add(scode, new IrcMethod(method));
            }
        }
Exemple #35
0
        private void ParseReply(string[] tokens)
        {
            ReplyCode code = (ReplyCode)int.Parse(tokens[1], CultureInfo.InvariantCulture);

            tokens[3] = RemoveLeadingColon(tokens[3]);
            switch (code)
            {
            //Messages sent upon successful registration
            case ReplyCode.RPL_WELCOME:
            case ReplyCode.RPL_YOURESERVICE:
                if (OnRegistered != null)
                {
                    OnRegistered();
                }
                break;

            case ReplyCode.RPL_NAMREPLY:
                if (OnNames != null)
                {
                    tokens[5] = RemoveLeadingColon(tokens[5]);
                    int      numberOfUsers = tokens.Length - 5;
                    string[] users         = new string[numberOfUsers];
                    Array.Copy(tokens, 5, users, 0, numberOfUsers);
                    OnNames(tokens[4],
                            users,
                            false);
                }
                break;

            case ReplyCode.RPL_ENDOFNAMES:
                if (OnNames != null)
                {
                    OnNames(tokens[3], new string[0], true);
                }
                break;

            case ReplyCode.ERR_NICKNAMEINUSE:
            case ReplyCode.ERR_NICKCOLLISION:
                if (OnNickError != null)
                {
                    tokens[4] = RemoveLeadingColon(tokens[4]);
                    OnNickError(tokens[3], CondenseStrings(tokens, 4));
                }
                break;

            default:
                HandleDefaultReply(code, tokens);
                break;
            }
        }
Exemple #36
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="code"></param>
 /// <param name="tokens"></param>
 private void HandleDefaultReply(ReplyCode code, string[] tokens)
 {
     if (code >= ReplyCode.ERR_NOSUCHNICK && code <= ReplyCode.ERR_USERSDONTMATCH)
     {
         if (OnError != null)
         {
             OnError(code, CondenseStrings(tokens, 3));
         }
     }
     else if (OnReply != null)
     {
         OnReply(code, CondenseStrings(tokens, 3));
     }
 }
        /// <summary>
        /// Constructor to create an instace of IrcMessageData
        /// </summary>
        /// <param name="ircclient">IrcClient the message originated from</param>
        /// <param name="from">combined nickname, identity and host of the user that sent the message (nick!ident@host)</param>
        /// <param name="nick">nickname of the user that sent the message</param>
        /// <param name="ident">identity (username) of the userthat sent the message</param>
        /// <param name="host">hostname of the user that sent the message</param>
        /// <param name="channel">channel the message originated from</param>
        /// <param name="message">message</param>
        /// <param name="rawmessage">raw message sent by the server</param>
        /// <param name="type">message type</param>
        /// <param name="replycode">message reply code</param>
        public IrcMessageData(IrcClient ircclient, string from, string nick, string ident, string host, string channel, string message, string rawmessage, ReceiveType type, ReplyCode replycode)
        {
            irc = ircclient;
            rawMessage = rawmessage;
            rawMessageArray = rawmessage.Split(new[] { ' ' });
            this.type = type;
            replyCode = replycode;
            prefix = from;
            this.nick = nick;
            this.ident = ident;
            this.host = host;
            this.channel = channel;

            // message is optional
            if (message == null) return;

            rest = message;
            messageArray = message.Split(new[] { ' ' });
        }
Exemple #38
0
 public void OnError( ReplyCode code, string message)
 {
     Console.WriteLine("An error of type " + code + " due to " + message + " has occurred.");
 }
Exemple #39
0
 public void OnError(ReplyCode code, string message)
 {
     Logger.Log.Write("An error of type: \"" + code + "\", message: \"" + message + "\"", ConsoleColor.Yellow);
 }
Exemple #40
0
        //Constructor for chunked handlers
        void ChunkedHandlerInitialisation(string name, ChunkedHandlerDelegateType chunkedHandlerDelegate, ContentType contentType = ContentType.Plain, params ArgumentType[] arguments)
        {
            IsContainer = false;
            IsDefaultHandler = false;
            IsChunkedHandler = true;

            //The reply code is currently not customisable because it's not a common use case for chunked handlers
            ChunkedReplyCode = ReplyCode.Ok;
            ChunkedContentType = contentType;

            Name = name;
            HandlerDelegate = null;
            ChunkedHandlerDelegate = chunkedHandlerDelegate;
            ArgumentTypes = arguments;
            Children = new List<Handler>();
            Parent = null;
        }
Exemple #41
0
 void Listener_OnError(ReplyCode code, string message)
 {
     switch (code)
     {
         case ReplyCode.ERR_BANNEDFROMCHAN:
             Server.s.Log("Your server is banned from the Global Chat Channel. Please appeal at mcgalaxy.tk");
             break;
         case ReplyCode.ERR_INVITEONLYCHAN:
             Server.s.Log("Cannot join Global Chat. (Channel is invite only (+i))");
             break;
         case ReplyCode.ERR_YOUREBANNEDCREEP:
             {
                 if (Server.irc) { if (Server.ircServer == server) return; }
                 Server.s.Log(message);
                 Server.s.Log("This means your server is banned from the Global Chat server, please contact a MCGalaxy Staff member for an unban.");
             }
             break;
     }
 }
Exemple #42
0
 private StatsQuery GetQueryType( ReplyCode code )
 {
     switch( code )
     {
         case ReplyCode.RPL_STATSLINKINFO:
             return StatsQuery.Connections;
         case ReplyCode.RPL_STATSCOMMANDS:
             return StatsQuery.CommandUsage;
         case ReplyCode.RPL_STATSUPTIME:
             return StatsQuery.Uptime;
         case ReplyCode.RPL_STATSOLINE:
             return StatsQuery.Operators;
         //Should never get here
         default:
             return StatsQuery.CommandUsage;
     }
 }
Exemple #43
0
 /// <summary>读取回复信息,接受者类型是手机号码
 /// </summary>
 /// <param name="buf">The buf.</param>
 public void ReadMobile(ByteBuffer buf)
 {
     IsQQ = false;
     Mobile = Utils.Util.GetString(buf, (byte)0, QQGlobal.QQ_MAX_SMS_MOBILE_LENGTH);
     buf.GetUShort();
     ReplyCode = (ReplyCode)buf.Get();
     int len = buf.Get() & 0xFF;
     Message = Utils.Util.GetString(buf, len);
     unknown = buf.Get();
 }
Exemple #44
0
 void Initialise(ReplyCode code, ContentType type)
 {
     Code = code;
     Type = type;
     IsChunkedHandler = false;
     ChunkedHandlerDelegate = null;
     IsReferral = false;
     Encoding = new UTF8Encoding();
 }
 void Listener_OnError(ReplyCode code, string message)
 {
     //Server.s.Log("IRC Error: " + message);
 }
Exemple #46
0
 //Constructor for non-chunked replies
 public Reply(ReplyCode code, ContentType type, string body)
 {
     Initialise(code, type);
     Body = body;
 }
Exemple #47
0
 /// <summary>
 /// Tell listeners that an error has been encountered
 /// </summary>
 internal void Error(ReplyCode code, string message)
 {
     if (OnError != null)
     {
         OnError(this, new ErrorMessageEventArgs(code, message));
     }
 }
Exemple #48
0
 public void IrcRemoveHandler(ReplyCode code, IRCDelegate method)
 {
     lock(Lock)
     {
         foreach(var nw in _networks)
             nw.Value.IrcRemoveHandler(code, method);
     }
 }
Exemple #49
0
 public void IrcRemoveHandler(ReplyCode code)
 {
     lock(Lock)
     {
         foreach(var nw in _networks)
             nw.Value.IrcRemoveHandler(code);
     }
 }
Exemple #50
0
 /// <summary>
 /// Method called upon an error being sent
 /// </summary>
 /// <param name="code">The error reply code</param>
 /// <param name="message">The accompanying error message</param>
 void Listener_OnError(ReplyCode code, string message)
 {
     ErrorReceived.Invoke(this, message);
 }
Exemple #51
0
 /// <summary>读取回复信息,接受者是一个QQ号
 /// </summary>
 /// <param name="buf">The buf.</param>
 public void ReadQQ(ByteBuffer buf)
 {
     IsQQ = true;
     QQ = buf.GetInt();
     ReplyCode = (ReplyCode)buf.Get();
     int len = buf.Get() & 0xFF;
     Message = Utils.Util.GetString(buf, len);
     unknown = buf.Get();
 }
Exemple #52
0
 public ReplyEventArgs(ReplyCode code, string message)
 {
     ReplyCode = code;
     Message = message;
 }
 protected override void ParseBody(ByteBuffer buf)
 {
     ReplyCode = (ReplyCode)buf.Get();
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="IRC"/> class.
        /// </summary>
        /// <param name="nick">Bot Nickname</param>
        /// <param name="realname">Realname</param>
        /// <param name="username">Username</param>
        /// <param name="server">Irc Host Address</param>
        /// <param name="port">Port</param>
        /// <param name="lastknown">Last known IRC Reply Code</param>
        /// <param name="colour">Console Color</param>
        /// <param name="channel">Starting channel</param>
        /// <param name="key">Starting channel's Key</param>
        /// <param name="owner">Bot Owner</param>
        /// <param name="debug">Debug Channel</param>
        public Irc( string nick, string realname, string username, string nickPass, string server, string serverPassword, int port, ReplyCode lastknown, ConsoleColor colour, string channel, string key = "", string owner = "", string debug = "", string debkey = "" )
        {
            settings = new Settings ( );

            this.nick = nick;
            this.realname = realname;
            this.username = username;
            this.host = server;
            this.port = port;
            this.code = lastknown;
            this.colour = colour;
            this.__nspass = nickPass;
            this._srvPass = serverPassword;
            _owner = owner;
            _dbgchan = debug;
            _dbkey = debkey;
            channelBuffer = new Stack<ChannelData> ( );
            if ( !string.IsNullOrEmpty ( channel ) ) startchan = channel;
            if ( !string.IsNullOrEmpty ( key ) ) startkey = key;

            songman = new LastFMSongManager ( );
            //songman.Listen ( );
        }
Exemple #55
0
 /// <summary>
 /// Tell listeners that an error has been encountered
 /// </summary>
 internal void Error( ReplyCode code, string message )
 {
     if( OnError != null )
     {
         OnError( code, message );
     }
 }
        /// <summary>
        /// Constructor to create an instace of IrcMessageData
        /// </summary>
        /// <param name="ircClient">IrcClient the message originated from</param>
        /// <param name="rawMessage">message as it appears on wire, stripped of newline</param>
        public IrcMessageData(IrcClient ircClient, string rawMessage)
        {
            if (rawMessage == null)
            {
                throw new ArgumentException("Cannot parse null message");
            }
            if (rawMessage == "")
            {
                throw new ArgumentException("Cannot parse empty message");
            }

            irc = ircClient;
            this.rawMessage = rawMessage;
            rawMessageArray = rawMessage.Split(' ');
            prefix = "";
            rest = "";

            int start = 0;
            int len = 0;
            if (rawMessageArray[0][0] == ':')
            {
                prefix = rawMessageArray[0].Substring(1);
                start = 1;
                len += prefix.Length + 1;
            }

            command = rawMessageArray[start];
            len += command.Length + 1;

            int length = rawMessageArray.Length;

            if (start + 1 < length)
            {
                for (int i = start + 1; i < rawMessageArray.Length; i++)
                {
                    if (rawMessageArray[i][0] == ':')
                    {
                        length = i;
                        break;
                    }
                    len += rawMessageArray[i].Length + 1;
                }

                args = new string[length - start - 1];
                Array.Copy(rawMessageArray, start + 1, args, 0, length - start - 1);
                if (length < rawMessageArray.Length)
                {
                    rest = this.rawMessage.Substring(this.rawMessage.IndexOf(':', len) + 1);
                    messageArray = rest.Split(' ');
                }
            }
            else
            {
                args = new string[0];
            }

            replyCode = ReplyCode.Null;
            type = ReceiveType.Unknown;

            ParseLegacyInfo();
        }
Exemple #57
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="code"></param>
 /// <param name="tokens"></param>
 private void HandleDefaultReply( ReplyCode code, string[] tokens )
 {
     if (code >= ReplyCode.ERR_NOSUCHNICK && code <= ReplyCode.ERR_USERSDONTMATCH)
     {
         if( OnError != null )
         {
             OnError(code, CondenseStrings( tokens, 3) );
         }
     }
     else if( OnReply != null )
     {
         OnReply(code, CondenseStrings( tokens, 3) );
     }
 }
Exemple #58
0
 private ReplyCode TranslateResultForClient(ReplyCode code)
 {
     switch (code)
     {
         case ReplyCode.InvalidEmail:
         case ReplyCode.InvalidPassword:
             return ReplyCode.LoginFailed;
         case ReplyCode.InvalidRequest:
         case ReplyCode.InvalidRequester:
         case ReplyCode.TooManyRequest:
             return ReplyCode.Failed;
     }
     return code;
 }
        // refactored old field parsing code below, ignore for own sanity
        private void ParseLegacyInfo()
        {
            Match match = PrefixRegex.Match(prefix);

            if (match.Success)
            {
                if (match.Groups[2].Success || match.Groups[3].Success || (prefix.IndexOf('.') < 0))
                    nick = match.Groups[1].ToString();
            }

            if (match.Groups[2].Success)
                ident = match.Groups[2].ToString().Substring(1);
            if (match.Groups[3].Success)
                host = match.Groups[3].ToString().Substring(1);

            int code;
            if (int.TryParse(command, out code))
            {
                replyCode = (ReplyCode)code;
            }
            else
            {
                replyCode = ReplyCode.Null;
            }
            if (replyCode != ReplyCode.Null)
            {
                // categorize replies

                switch (replyCode)
                {
                    case ReplyCode.Welcome:
                    case ReplyCode.YourHost:
                    case ReplyCode.Created:
                    case ReplyCode.MyInfo:
                    case ReplyCode.Bounce:
                    case ReplyCode.SaslSuccess:
                    case ReplyCode.SaslFailure1:
                    case ReplyCode.SaslFailure2:
                    case ReplyCode.SaslAbort:
                        type = ReceiveType.Login;
                        break;

                    case ReplyCode.LuserClient:
                    case ReplyCode.LuserOp:
                    case ReplyCode.LuserUnknown:
                    case ReplyCode.LuserMe:
                    case ReplyCode.LuserChannels:
                        type = ReceiveType.Info;
                        break;

                    case ReplyCode.MotdStart:
                    case ReplyCode.Motd:
                    case ReplyCode.EndOfMotd:
                        type = ReceiveType.Motd;
                        break;

                    case ReplyCode.NamesReply:
                    case ReplyCode.EndOfNames:
                        type = ReceiveType.Name;
                        break;

                    case ReplyCode.WhoReply:
                    case ReplyCode.EndOfWho:
                        type = ReceiveType.Who;
                        break;

                    case ReplyCode.ListStart:
                    case ReplyCode.List:
                    case ReplyCode.ListEnd:
                        type = ReceiveType.List;
                        break;

                    case ReplyCode.BanList:
                    case ReplyCode.EndOfBanList:
                        type = ReceiveType.BanList;
                        break;

                    case ReplyCode.Topic:
                    case ReplyCode.NoTopic:
                        type = ReceiveType.Topic;
                        break;

                    case ReplyCode.WhoIsUser:
                    case ReplyCode.WhoIsServer:
                    case ReplyCode.WhoIsOperator:
                    case ReplyCode.WhoIsIdle:
                    case ReplyCode.WhoIsChannels:
                    case ReplyCode.EndOfWhoIs:
                        type = ReceiveType.WhoIs;
                        break;

                    case ReplyCode.WhoWasUser:
                    case ReplyCode.EndOfWhoWas:
                        type = ReceiveType.WhoWas;
                        break;

                    case ReplyCode.UserModeIs:
                        type = ReceiveType.UserMode;
                        break;

                    case ReplyCode.ChannelModeIs:
                        type = ReceiveType.ChannelMode;
                        break;

                    default:
                        if ((code >= 400) &&
                            (code <= 599))
                        {
                            type = ReceiveType.ErrorMessage;
                        }
                        else
                        {
                            type = ReceiveType.Unknown;
                        }
                        break;
                }
            }
            else
            {
                // categorize commands

                switch (command)
                {
                    case "PING":
                        type = ReceiveType.Unknown;
                        break;

                    case "ERROR":
                        type = ReceiveType.Error;
                        break;

                    case "PRIVMSG":
                        if (args.Length > 0 && rest.StartsWith("\x1" + "ACTION") && rest.EndsWith("\x1"))
                        {
                            switch (args[0][0])
                            {
                                case '#':
                                case '!':
                                case '&':
                                case '+':
                                    type = ReceiveType.ChannelAction;
                                    break;

                                default:
                                    type = ReceiveType.QueryAction;
                                    break;
                            }
                        }
                        else if (rest.StartsWith("\x1") && rest.EndsWith("\x1"))
                        {
                            type = ReceiveType.CtcpRequest;
                        }
                        else if (args.Length > 0)
                        {
                            switch (args[0][0])
                            {
                                case '#':
                                case '!':
                                case '&':
                                case '+':
                                    type = ReceiveType.ChannelMessage;
                                    break;

                                default:
                                    type = ReceiveType.QueryMessage;
                                    break;
                            }
                        }
                        break;

                    case "NOTICE":
                        if (rest.StartsWith("\x1") && rest.EndsWith("\x1"))
                        {
                            type = ReceiveType.CtcpReply;
                        }
                        else if (args.Length > 0)
                        {
                            switch (args[0][0])
                            {
                                case '#':
                                case '!':
                                case '&':
                                case '+':
                                    type = ReceiveType.ChannelNotice;
                                    break;

                                default:
                                    type = ReceiveType.QueryNotice;
                                    break;
                            }
                        }
                        break;

                    case "INVITE":
                        type = ReceiveType.Invite;
                        break;

                    case "JOIN":
                        type = ReceiveType.Join;
                        break;

                    case "PART":
                        type = ReceiveType.Part;
                        break;

                    case "TOPIC":
                        type = ReceiveType.TopicChange;
                        break;

                    case "NICK":
                        type = ReceiveType.NickChange;
                        break;

                    case "KICK":
                        type = ReceiveType.Kick;
                        break;

                    case "MODE":
                        switch (args[0][0])
                        {
                            case '#':
                            case '!':
                            case '&':
                            case '+':
                                type = ReceiveType.ChannelModeChange;
                                break;

                            default:
                                type = ReceiveType.UserModeChange;
                                break;
                        }
                        break;

                    case "QUIT":
                        type = ReceiveType.Quit;
                        break;

                    case "CAP":
                    case "AUTHENTICATE":
                        type = ReceiveType.Other;
                        break;
                }
            }

            switch (type)
            {
                case ReceiveType.Join:
                case ReceiveType.Kick:
                case ReceiveType.Part:
                case ReceiveType.TopicChange:
                case ReceiveType.ChannelModeChange:
                case ReceiveType.ChannelMessage:
                case ReceiveType.ChannelAction:
                case ReceiveType.ChannelNotice:
                    channel = rawMessageArray[2];
                    break;

                case ReceiveType.Who:
                case ReceiveType.Topic:
                case ReceiveType.Invite:
                case ReceiveType.BanList:
                case ReceiveType.ChannelMode:
                    channel = rawMessageArray[3];
                    break;

                case ReceiveType.Name:
                    channel = rawMessageArray[4];
                    break;
            }

            switch (replyCode)
            {
                case ReplyCode.List:
                case ReplyCode.ListEnd:
                case ReplyCode.ErrorNoChannelModes:
                    channel = args[1];
                    break;
            }

            if (channel != null && channel.StartsWith(":"))
            {
                channel = Channel.Substring(1);
            }
        }
Exemple #60
0
 //Constructor for chunked replies
 public Reply(ReplyCode code, ContentType type, ChunkedHandlerDelegateType chunkedHandlerDelegate)
 {
     Initialise(code, type);
     IsChunkedHandler = true;
     ChunkedHandlerDelegate = chunkedHandlerDelegate;
 }