Beispiel #1
0
            public UniRx.IObservable <bool> Send(string command, Newtonsoft.Json.Linq.JToken payload)
            {
                var packet = new PROTOCOL();

                packet.ver     = PROTOCOL.VERSION;
                packet.serial  = last_send.serial + 1;
                packet.utc     = UnixDateTime.ToUnixTimeMilliseconds(System.DateTime.UtcNow);
                packet.command = command;
                packet.payload = payload;
                last_send      = packet;
                var json = Newtonsoft.Json.JsonConvert.SerializeObject(packet);

                return(socket.Send(json));
            }
Beispiel #2
0
        public static void AddStrongholdProfileToPacket(Session session, IStronghold stronghold, Packet packet)
        {
            if (!session.Player.IsInTribe || !stronghold.BelongsTo(session.Player.Tribesman.Tribe))
            {
                packet.AddByte(0);
                packet.AddUInt32(stronghold.PrimaryPosition.X);
                packet.AddUInt32(stronghold.PrimaryPosition.Y);
            }
            else
            {
                packet.AddByte(1);
                packet.AddUInt32(stronghold.ObjectId);
                packet.AddString(stronghold.Name);
                packet.AddByte(stronghold.Lvl);
                packet.AddFloat((float)stronghold.Gate);
                packet.AddInt32(stronghold.GateMax);
                packet.AddFloat((float)stronghold.VictoryPointRate);
                packet.AddUInt32(UnixDateTime.DateTimeToUnix(stronghold.DateOccupied.ToUniversalTime()));
                packet.AddUInt32(stronghold.PrimaryPosition.X);
                packet.AddUInt32(stronghold.PrimaryPosition.Y);
                AddToPacket(stronghold.State, packet);

                packet.AddUInt16(stronghold.Troops.Size);
                foreach (var troop in stronghold.Troops)
                {
                    packet.AddUInt32(troop.City.Owner.PlayerId);
                    packet.AddUInt32(troop.City.Id);
                    packet.AddString(troop.City.Owner.Name);
                    packet.AddString(troop.City.Name);
                    packet.AddUInt16(troop.TroopId);

                    //Actual formation and unit counts
                    packet.AddByte(troop.FormationCount);
                    foreach (var formation in troop)
                    {
                        packet.AddByte((byte)formation.Type);
                        packet.AddByte((byte)formation.Count);
                        foreach (var kvp in formation)
                        {
                            packet.AddUInt16(kvp.Key);
                            packet.AddUInt16(kvp.Value);
                        }
                    }
                }
            }
        }
        public void SerializationTest()
        {
            var unixDateTime = new UnixDateTime(UnixTime);

            var serializer = new XmlSerializer(typeof(UnixDateTime));

            var xml = new StringBuilder();

            using (var sw = new StringWriter(xml))
            {
                serializer.Serialize(sw, unixDateTime);
            }

            const string expectedXml = @"<?xml version=""1.0"" encoding=""utf-16""?>
<UnixDateTime>1388497944</UnixDateTime>";

            Assert.That(xml.ToString(), Is.EqualTo(expectedXml));
        }
