Пример #1
0
        private static string PrintString(PyString str, string indention)
        {
            // aggressive destiny update pretty printing
            #if false
            UpdateReader reader;
            try
            {
                reader = new UpdateReader();
                reader.Read(new MemoryStream(str.Raw));
            }
            catch (Exception)
            {
                reader = null;
            }

            if (reader == null)
                return indention + "[PyString \"" + str.Value + "\"]";

            return eveDestiny.PrettyPrinter.Print(reader, indention);
            #endif
            return indention + "[PyString \"" + str.Value + "\"]";
        }
        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();
        }
Пример #3
0
        public bool Decode(PyObject from)
        {
            if (from.Type != PyObjectType.ObjectData)
            {
                return(false);
            }

            PyObjectData obj = from.As <PyObjectData>();

            if (obj.Name != "macho.MachoAddress")
            {
                return(false);
            }

            if (obj.Arguments.Type != PyObjectType.Tuple)
            {
                return(false);
            }

            PyTuple args = obj.Arguments.As <PyTuple>();

            if (args.Items.Count < 3)
            {
                return(false);
            }

            if (args.Items[0].Type != PyObjectType.String)
            {
                return(false);
            }

            PyString typei = args.Items[0].As <PyString>();

            switch (typei.Value)
            {
            case "A":
                if (args.Items.Count != 3)
                {
                    return(false);
                }

                if (!DecodeService(args.Items[1]) || !DecodeCallID(args.Items[2]))
                {
                    return(false);
                }

                type = AddrType.Any;
                break;

            case "N":
                if (args.Items.Count != 4)
                {
                    return(false);
                }

                if (!DecodeTypeID(args.Items[1]) || !DecodeService(args.Items[2]) || !DecodeCallID(args.Items[3]))
                {
                    return(false);
                }

                type = AddrType.Node;

                break;

            case "C":
                if (args.Items.Count != 4)
                {
                    return(false);
                }

                if (!DecodeTypeID(args.Items[1]) || !DecodeCallID(args.Items[2]) || !DecodeService(args.Items[3]))
                {
                    return(false);
                }

                type = AddrType.Client;

                break;

            case "B":
                if (args.Items.Count != 4)
                {
                    return(false);
                }

                type = AddrType.Broadcast;

                if (args.Items[1].Type != PyObjectType.String)
                {
                    return(false);
                }

                if (args.Items[3].Type != PyObjectType.String)
                {
                    return(false);
                }

                PyString bid = args.Items[1].As <PyString>();
                PyString idt = args.Items[3].As <PyString>();

                service    = bid.Value;
                bcast_type = idt.Value;

                break;

            default:
                return(false);
            }

            return(true);
        }