uint16ToByteArray() public static method

public static uint16ToByteArray ( UInt16 data, int reversed ) : byte[]
data System.UInt16
reversed int
return byte[]
Esempio n. 1
0
        public void sendMarketPlaceList(WorldClient client)
        {
            // ToDo: make it dynamic with database later (but the "handler" should give the items as arguments for this method
            // List Marketplace Items

            byte[] headerSeperator = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

            // Should foreach this later on "Real Server"
            DynamicArray listItems = new DynamicArray();

            listItems.append(StringUtils.hexStringToBytes("8703000000000034bdcf1200401f00000310db6a4a")); // Foot Wear
            listItems.append(0x00);                                                                       // Seperate each item

            listItems.append(StringUtils.hexStringToBytes("2e00000003a04a000bd012000000FFFF01aedc6a4a")); // Google
            listItems.append(0x00);                                                                       // Seperate each item

            listItems.append(StringUtils.hexStringToBytes("721a000003a04a000bd012000000FFFF01aedc6a4a")); // Item Data
            listItems.append(0x00);                                                                       // Seperate each item

            listItems.append(StringUtils.hexStringToBytes("2e00000003a04a000bd01200000000FF01aedc6a4a")); // Item Data
            listItems.append(0x00);                                                                       // Seperate each item

            // get data size
            byte[] itemSize = NumericalUtils.uint16ToByteArray((UInt16)listItems.getBytes().Length, 1);

            PacketContent pak = new PacketContent();

            pak.addUint16((UInt16)RPCResponseHeaders.SERVER_LOAD_MARKERPLACE, 0);
            pak.addUintShort(9); // list offset
            pak.addByteArray(headerSeperator);
            pak.addUint16((UInt16)listItems.getBytes().Length, 1);
            pak.addByteArray(listItems.getBytes());
            client.messageQueue.addRpcMessage(pak.returnFinalPacket());
        }
Esempio n. 2
0
        public void generateRpcMessageData()
        {
            // Example : 04 01 00 15 01 + submessages
            // Strcut: uint8 04 header + uint8 listcount + uint16 currentRPCCounter + submessageCounter (list1)
            // If you have 2 lists , the data struct is : uint8 submessagecount + submessages

            // TODO!!! FINALIZE!!
            // Here goes code from RPCPacket (As it should be generated on the fly)
            if (RPCMessages.Count > 0)
            {
                content.append((byte)ProtocolHeaders.RPC_PROTOCOL);
                // ToDo: Figure out what the "Lists" Count should handle ...maybe different types?
                // Why not having just one List and adding them all ? Maybe a list has a limit ?
                content.append(0x01); // List Count for RPC Messages
                Output.WriteLine(" RPC COUNTER BYTES :" + StringUtils.bytesToString(NumericalUtils.uint16ToByteArray(playerData.getRPCCounter(), 0)));
                content.append(NumericalUtils.uint16ToByteArray(playerData.getRPCCounter(), 0));
                content.append(NumericalUtils.uint16ToByteArrayShort((UInt16)RPCMessages.Count));
                foreach (SequencedMessage message in RPCMessages)
                {
                    content.append(message.content);
                }

                // Set new RPC Counter
                UInt16 incrementRpcCounter = playerData.getRPCCounter();
                Output.WriteDebugLog("Before RPC Counter :" + incrementRpcCounter.ToString());
                incrementRpcCounter += (ushort)RPCMessages.Count;
                playerData.setRPCCounter(incrementRpcCounter);
                Output.WriteDebugLog("After RPC Counter :" + incrementRpcCounter.ToString() + " (should added " + RPCMessages.Count.ToString() + ")");
            }
        }
Esempio n. 3
0
        public void sendTCPVariableLenPacket(byte[] packet, NetworkStream client)
        {
            byte[] size     = { };
            byte[] bytesize = { };

            if (packet.Length > 127)
            {
                //Do NOT reverse here :P
                bytesize = NumericalUtils.uint16ToByteArray((UInt16)(packet.Length + 0x8000), 0);
            }
            else
            {
                bytesize = NumericalUtils.uint16ToByteArrayShort((ushort)packet.Length);
            }

            byte[] finalPacket = new byte[packet.Length + bytesize.Length];

            DynamicArray din = new DynamicArray();

            din.append(bytesize);
            din.append(packet);

            finalPacket = din.getBytes();

            try
            {
                client.Write(finalPacket, 0, finalPacket.Length);
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR ex: " + ex.ToString());
                throw;
            }
            client.Flush();
        }
