Ejemplo n.º 1
0
 public CommandHandler()
 {
     this.au = new ArrayUtils();
     this.su = new StringUtils();
     this.nu = new NumericalUtils();
     this.pu = new PacketsUtils();
 }
Ejemplo n.º 2
0
        private int twofishEncrypt()
        {
            ArrayUtils au = new ArrayUtils();
            byte[] key = { 0xa4,0x46,0xdc,0x73,0x25,0x08,0xee,0xb7,0x6c,0x9e,0xb4,0x4a,0xb8,0xe7,0x11,0x03 };
            byte[] iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            byte[] plainText = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
            byte[] knownResult = {0xba,0x05,0xf5,0x6e,0x86,0x5f,0xb6,0xc9,0xb2,0x1d,0xe1,0x00,0xb6,0xec,0x46,0xe9};
            byte[] result = new byte[16];
            MxoTwofish tf = new MxoTwofish();
            tf.setIV(iv);
            tf.setKey(key);
            tf.encrypt(plainText,result);

            if (!ArrayUtils.equal(knownResult, result)){
                Output.Write("Failed\n");
                Output.WriteLine(StringUtils.bytesToString(knownResult));
                Output.WriteLine(StringUtils.bytesToString(result));
                return 0;
            }
            Output.Write("OK\n");
            return 1;
        }
Ejemplo n.º 3
0
        public void processObjectStatic(ref byte[] packet)
        {
            byte[] objectID = new byte[4];
            byte[] sectorID = new byte[2];
            ArrayUtils.copyTo(packet, 0, objectID, 0, 4);
            ArrayUtils.copyTo(objectID, 2, sectorID, 0, 2);


            UInt32 numericObjectId = NumericalUtils.ByteArrayToUint32(objectID, 1);

            // Ok sector Bytes are something like 30 39 (reversed but the result must be 39 03)
            UInt16 numericSectorId = NumericalUtils.ByteArrayToUint16(sectorID, 1);
            // strip out object id
            string id = StringUtils.bytesToString_NS(objectID);


            // get the type
            byte[] objectType = new byte[1];
            ArrayUtils.copy(packet, 4, objectType, 0, 1);
            int objectTypeID = packet[4];

            DataLoader        objectLoader = DataLoader.getInstance();
            StaticWorldObject objectValues = objectLoader.getObjectValues(NumericalUtils.ByteArrayToUint32(objectID, 1));


            // create a new System message but fill it in the switch block
            ServerPackets pak = new ServerPackets();

            switch (objectTypeID)
            {
            // Case 03 is not only a staticWorldObject ...
            case (int)objectTypesStatic.DOOR:

                Output.writeToLogForConsole("[OI HELPER] INTERACT WITH DOOR | Object ID :" + id + " Sector ID : " + numericSectorId);

                // just a test

                if (objectValues != null && objectValues.type != null)
                {
                    GameObjectItem item = objectLoader.getGameObjectItemById(NumericalUtils.ByteArrayToUint16(objectValues.type, 1));
                    //Store.currentClient.messageQueue.addRpcMessage(PacketsUtils.createSystemMessage("[OI HELPER] Door StrType: !" + item.getName() + " with Type ID " + StringUtils.bytesToString_NS(objectValues.type), Store.currentClient));
                    this.processObjectInteraction(objectValues, item);
                }

                break;

            case (int)objectTypesStatic.HARDLINE_SYNC:

                pak.sendSystemChatMessage(Store.currentClient, "Hardline Interaction(not done yet)!", "MODAL");
                break;

            case (int)objectTypesStatic.HARDLINE_UPLOAD:
                Output.writeToLogForConsole("[OBJECT HELPER] Upload Hardline will be used for combat tests");
                Store.currentClient.playerData.lastClickedObjectId = numericObjectId;
                new TestUnitHandler().processTestCombat(ref packet);
                break;

            case (int)objectTypesStatic.HARDLINE_LAEXIT:
                // Exit LA
                pak.sendSystemChatMessage(Store.currentClient, "Exit to LA Dialog should popup", "MODAL");
                new TeleportHandler().processHardlineExitRequest();
                break;

            case (int)objectTypesStatic.HUMAN_NPC:
                pak.sendSystemChatMessage(Store.currentClient, "Open Vendor Dialog for Object ID" + StringUtils.bytesToString_NS(objectID), "MODAL");
                this.processVendorOpen(ref objectID);
                break;

            case (int)objectTypesStatic.COLLECTOR:
                pak.sendSystemChatMessage(Store.currentClient, "Collector Interaction (not done yet)!", "MODAL");
                break;

            case (int)objectTypesStatic.ENVIROMENT:
                GameObjectItem enviromentItem   = objectLoader.getGameObjectItemById(NumericalUtils.ByteArrayToUint16(objectValues.type, 1));
                UInt16         enviromentTypeID = NumericalUtils.ByteArrayToUint16(objectValues.type, 1);
                switch (enviromentTypeID)
                {
                case 6952:
                    // ToDo: implement Elevator Panel
                    pak.sendElevatorPanel(Store.currentClient, objectValues);
                    break;

                default:
                    pak.sendSystemChatMessage(Store.currentClient, "Enviroment Type ID " + objectValues.type + " name " + enviromentItem.getName(), "MODAL");
                    break;
                }
                pak.sendSystemChatMessage(Store.currentClient, "Enviroment Type ID " + objectValues.type + " name " + enviromentItem.getName(), "MODAL");
                break;


            default:
                pak.sendSystemChatMessage(Store.currentClient, "[OI HELPER] Unknown Object Type : " + objectTypeID.ToString() + "| Object ID :" + id, "MODAL");
                break;
            }
        }