Beispiel #4
0
        /// <summary>
        /// Updates the TTL, Mapping Flag, Look-up Time out, Cache Time out and Result Domain to the values specified as the input parameters of this method. If a new value for a parameter is not specified, then the current value for the parameter is not changed. The method returns a reference to the modified object as an output parameter.
        /// </summary>
        /// <param name="ttl">Optional - Time, in seconds, that the RR can be cached by a DNS resolver.</param>
        /// <param name="algorithm">Algorithm used with the key specified in the resource record. </param>
        /// <param name="keyTag">Method used to choose a key that verifies an SIG. See RFC 2535, Appendix C for the method used to calculate a KeyTag.</param>
        /// <param name="labels">Unsigned count of labels in the original SIG RR owner name. The count does not include the NULL label for the root, nor any initial wildcards.</param>
        /// <param name="originalTTL">TTL of the RR set signed by the SIG.</param>
        /// <param name="signature">Signature, represented in base 64, formatted as defined in RFC 2535, Appendix A.</param>
        /// <param name="signatureExpiration">Signature expiration date, expressed in seconds since the beginning of January 1, 1970, Greenwich Mean Time (GMT), excluding leap seconds.</param>
        /// <param name="signatureInception">Date and time at which the Signature becomes valid, expressed in seconds since the beginning of January 1, 1970, Greenwich Mean Time (GMT), excluding leap seconds.</param>
        /// <param name="signerName">Domain name of the signer that generated the SIG RR.</param>
        /// <param name="typeCovered">Type of RR covered by this SIG.</param>
        /// <returns>the modified object.</returns>
        public SIGType Modify(TimeSpan?ttl, UInt16 typeCovered,
                              AlgorithmEnum algorithm,
                              UInt16 labels,
                              TimeSpan originalTTL,
                              UnixDateTime signatureExpiration,
                              UnixDateTime signatureInception,
                              UInt16 keyTag,
                              string signerName,
                              string signature)
        {
            ManagementBaseObject inParams = m_mo.GetMethodParameters("Modify");

            if ((ttl != null) && (ttl != this.TTL))
            {
                inParams["TTL"] = ttl.Value.TotalSeconds;
            }

            //these are not optional, need to check if record is deleted if the same
            inParams["Algorithm"]           = (UInt16)algorithm;
            inParams["Labels"]              = labels;
            inParams["OriginalTTL"]         = originalTTL.TotalSeconds;
            inParams["SignatureExpiration"] = signatureExpiration.Unix;
            inParams["SignatureInception"]  = signatureInception.Unix;
            inParams["KeyTag"]              = keyTag;
            inParams["SignerName"]          = signerName;
            inParams["Signature"]           = signature;

            //return new SIGType((ManagementObject)m_mo.InvokeMethod("Modify", inParams, null));
            try
            {
                return(new SIGType(new ManagementObject(m_mo.Scope, new ManagementPath(m_mo.InvokeMethod("Modify", inParams, null)["RR"].ToString()), null)));
            }
            catch (ManagementException me)
            {
                throw new WMIException(me);
            }
        }
        /// <summary>
        ///     Read an object from JSON.
        /// </summary>
        /// <param name="reader">
        ///     The <see cref="JsonReader"/> to read from.
        /// </param>
        /// <param name="objectType">
        ///     The type of object to read.
        /// </param>
        /// <param name="existingValue">
        ///     The existing value (if any).
        /// </param>
        /// <param name="serializer">
        ///     The current <see cref="JsonSerializer"/>.
        /// </param>
        /// <returns>
        ///     The deserialised object.
        /// </returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            if (reader.TokenType == JsonToken.Null)
            {
                return(null);
            }

            if (reader.TokenType != JsonToken.StartArray)
            {
                throw new JsonException("Expected start of array.");
            }

            JArray array = JArray.Load(reader);

            if (array.Count != 2)
            {
                throw new JsonException("Expected array of length 2.");
            }

            long ticks = array[0].Value <long>();

            DateTime timestamp = UnixDateTime.FromUnix(
                array[0].Value <long>()
                );
            JValue jValue = (JValue)array[1];

            return(new PrometheusValue
            {
                Timestamp = timestamp,
                Value = jValue.Value.ToString()
            });
        }
Beispiel #6
0
        /// <summary></summary>
        private void OnLLRPClientRoAccessReportReceived(MSG_RO_ACCESS_REPORT msg)
        {
            if (msg.Custom.Length > 0)
            {
                for (int i = 0; i < msg.Custom.Length; ++i)
                {
                    IParameter custom = msg.Custom[i];

                    if (custom is PARAM_ImpinjExtendedTagInformation)
                    {
                        PARAM_ImpinjExtendedTagInformation info = (PARAM_ImpinjExtendedTagInformation)custom;
                        string epc = info.EPCData[0].EPC.ToHexString();

                        if (info.ImpinjDirectionReportData != null)
                        {
                            byte firstSeenSectorId = info.ImpinjDirectionReportData.FirstSeenSectorID;
                            byte lastSeenSectorId  = info.ImpinjDirectionReportData.LastSeenSectorID;

                            ENUM_ImpinjDirectionTagPopulationStatus status = info.ImpinjDirectionReportData.TagPopulationStatus;
                            ENUM_ImpinjDirectionReportType          type   = info.ImpinjDirectionReportData.Type;

                            DateTime dtFirstSeen = UnixDateTime.Convert(info.ImpinjDirectionReportData.FirstSeenTimestampUTC);
                            DateTime dtLastSeen  = UnixDateTime.Convert(info.ImpinjDirectionReportData.LastSeenTimestampUTC);

                            /*
                             * Console.Error.WriteLine($"{epc} Type: {type}, Status: {status}");
                             * Console.Error.WriteLine($"  Sector: {firstSeenSectorId} => {lastSeenSectorId}");
                             * Console.Error.WriteLine($"{dtFirstSeen.ToString("yyyy-MM-ddTHH:mm:ss")} => {dtLastSeen.ToString("yyyy-MM-ddTHH:mm:ss")}");
                             */

                            Console.Error.WriteLine($"{epc},{dtFirstSeen.ToString(DateTimeFormat)},{dtLastSeen.ToString(DateTimeFormat)},{type},{firstSeenSectorId},{lastSeenSectorId},{status}");
                        }
                    }
                }
            }
        }
