Пример #1
0
        /// <summary>
        /// Simple helper method that creates a correct IntegerIntegerListDictionary and returns
        /// it's PyDataType representation, ready to be sent to the EVE Online client
        ///
        /// IMPORTANT: The first field MUST be ordered (direction doesn't matter) for this method
        /// to properly work
        /// </summary>
        /// <param name="reader">The MySqlDataReader to read the data from</param>
        /// <returns></returns>
        public static PyDictionary <PyInteger, PyList <PyInteger> > FromMySqlDataReader(MySqlDataReader reader)
        {
            PyDictionary <PyInteger, PyList <PyInteger> > result = new PyDictionary <PyInteger, PyList <PyInteger> >();

            Type keyType = reader.GetFieldType(0);
            Type valType = reader.GetFieldType(1);

            if (keyType != typeof(long) && keyType != typeof(int) && keyType != typeof(short) &&
                keyType != typeof(byte) && keyType != typeof(ulong) && keyType != typeof(uint) &&
                keyType != typeof(ushort) && keyType != typeof(sbyte) && valType != typeof(long) &&
                valType != typeof(int) && valType != typeof(short) && valType != typeof(byte) &&
                valType != typeof(ulong) && valType != typeof(uint) && valType != typeof(ushort) &&
                valType != typeof(sbyte))
            {
                throw new InvalidDataException("Expected two fields of type int");
            }

            // get first key and start preparing the values
            int key = 0;

            PyList <PyInteger> currentList = new PyList <PyInteger>();

            while (reader.Read() == true)
            {
                // ignore null keys
                if (reader.IsDBNull(0) == true)
                {
                    continue;
                }

                int newKey = reader.GetInt32(0);
                int val    = 0;

                // if the read key doesn't match the one read earlier
                if (newKey != key)
                {
                    // do not add an entry to the dict unless the old id was present
                    if (key != 0)
                    {
                        result[key] = currentList;
                    }

                    currentList = new PyList <PyInteger>();
                    key         = newKey;
                }

                if (reader.IsDBNull(1) == false)
                {
                    val = reader.GetInt32(1);
                }

                // add the current value to the list
                currentList.Add(val);
            }

            // ensure the last key is saved to the list
            result[key] = currentList;

            return(result);
        }
Пример #2
0
        public PyDataType GetStats_TopAndAllKillsAndVPs(CallInformation call)
        {
            PyDictionary values = new PyDictionary()
            {
                ["killsY"]     = 0,
                ["killsLW"]    = 0,
                ["killsTotal"] = 0,
                ["vpY"]        = 0,
                ["vpLW"]       = 0,
                ["vpTotal"]    = 0
            };

            return(new PyList(2)
            {
                [0] = new PyDictionary()
                {
                    [(int)Groups.Corporation] = values,
                    [(int)Groups.Character] = values,
                },
                [1] = new PyDictionary()
                {
                    [(int)Groups.Corporation] = values,
                    [(int)Groups.Character] = values,
                }
            });
        }
Пример #3
0
 private void ExtractExtraCharacterAppearance(PyDictionary data, out PyInteger accessoryID,
                                              out PyInteger beardID, out PyInteger decoID, out PyInteger lipstickID, out PyInteger makeupID,
                                              out PyDecimal morph1e, out PyDecimal morph1n, out PyDecimal morph1s, out PyDecimal morph1w,
                                              out PyDecimal morph2e, out PyDecimal morph2n, out PyDecimal morph2s, out PyDecimal morph2w,
                                              out PyDecimal morph3e, out PyDecimal morph3n, out PyDecimal morph3s, out PyDecimal morph3w,
                                              out PyDecimal morph4e, out PyDecimal morph4n, out PyDecimal morph4s, out PyDecimal morph4w)
 {
     data.TryGetValue("accessoryID", out accessoryID);
     data.TryGetValue("beardID", out beardID);
     data.TryGetValue("decoID", out decoID);
     data.TryGetValue("lipstickID", out lipstickID);
     data.TryGetValue("makeupID", out makeupID);
     data.TryGetValue("morph1e", out morph1e);
     data.TryGetValue("morph1n", out morph1n);
     data.TryGetValue("morph1s", out morph1s);
     data.TryGetValue("morph1w", out morph1w);
     data.TryGetValue("morph2e", out morph2e);
     data.TryGetValue("morph2n", out morph2n);
     data.TryGetValue("morph2s", out morph2s);
     data.TryGetValue("morph2w", out morph2w);
     data.TryGetValue("morph3e", out morph3e);
     data.TryGetValue("morph3n", out morph3n);
     data.TryGetValue("morph3s", out morph3s);
     data.TryGetValue("morph3w", out morph3w);
     data.TryGetValue("morph4e", out morph4e);
     data.TryGetValue("morph4n", out morph4n);
     data.TryGetValue("morph4s", out morph4s);
     data.TryGetValue("morph4w", out morph4w);
 }