Esempio n. 4
0
        private byte[] getRpcBytes()
        {
            UInt16 rpcCounter = destClient.playerData.getRPCCounter();

            byte [] rpc = NumericalUtils.uint16ToByteArray(rpcCounter, 0);
            return(rpc);
        }
Esempio n. 5
0
        public void addSizedTerminatedString(string value)
        {
            int size = value.Length + 1;

            packet.append(NumericalUtils.uint16ToByteArray((UInt16)size, 1));
            packet.append(StringUtils.stringToBytes(value));
            packet.append(0x00);
        }
Esempio n. 6
0
        public byte[] getByteContents()
        {
            DynamicArray response = new DynamicArray();

            byte[] numWorldsH = NumericalUtils.uint16ToByteArray((UInt16)numWorlds, 1);
            response.append(numWorldsH);
            response.append(worlds.getBytes());
            return(response.getBytes());
        }
Esempio n. 7
0
        public byte[] getByteContents()
        {
            DynamicArray response = new DynamicArray();

            byte[] totalCharsH = NumericalUtils.uint16ToByteArray((UInt16)totalChars, 1);
            response.append(totalCharsH);
            response.append(charData.getBytes());
            response.append(charNames.getBytes());
            return(response.getBytes());
        }
Esempio n. 8
0
        /// <summary>
        /// This sends a View Create/Update/Delete Packet to all Players
        /// </summary>
        /// <param name="data">Packet Stream without ViewID</param>
        /// <param name="charId">from charId</param>
        /// <param name="goId">from GoId</param>
        public void sendViewPacketToAllPlayers(byte[] data, UInt32 charId, UInt32 goId, UInt64 entityId)
        {
            // Send a global message to all connected Players (like shut down Server announce or something)
            lock (Clients.SyncRoot)
            {
                foreach (string clientKey in Clients.Keys)
                {
                    WorldClient client = Clients[clientKey] as WorldClient;
                    if (client.playerData.getCharID() != charId)
                    {
                        Output.Write("[ViewThread] Handle View For all Packet for charId : " + charId.ToString());
                        // Get or generate a View for the GoID
                        ClientView   view    = client.viewMan.getViewForEntityAndGo(entityId, goId);
                        DynamicArray content = new DynamicArray();

                        if (view.viewCreated == false)
                        {
                            Output.WriteDebugLog("Created View Id : " + view.ViewID.ToString());
                            // if view is new , add the viewId at the end (cause its creation)
                            // Remove the 03 01 00 (as it was generate previosly)
                            content.append(data);
                            content.append(NumericalUtils.uint16ToByteArray(view.ViewID, 1));
                            content.append(0x00); // View Zero
                        }
                        else
                        {
                            // Update View
                            content.append(NumericalUtils.uint16ToByteArray(view.ViewID, 1));
                            content.append(data);
                            content.append(0x00); // View Zero

                            Output.WriteDebugLog("Update View Id : " + view.ViewID.ToString());
                        }

                        if (view.viewNeedsToBeDeleted == true)
                        {
                            content.append(0x01);
                            content.append(0x00);
                            content.append(0x01); // Comand (Delete)
                            content.append(0x01); // NumViews (1 currently)
                            content.append(0x00);
                            content.append(NumericalUtils.uint16ToByteArray(view.ViewID, 1));
                            content.append(0x00);
                        }


                        // ToDo: handle viewId for packets (For creation it needs to be append to the end, for update at the start )
                        // ToDo: Complete this :)
                        client.messageQueue.addObjectMessage(content.getBytes(), false);
                        client.flushQueue();
                        Output.WriteLine("[World View Server] CharId: " + client.playerData.getCharID().ToString() + " )");
                    }
                }
            }
        }
Esempio n. 9
0
        public void addCharacter(string charName, int charId, int status, int serverId)
        {
            byte[] charNameB = new byte[charName.Length + 3];
            byte[] hexSize   = NumericalUtils.uint16ToByteArray((UInt16)(charName.Length + 1), 1);
            charNameB[0] = hexSize[0];
            charNameB[1] = hexSize[1];
            charNameB[charName.Length + 2] = 0x00;
            for (int i = 0; i < charName.Length; i++)
            {
                charNameB[2 + i] = (byte)charName[i];
            }


            byte[] charDataB = new byte[14];
            byte[] charIdB   = NumericalUtils.uint32ToByteArray((UInt32)charId, 1);
            charDataB[3]  = charIdB[0];
            charDataB[4]  = charIdB[1];
            charDataB[5]  = charIdB[2];
            charDataB[6]  = charIdB[3];
            charDataB[9]  = 0x00;
            charDataB[10] = (byte)status;
            charDataB[11] = 0x00;
            charDataB[12] = (byte)serverId;

            numChars++; // Lets say we have done one ;)

            int offset = 0;

            // Use formula to calculate offset here

            offset = 14 + (14 * (totalChars - numChars));

            if (numChars == 1)
            {
                offset += 0;
            }
            else
            {
                offset += charNames.getSize();
            }

            // End of formula

            byte[] offsetH = NumericalUtils.uint16ToByteArray((UInt16)offset, 1);
            charDataB[1] = offsetH[0];
            charDataB[2] = offsetH[1];

            // After all calculations, append it to the dynamic arrays
            charData.append(charDataB);
            charNames.append(charNameB);
        }
