private void SetUserPins(Octet pinState) { UserPin1Annunciator.Mute = !pinState[0]; UserPin2Annunciator.Mute = !pinState[1]; UserPin3Annunciator.Mute = !pinState[2]; UserPin4Annunciator.Mute = !pinState[3]; }
public RoleList(Octet data) { _packetLength = data.UnMarshalByte(); _userId = data.UnMarshalInt32(); _unknown1 = data.UnMarshalInt32(); _unknown2 = data.UnMarshalInt32(); }
public CMKey(Octet data) { _packetLength = data.UnMarshalByte(); _keyLength = data.UnMarshalByte(); _key = data.UnMarshalBytes(_keyLength); _unknown = data.UnMarshalByte(); }
public void SetUserOutputPins(Octet newState) { Log.Info() .Message($"User output pins set to {newState}") .Write(); decoratedState.SetUserOutputPins(newState); }
private byte[] _hash; // Hashed password public Login(Octet data) { _packetLength = data.UnMarshalByte(); _usernameLength = data.UnMarshalByte(); _username = Encoding.ASCII.GetString(data.UnMarshalBytes(_usernameLength)); _hashLength = data.UnMarshalByte(); _hash = data.UnMarshalBytes(_hashLength); }
void WriteOctet(Octet data) { // The 74HCT595 shift register accepts the most significant bit first. // SO whatever is shifted in forst ends up on output Q7/QH/Pin 7. for (int i = 7; i >= 0; i--) { WriteOneBit(data[i]); } serialClockPositiveEdge.Low(); // Leave the clock low }
public override byte[] GetBytes() { Octet octet = new Octet(); octet.Marshal(_packetId); octet.Marshal(_packetLength); octet.Marshal(_keyLength); octet.Marshal(_key); octet.Marshal(_unknown); return(octet.GetBytes()); }
/// <summary> /// Writes the specified data pattern and latches it onto the output pins. /// The operation is thread-safe. /// </summary> /// <param name="data"> /// The bit pattern to be written. /// Octet[0] corresponds to output Q0 and Octet[7] corresponds to output Q7. /// </param> public void Write(Octet data) { lock (syncObject) // prevent race condition { latchPositiveEdge.Low(); WriteOctet(data); latchPositiveEdge.High(); outputs = data; outputEnableActiveLow.Low(); } }
private IPv4 GetEnteredIP() { // Lấy các Octet đã nhập trên Form Octet firstOctet = new Octet((int)this.num_firstOctet.Value); Octet secondOctet = new Octet((int)this.num_secondOctet.Value); Octet thirdOctet = new Octet((int)this.num_thirdOctet.Value); Octet fourthOctet = new Octet((int)this.num_fourthOctet.Value); int suffix = (int)this.num_suffix.Value; return(new IPv4(firstOctet, secondOctet, thirdOctet, fourthOctet, suffix)); }
public static AmqpTestFramework WithDefaultProtocolHeaderNegotiation(this AmqpTestFramework testFramework) { return(testFramework .On <ProtocolHeader>((connectionId, frame) => testFramework.Send(connectionId, new MethodFrame <Connection.Start>(frame.Channel, new Connection.Start { VersionMajor = Octet.From((byte)frame.Message.Version.Major), VersionMinor = Octet.From((byte)frame.Message.Version.Minor), Locales = Longstr.From(Encoding.UTF8.GetBytes("en_US")), Mechanisms = Longstr.From(Encoding.UTF8.GetBytes("PLAIN")), })))); }
public override byte[] GetBytes() { Octet octet = new Octet(); octet.Marshal(_packetId); octet.Marshal(_packetLength); octet.Marshal(_errorCode); octet.Marshal(_msgLength); octet.Marshal(_msg); octet.Marshal(_unknown2); return(octet.GetBytes()); }
public override byte[] GetBytes() { Octet data = new Octet(); data.Marshal(_packetId); data.MarshalCuint(_packetLength); data.Marshal(_unknown1); data.Marshal(_slot); data.Marshal(_userId); data.Marshal(_unknown2); data.Marshal(_charData); return(data.GetBytes()); }
public override byte[] GetBytes() { Octet data = new Octet(); data.Marshal(_packetId); data.Marshal(_packetLength); data.Marshal(_userId); data.Marshal(_unknown); data.Marshal(_lastLoginTimestamp); data.Marshal(_lastLoginIPAddr); data.Marshal(_currentIPAddr); return(data.GetBytes()); }
private void ClearPacketHandler(byte[] recvbuf, int buflen) { if (buflen == 0) { Console.WriteLine("Client sent empty packet. Disconnecting..."); IsConnected = false; return; } byte[] arrData = new byte[buflen]; Array.Copy(recvbuf, arrData, buflen); Octet data = new Octet(arrData); byte packetid = data.UnMarshalByte(); switch (packetid) { case (byte)LinkServerPacket.LoginRequest: Login loginPacket = new Login(data); _username = loginPacket.Username; _passwordHash = loginPacket.Hash; Console.WriteLine("User {0} is trying to login", _username); string passHash = BitConverter.ToString(_passwordHash).Replace("-", string.Empty); string dbHashString = _database.GetUserPasswd(_username, passHash); if (dbHashString.Equals(passHash)) { SMKey smkeyPacket = new SMKey(); SendReply(smkeyPacket.GetBytes()); _smKey = smkeyPacket.GetSMKey(); HMACMD5 hmacmd5 = new HMACMD5(Encoding.ASCII.GetBytes(_username)); byte[] array = new byte[_passwordHash.Length + _smKey.Length]; _passwordHash.CopyTo(array, 0); _smKey.CopyTo(array, _passwordHash.Length); byte[] RC4_C2SKEY = hmacmd5.ComputeHash(array); C2S_Crypto = new RC4(RC4_C2SKEY); _isEncrypted = true; } else { ErrorInfo errorPacket = new ErrorInfo(2); SendReply(errorPacket.GetBytes()); Console.WriteLine("Login error!"); } break; default: IsConnected = false; Console.WriteLine("Unknown packet. Disconnecting..."); Console.WriteLine(BitConverter.ToString(recvbuf, 0, buflen)); break; } }
private void EncryptedPacketHandler(byte[] recvbuf, int buflen) { if (buflen == 0) { Console.WriteLine("Client sent empty packet. Disconnecting..."); IsConnected = false; return; } byte[] arrData = new byte[buflen]; Array.Copy(recvbuf, arrData, buflen); C2S_Crypto.decrypt(arrData); Octet data = new Octet(arrData); byte packetid = data.UnMarshalByte(); switch (packetid) { case (byte)LinkServerPacket.KeyExchange: CMKey smkeyPacket = new CMKey(data); _cmKey = smkeyPacket.GetCMKey(); HMACMD5 hmacmd5 = new HMACMD5(Encoding.ASCII.GetBytes(_username)); byte[] array = new byte[_passwordHash.Length + _cmKey.Length]; _passwordHash.CopyTo(array, 0); _cmKey.CopyTo(array, _passwordHash.Length); byte[] RC4_S2CKEY = hmacmd5.ComputeHash(array); S2C_Crypto = new RC4(RC4_S2CKEY); _isCompressed = true; _userId = _database.GetIdByUsername(_username); OnlineAnnounce announcePacket = new OnlineAnnounce(_userId); SendReply(announcePacket.GetBytes()); break; case (byte)LinkServerPacket.RoleList: RoleList roleListPacket = new RoleList(data); Console.WriteLine("TODO: Get Roles by ID"); LastLoginInfo loginInfo = new LastLoginInfo(_userId); SendReply(loginInfo.GetBytes()); //Console.WriteLine("TODO: Iterate over roles and send them"); //// Finally... //RoleListRe finalRole = new RoleListRe(-1, _userId); //SendReply(finalRole.GetBytes()); break; default: IsConnected = false; Console.WriteLine("Unknown packet. Disconnecting..."); Console.WriteLine(BitConverter.ToString(arrData, 0, arrData.Length)); break; } }
public override byte[] GetBytes() { Octet data = new Octet(); data.Marshal(_packetId); data.Marshal(_packetLength); data.Marshal(_userId); data.Marshal(0); data.Marshal(0); data.Marshal((byte)0x03); data.Marshal(0); data.Marshal(-1); data.Marshal(new byte[8]); return(data.GetBytes()); }
public static char[] ReturnRandomCharArray(int ArrayLength) { List <char> RandomArray = new List <char>(); while (RandomArray.Count < ArrayLength) { long Now = DateTime.Now.ToBinary(); foreach (byte Octet in BitConverter.GetBytes(Now)) { RandomArray.AddRange(Octet.ToString().ToCharArray()); } } return(RandomArray.ToArray()); }
public void UpdateTextsData(NetworkMeasure data) { tbMainDisplay.Text = $"{data.TotalMonth.ToString(3)} / {data.TrafficMaxLimit}"; double percents = Math.Round(data.TotalMonth / data.TrafficMaxLimit * 100, 4); tbPercents.Text = $"{percents} %"; progressBar.Value = percents; if (data.DownloadRate > Octet.FromMega(1)) { tbNetUse.Text = "Un téléchargement est certainement en cours !"; } else { tbNetUse.Text = "Utilisation normale de la bande passante."; } }
public override byte[] GetBytes() { Octet octet = new Octet(); octet.Marshal(_packetId); octet.Marshal(_packetLength); octet.Marshal(_keyLength); octet.Marshal(_serverLoad); octet.Marshal(_unknown1); octet.Marshal(_serverFlags); octet.Marshal(_unknown2); octet.Marshal(_key); octet.Marshal(_gameVersion); octet.Marshal(_authMethod); octet.Marshal(_clientSignatureLength); octet.Marshal(_clientSignature); octet.Marshal(_expMultiplier); return(octet.GetBytes()); }
/* * We override OnCompleted so that we have a chance to extract the new user pins * value from the response. */ protected override void OnCompleted() { if (Response.Any()) { var responseString = Response.Single(); var status = factory.FromStatusPacket(responseString); UserPins = status.UserPins; } /* * it is super important that DeviceTransaction.OnCompleted gets called! * This is what ultimately marks the transaction as completed. * Note the call sequence of these virtual methods: * SetUserPinsTransaction.OnCompleted() * └> StatusTransaction.OnCompleted * └> DeviceTransaction.OnCompleted() */ base.OnCompleted(); }
/// <summary> /// Converts a string of address to octet array. /// </summary> /// <param name="addr">A string of address look like 192.168.0.192</param> /// <returns></returns> public static Octet[] ToOctet(string addr) { Octet[] octet = new Octet[4]; for (int i = 0; i < octet.Length; i++) { int index = addr.IndexOf('.'); if (index != -1) { octet[i] = new Octet(int.Parse(addr.Substring(0, index))); addr = addr.Substring(index + 1); } else { octet[i] = new Octet(int.Parse(addr)); addr = null; } } return octet; }
public void SetUserOutputPins(Octet newState) { throw uninitialized; }
/// <inheritdoc /> public SetUserPinTransaction(Octet pins) : base(string.Format(Constants.CmdSetUserPins, (byte)pins)) { }
public override string ToString() { return(Octet.ToString("X2")); }
public void SetUserOutputPins(Octet newState) { channel.Send(string.Format(Constants.CmdSetUserPins, (byte)newState)); }
/// <summary> /// Initialize address with default value. /// </summary> public NetworkAddress() { for (int i = 0; i < _octet.Length; i++) _octet[i] = new Octet(); }
/// <summary> /// Converts a 32-bit binary string to octet array /// </summary> /// <param name="binaryString">32-bit binary string.</param> /// <returns></returns> public static Octet[] ToOctetFromBinaryString(string binaryString) { Octet[] octet = new Octet[4]; int i = 0; for (int index = 0; index < octet.Length; index++) { octet[index] = new Octet(binaryString.Substring(i, 8)); i += 8; } return octet; }
/// <summary> /// Converts decimal values of octets to octet array. /// </summary> /// <param name="octet1">The first octet.</param> /// <param name="octet2">The second octet.</param> /// <param name="octet3">The third octet.</param> /// <param name="octet4">The fourth octet.</param> /// <returns></returns> public static Octet[] ToOctet(int octet1, int octet2, int octet3, int octet4) { Octet[] octet = new Octet[4]; octet[0] = new Octet(octet1); octet[1] = new Octet(octet2); octet[2] = new Octet(octet3); octet[3] = new Octet(octet4); return octet; }
public void SetUserOutputPins(Octet newState) { UserPins = newState; CurrentState.SetUserOutputPins(newState); }
public virtual void SetUserOutputPins(Octet newState) { }
public void UpdateTextsData(NetworkMeasure newData, NetworkMeasure oldData) { //text tbDownTotal.Text = newData.CurrentDownload; tbUpTotal.Text = newData.CurrentUpload; tbDownTraffic.Text = newData.DownloadRate; tbUpTraffic.Text = newData.UploadRate; tbDownEv.Text = newData.CurrentDownload - oldData.CurrentDownload; tbUpEv.Text = newData.CurrentUpload - oldData.CurrentUpload; tbHeaderEv.Text = "Evolution depuis " + oldData.DateTime.ToString("T"); //start day lblStartDay.Content = newData.StartDay; //Days int daysInMonth = GetDaysBetween(DateTime.Now, DateTime.Now.AddMonths(1)); int startDay = newData.StartDay; DateTime now = DateTime.Now; int remainingDays; if (now.Day < startDay) { remainingDays = startDay - now.Day; } else { remainingDays = DateTime.DaysInMonth(now.Year, now.Month) - now.Day + startDay; } //At the start, the newData per day we have Octet newDataPerDay = newData.TrafficMaxLimit / daysInMonth; //Now, the newData remaining per remaining day Octet newDataRemainPerDay = (newData.TrafficMaxLimit - newData.TotalMonth) / remainingDays; this.lblDataPerDayStart.Content = newDataPerDay.ToString(); this.lblDataPerDayRemain.Content = newDataRemainPerDay.ToString(); if (newDataPerDay > newDataRemainPerDay) { this.lblDataPerDayRemain.Foreground = App.colorHighWarning; } else { this.lblDataPerDayRemain.Foreground = App.colorGood; } //colorization if (newData.DownloadRate > Octet.FromMega(5)) { this.tbDownTraffic.Foreground = App.colorHighWarning; } else if (newData.DownloadRate > Octet.FromMega(1)) { this.tbDownTraffic.Foreground = App.colorWarning; } else { this.tbDownTraffic.Foreground = App.colorNormalBlack; } if (newData.UploadRate > Octet.FromMega(2)) { this.tbUpTraffic.Foreground = App.colorHighWarning; } else if (newData.UploadRate > Octet.FromKilo(500)) { this.tbUpTraffic.Foreground = App.colorWarning; } else { this.tbUpTraffic.Foreground = App.colorNormalBlack; } int GetDaysBetween(DateTime start, DateTime stop) => (int)(stop - start).TotalDays; }
public override void SetUserOutputPins(Octet newState) { base.SetUserOutputPins(newState); machine.ControllerActions.SetUserOutputPins(newState); }