Ejemplo n.º 4
0
        public void certConnectRequest(byte[] packet, NetworkStream client)
        {
            int firstnum  = BitConverter.ToInt16(packet, 3);
            int authstart = BitConverter.ToInt16(packet, 5);

            if (firstnum != 3)
            {
                //showMarginDebug("FirstNum is not 3, it is" + firstnum);
            }

            if (authstart != 310)
            {
                //showMarginDebug("AuthStart is not 0x3601");
            }



            // Get the Signature
            byte[] signature = new byte[128];

            ArrayUtils.copy(packet, 7, signature, 0, 128);

            // TODO MD5 Signature and verify it with RSA to check if everything is correct

            // Get the signedData
            byte[] signedData = new byte[packet.Length - 135];
            ArrayUtils.copy(packet, 135, signedData, 0, packet.Length - 135);
            int userid = BitConverter.ToInt32(signedData, 1);

            this.userID = (UInt32)userid;


            // Stripout Exponent and Modulus

            byte[] exponent = { 0x00, 0x00, 0x00, 0x11 };
            byte[] modulus  = new byte[96];

            ArrayUtils.copy(signedData, 82, modulus, 0, 96);

            // Init our encryptor with users modulus and exponent
            marginEncr.setUserPubKey(exponent, modulus);
            // build the final packet, it consists of 1 byte 0x00 + twofish key for world and margin + encryptIV

            byte[] encryptMeResponse = new byte[33];
            encryptMeResponse[0] = 0x00;

            ArrayUtils.copy(marginEncr.getTFKey(), 0, encryptMeResponse, 1, 16);
            ArrayUtils.copy(marginEncr.getIV(), 0, encryptMeResponse, 17, 16);

            byte[] encryptedShit = { };
            encryptedShit = marginEncr.encryptUsersPublic(encryptMeResponse);

            byte[] blobSize = NumericalUtils.uint16ToByteArray((UInt16)encryptedShit.Length, 1);

            byte[] header = { 0x02, 0x03, 0x00 };
            // Write final packet

            DynamicArray din = new DynamicArray();

            din.append(header);
            din.append(blobSize);
            din.append(encryptedShit);

            sendTCPVariableLenPacket(din.getBytes(), client);
        }