Пример #4
0
        /// <summary>
        /// <seealso cref="Marshal.ProcessDictionary"/>
        ///
        /// Opcodes supported:
        /// <seealso cref="Opcode.Dictionary"/>
        /// </summary>
        /// <param name="opcode">Type of object to parse</param>
        /// <returns>The decoded python type</returns>
        /// <exception cref="InvalidDataException">If any error was found in the data</exception>
        private PyDataType ProcessDictionary(Opcode opcode)
        {
            if (opcode != Opcode.Dictionary)
            {
                throw new InvalidDataException($"Trying to parse a {opcode} as Dictionary");
            }

            PyDictionary dictionary = new PyDictionary();
            uint         size       = this.mReader.ReadSizeEx();

            while (size-- > 0)
            {
                PyDataType value = this.Process(false);
                PyDataType key   = this.Process(false);

                if (key is PyString == false)
                {
                    throw new InvalidDataException($"Expected String as Dictionary key, but gor {key.GetType()}");
                }

                dictionary[key as PyString] = value;
            }

            return(dictionary);
        }
Пример #5
0
        /// <summary>
        /// <seealso cref="Marshal.ProcessObject"/>
        ///
        /// Opcodes supported:
        /// <seealso cref="Opcode.ObjectType1"/>
        /// <seealso cref="Opcode.ObjectType2"/>
        /// </summary>
        /// <param name="opcode">Type of object to parse</param>
        /// <returns>The decoded python type</returns>
        /// <exception cref="InvalidDataException">If any error was found in the data</exception>
        protected virtual PyDataType ProcessObject(Opcode opcode)
        {
            if (opcode != Opcode.ObjectType1 && opcode != Opcode.ObjectType2)
            {
                throw new InvalidDataException($"Trying to parse a {opcode} as ObjectEx");
            }

            PyTuple      header = this.Process(false) as PyTuple;
            PyList       list   = new PyList();
            PyDictionary dict   = new PyDictionary();

            while (this.mReader.PeekChar() != Marshal.PACKED_TERMINATOR)
            {
                list.Add(this.Process(false));
            }

            // ignore packed terminator
            this.mReader.ReadByte();

            while (this.mReader.PeekChar() != Marshal.PACKED_TERMINATOR)
            {
                PyString   key   = this.Process(false) as PyString;
                PyDataType value = this.Process(false);

                dict[key] = value;
            }

            // ignore packed terminator
            this.mReader.ReadByte();

            return(new PyObject(opcode == Opcode.ObjectType2, header, list, dict));
        }
