示例#1
0
        private static PyObject HandleObject(PyObjectEx dat, Connection connection)
        {
            // Only exceptions should be this type
            PyException ex = new PyException();

            if (ex.Decode(dat) == false)
            {
                Log.Error("Connection", "Unhandled PyObjectEx packet");
                return(null);
            }

            Log.Error("Connection", "Got an exception packet of type: " + ex.exception_type + ". " + ex.message);
            return(null);
        }
示例#2
0
        public PyObject Encode()
        {
            PyTuple args = new PyTuple();

            args.Items.Add(new PyToken("dbutil.CRowset"));

            PyDict dict = new PyDict();

            dict.Set("header", descriptor.Encode());

            PyObjectEx res = new PyObjectEx();

            res.IsType2 = true;

            args.Items.Add(dict);
            res.List = items.Items;

            return(res);
        }
示例#3
0
        public bool Decode(PyObject data)
        {
            if (data.Type != PyObjectType.ObjectEx)
            {
                Log.Error("PyException", "Wrong container type");
                return(false);
            }

            PyObjectEx p = data.As <PyObjectEx>();

            if (p.IsType2 == true)
            {
                Log.Error("PyException", "Wrong PyObjectEx type, expected Normal, but got Type2");
                return(false);
            }

            if (p.Header.Type != PyObjectType.Tuple)
            {
                Log.Error("PyException", "Wrong item 1 type");
                return(false);
            }

            PyTuple args = p.Header.As <PyTuple>();

            if (args.Items.Count != 3)
            {
                Log.Error("PyException", "Wrong tuple 1 item count, expected 3 but got " + args.Items.Count);
                return(false);
            }

            if (args.Items[0].Type != PyObjectType.Token)
            {
                Log.Error("PyException", "Wrong tuple item 1 type");
                return(false);
            }

            PyToken type = args.Items[0].As <PyToken>();

            exception_type = type.Token;

            if (exception_type.StartsWith("exceptions.") == false)
            {
                Log.Warning("PyException", "Trying to decode a non-exception packet: " + exception_type);
                return(false);
            }

            if (args.Items[1].Type != PyObjectType.Tuple)
            {
                Log.Error("PyException", "Wrong tuple item 2 type");
                return(false);
            }

            PyTuple msg = args.Items[1].As <PyTuple>();

            if (msg.Items.Count != 1)
            {
                Log.Error("PyException", "Wrong item 2 tuple count, expected 1 but got " + msg.Items.Count);
                return(false);
            }

            if (msg.Items[0].Type != PyObjectType.String)
            {
                Log.Error("PyException", "Wrong tuple 2 item 1 type");
                return(false);
            }

            PyString msg_data = msg.Items[0].As <PyString>();

            message = msg_data.Value;

            if (args.Items[2].Type != PyObjectType.Dict)
            {
                Log.Error("PyException", "Wrong tuple 1 item 3 type");
                return(false);
            }

            PyDict info = args.Items[2].As <PyDict>();

            if (info.Contains("origin") == false)
            {
                Log.Error("PyException", "Dict item 1 doesnt has key origin");
                return(false);
            }

            origin = info.Get("origin").As <PyString>().Value;

            if (info.Contains("reasonArgs") == false)
            {
                Log.Error("PyException", "Dict item 1 doesn has key reasonArgs");
                return(false);
            }

            reasonArgs = info.Get("reasonArgs").As <PyDict>();

            if (info.Contains("clock") == false)
            {
                Log.Error("PyException", "Dict item 1 doesnt has key clock");
                return(false);
            }

            clock = info.Get("clock").IntValue;

            if (info.Contains("loggedOnUserCount") == false)
            {
                Log.Error("PyException", "Dict item 1 doesnt has key loggedOnUserCount");
                return(false);
            }

            loggedOnUserCount = info.Get("loggedOnUserCount");

            if (info.Contains("region") == false)
            {
                Log.Error("PyException", "Dict item 1 doesnt has key region");
                return(false);
            }

            region = info.Get("region").As <PyString>().Value;

            if (info.Contains("reason") == false)
            {
                Log.Error("PyException", "Dict item 1 doesnt has key reason");
                return(false);
            }

            reason = info.Get("reason").As <PyString>().Value;

            if (info.Contains("version") == false)
            {
                Log.Error("PyException", "Dict item 1 doesnt has key version");
                return(false);
            }

            version = info.Get("version").As <PyFloat>().Value;

            if (info.Contains("build") == false)
            {
                Log.Error("PyException", "Dict item 1 doesnt has key build");
                return(false);
            }

            build = info.Get("build").As <PyInt>().Value;

            if (info.Contains("reasonCode") == false)
            {
                Log.Error("PyException", "Dict item 1 doesnt has key reasonCode");
                return(false);
            }

            reasonCode = info.Get("reasonCode").StringValue;

            if (info.Contains("codename") == false)
            {
                Log.Error("PyException", "Dict item 1 doesnt has key codename");
                return(false);
            }

            codename = info.Get("codename").As <PyString>().Value;

            if (info.Contains("machoVersion") == false)
            {
                Log.Error("PyException", "Dict item 1 doesnt has key machoVersion");
                return(false);
            }

            machoVersion = info.Get("machoVersion").As <PyInt>().Value;

            return(true);
        }