Ejemplo n.º 5
0
        private void loadCharacter(byte[] packet, NetworkStream client, UInt32 theCharId)
        {
            byte[] charIDB = new byte[4];

            if (theCharId == 0)
            {
                ArrayUtils.copy(packet, 3, charIDB, 0, 4); //Offset for charID is 3 in request
                uint charId = (uint)NumericalUtils.ByteArrayToUint32(charIDB, 1);
                // Remove current instances for this character
                if (Store.margin.isAnotherClientActive(charId) == true)
                {
                    CharacterAlreadyInUseReply(client);
                    return;
                }
                this.newCharID = charId;
            }


            charIDB = NumericalUtils.uint32ToByteArray(this.newCharID, 1);

            //New harcoded sessionID is: ac 53 02 00
            //Old is: 28 A9 02 00
            string [] marginValues = new string[0x0e];
            marginValues[8]   = "000b10001e000700000001000800000000000a00000003000d00000000001c0000000100";
            marginValues[0xc] = "000e10000000";
            marginValues[0xd] = "010f10000000";

            // Some Items
            string itemData = "0170A7000000000010" + "020B8F00000000001803B80200000000001804EE9900000000000005F399000000000000065F0900000000100007C80900000000000008D59D000000000C0009EA040000000000480AD61E0000000000380BF21800000000001C0C66900000000000140DB30400000000001C0E04A80000000018000F3743000000000028108D2200000000002411441A00000000004415808C00000000004462EB0300000000001C63CC5A00000000004464ECB2000000000048651CB3000000000038663E9500000000006868EA0400000000001C";

            byte[] inventory = StringUtils.hexStringToBytes(itemData);

            // Loaded Abilities
            string loadedAbs = "000032080080070000E400800B0000E002800C00006403800E0000340180110032B400801600322C0080290032D404802B0000DC04802F00322800803000323000803E0001E404804200322005805D0000E800805E0032D000805F00327C01806B00008801806F00001C0580990001280580A40000A40080A60000AC0080AC0000EC0080B00000000180B10000040180B80032240180BB0032300180BC00004C0180C50000A00080D80001EC0480DD00012C0580EA0001E80480F400013005800D01013405801D0101680780200132740580280100E004802C01013805803601018C05803801017805803A01325C0780490100840180520100D8088056010124";

            byte[] loadAbilitys = StringUtils.hexStringToBytes(loadedAbs);

            // Known Abilities
            string abilityData = "0000320800800100014800800200017C0080030000080280040000140380050001300480060001B40080070000E4008008000018038009000F9400800A0000E002800B0000E002800C00006403800D00009000800E00003401800F00018C00801000006C0080110032B40080120000E402801300001003801400016400801500322004801600322C0080170001AC09801800012C008019000F9400801A0032C401801B00010800801C00018400801D0000F803801E001A3802801F00010400802000006C0280210001240580220032B40980230032640680240001680080250087DF11842600000400802700001C0080280032540480290032D404802A003210";

            byte[] knownAbilitiys = StringUtils.hexStringToBytes(abilityData);


            // Known Hardlines
            string hardlineData = "0207000000021f000000022300000002240000000225000000022600000002270000000229000000022b000000022f00000002300000000231000000023200000002340000000235000000023600000002370000000238000000023b000000023f000000024000000002410000000243000000024500000002480000000249000000024a000000024b000000024d000000024e000000024f000000025000000002510000000252000000025400000002550000000256000000025700000002580000000259000000025a000000025b000000025c000000025d000000025e000000025f000000026000000002610000000262000000026300000002640000000265000000026600000002670000000269000000026a000000026b000000026c000000026d000000026e000000026f000000027000000002710000000130000000013100000001370000000141000000014500000001480000000149000000014a000000014b000000014c000000014e000000014f0000000150000000015100000001520000000163000000016400000001650000000166000000016700000001680000000169000000016a000000016b000000016d000000016f00000001700000000171000000017200000001730000000174000000017700000001780000000179000000017a000000017b000000017c000000017d000000017e000000017f000000018000000001810000000182000000018300000001840000000185000000018600000001870000000188000000018a000000018b000000018c000000018d000000018e000000019000000001910000000192000000019300000001940000000195000000019600000001970000000198000000019900000003020000000303000000030400000003050000000306000000030700000003080000000309000000030a000000030b000000030c000000030d000000030e000000030f000000031000000003110000000312000000031300000003140000000315000000031600000003170000000318000000";

            //string hardlineData = Store.dbManager.MarginDbHandler.loadAllHardlines();
            byte[] knownHardlines = StringUtils.hexStringToBytes(hardlineData);


            // Contacts
            string missionContacts = "0700000001000800000000000a00000003000d00000000001c0000000100";

            byte[] knownContacts = StringUtils.hexStringToBytes(missionContacts);

            byte[] codeArchiveTest = StringUtils.hexStringToBytes("04000000A7010000AC010000CC010000D1010000D60100001302000019020000650200006602000068020000B4020000B5020000B6020000BB020000BC020000C2020000C4020000D5020000D6020000DE020000E2020000E3020000E6020000E7020000E90200003F03000086030000A0030000AA030000E3030000FC030000FE030000030400000604000008040000090400000A040000270400004C0400004E040000BB040000C2040000CE040000EB040000EC040000EE040000F5040000F6040000F7040000F9040000540900005F09000082090000BE090000BF090000C1090000C4090000C7090000C8090000C9090000040A0000080A0000B0120000");

            byte[] empty = new byte[0];

            // New Margin Method to send Data

            // Pre-Load Abilities so that we just need to filter the result later
            loadAbilities((int)this.newCharID);

            sendMarginCharData(empty, 0x01, client);
            sendMarginCharData(loadBackgroundInfo((int)this.newCharID), 0x02, client);
            sendMarginCharData(empty, 0x03, client);                              // BuddyList (but old one)
            sendMarginCharData(empty, 0x04, client);                              // Unknown - no one has data there so ignore it
            sendMarginCharData(loadInventory((int)this.newCharID), 0x05, client); // Inventory
            //sendMarginCharData(StringUtils.hexStringToBytes(itemData), 0x05, client);            // Inventory CR1
            sendMarginCharData(loadEquippedAbilities(), 0x06, client);            // Loaded Abilitys
            //sendMarginCharData(empty, 0x06, client);                          // Loaded Abilitys CR1
            sendMarginCharData(loadKnownAbilities(), 0x07, client);               // Known Abilities
            sendMarginCharData(knownHardlines, 0x08, client);                     // Hardlines
            sendMarginCharData(empty, 0x09, client);                              // Access Nodes?
            //sendMarginCharData(codeArchiveTest, 0x0a, client);                // Code Storage
            sendMarginCharData(empty, 0x0a, client);                              // Code Storage CR1
            sendMarginCharData(knownContacts, 0x0b, client);                      // Contacts
            sendMarginCharData(empty, 0x0e, client);

            // ModT (has a seperate format)
            sendMarginData("1000000000" + StringUtils.bytesToString_NS(charIDB) + "10270d010f10000000", client);

            /* This is the server MOTD announcement (its disabled now) */

            /*DynamicArray announcement = new DynamicArray();
             * byte[] header = {0x10,0x00,0x00,0x00,0x00,0xac,0x53,0x02,0x00,0x10,0x27,0x0E,0x01,0x0D,0x10,0x00};
             * TimeUtils tim = new TimeUtils();
             * byte[] currentTime = tim.getUnixTime();
             * //Load motd from file
             * XmlParser xmlP = new XmlParser();
             * string[] data=xmlP.loadDBParams("Config.xml");
             * string motd=data[5];
             *
             * if (!motd.Equals("")){ // if MOTD not empty
             *      byte[] text = StringUtils.stringToBytes(motd);
             *      byte[] size = NumericalUtils.uint16ToByteArray((UInt16)(currentTime.Length+text.Length),1);
             *
             *      announcement.append(header);
             *      announcement.append(size);
             *      announcement.append(currentTime);
             *      announcement.append(text);
             *
             * byte[] encryptedResponse14 = marginEncr.encrypt(announcement.getBytes());
             * sendTCPVariableLenPacket(encryptedResponse14, client);
             * }*/
            /* End of the MOTD */

            //Output.WriteLine("[MARGIN] UserID "+this.userID+" waiting for session reply from world");
            //waitForWorldReply(); //TODO: enabling this outputted the "no usage" bug
            //Output.WriteLine("[MARGIN] World Session Reply OK for UserID "+this.userID);

            //System.Threading.Thread.Sleep(1000);
            //EstablishUDPSessionReply(packet, client);
        }