Пример #6
0
        public PyDataType GetStationInfo()
        {
            PyDictionary data = new PyDictionary
            {
                ["stationID"]             = this.ID,
                ["security"]              = this.Security,
                ["dockingCostPerVolume"]  = this.DockingCostPerVolume,
                ["maxShipVolumeDockable"] = this.MaxShipVolumeDockable,
                ["officeRentalCost"]      = this.OfficeRentalCost,
                ["operationID"]           = this.Operations.OperationID,
                ["stationTypeID"]         = this.Type.ID,
                ["ownerID"]         = this.OwnerID,
                ["solarSystemID"]   = this.SolarSystemID,
                ["constellationID"] = this.ConstellationID,
                ["regionID"]        = this.RegionID,
                ["stationName"]     = this.Name,
                ["x"] = this.X,
                ["y"] = this.Y,
                ["z"] = this.Z,
                ["reprocessingEfficiency"]   = this.ReprocessingEfficiency,
                ["reprocessingStationsTake"] = this.ReprocessingStationsTake,
                ["reprocessingHangarFlag"]   = this.ReprocessingHangarFlag,
                ["description"] = this.Operations.Description,
                ["serviceMask"] = this.Operations.ServiceMask
            };

            // TODO: CREATE OBJECTS FOR CONSTELLATION AND REGION ID SO THESE CAN BE FETCHED FROM MEMORY INSTEAD OF DATABASE

            return(KeyVal.FromDictionary(data));
        }
Пример #7
0
 public PyException(string type, string reason, PyDataType extra, PyDictionary keywords)
 {
     this.Type     = type;
     this.Reason   = reason;
     this.Extra    = extra;
     this.Keywords = keywords;
 }
Пример #8
0
 public void AddRow(int itemID, PyPackedRow entityRow, PyDictionary effects, PyDictionary attributes, long time)
 {
     this.AddRow(itemID, (PyList) new PyDataType[]
     {
         itemID, entityRow, effects, attributes, time
     });
 }
Пример #9
0
 public PyObject(bool isType2, PyTuple header, PyList list = null, PyDictionary dict = null) : base(PyObjectType.Object)
 {
     this.IsType2    = isType2;
     this.Header     = header;
     this.List       = list ?? new PyList();
     this.Dictionary = dict ?? new PyDictionary();
 }
Пример #10
0
 protected PyPacket()
 {
     this.Type        = PacketType.__Fake_Invalid_Type;
     this.UserID      = 0;
     this.Payload     = null;
     this.OutOfBounds = null;
     this.Source      = null;
     this.Destination = null;
 }
Пример #11
0
        public PyDataType BeanCount(PyInteger stackID, PyDictionary namedPayload, object client)
        {
            PyTuple res = new PyTuple(2);

            res[0] = new PyNone();
            res[1] = new PyInteger(0);

            return(res);
        }
Пример #12
0
        public PyDataType GetMyKillRights(CallInformation call)
        {
            PyDictionary killRights   = new PyDictionary();
            PyDictionary killedRights = new PyDictionary();

            return(new PyTuple(new PyDataType[]
            {
                killRights, killedRights
            }));
        }
Пример #13
0
        /// <summary>
        /// Converts the given <paramref name="data"/> to it's byte array representation.
        /// Dictionaries are complex, massive objects that encode other python objects
        /// Uses extended size indicator to specify the amount of key-value pairs available
        ///
        /// The following opcodes are supported
        /// <seealso cref="Opcode.Dictionary" /> 2 bytes minimum, extended size indicator, values are encoded as value-key values in python types
        /// </summary>
        /// <param name="writer">Where to write the encoded data to</param>
        /// <param name="dictionary">The value to write</param>
        private static void ProcessDictionary(BinaryWriter writer, PyDictionary dictionary)
        {
            writer.WriteOpcode(Opcode.Dictionary);
            writer.WriteSizeEx(dictionary.Length);

            foreach (KeyValuePair <PyDataType, PyDataType> pair in dictionary)
            {
                Process(writer, pair.Value);
                Process(writer, pair.Key);
            }
        }
Пример #14
0
        public PyDataType BatchCertificateUpdate(PyDictionary updates, CallInformation call)
        {
            call.Client.EnsureCharacterIsSelected();

            foreach (KeyValuePair <PyDataType, PyDataType> update in updates)
            {
                this.UpdateCertificateFlags(update.Key as PyInteger, update.Value as PyInteger, call);
            }

            return(null);
        }
Пример #15
0
        public PyDictionary GetHints(Dictionary <string, string> list)
        {
            PyDictionary hints = new PyDictionary();

            foreach (KeyValuePair <string, string> pair in list)
            {
                hints[pair.Value] = this.GetHint(pair.Key);
            }

            return(hints);
        }
