コード例 #1
0
ファイル: MessageV04.cs プロジェクト: Wassili-Hense/Host.v04e
        public static MessageV04 Parse(string msg)
        {
            if (msg == null || msg.Length < 2)
            {
                return(Null);
            }
            MessageV04 m   = Null;
            Cmd        cmd = (Cmd)msg[0];
            long       mid = 0;
            int        pos = 1;

            if (msg[pos] != ' ')
            {
                if (msg.Length < 5)
                {
                    Log.Warning("MessageV04({0}) - MId is too short", msg);
                }
                int j;
                for (; pos < 5; pos++)
                {
                    j = AB.IndexOf(msg[pos]);
                    if (j < 0)
                    {
                        if (_verbose.As <bool>())
                        {
                            Log.Warning("MessageV04({0}) - bad char in MId", msg);
                        }
                        return(Null);
                    }
                    mid = (mid * 64) + j;
                }
            }
            string[] payload;
            if (msg.Length > pos)
            {
                payload = msg.Substring(pos).Split('\x1E');
            }
            else
            {
                payload = null;
            }
            m = new MessageV04(cmd, mid, payload);

            return(m);
        }
コード例 #2
0
        protected override void OnMessage(MessageEventArgs e)
        {
            MessageV04 msg;

            if (e.Type == Opcode.Text)
            {
                msg = MessageV04.Parse(e.Data);
            }
            else
            {
                return;
            }
            switch (msg.cmd)
            {
            case MessageV04.Cmd.Connect:
                if (_ses != null)
                {
                    _ses.Close();
                }
                string un, up;
                if (msg.payload == null || msg.payload.Length < 1)
                {
                    un = string.Empty;
                    up = string.Empty;
                }
                else
                {
                    un = msg.payload[0];
                    up = msg.payload.Length > 1?msg.payload[1]:string.Empty;
                }
                if (!CheckAuth(un, up, _remoteEndPoint.Address.IsLocal()))
                {
                    Send((new MessageV04(MessageV04.Cmd.Nack, msg.mid, "Bad username or password")).ToString());
                    X13.lib.Log.Warning("{0} logon as {1} failed", _remoteEndPoint.Address, un);
                    Sessions.CloseSession(base.ID);
                    break;
                }
                _ses          = Session.Get(null, _remoteEndPoint, true);
                _ses.userName = un;
                Send((new MessageV04(MessageV04.Cmd.Ack, msg.mid, _ses.id)).ToString());
                break;
            }
        }
コード例 #3
0
ファイル: MessageV04.cs プロジェクト: Wassili-Hense/Host.v04e
 static MessageV04()
 {
     Null     = new MessageV04(Cmd.Empty, 0, null);
     _verbose = Topic.root.Get("/etc/Server/verbose");
 }