Ejemplo n.º 6
0
        private void createCharacterRSI(byte[] packet, NetworkStream client)
        {
            // Instance the Data Loader
            DataLoader itemLoader = DataLoader.getInstance();

            isNewCreatedChar = true;
            string debugHexPacket = StringUtils.bytesToString_NS(packet);

            // ToDo: Replace all with Packet Reader Instance
            PacketReader reader = new PacketReader(packet);

            reader.incrementOffsetByValue(3);


            UInt16 body   = 0;
            UInt16 gender = 0;


            UInt16 skintone = reader.readUInt16(1);

            reader.setOffsetOverrideValue(7);
            UInt16 bodyTypeId = reader.readUInt16(1);

            reader.setOffsetOverrideValue(15);
            UInt16 hairId = reader.readUInt16(1);

            reader.setOffsetOverrideValue(19);
            UInt16 haircolor = reader.readUInt16(1);

            reader.setOffsetOverrideValue(23);
            UInt16 tattoo = reader.readUInt16(1);

            reader.setOffsetOverrideValue(27);
            UInt16 headId = reader.readUInt16(1);

            reader.setOffsetOverrideValue(31);
            UInt16 facialDetail = reader.readUInt16(1);

            reader.setOffsetOverrideValue(35);
            // ToDo: it has a bug - figure out correct position
            UInt16 facialDetailColor = reader.readUInt16(1);

            // ToDo: Remove this when facialDetailColor is parsed properly
            facialDetailColor = 0;
            reader.setOffsetOverrideValue(67);
            UInt16 profession = reader.readUInt16(1);


            // lets read the values
            // the IDs for the Appeareance is always uint16 goID
            // Extra Hint: there are no leggins in Char Creation Process
            reader.setOffsetOverrideValue(35);
            UInt16 hatId = reader.readUInt16(1);

            reader.setOffsetOverrideValue(39);
            UInt16 eyewearId = reader.readUInt16(1);

            reader.setOffsetOverrideValue(43);
            UInt16 shirtId = reader.readUInt16(1);

            reader.setOffsetOverrideValue(47);
            UInt16 glovesId = reader.readUInt16(1);

            reader.setOffsetOverrideValue(51);
            UInt16 outerwearId = reader.readUInt16(1);

            reader.setOffsetOverrideValue(55);
            UInt16 pantsId = reader.readUInt16(1);

            reader.setOffsetOverrideValue(63);
            UInt16 footwearId = reader.readUInt16(1);


            // Get Values by "NewRSI" IDs
            NewRSIItem hairItem = itemLoader.getNewRSIItemByTypeAndID("HAIR", hairId);
            NewRSIItem bodyItem = itemLoader.getNewRSIItemByTypeAndID("BODY", (ushort)bodyTypeId);
            NewRSIItem headItem = itemLoader.getNewRSIItemByTypeAndID("HEAD", headId);

            Store.dbManager.MarginDbHandler.updateRSIValue("body", bodyItem.internalId.ToString(), newCharID);
            Store.dbManager.MarginDbHandler.updateRSIValue("sex", bodyItem.gender.ToString(), newCharID);
            Store.dbManager.MarginDbHandler.updateRSIValue("face", headItem.internalId.ToString(), newCharID);              // ToDo:
            Store.dbManager.MarginDbHandler.updateRSIValue("hair", hairItem.internalId.ToString(), newCharID);
            Store.dbManager.MarginDbHandler.updateRSIValue("haircolor", haircolor.ToString(), newCharID);                   // ToDo: check if it is correct
            Store.dbManager.MarginDbHandler.updateRSIValue("tattoo", tattoo.ToString(), newCharID);                         // ToDo:
            Store.dbManager.MarginDbHandler.updateRSIValue("facialdetail", facialDetail.ToString(), newCharID);             // ToDo:
            Store.dbManager.MarginDbHandler.updateRSIValue("facialdetailcolor", facialDetailColor.ToString(), newCharID);   // ToDo:
            Store.dbManager.MarginDbHandler.updateRSIValue("skintone", skintone.ToString(), newCharID);


            // Clothing Items
            ClothingItem shirt     = itemLoader.getItemValues(shirtId);
            ClothingItem pants     = itemLoader.getItemValues(pantsId);
            ClothingItem outerwear = itemLoader.getItemValues(outerwearId);
            ClothingItem hat       = itemLoader.getItemValues(hatId);
            ClothingItem eyewear   = itemLoader.getItemValues(eyewearId);
            ClothingItem footwear  = itemLoader.getItemValues(footwearId);
            ClothingItem gloves    = itemLoader.getItemValues(glovesId);

            Store.dbManager.MarginDbHandler.updateRSIValue("hat", hat.getModelId().ToString(), newCharID);
            Store.dbManager.MarginDbHandler.updateRSIValue("shirt", shirt.getModelId().ToString(), newCharID);
            Store.dbManager.MarginDbHandler.updateRSIValue("shirtcolor", shirt.getColorId().ToString(), newCharID);
            Store.dbManager.MarginDbHandler.updateRSIValue("coat", outerwear.getModelId().ToString(), newCharID);
            Store.dbManager.MarginDbHandler.updateRSIValue("coatcolor", outerwear.getColorId().ToString(), newCharID);
            Store.dbManager.MarginDbHandler.updateRSIValue("pants", pants.getModelId().ToString(), newCharID);
            Store.dbManager.MarginDbHandler.updateRSIValue("pantscolor", pants.getColorId().ToString(), newCharID);
            Store.dbManager.MarginDbHandler.updateRSIValue("shoes", footwear.getModelId().ToString(), newCharID);
            Store.dbManager.MarginDbHandler.updateRSIValue("shoecolor", footwear.getColorId().ToString(), newCharID);
            Store.dbManager.MarginDbHandler.updateRSIValue("glasses", eyewear.getModelId().ToString(), newCharID);
            Store.dbManager.MarginDbHandler.updateRSIValue("glassescolor", eyewear.getColorId().ToString(), newCharID);
            Store.dbManager.MarginDbHandler.updateRSIValue("gloves", gloves.getModelId().ToString(), newCharID);

            Store.dbManager.MarginDbHandler.AddItemToSlot(hatId, 0x61, newCharID);
            Store.dbManager.MarginDbHandler.AddItemToSlot(eyewearId, 0x62, newCharID);
            Store.dbManager.MarginDbHandler.AddItemToSlot(shirtId, 0x63, newCharID);
            Store.dbManager.MarginDbHandler.AddItemToSlot(glovesId, 0x64, newCharID);
            Store.dbManager.MarginDbHandler.AddItemToSlot(outerwearId, 0x65, newCharID);
            Store.dbManager.MarginDbHandler.AddItemToSlot(pantsId, 0x66, newCharID);
            Store.dbManager.MarginDbHandler.AddItemToSlot(footwearId, 0x68, newCharID);


            // FirstName
            UInt16 currentOffset = 79;

            byte[] firstNameLenBytes = new byte[2];
            ArrayUtils.copy(packet, currentOffset, firstNameLenBytes, 0, 2);
            UInt16 firstNameLen = NumericalUtils.ByteArrayToUint16(firstNameLenBytes, 1);

            currentOffset += 2;

            byte[] firstNameBytes = new byte[NumericalUtils.ByteArrayToUint16(firstNameLenBytes, 1) - 1];
            ArrayUtils.copy(packet, currentOffset, firstNameBytes, 0, firstNameLen - 1);
            string firstNameString = StringUtils.charBytesToString(firstNameBytes);

            currentOffset += firstNameLen;

            // LastName
            byte[] lastNameLenBytes = new byte[2];
            ArrayUtils.copy(packet, currentOffset, lastNameLenBytes, 0, 2);
            UInt16 lastNameLen = NumericalUtils.ByteArrayToUint16(lastNameLenBytes, 1);

            currentOffset += 2;

            byte[] lastNameBytes = new byte[NumericalUtils.ByteArrayToUint16(lastNameLenBytes, 1) - 1];
            ArrayUtils.copy(packet, currentOffset, lastNameBytes, 0, lastNameLen - 1);
            string lastNameString = StringUtils.charBytesToString(lastNameBytes);

            currentOffset += lastNameLen;

            // Description
            byte[] descriptionLenBytes = new byte[2];
            ArrayUtils.copy(packet, currentOffset, descriptionLenBytes, 0, 2);
            UInt16 descriptionLen = NumericalUtils.ByteArrayToUint16(descriptionLenBytes, 1);

            currentOffset += 2;

            byte[] descriptionBytes = new byte[NumericalUtils.ByteArrayToUint16(descriptionLenBytes, 1) - 1];
            ArrayUtils.copy(packet, currentOffset, descriptionBytes, 0, descriptionLen - 1);
            string descriptionString = StringUtils.charBytesToString(descriptionBytes);

            currentOffset += lastNameLen;

            // Update Characters values
            Store.dbManager.MarginDbHandler.updateCharacter(firstNameString, lastNameString, descriptionString, newCharID);

            // Add the Basic Abilitys...
            addStartAbilitys(newCharID);

            // we have all created - lets load the charData
            loadCharacter(packet, client, this.newCharID);
        }
