internal override byte[] GenerateBytes() { var innerTransactionBytes = InnerTransaction.GenerateBytes(); var builder = new FlatBufferBuilder(1); var signer = MultisigTransactionBuffer.CreatePublicKeyVector(builder, GetSigner()); var innerTransaction = MultisigTransactionBuffer.CreateInnerTransactionBytesVector(builder, innerTransactionBytes); MultisigTransactionBuffer.StartMultisigTransactionBuffer(builder); MultisigTransactionBuffer.AddTransactionType(builder, TransactionType.GetValue()); MultisigTransactionBuffer.AddVersion(builder, BitConverter.ToInt16(new byte[] { ExtractVersion(Version), 0 }, 0)); MultisigTransactionBuffer.AddNetwork(builder, BitConverter.ToInt16(new byte[] { 0, NetworkType.GetNetwork() }, 0)); MultisigTransactionBuffer.AddTimestamp(builder, NetworkTime.EpochTimeInMilliSeconds()); MultisigTransactionBuffer.AddPublicKeyLen(builder, 32); MultisigTransactionBuffer.AddPublicKey(builder, signer); MultisigTransactionBuffer.AddFee(builder, Fee); MultisigTransactionBuffer.AddDeadline(builder, Deadline.Ticks); MultisigTransactionBuffer.AddInnerTransactionLength(builder, innerTransactionBytes.Length); MultisigTransactionBuffer.AddInnerTransactionBytes(builder, innerTransaction); var codedTransfer = MultisigTransactionBuffer.EndMultisigTransactionBuffer(builder); builder.Finish(codedTransfer.Value); return(new MultisigTransactionSchema().Serialize(builder.SizedByteArray())); }
internal override byte[] GenerateBytes() { var builder = new FlatBufferBuilder(1); var signer = SignatureTransactionBuffer.CreatePublicKeyVector(builder, GetSigner()); var hash = SignatureTransactionBuffer.CreateHashVector(builder, OtherHash.FromHex()); var address = SignatureTransactionBuffer.CreateMultisigAddressVector(builder, Encoding.UTF8.GetBytes(MultisigAddress.Plain)); SignatureTransactionBuffer.StartSignatureTransactionBuffer(builder); SignatureTransactionBuffer.AddTransactionType(builder, TransactionType.GetValue()); SignatureTransactionBuffer.AddVersion(builder, BitConverter.ToInt16(new byte[] { ExtractVersion(Version), 0 }, 0)); SignatureTransactionBuffer.AddNetwork(builder, BitConverter.ToInt16(new byte[] { 0, NetworkType.GetNetwork() }, 0)); SignatureTransactionBuffer.AddTimestamp(builder, NetworkTime.EpochTimeInMilliSeconds()); SignatureTransactionBuffer.AddPublicKeyLen(builder, 32); SignatureTransactionBuffer.AddPublicKey(builder, signer); SignatureTransactionBuffer.AddFee(builder, Fee); SignatureTransactionBuffer.AddDeadline(builder, Deadline.Ticks); SignatureTransactionBuffer.AddHashObjLength(builder, 0x24); SignatureTransactionBuffer.AddSha3HashLength(builder, 0x20); SignatureTransactionBuffer.AddHash(builder, hash); SignatureTransactionBuffer.AddAddressLength(builder, 0x28); SignatureTransactionBuffer.AddMultisigAddress(builder, address); var result = SignatureTransactionBuffer.EndSignatureTransactionBuffer(builder); builder.Finish(result.Value); return(new SignatureTransactionSchema().Serialize(builder.SizedByteArray())); }
internal override byte[] GenerateBytes() { var builder = new FlatBufferBuilder(1); var mosaicName = Encoding.UTF8.GetBytes(MosaicId.Name); var namespaceName = Encoding.UTF8.GetBytes(MosaicId.NamespaceId.Name); var signerVector = SupplyChangeBuffer.CreatePublicKeyVector(builder, GetSigner()); var namespaceVector = SupplyChangeBuffer.CreateNamespaceIdstringVector(builder, namespaceName); var mosaicNameVector = SupplyChangeBuffer.CreateMosaicNameStringVector(builder, mosaicName); SupplyChangeBuffer.StartSupplyChangeBuffer(builder); SupplyChangeBuffer.AddTransactionType(builder, TransactionType.GetValue()); SupplyChangeBuffer.AddVersion(builder, BitConverter.ToInt16(new byte[] { ExtractVersion(Version), 0 }, 0)); SupplyChangeBuffer.AddNetwork(builder, BitConverter.ToInt16(new byte[] { 0, NetworkType.GetNetwork() }, 0)); SupplyChangeBuffer.AddTimestamp(builder, NetworkTime.EpochTimeInMilliSeconds()); SupplyChangeBuffer.AddPublicKeyLen(builder, 32); SupplyChangeBuffer.AddPublicKey(builder, signerVector); SupplyChangeBuffer.AddFee(builder, Fee); SupplyChangeBuffer.AddDeadline(builder, Deadline.Ticks); SupplyChangeBuffer.AddLengthOfMosaicIdStructure(builder, 8 + namespaceName.Length + mosaicName.Length); SupplyChangeBuffer.AddLengthOfNamespaceIdString(builder, namespaceName.Length); SupplyChangeBuffer.AddNamespaceIdstring(builder, namespaceVector); SupplyChangeBuffer.AddLengthOfMosaicNameString(builder, mosaicName.Length); SupplyChangeBuffer.AddMosaicNameString(builder, mosaicNameVector); SupplyChangeBuffer.AddSupplyType(builder, SupplyType); SupplyChangeBuffer.AddDelta(builder, Delta); var codedTransfer = ImportanceTransferBuffer.EndImportanceTransferBuffer(builder); builder.Finish(codedTransfer.Value); return(new SupplyChangeTransactionSchema().Serialize(builder.SizedByteArray())); }
protected override ProcessResult process(BodyKinematicUpdateMessage msg) { var player = context.clients.SingleOrDefault(x => x.uid == msg.sourceUid); if (player == null) { Global.log.trace($"kinematic update was for body with unknown owner: {msg} (from {msg.sourceUid})"); return(ProcessResult.Fail); } var now = NetworkTime.time(); var userBodies = context.scene.bodies[player]; var body = userBodies.SingleOrDefault(x => x.id == msg.bodyId); if (body == null) { Global.log.trace($"kinematic update was for body with unknown body id ({msg.bodyId}): {msg} (from {msg.sourceUid})"); return(ProcessResult.Fail); } body.lastReceivedTime = now; body.lastSnapshotTime = msg.time; body.pos = msg.pos; body.vel = msg.vel; body.angle = msg.angle; body.angularVelocity = msg.angularVelocity; return(ProcessResult.Relay); }
internal override byte[] GenerateBytes() { var builder = new FlatBufferBuilder(1); var signer = ImportanceTransferBuffer.CreatePublicKeyVector(builder, GetSigner()); var remote = ImportanceTransferBuffer.CreateRemotePublicKeyVector(builder, RemoteAccount.PublicKey.FromHex()); ImportanceTransferBuffer.StartImportanceTransferBuffer(builder); ImportanceTransferBuffer.AddTransactionType(builder, TransactionType.GetValue()); ImportanceTransferBuffer.AddVersion(builder, BitConverter.ToInt16(new byte[] { ExtractVersion(Version), 0 }, 0)); ImportanceTransferBuffer.AddNetwork(builder, BitConverter.ToInt16(new byte[] { 0, NetworkType.GetNetwork() }, 0)); ImportanceTransferBuffer.AddTimestamp(builder, NetworkTime.EpochTimeInMilliSeconds()); ImportanceTransferBuffer.AddPublicKeyLen(builder, 32); ImportanceTransferBuffer.AddPublicKey(builder, signer); ImportanceTransferBuffer.AddFee(builder, Fee); ImportanceTransferBuffer.AddDeadline(builder, Deadline.TimeStamp); ImportanceTransferBuffer.AddMode(builder, Mode.GetValue()); ImportanceTransferBuffer.AddRemotePublicKeyLen(builder, 32); ImportanceTransferBuffer.AddRemotePublicKey(builder, remote); var codedTransfer = ImportanceTransferBuffer.EndImportanceTransferBuffer(builder); builder.Finish(codedTransfer.Value); return(new ImportanceTransferSchema().Serialize(builder.SizedByteArray())); }
/// <summary> /// Initializes a new signed instance of the <see cref="MultisigTransaction"/> class. /// </summary> /// <param name="networkType">Type of the network.</param> /// <param name="version">The version.</param> /// <param name="networkTime">The networkTime.</param> /// <param name="deadline">The deadline.</param> /// <param name="fee">The fee.</param> /// <param name="innerTransaction">The inner transaction.</param> /// <param name="signature">The signature.</param> /// <param name="signer">The signer.</param> /// <param name="transactionInfo">The transaction information.</param> public MultisigTransaction(NetworkType.Types networkType, int version, NetworkTime networkTime, Deadline deadline, ulong fee, Transaction innerTransaction, string signature, PublicAccount signer, TransactionInfo transactionInfo) { TransactionType = TransactionTypes.Types.Multisig; NetworkType = networkType; Version = version; NetworkTime = networkTime; Deadline = deadline; Fee = fee == 0 ? 150000 : fee; InnerTransaction = innerTransaction; Signer = signer; Signature = signature; TransactionInfo = transactionInfo; }
/// <summary> /// Initializes a new signed instance of the <see cref="ImportanceTransferTransaction"/> class. /// </summary> /// <param name="networkType">Type of the network.</param> /// <param name="version">The version.</param> /// <param name="networkTime">The networkTime.</param> /// <param name="deadline">The deadline.</param> /// <param name="fee">The fee.</param> /// <param name="mode">The mode.</param> /// <param name="remoteAccount">The remote account.</param> /// <param name="signature">The signature.</param> /// <param name="signer">The signer.</param> /// <param name="transactionInfo">The transaction information.</param> public ImportanceTransferTransaction(NetworkType.Types networkType, int version, NetworkTime networkTime, Deadline deadline, ulong fee, ImportanceTransferMode.Mode mode, PublicAccount remoteAccount, string signature, PublicAccount signer, TransactionInfo transactionInfo) { TransactionType = TransactionTypes.Types.ImportanceTransfer; Version = version; NetworkTime = networkTime; Deadline = deadline; NetworkType = networkType; Signature = signature; Signer = signer; TransactionInfo = transactionInfo; Fee = fee == 0 ? 150000 : fee; RemoteAccount = remoteAccount; Mode = mode; }
/// <summary> /// Initializes a new signed instance of the <see cref="ProvisionNamespaceTransaction"/> class. /// </summary> /// <param name="networkType">Type of the network.</param> /// <param name="version">The version.</param> /// <param name="networkTime">The networkTime.</param> /// <param name="deadline">The deadline.</param> /// <param name="fee">The fee.</param> /// <param name="newPart">The new part.</param> /// <param name="parent">The parent.</param> /// <param name="signature">The signature.</param> /// <param name="signer">The signer.</param> /// <param name="transactionInfo">The transaction information.</param> public ProvisionNamespaceTransaction(NetworkType.Types networkType, int version, NetworkTime networkTime, Deadline deadline, ulong fee, string newPart, string parent, string signature, PublicAccount signer, TransactionInfo transactionInfo) { TransactionType = TransactionTypes.Types.ProvisionNamespace; Version = version; NetworkTime = networkTime; Deadline = deadline; NetworkType = networkType; Signature = signature; Signer = signer; TransactionInfo = transactionInfo; Fee = fee == 0 ? 150000 : fee; Parent = parent; NewPart = newPart; }
/// <summary> /// Initializes a new signed instance of the <see cref="MultisigAggregateModificationTransaction"/> class. /// </summary> /// <param name="networkType">Type of the network.</param> /// <param name="version">The version.</param> /// <param name="networkTime">The networkTime.</param> /// <param name="deadline">The deadline.</param> /// <param name="fee">The fee.</param> /// <param name="relativeChange">The relative change.</param> /// <param name="modifications">The modifications.</param> /// <param name="signature">The signature.</param> /// <param name="signer">The signer.</param> /// <param name="transactionInfo">The transaction information.</param> public MultisigAggregateModificationTransaction(NetworkType.Types networkType, int version, NetworkTime networkTime, Deadline deadline, ulong fee, int relativeChange, List <MultisigModification> modifications, string signature, PublicAccount signer, TransactionInfo transactionInfo) { TransactionType = TransactionTypes.Types.MultisigAggregateModification; Version = version; NetworkTime = networkTime; Deadline = deadline; NetworkType = networkType; Signature = signature; Signer = signer; TransactionInfo = transactionInfo; Fee = fee == 0 ? 500000 : fee; RelativeChange = relativeChange; Modifications = modifications; }
/// <summary> /// Initializes a new signed instance of the <see cref="CosignatureTransaction"/> class. /// </summary> /// <param name="networkType">Type of the network.</param> /// <param name="version">The version.</param> /// <param name="networkTime">The networkTime.</param> /// <param name="deadline">The deadline.</param> /// <param name="fee">The fee.</param> /// <param name="hash">The hash of the transaction to sign.</param> /// <param name="multisigAddress">The multisig address.</param> /// <param name="signature">The signature.</param> /// <param name="signer">The signer.</param> /// <param name="transactionInfo">The transaction information.</param> public CosignatureTransaction(NetworkType.Types networkType, int version, NetworkTime networkTime, Deadline deadline, ulong fee, string hash, Address multisigAddress, string signature, PublicAccount signer, TransactionInfo transactionInfo) { TransactionType = TransactionTypes.Types.SignatureTransaction; Version = version; NetworkTime = networkTime; Deadline = deadline; NetworkType = networkType; Signature = signature; Signer = signer; TransactionInfo = transactionInfo; Fee = fee == 0 ? 150000 : fee; OtherHash = hash; MultisigAddress = multisigAddress; }
protected override void BeforePump() { NetworkTime.Update(); if (has_spawned) { UserInput.Read(); if (ticks == send_rate) { SendCommands(); } } }
internal override byte[] GenerateBytes() { var builder = new FlatBufferBuilder(1); var signer = MultisigAggregateModificationBuffer.CreatePublicKeyVector(builder, GetSigner()); var mods = new Offset <ModificationBuffer> [Modifications.Count]; for (var index = 0; index < Modifications.Count; index++) { var cosig = ModificationBuffer.CreateCosignatoryPublicKeyVector(builder, Modifications[index].CosignatoryPublicKey.PublicKey.FromHex()); ModificationBuffer.StartModificationBuffer(builder); ModificationBuffer.AddStructureLength(builder, 0x28); ModificationBuffer.AddModificationType(builder, Modifications[index].ModificationType.GetValue()); ModificationBuffer.AddCosignatoryPublicKeyLen(builder, 32); ModificationBuffer.AddCosignatoryPublicKey(builder, cosig); mods[index] = ModificationBuffer.EndModificationBuffer(builder); } var modificationsVector = MultisigAggregateModificationBuffer.CreateModificationsVector(builder, mods); MultisigAggregateModificationBuffer.StartMultisigAggregateModificationBuffer(builder); MultisigAggregateModificationBuffer.AddTransactionType(builder, TransactionType.GetValue()); MultisigAggregateModificationBuffer.AddVersion(builder, BitConverter.ToInt16(new byte[] { ExtractVersion(Version), 0 }, 0)); MultisigAggregateModificationBuffer.AddNetwork(builder, BitConverter.ToInt16(new byte[] { 0, NetworkType.GetNetwork() }, 0)); MultisigAggregateModificationBuffer.AddTimestamp(builder, NetworkTime.EpochTimeInMilliSeconds()); MultisigAggregateModificationBuffer.AddPublicKeyLen(builder, 32); MultisigAggregateModificationBuffer.AddPublicKey(builder, signer); MultisigAggregateModificationBuffer.AddFee(builder, Fee); MultisigAggregateModificationBuffer.AddDeadline(builder, Deadline.Ticks); MultisigAggregateModificationBuffer.AddNumerOfModifications(builder, Modifications.Count); MultisigAggregateModificationBuffer.AddModifications(builder, modificationsVector); MultisigAggregateModificationBuffer.AddMinimumCosignatoriesLength(builder, RelativeChange == 0 ? 0 : 0x04); if (RelativeChange > 0) { MultisigAggregateModificationBuffer.AddRelativeChange(builder, RelativeChange); } var codedTransfer = MultisigAggregateModificationBuffer.EndMultisigAggregateModificationBuffer(builder); builder.Finish(codedTransfer.Value); var bytes = new MultisigAggregateModificationSchema().Serialize(builder.SizedByteArray()); return(RelativeChange > 0 ? bytes : bytes.Take(0, bytes.Length - 1)); // flatbuffers is appending 0x00 to the stream as a default value due to the missing relative change when its not included in the transaction so im just cutting off the 0x00 as a short term fix. will fix sometime this decade. }
/// <summary> /// Initializes a new signed instance of the <see cref="TransferTransaction"/> class. /// </summary> /// <param name="networkType">Type of the network.</param> /// <param name="version">The version.</param> /// <param name="networkTime">The networkTime.</param> /// <param name="deadline">The deadline.</param> /// <param name="fee">The fee.</param> /// <param name="recipient">The recipient.</param> /// <param name="mosaics">The mosaics.</param> /// <param name="message">The message.</param> /// <param name="signature">The signature.</param> /// <param name="signer">The signer.</param> /// <param name="transactionInfo">The transaction information.</param> /// <exception cref="System.ArgumentNullException">recipient</exception> internal TransferTransaction(NetworkType.Types networkType, int version, NetworkTime networkTime, Deadline deadline, ulong fee, Address recipient, List <MosaicAmount> mosaics, IMessage message, string signature, PublicAccount signer, TransactionInfo transactionInfo) { Address = recipient ?? throw new ArgumentNullException(nameof(recipient)); Mosaics = mosaics ?? new List <MosaicAmount>(); TransactionType = TransactionTypes.Types.Transfer; Version = version; NetworkTime = networkTime; Deadline = deadline; Message = message ?? EmptyMessage.Create(); NetworkType = networkType; Signature = signature; Signer = signer; TransactionInfo = transactionInfo; Fee = fee == 0 ? CalculateFee() : fee; }
/// <summary> /// Initializes a new signed instance of the <see cref="SupplyChangeTransaction"/> class. /// </summary> /// <param name="networkType">Type of the network.</param> /// <param name="version">The version.</param> /// <param name="networkTime">The networkTime.</param> /// <param name="deadline">The deadline.</param> /// <param name="fee">The fee.</param> /// <param name="delta">The delta.</param> /// <param name="mosaicId">The mosaic identifier.</param> /// <param name="supplyType">Type of the supply.</param> /// <param name="signature">The signature.</param> /// <param name="signer">The signer.</param> /// <param name="transactionInfo">The transaction information.</param> public SupplyChangeTransaction(NetworkType.Types networkType, int version, NetworkTime networkTime, Deadline deadline, ulong fee, ulong delta, MosaicId mosaicId, int supplyType, string signature, PublicAccount signer, TransactionInfo transactionInfo) { TransactionType = TransactionTypes.Types.SupplyChange; Version = version; NetworkTime = networkTime; Deadline = deadline; NetworkType = networkType; Signature = signature; Signer = signer; TransactionInfo = transactionInfo; Fee = fee == 0 ? 150000 : fee; Delta = delta; MosaicId = mosaicId; SupplyType = supplyType; }
void Update() { NetworkTime.Update(); for (var i = 0; i < net_states.Count; ++i) { if (LidPeer.isserver) { net_states[i].NetworkUpdateServer(); } else { net_states[i].NetworkUpdateClient(); } } }
/// <summary> /// Initializes a new signed instance of the <see cref="MosaicDefinitionTransaction"/> class. /// </summary> /// <param name="networkType">Type of the network.</param> /// <param name="version">The version.</param> /// <param name="networkTime">The networkTime.</param> /// <param name="deadline">The deadline.</param> /// <param name="fee">The fee.</param> /// <param name="properties">The properties.</param> /// <param name="mosaic">The mosaic.</param> /// <param name="mosaicLevy">The mosaic levy.</param> /// <param name="creator">The creator.</param> /// <param name="description">The description.</param> /// <param name="signature">The signature.</param> /// <param name="signer">The signer.</param> /// <param name="transactionInfo">The transaction information.</param> /// <exception cref="System.ArgumentNullException"> /// properties /// or /// mosaic /// or /// creator /// </exception> public MosaicDefinitionTransaction(NetworkType.Types networkType, int version, NetworkTime networkTime, Deadline deadline, ulong fee, MosaicProperties properties, MosaicId mosaic, MosaicLevy mosaicLevy, PublicAccount creator, string description, string signature, PublicAccount signer, TransactionInfo transactionInfo) { TransactionType = TransactionTypes.Types.MosaicDefinition; Version = version; NetworkTime = networkTime; Deadline = deadline; NetworkType = networkType; Fee = fee == 0 ? 150000 : fee; Properties = properties ?? throw new ArgumentNullException(nameof(properties)); Mosaic = mosaic ?? throw new ArgumentNullException(nameof(mosaic)); Creator = creator ?? throw new ArgumentNullException(nameof(creator)); Description = description; MosaicLevy = mosaicLevy; Signature = signature; Signer = signer; TransactionInfo = transactionInfo; }
internal override byte[] GenerateBytes() { var builder = new FlatBufferBuilder(1); var signer = ProvisionNamespaceTransactionBuffer.CreatePublicKeyVector(builder, GetSigner()); var sink = ProvisionNamespaceTransactionBuffer.CreateSinkAddressStringVector(builder, GetFeeSinkAddress()); var newPart = ProvisionNamespaceTransactionBuffer.CreateNewPartStringVector(builder, Encoding.UTF8.GetBytes(NewPart)); var parent = new VectorOffset(); if (Parent != null) { parent = ProvisionNamespaceTransactionBuffer.CreateParentStringVector(builder, Encoding.UTF8.GetBytes(Parent)); } ProvisionNamespaceTransactionBuffer.StartProvisionNamespaceTransaction(builder); ProvisionNamespaceTransactionBuffer.AddTransactionType(builder, TransactionType.GetValue()); ProvisionNamespaceTransactionBuffer.AddVersion(builder, BitConverter.ToInt16(new byte[] { ExtractVersion(Version), 0 }, 0)); ProvisionNamespaceTransactionBuffer.AddNetwork(builder, BitConverter.ToInt16(new byte[] { 0, NetworkType.GetNetwork() }, 0)); ProvisionNamespaceTransactionBuffer.AddTimestamp(builder, NetworkTime.EpochTimeInMilliSeconds()); ProvisionNamespaceTransactionBuffer.AddPublicKeyLen(builder, 32); ProvisionNamespaceTransactionBuffer.AddPublicKey(builder, signer); ProvisionNamespaceTransactionBuffer.AddFee(builder, Fee); ProvisionNamespaceTransactionBuffer.AddDeadline(builder, Deadline.Ticks); ProvisionNamespaceTransactionBuffer.AddSinkAddressLength(builder, 40); ProvisionNamespaceTransactionBuffer.AddSinkAddressString(builder, sink); ProvisionNamespaceTransactionBuffer.AddRentalFee(builder, Parent == null ? 0x5F5E100 : 0x989680); ProvisionNamespaceTransactionBuffer.AddNewPartLength(builder, Encoding.UTF8.GetBytes(NewPart).Length); ProvisionNamespaceTransactionBuffer.AddNewPartString(builder, newPart); ProvisionNamespaceTransactionBuffer.AddParentLength(builder, Parent == null ? 4294967295 : (uint)Encoding.UTF8.GetBytes(Parent).Length); // 14 if (Parent != null) { ProvisionNamespaceTransactionBuffer.AddParentString(builder, parent); } var codedTransfer = ProvisionNamespaceTransactionBuffer.EndProvisionNamespaceTransaction(builder); builder.Finish(codedTransfer.Value); var tempBytes = new ProvisionNamespaceSchema().Serialize(builder.SizedByteArray()); return(Parent == null?tempBytes.Take(tempBytes.Length - 1).ToArray() : tempBytes); }
protected override ProcessResult process(BodyLifetimeUpdateMessage msg) { var player = context.clients.SingleOrDefault(x => x.uid == msg.sourceUid); if (player == null) { Global.log.trace($"lifetime update was for body with unknown owner: {msg} (from {msg.sourceUid})"); return(ProcessResult.Fail); } var now = NetworkTime.time(); if (msg.exists) { // create // TODO: assert not exists var userBodies = context.scene.bodies[player]; if (userBodies.Any(x => x.id == msg.bodyId)) { Global.log.trace($"lifetime update (create) was for a body ({msg.bodyId}) that already exists: {msg} (from {msg.sourceUid})"); return(ProcessResult.Fail); } userBodies.Add(new NetScene.Body(msg.sourceUid, msg.time, now, msg.bodyId, msg.syncTag, new PackedVec2(0, 0), new PackedVec2(0, 0), 0, 0)); } else { // remove // TODO: assert exists var userBodies = context.scene.bodies[player]; var body = userBodies.SingleOrDefault(x => x.id == msg.bodyId); if (body == null) { Global.log.trace($"lifetime update (destroy) was for a body ({msg.bodyId}) that doesn't exist: {msg} (from {msg.sourceUid})"); return(ProcessResult.Fail); } userBodies.Remove(body); } return(ProcessResult.Relay); }
protected override void OnDataMessage(NetIncomingMessage msg) { // Update estimated local time NetworkTime.step = msg.ReadInt32(); NetworkTime.SetOffset(NetworkTime.step / 66.66666666f, rtt); Debug.Log("local: " + NetworkTime.gameTime); Debug.Log("remote: " + (NetworkTime.step / 66.66666666f)); // Read message flag switch (msg.ReadByte()) { case NetworkPeer.REMOTE_CALL_FLAG: NetworkRemoteCallReceiver.ReceiveRemoteCall(msg); break; case NetworkPeer.ACTOR_EVENT_FLAG: ReceiveObjectState(msg); break; } }
/// <summary> /// Generates the bytes. /// </summary> /// <returns>The transaction bytes.</returns> internal override byte[] GenerateBytes() { var builder = new FlatBufferBuilder(1); var signer = TransferTransactionBuffer.CreatePublicKeyVector(builder, GetSigner()); var recipientVector = TransferTransactionBuffer.CreateRecipientVector(builder, Encoding.UTF8.GetBytes(Address.Plain)); if (Message == null) { Message = EmptyMessage.Create(); } var messageBytePayload = Message.GetPayload(); var payload = MessageBuffer.CreatePayloadVector(builder, messageBytePayload); var messageBuff = new Offset <MessageBuffer> [1]; MessageBuffer.StartMessageBuffer(builder); if (messageBytePayload.Length > 0) { MessageBuffer.AddType(builder, Message.GetMessageType().GetValue()); } if (messageBytePayload.Length > 0) { MessageBuffer.AddPayloadLen(builder, messageBytePayload.Length); } if (messageBytePayload.Length > 0) { MessageBuffer.AddPayload(builder, payload); } messageBuff[0] = MessageBuffer.EndMessageBuffer(builder); var messageVector = TransferTransactionBuffer.CreateMessageVector(builder, messageBuff); var mosaics = new Offset <MosaicBuffer> [Mosaics.Count]; for (var index = 0; index < Mosaics.Count; index++) { var mosaic = Mosaics[index]; var namespaceVector = MosaicBuffer.CreateNamespaceStringVector(builder, Encoding.UTF8.GetBytes(mosaic.NamespaceName)); var mosaicNameVector = MosaicBuffer.CreateMosaicIdStringVector(builder, Encoding.UTF8.GetBytes(mosaic.MosaicName)); MosaicBuffer.StartMosaicBuffer(builder); var nsLen = Encoding.Default.GetBytes(mosaic.NamespaceName).Length; var msLen = Encoding.Default.GetBytes(mosaic.MosaicName).Length; MosaicBuffer.AddMosaicStructureLen(builder, 20 + nsLen + msLen); MosaicBuffer.AddMosaicIdStructureLen(builder, nsLen + msLen + 8); MosaicBuffer.AddNamespaceIdLen(builder, nsLen); MosaicBuffer.AddNamespaceString(builder, namespaceVector); MosaicBuffer.AddMosaicIdLen(builder, msLen); MosaicBuffer.AddMosaicIdString(builder, mosaicNameVector); MosaicBuffer.AddQuantity(builder, mosaic.Amount); mosaics[index] = MosaicBuffer.EndMosaicBuffer(builder); } var mosaicsVector = TransferTransactionBuffer.CreateMosaicsVector(builder, mosaics); TransferTransactionBuffer.StartTransferTransactionBuffer(builder); TransferTransactionBuffer.AddTransactionType(builder, TransactionType.GetValue()); TransferTransactionBuffer.AddVersion(builder, BitConverter.ToInt16(new byte[] { ExtractVersion(Version), 0 }, 0)); TransferTransactionBuffer.AddNetwork(builder, BitConverter.ToInt16(new byte[] { 0, NetworkType.GetNetwork() }, 0)); TransferTransactionBuffer.AddTimestamp(builder, NetworkTime.EpochTimeInMilliSeconds()); TransferTransactionBuffer.AddPublicKeyLen(builder, 32); TransferTransactionBuffer.AddPublicKey(builder, signer); TransferTransactionBuffer.AddFee(builder, Fee); TransferTransactionBuffer.AddDeadline(builder, Deadline.Ticks); TransferTransactionBuffer.AddRecipientLen(builder, 40); TransferTransactionBuffer.AddRecipient(builder, recipientVector); TransferTransactionBuffer.AddAmount(builder, 1000000); TransferTransactionBuffer.AddMessageFieldLen(builder, Message.GetLength() == 0 ? 0 : Message.GetLength() + 8); TransferTransactionBuffer.AddMessage(builder, messageVector); TransferTransactionBuffer.AddNoOfMosaics(builder, Mosaics.Count); TransferTransactionBuffer.AddMosaics(builder, mosaicsVector); var codedTransfer = TransferTransactionBuffer.EndTransferTransactionBuffer(builder); builder.Finish(codedTransfer.Value); return(new TransferTransactionSchema().Serialize(builder.SizedByteArray())); }
public virtual void reset() { time = NetworkTime.time(); }
internal override byte[] GenerateBytes() { var builder = new FlatBufferBuilder(1); var signer = MosaicDefinitionTransactionBuffer.CreatePublicKeyVector(builder, GetSigner()); var creatorVector = MosaicDefinitionTransactionBuffer.CreateCreatorPublicKeyVector(builder, Creator.PublicKey.FromHex()); var descriptionVector = MosaicDefinitionTransactionBuffer.CreateDescriptionStringVector(builder, Encoding.UTF8.GetBytes(Description)); var nammespaceVector = MosaicDefinitionTransactionBuffer.CreateNamespaceIdStringVector(builder, Encoding.UTF8.GetBytes(Mosaic.NamespaceId)); var mosaicNameVector = MosaicDefinitionTransactionBuffer.CreateMosaicNameStringVector(builder, Encoding.UTF8.GetBytes(Mosaic.Name)); var feeSinkVector = MosaicDefinitionTransactionBuffer.CreateFeeSinkAddressVector(builder, Encoding.UTF8.GetBytes(new Address("53e140b5947f104cabc2d6fe8baedbc30ef9a0609c717d9613de593ec2a266d3", NetworkType).Plain)); var definitionStructureLength = 60 + Encoding.UTF8.GetBytes(Mosaic.NamespaceId).Length + Encoding.UTF8.GetBytes(Mosaic.Name).Length + Encoding.UTF8.GetBytes(Description).Length; var propertiesOffset = new Offset <MosaicPropertyBuffer> [4]; foreach (var property in Properties.Properties) { var name = Encoding.Default.GetBytes(property.Item1); var value = Encoding.Default.GetBytes(property.Item2.ToLower()); definitionStructureLength += 12 + name.Length + value.Length; var nameVector = MosaicPropertyBuffer.CreatePropertyNameVector(builder, name); var valueVector = MosaicPropertyBuffer.CreatePropertyValueVector(builder, value); MosaicPropertyBuffer.StartMosaicPropertyBuffer(builder); MosaicPropertyBuffer.AddLengthOfPropertyStructure(builder, 8 + name.Length + value.Length); MosaicPropertyBuffer.AddLengthOfPropertyName(builder, name.Length); MosaicPropertyBuffer.AddPropertyName(builder, nameVector); MosaicPropertyBuffer.AddLengthOfPropertyValue(builder, value.Length); MosaicPropertyBuffer.AddPropertyValue(builder, valueVector); propertiesOffset[Properties.Properties.IndexOf(property)] = MosaicPropertyBuffer.EndMosaicPropertyBuffer(builder); } var mosaicPropertyVector = MosaicDefinitionTransactionBuffer.CreatePropertiesVector(builder, propertiesOffset); var levyVector = new Offset <MosaicLevyBuffer> [1]; if (MosaicLevy != null) { var mosaicName = Encoding.UTF8.GetBytes(MosaicLevy.Name); var namespaceName = Encoding.UTF8.GetBytes(MosaicLevy.NamespaceId); var recipient = Encoding.UTF8.GetBytes(MosaicLevy.Recipient.Plain); definitionStructureLength += 68 + namespaceName.Length + mosaicName.Length; var mosaicLevyNameVector = MosaicLevyBuffer.CreateMosaicNameStringVector(builder, mosaicName); var namespaceLevyNameVector = MosaicLevyBuffer.CreateNamespaceIdStringVector(builder, namespaceName); var recipientVector = MosaicLevyBuffer.CreateRecipientAddressVector(builder, recipient); MosaicLevyBuffer.StartMosaicLevyBuffer(builder); MosaicLevyBuffer.AddLengthOfLevyStructure(builder, 68 + namespaceName.Length + mosaicName.Length); MosaicLevyBuffer.AddFeeType(builder, MosaicLevy.FeeType); MosaicLevyBuffer.AddLengthOfRecipientAddress(builder, 40); MosaicLevyBuffer.AddRecipientAddress(builder, recipientVector); MosaicLevyBuffer.AddLengthOfMosaicIdStructure(builder, 8 + namespaceName.Length + mosaicName.Length); MosaicLevyBuffer.AddLengthOfMosaicNamespaceId(builder, namespaceName.Length); MosaicLevyBuffer.AddNamespaceIdString(builder, namespaceLevyNameVector); MosaicLevyBuffer.AddLengthMosaicNameString(builder, mosaicName.Length); MosaicLevyBuffer.AddMosaicNameString(builder, mosaicLevyNameVector); MosaicLevyBuffer.AddFeeQuantity(builder, MosaicLevy.Fee); levyVector[0] = MosaicLevyBuffer.EndMosaicLevyBuffer(builder); } else { MosaicLevyBuffer.StartMosaicLevyBuffer(builder); MosaicLevyBuffer.AddLengthOfLevyStructure(builder, 0); levyVector[0] = MosaicLevyBuffer.EndMosaicLevyBuffer(builder); } var levyVectorOffset = MosaicDefinitionTransactionBuffer.CreateMosaicLevyVector(builder, levyVector); MosaicDefinitionTransactionBuffer.StartMosaicDefinitionTransactionBuffer(builder); var namespaceBytes = Encoding.UTF8.GetBytes(Mosaic.NamespaceId); var mosaicNameBytes = Encoding.UTF8.GetBytes(Mosaic.Name); var descriptionBytes = Encoding.UTF8.GetBytes(Description); MosaicDefinitionTransactionBuffer.AddTransactionType(builder, TransactionType.GetValue()); MosaicDefinitionTransactionBuffer.AddVersion(builder, BitConverter.ToInt16(new byte[] { ExtractVersion(Version), 0 }, 0)); MosaicDefinitionTransactionBuffer.AddNetwork(builder, BitConverter.ToInt16(new byte[] { 0, NetworkType.GetNetwork() }, 0)); MosaicDefinitionTransactionBuffer.AddTimestamp(builder, NetworkTime.EpochTimeInMilliSeconds()); MosaicDefinitionTransactionBuffer.AddPublicKeyLen(builder, 32); MosaicDefinitionTransactionBuffer.AddPublicKey(builder, signer); MosaicDefinitionTransactionBuffer.AddFee(builder, Fee); MosaicDefinitionTransactionBuffer.AddDeadline(builder, Deadline.TimeStamp); MosaicDefinitionTransactionBuffer.AddMosaicDefinitionStructureLength(builder, definitionStructureLength); MosaicDefinitionTransactionBuffer.AddLengthCreatorPublicKey(builder, 32); MosaicDefinitionTransactionBuffer.AddCreatorPublicKey(builder, creatorVector); MosaicDefinitionTransactionBuffer.AddLengthOfMosaicIdStructure(builder, 8 + namespaceBytes.Length + mosaicNameBytes.Length); MosaicDefinitionTransactionBuffer.AddLengthOfNamespaceIdString(builder, namespaceBytes.Length); MosaicDefinitionTransactionBuffer.AddNamespaceIdString(builder, nammespaceVector); MosaicDefinitionTransactionBuffer.AddLengthOfMosaicNameString(builder, mosaicNameBytes.Length); MosaicDefinitionTransactionBuffer.AddMosaicNameString(builder, mosaicNameVector); MosaicDefinitionTransactionBuffer.AddLengthOfDescription(builder, descriptionBytes.Length); MosaicDefinitionTransactionBuffer.AddDescriptionString(builder, descriptionVector); MosaicDefinitionTransactionBuffer.AddNoOfProperties(builder, 4); MosaicDefinitionTransactionBuffer.AddProperties(builder, mosaicPropertyVector); MosaicDefinitionTransactionBuffer.AddMosaicLevy(builder, levyVectorOffset); MosaicDefinitionTransactionBuffer.AddLenFeeSinkAddress(builder, 40); MosaicDefinitionTransactionBuffer.AddFeeSinkAddress(builder, feeSinkVector); MosaicDefinitionTransactionBuffer.AddFeeQuantity(builder, 10000000); var transction = MosaicDefinitionTransactionBuffer.EndMosaicDefinitionTransactionBuffer(builder); builder.Finish(transction.Value); var temp = new MosaicDefinitionTransactionSchema().Serialize(builder.SizedByteArray()); return(MosaicLevy == null?temp.Take(temp.Length - 61).Concat(temp.Skip(temp.Length - 52)).ToArray() : temp); // hackery to remove default flatbuffers values when no levy is included. }
public void ResetTimeServerListQueryStartIndex() { // 유저용 응급 기능이다. BLACK_ADMIN으로 감싸지 말것. NetworkTime.ResetTimeServerListQueryStartIndex(); }
public void OnAfterDeserialize() { dateTime = NetworkTime.ParseExactUtc(_dateTime); }
protected override void BeforePump() { NetworkTime.Update(); NetworkTime.UpdateServerStep(); }
public void OnBeforeSerialize() { _dateTime = NetworkTime.ToString(dateTime); }
void Awake() { m_instance = this; }
private void processBodyUpdates(List <Entity> entities) { // handle queued updates in message queues // Global.log.trace($"== body syncer entity system - update() called, pending: {syncer.bodyUpdates.Count}"); var remoteBodyUpdates = 0U; var localBodyUpdates = 0U; while (syncer.incomingBodyUpdates.TryDequeue(out var bodyUpdate)) { bool isLocalBodyUpdate = bodyUpdate.sourceUid == syncer.uid; // update counters if (isLocalBodyUpdate) { localBodyUpdates++; } else { remoteBodyUpdates++; } #if DEBUG if (syncer.debug) { // dump update type var kind = isLocalBodyUpdate ? "LOCAL" : "REMOTE"; } #endif if (isLocalBodyUpdate) { // this is for resolving desyncs from an authoritative update // TODO: confirm local bodies with local body updates // continue; } var timeNow = NetworkTime.time(); var timeOffsetMs = timeNow - bodyUpdate.time; if (timeOffsetMs < 0) { // we're getting updates from the future? log in relative time // Global.log.warn( // $"received an update {timeOffsetMs}ms in the future (current: {NetworkTime.timeSinceStart})," + // $" (frame {bodyUpdate.time - NetworkTime.startTime}). perhaps system clocks are out of sync?"); } switch (bodyUpdate) { case BodyKinUpdate kinUpdate: { // find corresponding body var body = findBodyById(entities, bodyUpdate.bodyId); if (body == null) { // we received an update of something we don't know of Global.log.warn( $"received a kinematic update for an unknown body (id {bodyUpdate.bodyId})"); break; } if (isLocalBodyUpdate) { // we do a sanity check to make sure our local entity isn't desynced var wasDesynced = resolveLocalDesync(body, kinUpdate); if (wasDesynced) { Global.log.trace( $"resolved desync for body {body}"); } } else if (body.interpolationType == SyncBody.InterpolationType.None) { // if no interpolation, then immediately apply the update if (body.syncedFields.HasFlag(SyncBody.InterpolatedFields.Pos)) { body.pos = kinUpdate.pos.unpack(); } if (body.syncedFields.HasFlag(SyncBody.InterpolatedFields.Vel)) { body.velocity = kinUpdate.vel.unpack(); } if (body.syncedFields.HasFlag(SyncBody.InterpolatedFields.Angle)) { body.angle = kinUpdate.angle; } if (body.syncedFields.HasFlag(SyncBody.InterpolatedFields.AngularVel)) { body.angularVelocity = kinUpdate.angularVelocity; } } else { // store in cache to be used by interpolator GAssert.Ensure(cachedKinStates.ContainsKey(body)); cachedKinStates[body].stateBuf .enqueue(new KinStateCache.StateFrame(kinUpdate, timeNow)); } break; } case BodyLifetimeUpdate lifetimeUpdate: { // we can ignore local lifetime updates if (isLocalBodyUpdate) { break; } if (!lifetimeUpdate.exists) { // the body is supposed to be dead, destroy it var body = findBodyById(entities, bodyUpdate.bodyId); if (body == null) { Global.log.warn( $"received a lifetime update to destroy an unknown body (id {bodyUpdate.bodyId})"); break; } beforeSyncedEntityDestroyed?.Invoke(body.Entity, body); lifetimeUpdate.applyTo(body); // remove snapshot cache cachedKinStates.Remove(body); } else { // let's create our echo entity var syncEntityName = $"{SYNC_PREFIX}_{bodyUpdate.bodyId}"; var syncNt = createSyncedEntity(syncEntityName, bodyUpdate.syncTag); if (syncNt == null) { Global.log.err( $"failed to create synced entity {syncEntityName} with tag {bodyUpdate.syncTag}"); continue; } var body = syncNt.GetComponent <SyncBody>(); bodyUpdate.applyTo(body); // this is a new body, immediately apply our first update body.Entity = syncNt; body.bodyId = bodyUpdate.bodyId; body.owner = bodyUpdate.sourceUid; entities.Add(syncNt); // update cache cachedKinStates[body] = new KinStateCache(interpCacheSize); } break; } } } #if DEBUG if (syncer.debug) { // log the count of body updates that happened this frame var totalBodyUpdates = localBodyUpdates + remoteBodyUpdates; if (totalBodyUpdates > 0) { Global.log.trace( $"processed ({localBodyUpdates} local) and ({remoteBodyUpdates} remote) body updates this frame"); // if (totalBodyUpdates >= syncer.incomingBodyUpdates.capacity) { // Global.log.trace( // $"body update ring buffer is full ({syncer.incomingBodyUpdates.capacity}), some updates may have been dropped"); // } } } #endif }
/// <summary> /// step all interpolations using cached kinematic states /// </summary> private void updateInterpolations() { foreach (var cachedKinState in cachedKinStates) { var body = cachedKinState.Key; var cache = cachedKinState.Value; var interpLag = cache.stateBuf.capacity - 1; if (cache.stateBuf.Count < cache.stateBuf.capacity) { continue; } var update0 = cache.stateBuf.peekAt(0); // start var update1 = cache.stateBuf.peekAt(1); // end // calculate time discrepancy var timeNow = NetworkTime.time(); // time between stored frames var timeDiff = (update1.data.time - update0.data.time) / 1000f; // time since we received the last frame var refRecvAt = update1.receivedAt; // time the end update was received var frameTime = 1f / syncer.netUps; // expected timestep for each frame var rawTimeSince = (timeNow - refRecvAt) / 1000f; // time since receiving the end update var relTimeSince = rawTimeSince - frameTime * (interpLag - 1); // relative time (adjusting for interpolation lag) // if our interpolation window exceeds the time window we received, skip if (relTimeSince > timeDiff) { continue; } var interpT = (relTimeSince / timeDiff); // progress in interpolation if (timeDiff == 0) { interpT = 1; // protect from NaN } #if DEBUG if (syncer.debug) { Global.log.trace( $"interpolate T: {interpT} (rawsince={rawTimeSince}, relsince={relTimeSince}, diff={timeDiff}"); } #endif // // just apply directly // update1.applyTo(body); switch (body.interpolationType) { case SyncBody.InterpolationType.Linear: if (body.syncedFields.HasFlag(SyncBody.InterpolatedFields.Pos)) { body.pos = InterpolationUtil.lerp(update0.data.pos.unpack(), update1.data.pos.unpack(), interpT); } if (body.syncedFields.HasFlag(SyncBody.InterpolatedFields.Vel)) { body.velocity = InterpolationUtil.lerp(update0.data.vel.unpack(), update1.data.vel.unpack(), interpT); } if (body.syncedFields.HasFlag(SyncBody.InterpolatedFields.Angle)) { body.angle = InterpolationUtil.lerp(update0.data.angle, update1.data.angle, interpT); } if (body.syncedFields.HasFlag(SyncBody.InterpolatedFields.AngularVel)) { body.angularVelocity = InterpolationUtil.lerp(update0.data.angularVelocity, update1.data.angularVelocity, interpT); } break; case SyncBody.InterpolationType.Hermite: if (body.syncedFields.HasFlag(SyncBody.InterpolatedFields.Pos)) { body.pos = InterpolationUtil.hermite(update0.data.pos.unpack(), update1.data.pos.unpack(), update0.data.vel.unpack() * Time.DeltaTime, update1.data.vel.unpack() * Time.DeltaTime, interpT); } if (body.syncedFields.HasFlag(SyncBody.InterpolatedFields.Vel)) { body.velocity = InterpolationUtil.lerp(update0.data.vel.unpack(), update1.data.vel.unpack(), interpT); } if (body.syncedFields.HasFlag(SyncBody.InterpolatedFields.Angle)) { body.angle = InterpolationUtil.hermite(update0.data.angle, update1.data.angle, update0.data.angularVelocity * Time.DeltaTime, update1.data.angularVelocity * Time.DeltaTime, interpT); } if (body.syncedFields.HasFlag(SyncBody.InterpolatedFields.AngularVel)) { body.angularVelocity = InterpolationUtil.lerp(update0.data.angularVelocity, update1.data.angularVelocity, interpT); } break; } } }