Пример #16
0
        /// <summary>
        /// Searches for a list of cache hints that hold information about the cached object
        /// </summary>
        /// <param name="list">The list of hints to look for, key is used as cached object name and value is used as name for the client</param>
        /// <returns>A dictionary ready for the EVE Client with the hints for the cached objects</returns>
        public PyDictionary <PyString, PyDataType> GetHints(Dictionary <string, string> list)
        {
            PyDictionary <PyString, PyDataType> hints = new PyDictionary <PyString, PyDataType>();

            foreach ((string key, string value) in list)
            {
                hints[value] = this.GetHint(key);
            }

            return(hints);
        }
Пример #17
0
        /// <summary>
        /// Simple helper method that creates the correct KeyVal data off a result row and
        /// returns it's PyDataType representation, ready to be sent to the EVE Online client
        /// </summary>
        /// <param name="connection">The connection used</param>
        /// <param name="reader"></param>
        /// <returns></returns>
        public static PyDataType FromMySqlDataReader(IDatabaseConnection connection, MySqlDataReader reader)
        {
            PyDictionary data = new PyDictionary();

            for (int i = 0; i < reader.FieldCount; i++)
            {
                data[reader.GetName(i)] = IDatabaseConnection.ObjectFromColumn(reader, connection.GetFieldType(reader, i), i);
            }

            return(new PyObjectData(OBJECT_NAME, data));
        }
Пример #18
0
 public void AddRow(int itemID, PyPackedRow entityRow, PyDictionary effects, PyDictionary attributes, long time)
 {
     this.AddRow(itemID, new PyList(5)
     {
         [0] = itemID,
         [1] = entityRow,
         [2] = effects,
         [3] = attributes,
         [4] = time
     });
 }
Пример #19
0
        public PyTuple GetMyKillRights(CallInformation call)
        {
            PyDictionary killRights   = new PyDictionary();
            PyDictionary killedRights = new PyDictionary();

            return(new PyTuple(2)
            {
                [0] = killRights,
                [1] = killedRights
            });
        }
Пример #20
0
        /// <summary>
        /// Builds the correct PyDictionary for the changes described by this notification
        /// </summary>
        /// <returns></returns>
        private PyDictionary <PyInteger, PyDataType> BuildChangeDictionary()
        {
            PyDictionary <PyInteger, PyDataType> result = new PyDictionary <PyInteger, PyDataType>();

            foreach ((ItemChange changeType, PyDataType oldValue) in this.Changes)
            {
                result[(int)changeType] = oldValue;
            }

            return(result);
        }
Пример #21
0
        /// <summary>
        /// Simple helper method that creates the correct KeyVal data off a result row and
        /// returns it's PyDataType representation, ready to be sent to the EVE Online client
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public static PyDataType FromMySqlDataReader(MySqlDataReader reader)
        {
            PyDictionary data = new PyDictionary();

            for (int i = 0; i < reader.FieldCount; i++)
            {
                data[reader.GetName(i)] = Utils.ObjectFromColumn(reader, i);
            }

            return(new PyObjectData(OBJECT_NAME, data));
        }
Пример #22
0
        public PyDataType BatchCertificateUpdate(PyDictionary updates, CallInformation call)
        {
            call.Client.EnsureCharacterIsSelected();

            foreach ((PyInteger key, PyInteger value) in updates.GetEnumerable <PyInteger, PyInteger>())
            {
                this.UpdateCertificateFlags(key, value, call);
            }

            return(null);
        }
Пример #23
0
        public PyDataType NumRequiringAttention(CallInformation call)
        {
            call.Client.EnsureCharacterIsSelected();

            // TODO: PROPERLY IMPLEMENT THIS
            PyDictionary requiringAttention = new PyDictionary();

            requiringAttention["n"]     = 0;
            requiringAttention["ncorp"] = 0;

            return(new PyObjectData("util.KeyVal", requiringAttention));
        }