Ejemplo n.º 7
0
        public void packetHandler(byte[] packet, NetworkStream client)
        {
            bool encrypted = true;
            byte opcode    = packet[2];

            byte[] data    = { };
            byte   pointer = packet[0];

            if (opcode == 0x01)
            {
                // Packet is unencrypted
                encrypted = false;
                data      = packet;
            }

            // This overrides the above IF for packets where 3rd position is a "01"
            // Happened someday, and screwed login... yeah, really
            if (pointer != 0x81)
            {
                encrypted = true;
            }

            if (encrypted == true)
            {
                byte[] encryptedPacket = { };
                if (packet[0] >= 0x80)
                {
                    // try to readjust the packet for one byte less if the lenght is too long
                    // just a crappy way
                    encryptedPacket = new byte[packet.Length - 1];
                    ArrayUtils.copy(packet, 1, encryptedPacket, 0, packet.Length - 1);
                }
                else
                {
                    encryptedPacket = packet;
                }
                // Get the IV from encrypted Packet and set it in encryptor/decryptor
                byte[] decrypted = marginEncr.decryptMargin(encryptedPacket);
                if (decrypted == null)
                {
                    // This shouldnt happen - but can happen
                    tcpClient.Close();
                    clientStream.Close();
                    return;
                }
                // Just 2 zero bytes for opcode handling later (As we use third byte for both state, encrypted or not
                byte[] spacer = { 0x00, 0x00 };

                DynamicArray din = new DynamicArray();
                din.append(spacer);
                din.append(decrypted);

                data = din.getBytes();
            }
            else
            {
                data = packet;
            }
            Output.WritePacketLog(data, "MARGINCLIENT", "0", "0", "0");

            if (data.Length >= 3)
            {
                opcode = data[2];

                //TODO: check if this needs "packet" or "data"
                switch (opcode)
                {
                case 0x01:
                    certConnectRequest(packet, client);

                    break;

                case 0x03:
                    certConnectReply(packet, client);

                    break;

                case 0x06:
                    connectChallenge(packet, client);

                    break;

                case 0x08:
                    ConnectChallengeResponse(packet, client);
                    break;

                case 0x0a:
                    //CharNameRequest
                    charNameRequest(data, client);
                    break;

                case 0x0c:
                    //TODO: this is creation. must be done someday
                    Output.writeToLogForConsole("CREATECHAR RSI VALUES:" + StringUtils.bytesToString(data));
                    //loadCharacter(data, client);
                    createCharacterRSI(data, client);
                    // Add the first abilitys
                    // AbilityID : 2147485696 (Awakened) Level 2
                    // AbilityID :

                    break;

                case 0x0d:
                    // Delete Charname Request
                    deleteCharName(data, client);
                    break;

                case 0x0f:
                    loadCharacter(data, client, 0);
                    break;
                }
            }
        }
