コード例 #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
ファイル: facWarMgr.cs プロジェクト: lanicon/EVESharp
        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
ファイル: Unmarshal.cs プロジェクト: lanicon/EVESharp
        /// <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
ファイル: Station.cs プロジェクト: lanicon/EVESharp
        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
ファイル: PyObject.cs プロジェクト: sn0opy/EVESharp
 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
ファイル: PyPacket.cs プロジェクト: lanicon/EVESharp
 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
ファイル: alert.cs プロジェクト: ozatomic/EVESharp
        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
ファイル: certificateMgr.cs プロジェクト: sn0opy/EVESharp
        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
ファイル: CacheStorage.cs プロジェクト: sn0opy/EVESharp
        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
ファイル: CacheStorage.cs プロジェクト: lanicon/EVESharp
        /// <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
ファイル: KeyVal.cs プロジェクト: lanicon/EVESharp
        /// <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
ファイル: ItemInfo.cs プロジェクト: lanicon/EVESharp
 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
ファイル: OnItemChange.cs プロジェクト: lanicon/EVESharp
        /// <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
ファイル: KeyVal.cs プロジェクト: sn0opy/EVESharp
        /// <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
ファイル: certificateMgr.cs プロジェクト: lanicon/EVESharp
        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
ファイル: IntRowDictionary.cs プロジェクト: lanicon/EVESharp
        /// <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
ファイル: BoundService.cs プロジェクト: sn0opy/EVESharp
        /// <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
ファイル: IntRowDictionary.cs プロジェクト: sn0opy/EVESharp
        /// <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)));
        }