Esempio n. 10
0
        public void processSelfUpdateHealth(UInt16 viewId, UInt16 healthC)
        {
            // ToDo: proove to remove
            DynamicArray din = new DynamicArray();

            din.append(0x03);
            din.append(NumericalUtils.uint16ToByteArray(viewId, 1));
            din.append(0x02);
            din.append(0x80);
            din.append(0x80);
            din.append(0x80);
            din.append(0x40);
            din.append(NumericalUtils.uint16ToByteArray(healthC, 1));
            din.append(0x00);
        }
Esempio n. 11
0
        public byte[] loadKnownAbilities()
        {
            DynamicArray din = new DynamicArray();

            foreach (MarginAbilityItem ability in Abilities)
            {
                Int32 finalAblityID = ability.getAbilityID() + ability.getLevel();

                string debugAbility = StringUtils.bytesToString(NumericalUtils.int32ToByteArray(finalAblityID, 1));
                din.append(NumericalUtils.uint16ToByteArray(ability.getSlot(), 1)); // slot
                din.append(NumericalUtils.int32ToByteArray(finalAblityID, 1));
            }

            return(din.getBytes());
        }
Esempio n. 12
0
        public void processSelfUpdateHealth(UInt16 viewId, UInt16 healthC)
        {
            DynamicArray din = new DynamicArray();

            din.append(0x03);
            din.append(NumericalUtils.uint16ToByteArray(viewId, 1));
            din.append(0x02);
            din.append(0x80);
            din.append(0x80);
            din.append(0x80);
            din.append(0x40);
            din.append(NumericalUtils.uint16ToByteArray(healthC, 1));
            din.append(0x00);
            // ToDO SEND PAK and get real health
        }
Esempio n. 13
0
        public void sendChatMessage(WorldClient fromClient, string message, UInt32 charId, string handle, string scope)
        {
            byte typeByte;

            switch (scope)
            {
            case "TEAM":
                typeByte = 0x05;
                break;

            case "CREW":
                typeByte = 0x02;
                break;

            case "FACTION":
                typeByte = 0x03;
                break;

            case "AREA":
                typeByte = 0x10;
                break;

            default:
                typeByte = 0x07;
                break;
            }


            UInt16 messageSize = (UInt16)(message.Length + 1);

            byte[] messageSizeHex = NumericalUtils.uint16ToByteArray(messageSize, 1);

            UInt32        offsetMessage = (uint)handle.Length + 35 + 2 + 2;
            PacketContent pak           = new PacketContent();

            pak.addByte((byte)RPCResponseHeaders.SERVER_CHAT_MESSAGE_RESPONSE);
            pak.addByte(typeByte);
            pak.addUint32(charId, 0);
            pak.addUint16(36, 0);
            pak.addUint32(offsetMessage, 0);
            pak.addHexBytes("000000000000000000000000000000000000000000000000");
            pak.addSizedTerminatedString(handle);
            pak.addSizedTerminatedString(message);
            Store.world.sendRPCToAllOtherPlayers(Store.currentClient.playerData, pak.returnFinalPacket());
        }
Esempio n. 14
0
        public byte[] loadEquippedAbilities()
        {
            DynamicArray din = new DynamicArray();

            //AbilityItem abTemp = AbilityDB.Find(delegate(AbilityItem a) { return a.getAbilityID() == id; });


            foreach (MarginAbilityItem ability in Abilities)
            {
                if (ability.getLoaded() == true)
                {
                    Int32 finalAblityID = ability.getAbilityID() + ability.getLevel();
                    din.append(NumericalUtils.uint16ToByteArray(ability.getSlot(), 1)); // slot
                    din.append(NumericalUtils.int32ToByteArray(finalAblityID, 1));
                }
            }
            return(din.getBytes());
        }