Ejemplo n.º 8
0
        public void processLoadAbility(ref byte[] packet)
        {
            // read the values from the packet
            byte[] staticObjectByteID = new byte[4];
            ArrayUtils.copyTo(packet, 0, staticObjectByteID, 0, 4);

            byte[] unloadFlagByte = new byte[2];
            ArrayUtils.copyTo(packet, 4, unloadFlagByte, 0, 2);

            byte[] loadFlagByte = new byte[2];
            ArrayUtils.copyTo(packet, 6, loadFlagByte, 0, 2);

            byte[] countAbilityBytes = new byte[2];
            ArrayUtils.copyTo(packet, 8, countAbilityBytes, 0, 2);
            UInt16 countAbilities = NumericalUtils.ByteArrayToUint16(countAbilityBytes, 1);

            // Get the Ability Related Header Data
            UInt32 staticObjectID = NumericalUtils.ByteArrayToUint32(staticObjectByteID, 1);
            UInt16 unloadFlag     = NumericalUtils.ByteArrayToUint16(unloadFlagByte, 1);
            UInt16 loadFlag       = NumericalUtils.ByteArrayToUint16(loadFlagByte, 1);

            int           pointer      = 11; // Start at index 11
            List <UInt16> abilitySlots = new List <UInt16>();

            for (int i = 1; i <= countAbilities; i++)
            {
                // This must be looped
                byte[] slotByteID = new byte[2];
                ArrayUtils.copyTo(packet, pointer, slotByteID, 0, 2);
                pointer = pointer + 2;

                byte[] abilityByteID = new byte[2];
                ArrayUtils.copyTo(packet, pointer, abilityByteID, 0, 2);
                pointer = pointer + 4;

                byte[] abilityByteLevel = new byte[2];
                ArrayUtils.copyTo(packet, pointer, abilityByteLevel, 0, 2);
                pointer = pointer + 3;


                UInt16 slotID       = NumericalUtils.ByteArrayToUint16(slotByteID, 1);
                UInt16 AbilityID    = NumericalUtils.ByteArrayToUint16(abilityByteID, 1);
                UInt16 AbilityLevel = NumericalUtils.ByteArrayToUint16(abilityByteLevel, 1);

                PacketContent pak = new PacketContent();
                if (unloadFlag > 0)
                {
                    pak.addUint16((UInt16)RPCResponseHeaders.SERVER_ABILITY_UNLOAD, 0);
                    pak.addByteArray(abilityByteID);
                }
                else
                {
                    pak.addUint16((UInt16)RPCResponseHeaders.SERVER_ABILITY_LOAD, 0);
                    pak.addByteArray(abilityByteID);
                    pak.addByteArray(abilityByteLevel);
                    pak.addByteArray(slotByteID);
                }
                abilitySlots.Add(slotID);
                Store.currentClient.messageQueue.addRpcMessage(pak.returnFinalPacket());
            }


            if (unloadFlag > 0)
            {
                Store.dbManager.WorldDbHandler.updateAbilityLoadOut(abilitySlots, 0);
            }
            else
            {
                Store.dbManager.WorldDbHandler.updateAbilityLoadOut(abilitySlots, 1);
            }
        }