Пример #24
0
        /// <summary>
        /// Simple helper method that creates a correct IntRowDictionary and returns
        /// it's PyDataType representation, ready to be sent to the EVE Online client
        /// </summary>
        /// <param name="connection">The database connection</param>
        /// <param name="reader">The MySqlDataReader to read the data from</param>
        /// <param name="keyColumnIndex">The column to use as index for the IntRowDictionary</param>
        /// <returns></returns>
        public static PyDictionary FromMySqlDataReader(IDatabaseConnection connection, MySqlDataReader reader, int keyColumnIndex)
        {
            PyDictionary result = new PyDictionary();

            connection.GetDatabaseHeaders(reader, out PyList <PyString> header, out FieldType[] fieldTypes);

            while (reader.Read() == true)
            {
                result [reader.GetInt32(keyColumnIndex)] = Row.FromMySqlDataReader(reader, header, fieldTypes);
            }

            return(result);
        }
Пример #25
0
        /// <summary>
        /// Simple helper method that creates a correct IntegerIntegerListDictionary and returns
        /// it's PyDataType representation, ready to be sent to the EVE Online client
        ///
        /// IMPORTANT: The first field MUST be ordered (direction doesn't matter) for this method
        /// to properly work
        /// </summary>
        /// <param name="connection">The connection used</param>
        /// <param name="reader">The MySqlDataReader to read the data from</param>
        /// <param name="keyColumnIndex">The column to use as index for the IntPackedRowListDictionary</param>
        /// <returns></returns>
        public static PyDataType FromMySqlDataReader(IDatabaseConnection connection, MySqlDataReader reader, int keyColumnIndex)
        {
            DBRowDescriptor descriptor = DBRowDescriptor.FromMySqlReader(connection, reader);
            PyDictionary    result     = new PyDictionary();

            Type keyType = reader.GetFieldType(keyColumnIndex);

            if (keyType != typeof(long) && keyType != typeof(int) && keyType != typeof(short) &&
                keyType != typeof(byte) && keyType != typeof(ulong) && keyType != typeof(uint) &&
                keyType != typeof(ushort) && keyType != typeof(sbyte))
            {
                throw new InvalidDataException("Expected key type of integer");
            }

            // get first key and start preparing the values
            int key = 0;

            PyList currentList = new PyList();

            while (reader.Read() == true)
            {
                // ignore null keys
                if (reader.IsDBNull(keyColumnIndex) == true)
                {
                    continue;
                }

                int newKey = reader.GetInt32(keyColumnIndex);

                // if the read key doesn't match the one read earlier
                if (newKey != key)
                {
                    // do not add an entry to the dict unless the old id was present
                    if (key != 0)
                    {
                        result[key] = currentList;
                    }

                    currentList = new PyList();
                    key         = newKey;
                }

                // add the current value to the list
                currentList.Add(PyPackedRow.FromMySqlDataReader(reader, descriptor));
            }

            // ensure the last key is saved to the list
            result[key] = currentList;

            return(result);
        }