Esempio n. 15
0
        public void processDecreaseCash(UInt16 amount, UInt16 type)
        {
            // send 02 04 01 00 16 01 0a 80 e4 ff 00 00 00 02 00 00 00;
            byte[] header  = { 0x80, 0xe4 };
            long   newCash = Store.currentClient.playerData.getInfo() - (long)amount;

            Store.currentClient.playerData.setInfo(newCash);

            Store.dbManager.WorldDbHandler.savePlayer(Store.currentClient);

            DynamicArray din = new DynamicArray();

            din.append(header);
            din.append(NumericalUtils.uint32ToByteArray((UInt32)newCash, 1));
            din.append(NumericalUtils.uint16ToByteArray(type, 1));
            din.append(0x00);
            din.append(0x00);
            Store.currentClient.messageQueue.addRpcMessage(din.getBytes());
        }
Esempio n. 16
0
        public static byte[] createSystemMessage(string message, WorldClient client)
        {
            byte[] messageBytes = StringUtils.stringToBytes(message + "\x00");

            DynamicArray din = new DynamicArray();

            UInt16 messageSize = (UInt16)(message.Length + 1);

            byte[] messageSizeHex = NumericalUtils.uint16ToByteArray(messageSize, 1);

            byte[] hexContents = StringUtils.hexStringToBytes("0700000000000000000024000000000000000000000000000000000000000000000000");

            din.append((byte)RPCResponseHeaders.SERVER_CHAT_MESSAGE_RESPONSE);
            din.append(hexContents);
            din.append(messageSizeHex);
            din.append(messageBytes);


            return(din.getBytes());
        }
Esempio n. 17
0
        /*
         * Add a RPC Message with size byte automatically to the queue
         */
        public void addRpcMessage(byte[] messageBlock)
        {
            byte[] rpcSizeByte;
            if (messageBlock.Length > 127)
            {
                rpcSizeByte = NumericalUtils.uint16ToByteArray((UInt16)(messageBlock.Length + 0x8000), 0);
            }
            else
            {
                rpcSizeByte = NumericalUtils.uint16ToByteArrayShort((UInt16)messageBlock.Length);
            }
            DynamicArray content = new DynamicArray();

            content.append(rpcSizeByte);
            content.append(messageBlock);

            SequencedMessage message = new SequencedMessage(content.getBytes());

            RPCMessagesQueue.Add(message);
        }
Esempio n. 18
0
        // Shows the Animation of a target Player
        public void processFXfromPlayer(UInt16 viewID, byte[] animation)
        {
            Random rand = new Random();
            ushort updateViewCounter = (ushort)rand.Next(3, 200);

            byte[] updateCount = NumericalUtils.uint16ToByteArrayShort(updateViewCounter);

            DynamicArray din = new DynamicArray();

            din.append(NumericalUtils.uint16ToByteArray(viewID, 1));
            din.append(0x00);
            din.append(0x80);
            din.append(0x80);
            din.append(0x80);
            din.append(0x0c);
            din.append(animation); // uint32 anim ID
            din.append(updateCount);
            din.append(0x00);
            din.append(0x00);

            Store.currentClient.messageQueue.addObjectMessage(din.getBytes(), false);
        }
Esempio n. 19
0
 public void addUint16(UInt16 value, int reversed)
 {
     packet.append(NumericalUtils.uint16ToByteArray(value, reversed));
 }