Ejemplo n.º 9
0
 public Protocol03Parser()
 {
     au = new ArrayUtils();
 }
Ejemplo n.º 10
0
        public int parseAttributes(ref byte[] buffer, int _offset)
        {
            _offset++;
            byte flag = 0x00;

            flag = BufferHandler.readByte(ref buffer, ref _offset);

            byte[] stateData = new byte[buffer.Length - _offset + 2];
            ArrayUtils.copy(buffer, _offset - 2, stateData, 0, buffer.Length - _offset + 2);
            //Flag Bits{0,0,0,0,Vector3f Position Update,  Yaw Update,Animation Update, AttributesPacked Update?}

            double x = 0;
            double y = 0;
            double z = 0;

            switch (flag)
            {
            case 0x02:
                Action.setValue(BufferHandler.readBytes(ref buffer, ref _offset, Action.getSize()));
                break;


            case 0x04:
                YawInterval.setValue(BufferHandler.readBytes(ref buffer, ref _offset, YawInterval.getSize()));
                break;


            case 0x08:
                x = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1);
                y = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1);
                z = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1);
                Position.setValue(NumericalUtils.doublesToLtVector3d(x, y, z));
                break;

            case 0x0a:
                YawInterval.setValue(BufferHandler.readByte(ref buffer, ref _offset));
                x = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1);
                y = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1);
                z = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1);
                Position.setValue(NumericalUtils.doublesToLtVector3d(x, y, z));
                break;

            case 0x0e:
                // UInt16 unknown + LtVector3f
                UInt16 unknown = NumericalUtils.ByteArrayToUint16(BufferHandler.readBytes(ref buffer, ref _offset, 2), 1);
                x = NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1);
                y = NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1);
                z = NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1);
                Position.setValue(NumericalUtils.doublesToLtVector3d(x, y, z));
                break;

            default:
                // ToDo: we need a proper way to proove if there is a 00 00 04 somewhere (and if set the offset to it)

                // If this doesnt match we need to write this somewhere...
                string message = "RPCMAIN : Unknown Client 03 Request Packet \r\n" +
                                 "Flag: " + flag + "\r\n " +
                                 "Content: \n" +
                                 StringUtils.bytesToString(stateData) + "\r\n";
                Output.WriteClientViewRequestLog(message);

                // ...and we dont want to crash so we just say "offset is full packet"
                _offset = buffer.Length - 1;
                break;
            }

            // TODO: update player attribute packets someday (announce it to my spawners)
            Store.world.sendViewPacketToAllPlayers(stateData, Store.currentClient.playerData.getCharID(), NumericalUtils.ByteArrayToUint16(Store.currentClient.playerInstance.GetGoid(), 1), Store.currentClient.playerData.getEntityId());
            return(_offset);
        }