示例#4
0
        public bool Decode(PyObject data)
        {
            if (data.Type != PyObjectType.Tuple)
            {
                Log.Error("AuthenticationReq", "Wrong type");
                return(false);
            }

            PyTuple tmp = data.As <PyTuple>();

            if (tmp.Items.Count != 2)
            {
                Log.Error("AuthenticationReq", "Wrong size, expected 2 but got " + tmp.Items.Count);
                return(false);
            }

            if (tmp.Items[0].Type != PyObjectType.String)
            {
                Log.Error("AuthenticationReq", "Wrong type for item 1");
                return(false);
            }

            if (tmp.Items[1].Type != PyObjectType.Dict)
            {
                Log.Error("AuthenticationReq", "Wrong type for item 2");
                return(false);
            }

            PyDict info = tmp.Items[1].As <PyDict>();

            if (info.Contains("boot_version") == false)
            {
                Log.Error("AuthenticationReq", "Dict item 1 doesnt has key boot_version");
                return(false);
            }

            boot_version = info.Get("boot_version").As <PyFloat>().Value;

            if (info.Contains("boot_region") == false)
            {
                Log.Error("AuthenticationReq", "Dict item 1 doesnt has key boot_region");
                return(false);
            }

            boot_region = info.Get("boot_region").As <PyString>().Value;

            if (info.Contains("user_password") == false)
            {
                Log.Error("AuthenticationReq", "Dict item 1 doesnt has key user_password");
                return(false);
            }

            if (info.Get("user_password").Type == PyObjectType.None)
            {
                user_password = null;
            }
            else
            {
                // user_password = info.Get("user_password").As<PyString>().Value;
                PyObjectEx obj = info.Get("user_password").As <PyObjectEx>();
                user_password = obj.Header.As <PyTuple>().Items[0].As <PyTuple>().Items[1].As <PyString>().Value;
            }

            if (info.Contains("user_affiliateid") == false)
            {
                Log.Error("AuthenticationReq", "Dict item 1 doesnt has key user_affiliateid");
                return(false);
            }

            user_affiliateid = info.Get("user_affiliateid").As <PyInt>().Value;

            if (info.Contains("user_password_hash") == false)
            {
                Log.Error("AuthenticationReq", "Dict item 1 doesnt has key user_password_hash");
                return(false);
            }

            if (info.Get("user_password_hash").Type == PyObjectType.None)
            {
                user_password_hash = null;
            }
            else
            {
                user_password_hash = info.Get("user_password_hash").As <PyString>().Value;
            }

            if (info.Contains("macho_version") == false)
            {
                Log.Error("AuthenticationReq", "Dict item 1 doesnt has key macho_version");
                return(false);
            }

            macho_version = info.Get("macho_version").As <PyInt>().Value;

            if (info.Contains("boot_codename") == false)
            {
                Log.Error("AuthenticationReq", "Dict item 1 doesnt has key boot_codename");
                return(false);
            }

            boot_codename = info.Get("boot_codename").As <PyString>().Value;

            if (info.Contains("boot_build") == false)
            {
                Log.Error("AuthenticationReq", "Dict item 1 doesnt has key boot_build");
                return(false);
            }

            boot_build = info.Get("boot_build").As <PyInt>().Value;

            if (info.Contains("user_name") == false)
            {
                Log.Error("AuthenticationReq", "Dict item 1 doesnt has key user_name");
                return(false);
            }

            user_name = info.Get("user_name").As <PyString>().Value;

            if (info.Contains("user_languageid") == false)
            {
                Log.Error("AuthenticationReq", "Dict item 1 doesnt has key user_languageid");
                return(false);
            }

            user_languageid = info.Get("user_languageid").As <PyString>().Value;

            return(true);
        }