Esempio n. 20
0
        public void parseCommand(string data)
        {
            Output.WriteLine("[Chat Command helper] Chat command is: '" + data + "'");
            string[] commands = data.Split(' ');

            string command = commands[0].ToLower();

            try{
                if (command.Equals("?fix") && commands.Length > 1)
                {
                    int maxRPC = int.Parse(commands[1]);
                    for (int i = 0; i < maxRPC; i++)
                    {
                        Store.currentClient.playerData.setRPCCounter((UInt16)i);
                        Store.currentClient.messageQueue.addRpcMessage(PacketsUtils.createSystemMessage("Trying to fix! " + i, Store.currentClient));
                    }
                }

                if (command.Equals("?teleport") && commands.Length == 4)
                {
                    // parse the coord parameters parameters as int
                    Store.currentClient.messageQueue.addObjectMessage(new PlayerHelper().teleport(int.Parse(commands[1]), int.Parse(commands[2]), int.Parse(commands[3])), false);
                    Store.currentClient.messageQueue.addRpcMessage(PacketsUtils.createSystemMessage("Teleported!", Store.currentClient));
                }

                if (command.Equals("?rsi") && commands.Length == 3)
                {
                    //parse the rsi part and value
                    Store.currentClient.messageQueue.addObjectMessage(new PlayerHelper().changeRsi(commands[1], int.Parse(commands[2])), false);
                    Store.currentClient.messageQueue.addRpcMessage(PacketsUtils.createSystemMessage("Rsi changed!", Store.currentClient));
                }


                if (command.StartsWith("?message"))
                {
                    Output.WriteLine("[COMMAND HELPER]MESSAGE RECEIVED");
                    byte[] theMessage = PacketsUtils.createSystemMessageWithoutRPC(commands[1]);
                    Store.world.sendRPCToAllPlayers(theMessage);
                }

                if (command.Equals("?playanim"))
                {
                    string animId = commands[1];
                    if (animId.Length == 4)
                    {
                        ServerPackets pak = new ServerPackets();
                        pak.sendPlayerAnimation(Store.currentClient, animId);
                    }
                }

                if (command.StartsWith("?playfx"))
                {
                    string       fxHEDID = commands[1];
                    DynamicArray din     = new DynamicArray();


                    byte[] animationId = StringUtils.hexStringToBytes(fxHEDID);
                    byte[] viewID      = { 0x02, 0x00 };

                    Random rand = new Random();
                    ushort updateViewCounter = (ushort)rand.Next(3, 200);
                    byte[] updateCount       = NumericalUtils.uint16ToByteArrayShort(updateViewCounter);

                    Output.WriteLine("Check if its really one byte or two : " + StringUtils.bytesToString(updateCount));


                    din.append(viewID);
                    din.append(0x02);
                    din.append(0x80);
                    din.append(0x80);
                    din.append(0x80);
                    din.append(0x90);
                    din.append(0xed);
                    din.append(0x00);
                    din.append(0x30);
                    din.append(animationId);
                    din.append(updateCount);

                    Store.currentClient.messageQueue.addObjectMessage(din.getBytes(), false);
                }

                if (command.Contains("?send"))
                {
                    // Sends a packet from a file
                    string     filename   = "packet.txt";
                    TextReader tr         = new StreamReader(filename);
                    string     hexContent = tr.ReadToEnd();
                    hexContent = hexContent.Replace(" ", string.Empty);
                    hexContent = hexContent.Replace(" ", Environment.NewLine);
                    tr.Close();

                    if (hexContent.Length > 0)
                    {
                        Store.currentClient.messageQueue.addObjectMessage(StringUtils.hexStringToBytes(hexContent), false);
                        Output.writeToLogForConsole("[SENDPACK FROM FILE] Content : " + hexContent);
                    }
                }

                if (command.Contains("?combat"))
                {
                    byte[]          dummypak = new byte[4];
                    TestUnitHandler test     = new TestUnitHandler();
                    test.testCloseCombat(ref dummypak);
                }

                if (command.Contains("?mob"))
                {
                    UInt32[] rsiIDs = new UInt32[10];
                    rsiIDs[0] = 0xB7010058;
                    rsiIDs[1] = 0x89090058;
                    rsiIDs[2] = 0xB5010058;
                    rsiIDs[3] = 0x3A030008;
                    rsiIDs[4] = 0x32030008;
                    rsiIDs[5] = 0xD0010058;
                    rsiIDs[6] = 0xD4010058;
                    rsiIDs[7] = 0xB8040004; // Smith
                    rsiIDs[8] = 0x92010058; // Seraph
                    rsiIDs[9] = 0x56050004;
                    Random rand  = new Random();
                    int    index = rand.Next(0, 9);

                    double x = 0; double y = 0; double z = 0;
                    byte[] Ltvector3d = Store.currentClient.playerInstance.Position.getValue();
                    NumericalUtils.LtVector3dToDoubles(Ltvector3d, ref x, ref y, ref z);

                    byte[] xPos = NumericalUtils.floatToByteArray((float)x, 1);
                    byte[] yPos = NumericalUtils.floatToByteArray((float)y, 1);
                    byte[] zPos = NumericalUtils.floatToByteArray((float)z, 1);

                    UInt64 currentEntityId = WorldSocket.entityIdCounter;
                    WorldSocket.entityIdCounter++;
                    uint rotation = 0;

                    npc theMob = new npc();
                    theMob.setEntityId(currentEntityId);
                    theMob.setDistrict(Convert.ToUInt16(data[0].ToString()));
                    theMob.setDistrictName(Store.currentClient.playerData.getDistrict());
                    theMob.setName("HD Protector");
                    theMob.setLevel(255);
                    theMob.setHealthM(UInt16.Parse(data[4].ToString()));
                    theMob.setHealthC(UInt16.Parse(data[5].ToString()));
                    theMob.setMobId((ushort)rsiIDs[index]);
                    theMob.setRsiHex(StringUtils.bytesToString_NS(NumericalUtils.uint32ToByteArray(rsiIDs[index], 1)));
                    theMob.setXPos(x);
                    theMob.setYPos(y);
                    theMob.setZPos(z);
                    theMob.xBase = x;
                    theMob.yBase = y;
                    theMob.zBase = z;
                    theMob.setRotation(rotation);
                    theMob.setIsDead(false);
                    theMob.setIsLootable(false);
                    WorldSocket.npcs.Add(theMob);

                    // we use this for a test to see if we can spawn mobs and how we can handle them
                    // We refactor this
                }



                if (command.Contains("?sendrpc"))
                {
                    // sends a RPC Packet from a File
                    string     filename   = "rpcpacket.txt";
                    TextReader tr         = new StreamReader(filename);
                    string     hexContent = tr.ReadToEnd();
                    hexContent = hexContent.Replace(" ", string.Empty);
                    hexContent = hexContent.Replace(" ", Environment.NewLine);
                    Output.Write("SEND RPC COMMAND : CONTENT : " + hexContent);
                    tr.Close();

                    if (hexContent.Length > 0)
                    {
                        Store.currentClient.messageQueue.addRpcMessage(StringUtils.hexStringToBytes(hexContent));
                        Output.writeToLogForConsole("[SENDRPC FROM FILE] Content : " + hexContent);
                    }
                }

                if (command.Contains("?checkrpc"))
                {
                    DynamicArray din = new DynamicArray();
                    din.append(StringUtils.hexStringToBytes("2E1000FF7D020024000000310000000000000000000000000000000000000000000000000B0053796E61707A65373737001D004F6E2079656168204920646F2072656D656D62657220796F75203A2900"));
                    Store.currentClient.messageQueue.addRpcMessage(din.getBytes());
                }

                if (command.Contains("?testrpc"))
                {
                    UInt16 maxRPC = 33279;
                    // Just to reference
                    if (Store.currentClient.playerData.currentTestRPC <= maxRPC)
                    {
                        // Only if it is below we send it - we test with a 5 size packet
                        DynamicArray din = new DynamicArray();
                        if (Store.currentClient.playerData.currentTestRPC < 127)
                        {
                            din.append(NumericalUtils.uint16ToByteArrayShort(Store.currentClient.playerData.currentTestRPC));
                        }
                        else
                        {
                            din.append(NumericalUtils.uint16ToByteArray(Store.currentClient.playerData.currentTestRPC, 0));
                        }

                        din.append(0x00);
                        din.append(0x00);
                        din.append(0x00);

                        Store.currentClient.messageQueue.addRpcMessage(din.getBytes());

                        ServerPackets pak = new ServerPackets();
                        pak.sendSystemChatMessage(Store.currentClient, "Test RPC Header : " + Store.currentClient.playerData.currentTestRPC.ToString(), "MODAL");

                        Store.currentClient.playerData.currentTestRPC++;
                    }
                }

                if (command.Equals("?save"))
                {
                    new PlayerHelper().savePlayerInfo(Store.currentClient);

                    ServerPackets pak = new ServerPackets();
                    pak.sendSaveCharDataMessage(Store.currentClient, StringUtils.charBytesToString_NZ(Store.currentClient.playerInstance.CharacterName.getValue()));
                }
            }
            catch (Exception e) {
                Store.currentClient.messageQueue.addRpcMessage(PacketsUtils.createSystemMessage("Error parsing command!", Store.currentClient));
                Output.WriteLine("[CHAT COMMAND PARSER] Error parsing request: " + data);
                Output.WriteLine("[CHAT COMMAND PARSER] DEBUG: " + e.Message + "\n" + e.StackTrace);
            }
        }
