/// <summary>
    /// Overloading that shift the precisions value of instance from right to left.
    /// </summary>
    /// <param name="instance"> Instance of object.</param>
    /// <param name="precisions"> Precisions value.</param>
    /// <returns> StringShift object with shifted value.</returns>
    public static StringShift operator >>(StringShift instance, int precisions)
    {
   
      string firstPart = instance.Value.Substring(precisions, instance.Value.Length - precisions);

      string secondPart = instance.Value.Substring(0, precisions);
    
      instance = new StringShift(firstPart + secondPart);

      return instance;
    }
Exemple #2
0
        public void ShiftFromLeftToRightEdge()
        {
            //Arrange
            StringShift actual    = new StringShift("Microsoft");
            int         precision = 9;

            //Act
            actual = (actual << precision);

            //Assert
            Assert.AreEqual(actual.Value, "Microsoft", "Error in shifting from left to right.");
        }
Exemple #3
0
        public void ShiftFromRightToLeft()
        {
            //Arrange
            StringShift actual    = new StringShift("Microsoft");
            int         precision = 2;

            //Act
            actual = (actual << precision);

            //Assert
            Assert.AreEqual(actual.Value, "ftMicroso", "Error in shifting from right to left.");
        }
Exemple #4
0
        public void EqualTestForEqualObject()
        {
            //Arrange
            StringShift first  = new StringShift("Microsoft");
            StringShift second = new StringShift("Microsoft");

            //Act
            bool isEqual = first == second;

            //Assert
            Assert.AreEqual(isEqual, true, "Error in equal overloading.");
        }
Exemple #5
0
        public static void OPCode(Decode decode)
        {
            try
            {
                Systems sys = (Systems)decode.Packet;
                sys.PacketInformation = decode;
                PacketReader Reader = new PacketReader(sys.PacketInformation.buffer);
                LogDebug.Show("Opcode: {0}", decode.opcode);
                Opcode opc = (Opcode)decode.opcode;
                switch (opc)
                {
                case Opcode._MSG_LOGIN:
                {
                    string username_shift = Reader.String(32);
                    string password_md5   = Reader.String(32);
                    Reader.Skip(4);
                    string client_mac = Reader.String(32);
                    Reader.Skip(32);
                    uint        unk3     = Reader.UInt32();
                    StringShift shift    = new StringShift();
                    string      username = shift.Parser(username_shift);
                    LogDebug.Show("username: {0}", username);
                    LogDebug.Show("password_md5: {0}", password_md5);
                    LogDebug.Show("Mac: {0}", client_mac);
                    LogDebug.Show("unk3: {0}", unk3);
                    int res = UserLogin(username, password_md5, client_mac);
                    if (res == (int)AuthenticationStatus.OK)
                    {
                        sys.client.SendC(NewCharacterPacket());
                    }
                    else if (res == (int)AuthenticationStatus.BANNED)
                    {
                        sys.client.SendC(UserFail(0xF0, Reason.BANNED));
                    }
                    else
                    {
                        sys.client.SendC(UserFail(0xF0, Reason.AUTH_FAILED));
                    }
                }
                break;

                default:
                    LogConsole.Show("Default Opcode: {0:X} - {1}", decode.opcode, opc);
                    LogDebug.HexDump(sys.PacketInformation.buffer, 16, true, false);
                    break;
                }
            }
            catch (Exception)
            {
            }
        }
Exemple #6
0
        private static void StringShiftTest()
        {
            string input = Console.ReadLine();

            byte[] arr = System.Text.Encoding.UTF8.GetBytes(input);

            string      inchar      = Console.ReadLine();
            int         shift       = Convert.ToInt32(inchar);
            StringShift stringShift = new StringShift();

            stringShift.LeftShiftM(ref arr, arr.Length, shift);

            Console.WriteLine("output: " + Encoding.UTF8.GetString(arr));
        }
Exemple #7
0
        public void ShiftFromLeftToRightThenFromRightToLeft()
        {
            //Arrange
            StringShift actual         = new StringShift("Microsoft");
            int         precisionRight = 4;
            int         precisionLeft  = 2;

            //Act
            actual = (actual << precisionRight);
            actual = (actual >> precisionLeft);

            //Assert
            Assert.AreEqual(actual.Value, "ftMicroso", "Error in shifting.");
        }