Пример #26
0
        /// <summary>
        /// Binds a new object of this type with the given objectData to provide a stateful
        /// interface to itself
        ///
        /// WARNING: Some MachoBindObject calls also include a call to a method inside the new stateful
        /// service, this also handles that behaviour
        /// </summary>
        /// <param name="objectData">The information of the object to be stateful about</param>
        /// <param name="callInfo">The information on the call</param>
        /// <param name="call">The call object with extra information</param>
        /// <returns></returns>
        protected PyDataType MachoBindObject(PyDataType objectData, PyDataType callInfo, CallInformation call)
        {
            // create the bound instance and register it in the bound services
            BoundService instance = this.CreateBoundInstance(objectData, call);

            // bind the service
            int boundID = this.BoundServiceManager.BoundService(instance);
            // build the bound service string
            string boundServiceStr = this.BoundServiceManager.BuildBoundServiceString(boundID);

            // TODO: the expiration time is 1 day, might be better to properly support this?
            // TODO: investigate these a bit more closely in the future
            // TODO: i'm not so sure about the expiration time
            PyTuple boundServiceInformation = new PyTuple(new PyDataType[]
            {
                boundServiceStr, DateTime.UtcNow.Add(TimeSpan.FromDays(1)).ToFileTime()
            });

            // after the service is bound the call can be run (if required)
            PyTuple result = new PyTuple(2);

            result[0] = new PySubStruct(new PySubStream(boundServiceInformation));

            if (callInfo is PyNone)
            {
                result[1] = null;
            }
            else
            {
                PyTuple      data           = callInfo as PyTuple;
                string       func           = data[0] as PyString;
                PyTuple      arguments      = data[1] as PyTuple;
                PyDictionary namedArguments = data[2] as PyDictionary;

                CallInformation callInformation = new CallInformation
                {
                    Client       = call.Client,
                    NamedPayload = namedArguments,
                    CallID       = call.CallID,
                    From         = call.From,
                    PacketType   = call.PacketType,
                    Service      = null,
                    To           = call.To
                };

                result[1] = this.BoundServiceManager.ServiceCall(boundID, func, arguments, callInformation);
            }

            return(result);
        }
Пример #27
0
        /// <summary>
        /// Simple helper method that creates a correct DictRowList and returns
        /// it's PyDataType representation, ready to be sent to the EVE Online client
        ///
        /// </summary>
        /// <param name="connection">The connection used</param>
        /// <param name="reader">The MySqlDataReader to read the data from</param>
        /// <returns></returns>
        public static PyDataType FromMySqlDataReader(IDatabaseConnection connection, MySqlDataReader reader)
        {
            PyDictionary result = new PyDictionary();

            connection.GetDatabaseHeaders(reader, out PyList <PyString> header, out FieldType[] fieldTypes);

            int index = 0;

            while (reader.Read() == true)
            {
                result[index++] = Row.FromMySqlDataReader(reader, header, fieldTypes);
            }

            return(result);
        }
Пример #28
0
        private void ProcessDictionary(PyDictionary dictionary)
        {
            this.mStringBuilder.AppendFormat("[PyDictionary {0} entries]", dictionary.Length);
            this.mStringBuilder.AppendLine();
            this.mIndentation++;

            // process all the keys and values
            foreach (KeyValuePair <PyDataType, PyDataType> pair in dictionary)
            {
                this.Process(pair.Key);
                this.Process(pair.Value);
            }

            this.mIndentation--;
        }
Пример #29
0
        /// <summary>
        /// Simple helper method that creates a correct IntRowDictionary and returns
        /// it's PyDataType representation, ready to be sent to the EVE Online client
        /// </summary>
        /// <param name="reader">The MySqlDataReader to read the data from</param>
        /// <returns></returns>
        public static PyDataType FromMySqlDataReader(MySqlDataReader reader, int keyColumnIndex)
        {
            PyDictionary result = new PyDictionary();
            PyList       header = new PyList(reader.FieldCount);

            for (int i = 0; i < reader.FieldCount; i++)
            {
                header [i] = reader.GetName(i);
            }

            while (reader.Read() == true)
            {
                result [reader.GetInt32(keyColumnIndex)] = Row.FromMySqlDataReader(reader, header);
            }

            return(result);
        }
Пример #30
0
        public PyDataType MachoBindObject(PyDictionary dictPayload, Client client)
        {
            // bind the service
            int boundID = this.BoundServiceManager.BoundService(this);
            // build the bound service string
            string boundServiceStr = this.BoundServiceManager.BuildBoundServiceString(boundID);

            // TODO: the expiration time is 1 day, might be better to properly support this?
            // TODO: investigate these a bit more closely in the future
            // TODO: i'm not so sure about the expiration time
            PyTuple boundServiceInformation = new PyTuple(new PyDataType[]
            {
                boundServiceStr, dictPayload, DateTime.UtcNow.Add(TimeSpan.FromDays(1)).ToFileTime()
            });

            return(new PySubStruct(new PySubStream(boundServiceInformation)));
        }