Esempio n. 21
0
        public byte[] encrypt(byte[] packet)
        {
            // Get timestamp
            byte[] timestamp = TimeUtils.getUnixTime();


            // get size
            int psize = packet.Length;

            byte[] size = NumericalUtils.uint16ToByteArray((UInt16)psize, 1);

            //showPacket(size, " Size ");

            // final Packet

            DynamicArray temp = new DynamicArray();

            temp.append(size);
            temp.append(timestamp);
            temp.append(packet);


            // compute CRC32
            byte[] crc32pax = crc32.checksumB(temp.getBytes(), 1);


            // Padding
            int totalLength = temp.getSize() + 4;
            int padding     = 16 - (totalLength % 16);

            byte[] paddingBytes = new byte[padding];

            for (int i = 0; i < padding; i++)
            {
                paddingBytes[i] = (byte)padding;
            }

            temp.append(paddingBytes);
            tf.setIV(IV);
            tf.setKey(TF_Key);

            // We init with 2 more than needed, so no memory reservation is done on dyn array
            DynamicArray finalPlainData = new DynamicArray();

            finalPlainData.append(crc32pax);
            finalPlainData.append(temp.getBytes());

            temp = null;             // Cleaning the house


            byte[] encryptedData = new byte[finalPlainData.getSize()];
            tf.encrypt(finalPlainData.getBytes(), encryptedData);


            finalPlainData = null;             // Cleaning the house (2)

            // add IV before the results

            DynamicArray response = new DynamicArray();

            response.append(IV);
            response.append(encryptedData);

            // Display HEX Values after Encryption
            return(response.getBytes());
        }
