Exemple #1
0
        /*
         * [PyObjectEx Normal]
         *   Header:
         *     [PyTuple 3 items]
         *       [PyToken carbon.common.script.net.machoNetExceptions.WrongMachoNode]
         *       [PyTuple 0 items]
         *       [PyDict 1 kvp]
         *         Key:[PyString "payload"]
         *         ==Value:[PyInt correctNode]
         *   List:
         *   Dictionary:
         */
        public WrongMachoNode(PyDict obj)
        {
            if (obj == null)
            {
                throw new InvalidDataException("WrongMachoNode: null dictionary.");
            }
            if (!obj.Contains("payload"))
            {
                throw new InvalidDataException("WrongMachoNode: Could not find key 'payload'.");
            }
            if (obj.Dictionary.Count > 1)
            {
                throw new InvalidDataException("WrongMachoNode: Too many values in dictionary.");
            }
            PyRep value = obj.Get("payload");

            correctNode = value.IntValue;
        }
Exemple #2
0
        private PyObject HandlePyPacket(PyPacket data)
        {
            // Just forward it if we dont want to look for a specific one
            if (data.dest.type == PyAddress.AddrType.Client)
            {
                // Look for SessionChangeNotifications
                if (data.type == Macho.MachoNetMsg_Type.SESSIONCHANGENOTIFICATION)
                {
                    // Search for address change in session
                    PyTuple payload = data.payload;
                    PyDict  session = payload.Items[0].As <PyTuple>().Items[1].As <PyDict>();

                    if (session.Contains("address") == true)
                    {
                        PyTuple address = session.Get("address").As <PyTuple>();

                        address[0] = new PyString(socket.GetAddress());
                        address[1] = new PyString(socket.GetAddress());
                        session.Set("address", address);
                    }

                    payload.Items[0].As <PyTuple>().Items[1] = session;

                    data.payload = payload;
                }

                // SendClient(data);
            }
            else if (data.dest.type == PyAddress.AddrType.Node)
            {
                // SendServer(data);
            }
            else if (data.dest.type == PyAddress.AddrType.Broadcast)
            {
                // What to do now ?
                Log.Error("Client", "Broadcast packets not supported yet");
                // throw new NotImplementedException("Broadcast packets are not supported yet");
            }

            return(data.Encode());
        }
Exemple #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);
        }
Exemple #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);
        }