Beispiel #7
0
        public static void AddToPacket(Logic.Notifications.Notification notification, Packet packet)
        {
            packet.AddUInt32(notification.GameObject.City.Id);
            packet.AddUInt32(notification.GameObject.ObjectId);
            packet.AddUInt32(notification.Action.ActionId);
            packet.AddUInt16((ushort)notification.Action.Type);

            var actionTime = notification.Action as IActionTime;

            if (actionTime != null)
            {
                packet.AddUInt32(actionTime.BeginTime == DateTime.MinValue
                                         ? 0
                                         : UnixDateTime.DateTimeToUnix(actionTime.BeginTime.ToUniversalTime()));
                packet.AddUInt32(actionTime.EndTime == DateTime.MinValue
                                         ? 0
                                         : UnixDateTime.DateTimeToUnix(actionTime.EndTime.ToUniversalTime()));
            }
            else
            {
                packet.AddUInt32(0);
                packet.AddUInt32(0);
            }
        }
        public void TestUnixDateTime()
        {
            UnixDateTime unixDateTime = new UnixDateTime(DateTime.Today);

            Assert.AreEqual(DateTime.Today, unixDateTime.ToDateTime());
        }
Beispiel #9
0
 /// <summary>
 /// Инициализирует новую команду.
 /// </summary>
 /// <param name="startTime">нижняя временная граница</param>
 /// <param name="endTime">верхняя временная граница</param>
 public GetStatisticsCommand(UnixDateTime startTime, UnixDateTime endTime)
     : base(CommandCode.GetStatistics)
 {
     Arguments.Add(this.startTime = startTime);
     Arguments.Add(this.endTime   = endTime);
 }