Esempio n. 22
0
 public byte[] GetGoid()
 {
     return(NumericalUtils.uint16ToByteArray(goid, 1));
 }
Esempio n. 23
0
        public static byte[] createMessage(string message, string type, WorldClient client)
        {
            byte typeByte;

            switch (type)
            {
            case "TEAM":
                typeByte = 0x05;
                break;

            case "CREW":
                typeByte = 0x02;
                break;

            case "FACTION":
                typeByte = 0x03;
                break;

            case "SYSTEM":
                typeByte = 0x07;
                break;

            case "MODAL":
                typeByte = 0x17;
                break;

            case "FRAMEMODAL":
                typeByte = 0xd7;
                break;

            case "BROADCAST":
                typeByte = 0xc7;
                break;

            case "AREA":
                typeByte = 0x10;
                break;

            default:
                typeByte = 0x07;
                break;
            }

            byte[] messageBytes = StringUtils.stringToBytes(message + "\x00");

            DynamicArray din = new DynamicArray();

            UInt16 messageSize = (UInt16)(message.Length + 1);

            byte[] messageSizeHex = NumericalUtils.uint16ToByteArray(messageSize, 1);
            byte[] hexContents    = StringUtils.hexStringToBytes("00000000000000000024000000000000000000000000000000000000000000000000");



            din.append((byte)RPCResponseHeaders.SERVER_CHAT_MESSAGE_RESPONSE); // Response header
            din.append(typeByte);
            din.append(hexContents);
            din.append(messageSizeHex);
            din.append(messageBytes);


            return(din.getBytes());
        }
Esempio n. 24
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);
        }
Esempio n. 25
0
        private void sendMarginCharData(byte[] data, byte opcode, NetworkStream client)
        {
            // This Method will be used to send the real Data to the client

            // Format for general LoadCharacterReply Responses:
            // 10 00 00 00 <- everytime the same
            // 00 f9 76 04 <- uint32 Char ID
            // 00 00 00 09 <- uint32 number of Character Replys (just raise one up)
            // 00 05 <- viewData opcode (what data is inside) uint16
            // 10 00 <- if it has Data it is 10 00 if not is just 00 00 (and no Data can follow up and packet ends here)
            // e1 00 <- short / uint16 data size
            // DATA

            byte[] header = { 0x10, 0x00, 0x00, 0x00 };
            // Raise one up
            loadCharCounter++;

            // Add the counter
            byte[] counterByte = new byte[4];
            counterByte = NumericalUtils.uint32ToByteArray(loadCharCounter, 1);

            // get the datasize for the packet
            byte[] dataSize = NumericalUtils.uint16ToByteArray((UInt16)data.Length, 1);

            // charId
            byte[] charID = NumericalUtils.uint32ToByteArray(this.newCharID, 0);

            // viewData code
            byte[] responseCode = { 0x00, opcode };

            string pakData = StringUtils.bytesToString_NS(header) +
                             StringUtils.bytesToString_NS(charID) +
                             StringUtils.bytesToString_NS(counterByte) +
                             StringUtils.bytesToString_NS(responseCode);

            string hasData;

            // this needs improvement...
            if (data.Length == 0 && opcode == 0x01)
            {
                hasData = "0000";
            }
            else
            {
                hasData = "1000" + StringUtils.bytesToString_NS(dataSize) + StringUtils.bytesToString_NS(data);
            }

            pakData += hasData;
            PacketContent pak = new PacketContent();

            // Dump the Packet Data to see whats in
            //Console.WriteLine("Response Load Pak : " + pakData);

            // Do the viewData
            byte[] response = StringUtils.hexStringToBytes(pakData);
            Output.WritePacketLog(StringUtils.bytesToString(response), "MARGINSERVER", "0", "0", "0");
            Output.WriteDebugLog("[MARGIN SERVER RESPONSE] for OPCODE " + opcode + " : " + StringUtils.bytesToString(response));
            byte[] encryptedResponse = marginEncr.encrypt(response);
            sendTCPVariableLenPacket(encryptedResponse, client);
            System.Threading.Thread.Sleep(50);
        }
Esempio n. 26
0
 public void addSizedString(string value)
 {
     packet.append(NumericalUtils.uint16ToByteArray((UInt16)value.Length, 1));
     packet.append(StringUtils.stringToBytes(value));
 }
Esempio n. 27
0
 public void setValue(UInt16 newValue)
 {
     byte[] t = NumericalUtils.uint16ToByteArray(newValue, 1);
     setValue(t);
 }
Esempio n. 28
0
        public void processOpenDoor(StaticWorldObject door)
        {
            UInt16 typeId = NumericalUtils.ByteArrayToUint16(door.type, 1);

            byte[] masterViewId = { 0x01, 0x00 };
            byte[] seperator    = { 0xcd, 0xab };

            Store.currentClient.playerData.newViewIdCounter++; // It is just for a test Later we will change this to have a List with Views and Object IDs

            byte[] disarmDifficultyMaybe = { 0x03, 0x84 };
            byte[] endViewID             = { 0x00, 0x00 };

            byte[] spawnCounter = NumericalUtils.uint16ToByteArrayShort(Store.currentClient.playerData.assignSpawnIdCounter());
            Output.WriteLine("[DOOR]POS X : " + door.pos_x.ToString() + " POS Y: " + door.pos_y.ToString() + " POS Z: " + door.pos_z.ToString() + ", TypeId: " + StringUtils.bytesToString_NS(door.type));

            switch (typeId)
            {
            case 417:
            case 419:
                // ToDo: Packet Format for Elevator
                // 02 03 01 00
                // 08
                // a3 01
                // 6b 01 f0 3d be
                // cd ab 03 88 00 00 00 00 ff ff 7f 3f 00 00 00 00 f3 04 35 33
                // 22 00 00 00 00 40 f4 fb 40 00 00 00 00 00 90 75 40 00 00 00 00 00 40 af 40 ff ff ff ff 19 00 00
                // 11 00 01 00 04 61 97 e1 47 f0 bf 2d 44 de 30 35 45 00 00
                PacketContent content = new PacketContent();
                content.addByteArray(masterViewId);
                content.addByte(0x08);
                content.addByteArray(door.type);
                content.addByteArray(NumericalUtils.uint32ToByteArray(door.mxoId, 1));
                content.addByteArray(spawnCounter);                            // Spawn Object Counter
                content.addByteArray(seperator);
                content.addByte(0x03);                                         // Number of Attributes to parse (3)
                content.addByte(0x88);                                         // GROUP 1 - more groups ON, Attribute 4 (305,Orientation,LTQuaternion,16) SET (10001000)
                content.addByteArray(StringUtils.hexStringToBytes(door.quat)); // ToDo: replace it later with the real LTQuaternion
                content.addByte(0x22);                                         // GROUP 2 - more groups OFF, Attribute 2,6  SET (00100010)
                content.addDoubleLtVector3d(door.pos_x, door.pos_y, door.pos_z);
                content.addByteArray(new byte[] { 0xff, 0xff, 0xff, 0xff });
                content.addByteArray(NumericalUtils.uint16ToByteArray(Store.currentClient.playerData.newViewIdCounter, 1));
                content.addByteArray(endViewID);
                content.addByte(0x00);
                Store.currentClient.messageQueue.addObjectMessage(content.returnFinalPacket(), false);
                break;

            case 2506:
                // ToDo: Packet Format for Elevator


                break;

            default:

                PacketContent contentDefault = new PacketContent();
                contentDefault.addByteArray(masterViewId);
                contentDefault.addByte(0x08);
                contentDefault.addByteArray(door.type);
                contentDefault.addByteArray(NumericalUtils.uint32ToByteArray(door.mxoId, 1));
                contentDefault.addByteArray(spawnCounter);     // Spawn Object Counter
                contentDefault.addByteArray(seperator);
                contentDefault.addByteArray(disarmDifficultyMaybe);
                contentDefault.addByte(0x00);                                                                  // isZionAligned?
                contentDefault.addByteArray(StringUtils.hexStringToBytes("0000000000803F000000000000000041")); // ToDo: replace it later with the real values from the object
                contentDefault.addDoubleLtVector3d(door.pos_x, door.pos_y, door.pos_z);
                contentDefault.addByteArray(StringUtils.hexStringToBytes("34080000"));
                contentDefault.addByteArray(NumericalUtils.uint16ToByteArray(Store.currentClient.playerData.newViewIdCounter, 1));
                contentDefault.addByteArray(endViewID);
                contentDefault.addByte(0x00);
                Store.currentClient.messageQueue.addObjectMessage(contentDefault.returnFinalPacket(), false);
                break;
            }
        }