Beispiel #10
0
        public static void AddTribeInfo(IStrongholdManager strongholdManager,
                                        ITribeManager tribeManager,
                                        Session session,
                                        ITribe tribe,
                                        Packet packet)
        {
            if (session.Player.IsInTribe && tribe.Id == session.Player.Tribesman.Tribe.Id)
            {
                packet.AddByte(1);
                packet.AddUInt32(tribe.Id);
                packet.AddUInt32(tribe.Owner.PlayerId);
                packet.AddByte(tribe.Level);
                packet.AddString(tribe.Name);
                packet.AddString(tribe.Description);
                packet.AddString(tribe.PublicDescription);
                packet.AddFloat((float)tribe.VictoryPoint);
                packet.AddUInt32(UnixDateTime.DateTimeToUnix(tribe.Created));
                AddToPacket(tribe.Resource, packet);

                packet.AddInt16((short)tribe.Count);
                foreach (var tribesman in tribe.Tribesmen)
                {
                    packet.AddUInt32(tribesman.Player.PlayerId);
                    packet.AddString(tribesman.Player.Name);
                    packet.AddInt32(tribesman.Player.GetCityCount());
                    packet.AddByte(tribesman.Rank.Id);
                    packet.AddUInt32(tribesman.Player.IsLoggedIn ? 0 : UnixDateTime.DateTimeToUnix(tribesman.Player.LastLogin));
                    AddToPacket(tribesman.Contribution, packet);
                }

                // Incoming List
                var incomingList = tribeManager.GetIncomingList(tribe).ToList();
                packet.AddInt16((short)incomingList.Count());
                foreach (var incoming in incomingList)
                {
                    AddToPacket(incoming.Target, packet);
                    AddToPacket(incoming.Source, packet);

                    packet.AddUInt32(UnixDateTime.DateTimeToUnix(incoming.EndTime.ToUniversalTime()));
                }

                // Assignment List
                packet.AddInt16(tribe.AssignmentCount);
                foreach (var assignment in tribe.Assignments)
                {
                    AddToPacket(assignment, packet);
                }

                // Strongholds
                var strongholds = strongholdManager.StrongholdsForTribe(tribe).ToList();
                packet.AddInt16((short)strongholds.Count);
                foreach (var stronghold in strongholds)
                {
                    packet.AddUInt32(stronghold.ObjectId);
                    packet.AddString(stronghold.Name);
                    packet.AddByte((byte)stronghold.StrongholdState);
                    packet.AddByte(stronghold.Lvl);
                    packet.AddFloat((float)stronghold.Gate);
                    packet.AddInt32(stronghold.GateMax);
                    packet.AddUInt32(stronghold.PrimaryPosition.X);
                    packet.AddUInt32(stronghold.PrimaryPosition.Y);
                    packet.AddInt32(stronghold.Troops.StationedHere().Sum(x => x.Upkeep));
                    packet.AddFloat((float)stronghold.VictoryPointRate);
                    packet.AddUInt32(UnixDateTime.DateTimeToUnix(stronghold.DateOccupied.ToUniversalTime()));
                    packet.AddUInt32(stronghold.GateOpenTo == null ? 0 : stronghold.GateOpenTo.Id);
                    packet.AddString(stronghold.GateOpenTo == null ? string.Empty : stronghold.GateOpenTo.Name);
                    if (stronghold.GateBattle != null)
                    {
                        packet.AddByte(1);
                        packet.AddUInt32(stronghold.GateBattle.BattleId);
                    }
                    else if (stronghold.MainBattle != null)
                    {
                        packet.AddByte(2);
                        packet.AddUInt32(stronghold.MainBattle.BattleId);
                    }
                    else
                    {
                        packet.AddByte(0);
                    }
                }

                // Attackable Strongholds
                strongholds = strongholdManager.OpenStrongholdsForTribe(tribe).ToList();
                packet.AddInt16((short)strongholds.Count);
                foreach (var stronghold in strongholds)
                {
                    packet.AddUInt32(stronghold.ObjectId);
                    packet.AddString(stronghold.Name);
                    packet.AddUInt32(stronghold.Tribe == null ? 0 : stronghold.Tribe.Id);
                    packet.AddString(stronghold.Tribe == null ? string.Empty : stronghold.Tribe.Name);
                    packet.AddByte((byte)stronghold.StrongholdState);
                    packet.AddByte(stronghold.Lvl);
                    packet.AddUInt32(stronghold.PrimaryPosition.X);
                    packet.AddUInt32(stronghold.PrimaryPosition.Y);
                    if (stronghold.GateBattle != null)
                    {
                        packet.AddByte(1);
                        packet.AddUInt32(stronghold.GateBattle.BattleId);
                    }
                    else if (stronghold.MainBattle != null)
                    {
                        packet.AddByte(2);
                        packet.AddUInt32(stronghold.MainBattle.BattleId);
                    }
                    else
                    {
                        packet.AddByte(0);
                    }
                }
            }
            else
            {
                packet.AddByte(0);
                packet.AddUInt32(tribe.Id);
                packet.AddString(tribe.Name);
                packet.AddString(tribe.PublicDescription);
                packet.AddByte(tribe.Level);
                packet.AddUInt32(UnixDateTime.DateTimeToUnix(tribe.Created));

                packet.AddByte((byte)tribe.Ranks.Count());
                foreach (var rank in tribe.Ranks)
                {
                    packet.AddString(rank.Name);
                }

                packet.AddInt16((short)tribe.Count);
                foreach (var tribesman in tribe.Tribesmen)
                {
                    packet.AddUInt32(tribesman.Player.PlayerId);
                    packet.AddString(tribesman.Player.Name);
                    packet.AddInt32(tribesman.Player.GetCityCount());
                    packet.AddByte(tribesman.Rank.Id);
                }

                var strongholds = strongholdManager.StrongholdsForTribe(tribe).ToList();
                packet.AddInt16((short)strongholds.Count);
                foreach (var stronghold in strongholds)
                {
                    packet.AddUInt32(stronghold.ObjectId);
                    packet.AddString(stronghold.Name);
                    packet.AddByte(stronghold.Lvl);
                    packet.AddUInt32(stronghold.PrimaryPosition.X);
                    packet.AddUInt32(stronghold.PrimaryPosition.Y);
                }
            }
        }