sendSystemChatMessage() public method

public sendSystemChatMessage ( WorldClient client, string message, string type ) : void
client WorldClient
message string
type string
return void
Exemplo n.º 1
0
        public void processCharacterAnimationSelf(UInt16 abilityID)
        {
            ServerPackets pak = new ServerPackets();

            // 2904 0429 = Hacker_VirusLaunch_A
            // 2a04 042a = Hacker_VirusLaunch_D
            // see movementAnims.tx - its for codes something (0x31)
            if (currentAbility.getAbilityExecutionFX() > 0)
            {
                pak.sendCastAbilityOnEntityId(2, currentAbility.getAbilityExecutionFX(), 200);
            }

            if (currentAbility.getCastingTime() > 0)
            {
                byte[] castAnimStart = currentAbility.getCastAnimStart();
                // Cast
                pak.sendSystemChatMessage(Store.currentClient,
                                          "Animation Starts with Byte ID " + StringUtils.bytesToString(castAnimStart), "BROADCAST");
                pak.sendPlayerAnimation(Store.currentClient, StringUtils.bytesToString_NS(castAnimStart));

                // And Time a "Damage" or "Buff" Animation
                int castingTime = (int)this.currentAbility.getCastingTime() * 1000;
                this.damageTimer = new Timer(abilityAnimateTheTarget, this, castingTime, 0);
            }
        }
Exemplo n.º 2
0
        public void processHardlineExitConfirm(ref byte[] packet)
        {
            ServerPackets packets = new ServerPackets();

            switch (packet[0])
            {
            case 0x01:
                ServerPackets serverPak = new ServerPackets();
                        #if DEBUG
                serverPak.sendSystemChatMessage(Store.currentClient, "Exit to LA init...", "MODAL");
                        #endif

                // Tell client we want to reset
                byte[] response = { 0x81, 0x07 };

                Store.currentClient.messageQueue.addRpcMessage(response);
                break;

            case 0x02:
                Store.currentClient.playerData.isJackoutInProgress = true;
                Store.currentClient.playerData.jackoutStartTime    = TimeUtils.getUnixTimeUint32();
                packets.sendJackoutEffect(Store.currentClient);
                break;
            }
        }
Exemplo n.º 3
0
        public void processAbility(ref byte[] packet)
        {
            byte[] ability    = { packet[0], packet[1] };
            byte[] targetView = { packet[2], packet[3] };
            UInt16 AbilityID  = NumericalUtils.ByteArrayToUint16(ability, 1);

            UInt16 viewId = 0;

            currentTargetViewId = NumericalUtils.ByteArrayToUint16(targetView, 1);


            // load the ability name from a list to see if we match the right ability
            DataLoader AbilityLoader = DataLoader.getInstance();

            this.currentAbility = AbilityLoader.getAbilityByID(AbilityID);

            // lets create a message for the client - we will later execute the right AbilityScript for it
            ServerPackets pak = new ServerPackets();

            pak.sendSystemChatMessage(Store.currentClient,
                                      "Ability ID is " + AbilityID.ToString() + " and the name is " + currentAbility.getAbilityName() +
                                      " and Target ViewId Is " + currentTargetViewId, "BROADCAST");

            // ToDo: do something with the entity (or queue a fx hit animation or something lol)
            this.processAbilityScript(this.currentAbility);
        }
Exemplo n.º 4
0
        public void processRegionLoaded(ref byte[] packet)
        {
            PacketReader pakReader = new PacketReader(packet);
            UInt16       sectorID  = pakReader.readUInt16(1);
            UInt16       objectID  = pakReader.readUInt16(1);
            float        xPos      = pakReader.readFloat(1);
            float        yPos      = pakReader.readFloat(1);
            float        zPos      = pakReader.readFloat(1);

            ServerPackets pak = new ServerPackets();

            #if DEBUG
            pak.sendSystemChatMessage(Store.currentClient, "Region Object ID " + objectID + " in Sector ID" + sectorID + " X:" + xPos + "Y:" + yPos + "Z:" + zPos, "BROADCAST");
            Output.WriteDebugLog("Region Object ID " + objectID + " in Sector ID" + sectorID + " X:" + xPos + "Y:" + yPos + "Z:" + zPos);
            #endif

            //Store.currentClient.messageQueue.addObjectMessage(StringUtils.hexStringToBytes("020002808080808010110000"));

            /*
             * Store.currentClient.messageQueue.addRpcMessage(StringUtils.hexStringToBytes("80B31100"));
             * Store.currentClient.messageQueue.addRpcMessage(StringUtils.hexStringToBytes("3A050011000A0050765053657276657200040002000000")); // PVP Server Setting
             * Store.currentClient.messageQueue.addRpcMessage(StringUtils.hexStringToBytes("3A0500170010005076504D6178536166654C6576656C0004000F000000")); // PVP Max Safe Level
             * Store.currentClient.messageQueue.addRpcMessage(StringUtils.hexStringToBytes("3A050014000D0057525F52657A4576656E7473002B0048616C6C6F7765656E5F4576656E742C57696E7465723348616C6C6F7765656E466C794579655453454300")); // WR_REZ_events, Halloween, winter etc.
             * Store.currentClient.messageQueue.addRpcMessage(StringUtils.hexStringToBytes("3A0500190012004576656E74536C6F74315F456666656374000000")); // Event Slot : 1_Effect
             * Store.currentClient.messageQueue.addRpcMessage(StringUtils.hexStringToBytes("3A0500190012004576656E74536C6F74325F456666656374000D00666C796D616E5F69646C653300")); // Event Slot : 2_Effect flyman_idle
             * Store.currentClient.messageQueue.addRpcMessage(StringUtils.hexStringToBytes("3A05001B001400466978656442696E6B49444F766572726964650002002000")); // FixedBinkIDOverride
             * Store.currentClient.messageQueue.addRpcMessage(StringUtils.hexStringToBytes("8167170020001C2200C60111000000000000002900000807006D786F656D750007006D786F656D750002000200000000000000")); // Holds character name
             * Store.currentClient.messageQueue.addRpcMessage(StringUtils.hexStringToBytes("80bd051100000000000001"));
             */
        }
Exemplo n.º 5
0
        public void processInvitePlayerToCrew(ref byte[] rpcData)
        {
            // Request Packet: 80 84 19 00 07 00 02 10 00 54 72 69 6e 69 74 79 73 27 73 20 43 72 65 77 00 07 00 54 68 65 4e 65 6f 00
            // Request Packet: 80 84 22 00 07 00 03 19 00 54 68 69 73 20 69 73 20 74 68 65 20 41 77 65 73 6f 6d 65 20 43 72 65 77 00 09 00 54 72 69 6e 69 74 79 73 00

            // Response

            // ToDO: add it to the tempCrews and check if name is reserved on DB (and check if double names are possible)
            // ToDo: Questions 1. should we persist it directly to reserve crewname in the DB ? maybe its better
            PacketReader pakRead = new PacketReader(rpcData);

            UInt16 someUint16   = pakRead.readUInt16(1);
            UInt16 someUint162  = pakRead.readUInt16(1);
            uint   orgId        = pakRead.readUint8();
            string crewName     = pakRead.readSizedZeroTerminatedString().Trim();
            string playerHandle = pakRead.readSizedZeroTerminatedString().Trim();

            bool isCrewNameAvailable = Store.dbManager.WorldDbHandler.isCrewNameAvailable(crewName);

            // ToDo: Just "reserve" the crewName - so if crewName exists and membercount is just one or zero and its older than a day - delete it (this can be done by the "isCrewNameAvailable" too).
            ServerPackets pak = new ServerPackets();

            if (isCrewNameAvailable)
            {
                Store.dbManager.WorldDbHandler.addCrew(crewName, StringUtils.charBytesToString_NZ(Store.currentClient.playerInstance.CharacterName.getValue()));
                pak.sendCrewInviteToPlayer(playerHandle, crewName);
            }
            else
            {
                pak.sendSystemChatMessage(Store.currentClient, "Crewname was already taken - please choose a new one", "BROADCAST");
            }
        }
Exemplo n.º 6
0
        public void processObjectDynamic(ref byte[] packet)
        {
            PacketReader reader = new PacketReader(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];


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

            #if DEBUG
            pak.sendSystemChatMessage(Store.currentClient, "Object Type ID IS " + objectTypeID.ToString() + " Dynamic Object RPC : " + StringUtils.bytesToString_NS(packet), "BROADCAST");
            #endif

            switch (objectTypeID)
            {
            case (int)objectTypesDynamic.LOOT:
                UInt32[] theTestArrayLoots = new UInt32[2];
                theTestArrayLoots[0] = NumericalUtils.ByteArrayToUint32(StringUtils.hexStringToBytes("8e220000"), 1);
                pak.SendLootWindow(5000, Store.currentClient, theTestArrayLoots);
                break;


            default:
                pak.sendSystemChatMessage(Store.currentClient, "[OI HELPER] Unknown Object Type : " + objectTypeID.ToString() + "| Object ID :" + id, "MODAL");
                break;
            }
        }
Exemplo n.º 7
0
        public void processTargetChange(ref byte[] rpcData, WorldClient currentClient)
        {
            UInt16 viewId  = NumericalUtils.ByteArrayToUint16(new byte[] { rpcData[0], rpcData[1] }, 1);
            ushort spawnId = rpcData[2];

            // ToDo: add this to the ClientData
            currentClient.playerData.currentSelectedTargetViewId  = viewId;
            currentClient.playerData.currentSelectedTargetSpawnId = spawnId;
            ServerPackets pak = new ServerPackets();

            pak.sendSystemChatMessage(Store.currentClient, "TARGET CHANGE For ViewID " + viewId.ToString() + " AND SPAWN ID : " + spawnId.ToString(), "MODAL");
        }
Exemplo n.º 8
0
        public void processHardlineExitConfirm(ref byte[] packet)
        {
            if (packet[0] == 0x01)
            {
                ServerPackets serverPak = new ServerPackets();
                serverPak.sendSystemChatMessage(Store.currentClient, "Exit to LA init...", "MODAL");

                // Tell client we want to reset
                byte[] response = { 0x81, 0x07 };

                Store.currentClient.messageQueue.addRpcMessage(response);
            }
        }
Exemplo n.º 9
0
        public void processHardlineExitConfirm(ref byte[] packet)
        {
            if (packet[0] == 0x01)
            {
                ServerPackets serverPak = new ServerPackets();
                serverPak.sendSystemChatMessage(Store.currentClient, "Exit to LA init...","MODAL");

                // Tell client we want to reset
                byte[] response = { 0x81, 0x07 };

                Store.currentClient.messageQueue.addRpcMessage(response);
            }
        }
Exemplo n.º 10
0
        public void processHardlineTeleport(ref byte[] packet)
        {
            // we dont care where the journey goes
            // just want to see IF the journey will do :)
            // for this just ack and send 0x42 packet
            byte[] sourceHardline = new byte[2];
            sourceHardline[0] = packet[0];
            sourceHardline[1] = packet[1];

            byte[] sourceDistrict = new byte[2];
            sourceDistrict[0] = packet[4];
            sourceDistrict[1] = packet[5];

            byte[] destHardline = new byte[2];
            destHardline[0] = packet[8];
            destHardline[1] = packet[9];

            byte[] destDistrict = new byte[2];
            destDistrict[0] = packet[12];
            destDistrict[1] = packet[13];

            UInt16 sourceHL  = NumericalUtils.ByteArrayToUint16(sourceHardline, 1);
            UInt16 sourceDIS = NumericalUtils.ByteArrayToUint16(sourceDistrict, 1);

            UInt16 destHL  = NumericalUtils.ByteArrayToUint16(destHardline, 1);
            UInt16 destDIS = NumericalUtils.ByteArrayToUint16(destDistrict, 1);

            // This should do the magic - we just catch
            Store.dbManager.WorldDbHandler.updateLocationByHL(destDIS, destHL);
            Store.dbManager.WorldDbHandler.updateSourceHlForObjectTracking(sourceDIS, sourceHL, Store.currentClient.playerData.lastClickedObjectId);

            #if DEBUG
            ServerPackets serverPak = new ServerPackets();
            serverPak.sendSystemChatMessage(Store.currentClient, "User wants teleport from : HL ID: " + sourceHL.ToString() + " (DIS: " + sourceDIS.ToString() + " ) TO HL ID: " + destHL.ToString() + " (DIS: " + destDIS.ToString() + ") ", "MODAL");
            #endif

            // Tell client we want to unload the World
            PacketContent pak = new PacketContent();
            pak.addUint16((UInt16)RPCResponseHeaders.SERVER_LOAD_RPC_RESET, 0);
            Store.currentClient.messageQueue.addRpcMessage(pak.returnFinalPacket());
            Store.currentClient.FlushQueue();
        }
Exemplo n.º 11
0
        public void processHardlineTeleport(ref byte[] packet)
        {
            // we dont care where the journey goes
            // just want to see IF the journey will do :)
            // for this just ack and send 0x42 packet
            byte[] sourceHardline = new byte[2];
            sourceHardline[0] = packet[0];
            sourceHardline[1] = packet[1];

            byte[] sourceDistrict = new byte[2];
            sourceDistrict[0] = packet[4];
            sourceDistrict[1] = packet[5];

            byte[] destHardline = new byte[2];
            destHardline[0]   = packet[8];
            destHardline[1]   = packet[9];

            byte[] destDistrict = new byte[2];
            destDistrict[0]   = packet[12];
            destDistrict[1]   = packet[13];

            UInt16 sourceHL   = NumericalUtils.ByteArrayToUint16(sourceHardline,1);
            UInt16 sourceDIS = NumericalUtils.ByteArrayToUint16(sourceDistrict,1);

            UInt16 destHL = NumericalUtils.ByteArrayToUint16(destHardline, 1);
            UInt16 destDIS = NumericalUtils.ByteArrayToUint16(destDistrict,1);

            // This should do the magic - we just catch
            Store.dbManager.WorldDbHandler.updateLocationByHL(destDIS, destHL);
            Store.dbManager.WorldDbHandler.updateSourceHlForObjectTracking(sourceDIS, sourceHL, Store.currentClient.playerData.lastClickedObjectId);

            ServerPackets serverPak = new ServerPackets();
            serverPak.sendSystemChatMessage(Store.currentClient,"User wants teleport from : HL ID: " + sourceHL.ToString() + " (DIS: " + sourceDIS.ToString() + " ) TO HL ID: " + destHL.ToString() + " (DIS: " + destDIS.ToString() + ") ","MODAL");

            // Tell client we want to unload the World
            PacketContent pak = new PacketContent();
            pak.addUint16((UInt16)RPCResponseHeaders.SERVER_LOAD_RPC_RESET, 0);
            Store.currentClient.messageQueue.addRpcMessage(pak.returnFinalPacket());
            Store.currentClient.flushQueue();
        }
Exemplo n.º 12
0
        private static void CheckPlayerMobViews()
        {
            // Spawn/Update for mobs
            int npcCount = WorldSocket.npcs.Count;

            for (int i = 0; i < npcCount; i++)
            {
                Mob thismob = (Mob)WorldSocket.npcs[i];

                lock (WorldSocket.Clients.SyncRoot)
                {
                    foreach (string clientKey in WorldSocket.Clients.Keys)
                    {
                        // Loop through all clients
                        WorldClient thisclient = WorldSocket.Clients[clientKey] as WorldClient;

                        if (thisclient.Alive == true)
                        {
                            // Check if

                            if (thisclient.playerData.getOnWorld() == true && thisclient.playerData.waitForRPCShutDown == false)
                            {
                                Maths  math    = new Maths();
                                double playerX = 0;
                                double playerY = 0;
                                double playerZ = 0;
                                NumericalUtils.LtVector3dToDoubles(thisclient.playerInstance.Position.getValue(), ref playerX, ref playerY, ref playerZ);
                                Maths mathUtils     = new Maths();
                                bool  mobIsInCircle = mathUtils.IsInCircle((float)playerX, (float)playerZ, (float)thismob.getXPos(), (float)thismob.getZPos(), 5000);

                                // Spawn Mob if its in Visibility Range
                                ClientView mobView = thisclient.viewMan.getViewForEntityAndGo(thismob.getEntityId(), NumericalUtils.ByteArrayToUint16(thismob.getGoId(), 1));
                                if (mobView.viewCreated == false && thismob.getDistrict() == thisclient.playerData.getDistrictId() && thisclient.playerData.getOnWorld() && mobIsInCircle)
                                {
                                    #if DEBUG
                                    ServerPackets pak = new ServerPackets();
                                    pak.sendSystemChatMessage(thisclient, "Mob with Name " + thismob.getName() + " with new View ID " + mobView.ViewID + " spawned", "BROADCAST");
                                    #endif

                                    ServerPackets mobPak = new ServerPackets();
                                    mobPak.SpawnMobView(thisclient, thismob, mobView);
                                    mobView.spawnId      = thisclient.playerData.spawnViewUpdateCounter;
                                    mobView.viewCreated  = true;
                                    thismob.isUpdateable = true;
                                    thismob.DoMobUpdate(thismob);
                                }

                                // Delete Mob's View from Client if we are outside
                                if (mobView.viewCreated == true && !mobIsInCircle && thismob.getDistrict() == thisclient.playerData.getDistrictId())
                                {
                                    // ToDo: delete mob
                                    ServerPackets packets = new ServerPackets();
                                    packets.sendDeleteViewPacket(thisclient, mobView.ViewID);
                                    #if DEBUG
                                    packets.sendSystemChatMessage(thisclient, "MobView (" + thismob.getName() + " LVL: " + thismob.getLevel() + " ) with View ID " + mobView.ViewID + " is out of range and is deleted!", "MODAL");
                                    #endif
                                    thisclient.viewMan.removeViewByViewId(mobView.ViewID);
                                    thismob.isUpdateable = false;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 13
0
        private static void CheckPlayerViews()
        {
            // Check for Player Views
            lock (WorldSocket.Clients.SyncRoot)
            {
                foreach (string clientKey in WorldSocket.Clients.Keys)
                {
                    // get Current client
                    WorldClient currentClient = WorldSocket.Clients[clientKey] as WorldClient;
                    // Loop all Clients and check if we need to create a view for it
                    foreach (string clientOtherKey in WorldSocket.Clients.Keys)
                    {
                        WorldClient otherClient = WorldSocket.Clients[clientOtherKey] as WorldClient;
                        if (otherClient != currentClient)
                        {
                            ClientView clientView = currentClient.viewMan.getViewForEntityAndGo(
                                otherClient.playerData.getEntityId(),
                                NumericalUtils.ByteArrayToUint16(otherClient.playerInstance.GetGoid(), 1));

                            // Create
                            Maths  math           = new Maths();
                            double currentPlayerX = 0;
                            double currentPlayerY = 0;
                            double currentPlayerZ = 0;

                            double otherPlayerX = 0;
                            double otherPlayerY = 0;
                            double otherPlayerZ = 0;

                            NumericalUtils.LtVector3dToDoubles(currentClient.playerInstance.Position.getValue(), ref currentPlayerX, ref currentPlayerY, ref currentPlayerZ);
                            NumericalUtils.LtVector3dToDoubles(currentClient.playerInstance.Position.getValue(), ref otherPlayerX, ref otherPlayerY, ref otherPlayerZ);
                            Maths mathUtils        = new Maths();
                            bool  playerIsInCircle = mathUtils.IsInCircle((float)currentPlayerX, (float)currentPlayerZ, (float)otherPlayerX, (float)otherPlayerZ, 5000);
                            if (clientView.viewCreated == false &&
                                currentClient.playerData.getDistrictId() == otherClient.playerData.getDistrictId() &&
                                otherClient.playerData.getOnWorld() && currentClient.playerData.getOnWorld() &&
                                playerIsInCircle)
                            {
                                // Spawn player
                                ServerPackets pak = new ServerPackets();
                                pak.sendSystemChatMessage(currentClient,
                                                          "Player " + StringUtils.charBytesToString_NZ(otherClient.playerInstance.CharacterName.getValue()) + " with new View ID " +
                                                          clientView.ViewID + " jacked in", "BROADCAST");
                                pak.sendPlayerSpawn(currentClient, otherClient, clientView.ViewID);
                                clientView.spawnId     = currentClient.playerData.spawnViewUpdateCounter;
                                clientView.viewCreated = true;
                            }


                            if (clientView.viewCreated && !playerIsInCircle)
                            {
                                // ToDo: delete mob
                                ServerPackets packets = new ServerPackets();
                                packets.sendSystemChatMessage(currentClient,
                                                              "Player " + StringUtils.charBytesToString_NZ(otherClient.playerInstance.CharacterName.getValue()) + " with View ID " + clientView.ViewID +
                                                              " jacked out!", "MODAL");
                                packets.sendDeleteViewPacket(currentClient, clientView.ViewID);
                                currentClient.viewMan.removeViewByViewId(clientView.ViewID);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 14
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);
            }
        }
Exemplo n.º 15
0
        public void processObjectInteraction(StaticWorldObject staticWorldObject, GameObjectItem item)
        {
            WorldSocket.gameServerEntities.Add(staticWorldObject);
            UInt16 typeId = NumericalUtils.ByteArrayToUint16(staticWorldObject.type, 1);

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

            NumericalUtils.uint16ToByteArrayShort(Store.currentClient.playerData.assignSpawnIdCounter());
            ServerPackets packets = new ServerPackets();

            packets.sendSystemChatMessage(Store.currentClient, "Door ID " + staticWorldObject.mxoId + " Type ID " + typeId.ToString() + " POS X:" + staticWorldObject.pos_x.ToString() + " Y:" + staticWorldObject.pos_y.ToString() + " Z:" + staticWorldObject.pos_z.ToString() + typeId, "BROADCAST");


            switch (typeId)
            {
            case 343:
            case 346:
            case 359:
            case 365:
            case 414:
            case 415:
            case 416:
            case 576:
            case 6958:
            case 6965:
            case 6963:
            case 6964:
            case 6972:
                // ObjectAttribute364
                ObjectAttributes364 door364 = new ObjectAttributes364("DOOR364", typeId, staticWorldObject.mxoId);
                door364.DisableAllAttributes();
                door364.Orientation.enable();
                door364.Position.enable();
                door364.CurrentState.enable();
                // Set Values
                door364.Position.setValue(NumericalUtils.doublesToLtVector3d(staticWorldObject.pos_x, staticWorldObject.pos_y, staticWorldObject.pos_z));
                door364.CurrentState.setValue(StringUtils.hexStringToBytes("34080000"));
                door364.Orientation.setValue(StringUtils.hexStringToBytes(staticWorldObject.quat));
                //door364.Orientation.setValue(StringUtils.hexStringToBytes("000000000000803F0000000000000000")); // ToDo: Replace it with staticWorldObject.quat when it is okay

                // ToDo: We make a little Entity "Hack" so that we have a unique id : metrid + fullmxostatic_id is entity
                String entityMxOHackString = "" + staticWorldObject.metrId + "" + staticWorldObject.mxoId;
                UInt64 entityId            = UInt64.Parse(entityMxOHackString);

                packets.sendSpawnStaticObject(Store.currentClient, door364, entityId);

                break;

            case 6601:
            case 6994:
            case 341:
            case 417:
            case 419:

                ObjectAttributes363 door363 = new ObjectAttributes363("DOOR363", typeId, staticWorldObject.mxoId);
                door363.DisableAllAttributes();
                door363.Orientation.enable();
                door363.Position.enable();
                door363.CurrentState.enable();
                // Set Values
                door363.Position.setValue(NumericalUtils.doublesToLtVector3d(staticWorldObject.pos_x, staticWorldObject.pos_y, staticWorldObject.pos_z));
                door363.Orientation.setValue(StringUtils.hexStringToBytes(staticWorldObject.quat));
                //door363.Orientation.setValue(StringUtils.hexStringToBytes("000000000000803F0000000000000000")); // ToDo: Replace it with staticWorldObject.quat when it is okay
                door363.CurrentState.setValue(StringUtils.hexStringToBytes("34080000"));

                // ToDo: We make a little Entity "Hack" so that we have a unique id : metrid + fullmxostatic_id is entity
                String entity363MxOHackString = "" + staticWorldObject.metrId + "" + staticWorldObject.mxoId;
                UInt64 entity363Id            = UInt64.Parse(entity363MxOHackString);

                packets.sendSpawnStaticObject(Store.currentClient, door363, entity363Id);
                break;

            case 592:
                new TeleportHandler().processHardlineExitRequest();
                break;

            default:
                new ServerPackets().sendSystemChatMessage(Store.currentClient, "Unknown Object Interaction with Object Type " + staticWorldObject.type + " and Name " + item.getName(), "MODAL");
                break;
            }
        }
Exemplo n.º 16
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;
            }
        }
Exemplo n.º 17
0
        /**
         * This handles all RPC requests for the client
         */

        public void HandleRpc(int header, ref byte[] rpcData)
        {
            ServerPackets pak = new ServerPackets();

            pak.sendSystemChatMessage(Store.currentClient, "Handle RPC Client Request Header " + StringUtils.bytesToString_NS(NumericalUtils.int32ToByteArray(header, 0)), "BROADCAST");
            switch (header)
            {
            case (int)RPCRequestHeader.CLIENT_SPAWN_READY:
                new PlayerHandler().processSpawn();
                new PlayerHandler().processAttributes();
                break;

            case (int)RPCRequestHeader.CLIENT_CLOSE_COMBAT:
                Output.WriteRpcLog("CLOSE COMBAT REQUEST");
                new TestUnitHandler().testCloseCombat(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_LEAVE_COMBAT:

                break;

            case (int)RPCRequestHeader.CLIENT_RANGE_COMBAT:
                Output.WriteRpcLog("RANGE COMBAT REQUEST");
                new TestUnitHandler().testCloseCombat(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_CHAT:
                new ChatHandler().processChat(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_OBJECTINTERACTION_DYNAMIC:
                new ObjectInteractionHandler().processObjectDynamic(ref rpcData);
                Output.writeToLogForConsole("RPCMAIN : Handle OBJECTINTERACTION_DYNAMIC");
                break;

            case (int)RPCRequestHeader.CLIENT_OBJECTINTERACTION_STATIC:
                new ObjectInteractionHandler().processObjectStatic(ref rpcData);
                Output.writeToLogForConsole("RPCMAIN : Handle OBJECTINTERACTION_STATIC");
                break;

            case (int)RPCRequestHeader.CLIENT_JUMP:
                Output.writeToLogForConsole("RPCMAIN : Handle JUMP");
                //ToDo: Split Jump and Hyperjump
                //new TestUnitHandler().processHyperJump(ref rpcData);
                new TestUnitHandler().processHyperJump(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_TARGET:
                new PlayerHelper().processTargetChange(ref rpcData, Store.currentClient);
                break;

            case (int)RPCRequestHeader.CLIENT_MISSION_REQUEST:
                new MissionHandler().processMissionList(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_MISSION_INFO:
                new MissionHandler().processLoadMissionInfo(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_MISSION_ACCEPT:
                new MissionHandler().processMissionaccept(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_MISSION_ABORT:
                new MissionHandler().processAbortMission(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_PARTY_LEAVE:
                break;

            // Team
            case (int)RPCRequestHeader.CLIENT_HANDLE_MISSION_INVITE:
                new TeamHandler().processTeamInviteAnswer(ref rpcData);
                break;

            // Faction and Crews
            case (int)RPCRequestHeader.CLIENT_FACTION_INFO:
                new FCHandler().processLoadFactionName(ref rpcData);
                // ToDo: implement response with following format :
                // size + 80 f5 + uint32 factionId + String(40 size? unusual...)
                // Example: 30 80 f5 11 ba 00 00 48 79 50 6e 30 74 69 5a 65 44 20 4d 69 4e 64 5a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
                break;

            // Abilitys
            case (int)RPCRequestHeader.CLIENT_UPGRADE_ABILITY_LEVEL:
                // ToDo: Research and implement^^
                break;

            case (int)RPCRequestHeader.CLIENT_ABILITY_HANDLER:
                new AbilityHandler().processAbility(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_CHANGE_CT:
                new PlayerHelper().processUpdateExp();
                break;

            case (int)RPCRequestHeader.CLIENT_ABILITY_LOADER:
                new PlayerHelper().processLoadAbility(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_HARDLINE_EXIT_LA_CONFIRM:
                new TeleportHandler().processHardlineExitConfirm(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_READY_WORLDCHANGE:
                Output.WriteLine("RPCMAIN : RESET_RPC detect");
                new TeleportHandler().processTeleportReset(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_TELEPORT_HL:
                new TeleportHandler().processHardlineTeleport(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_HARDLINE_STATUS_REQUEST:
                new TeleportHandler().processHardlineStatusRequest(ref rpcData);
                break;


            // Inventory
            case (int)RPCRequestHeader.CLIENT_ITEM_MOVE_SLOT:
                new InventoryHandler().processItemMove(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_ITEM_RECYCLE:
                new InventoryHandler().processItemDelete(ref rpcData);
                break;

            // Vendor
            case (int)RPCRequestHeader.CLIENT_VENDOR_BUY:
                new VendorHandler().processBuyItem(ref rpcData);
                break;

            // MarketPlace
            case (int)RPCRequestHeader.CLIENT_MP_OPEN:
                new TestUnitHandler().processMarketTest(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_MP_LIST_ITEMS:
                new MarketPlaceHandler().processMarketplaceList(ref rpcData);
                break;


            // Command Helper
            case (int)RPCRequestHeader.CLIENT_CMD_WHEREAMI:
                new CommandHandler().processWhereamiCommand(ref rpcData);
                break;

            // Emote and Mood Helpers
            case (int)RPCRequestHeader.CLIENT_CHANGE_MOOD:
                new PlayerHandler().processMood(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_EMOTE:
                new PlayerHandler().processEmote(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_REGION_LOADED:
                new RegionHandler().processRegionLoaded(ref rpcData);
                //new PlayerInitHelper().processRegionSettings();
                break;


            default:
                //PASS :D
                byte[] headers = NumericalUtils.int32ToByteArray(header, 1);

                string message = "RPCMAIN : Unknown Header " + StringUtils.bytesToString_NS(new byte[] { headers[0], headers[1] }) + " \n Content:\n " + StringUtils.bytesToString_NS(rpcData);
                Output.WriteLine(message);
                Output.WriteRpcLog(message);

                break;
            }
        }
Exemplo n.º 18
0
 public void processTargetChange(ref byte[] rpcData, WorldClient currentClient)
 {
     UInt16 viewId = NumericalUtils.ByteArrayToUint16(new byte[] { rpcData[0], rpcData[1] }, 1);
     ushort spawnId = rpcData[2];
     // ToDo: add this to the ClientData
     currentClient.playerData.currentSelectedTargetViewId = viewId;
     currentClient.playerData.currentSelectedTargetSpawnId = spawnId;
     ServerPackets pak = new ServerPackets();
     pak.sendSystemChatMessage(Store.currentClient, "TARGET CHANGE For ViewID " + viewId.ToString() + " AND SPAWN ID : " + spawnId.ToString(), "MODAL");
 }
Exemplo n.º 19
0
        public void ViewVisibleThread()
        {
            Output.WriteLine("[WORLD SERVER]View Visible Thread started");
            while (true)
            {
                ArrayList deadPlayers    = new ArrayList();
                ArrayList removeEntities = new ArrayList();

                // Clean
                lock (WorldSocket.Clients.SyncRoot)
                {
                    foreach (string clientKey in WorldSocket.Clients.Keys)
                    {
                        // Collect dead players to arraylist
                        WorldClient thisclient = WorldSocket.Clients[clientKey] as WorldClient;

                        if (thisclient.Alive == false)
                        {
                            // Add dead Player to the List - we need later to clear them
                            deadPlayers.Add(clientKey);
                        }
                    }
                    cleanDeadPlayers(deadPlayers);
                }

                // Check for Player Views
                lock (WorldSocket.Clients.SyncRoot)
                {
                    foreach (string clientKey in WorldSocket.Clients.Keys)
                    {
                        // get Current client
                        WorldClient currentClient = WorldSocket.Clients[clientKey] as WorldClient;
                        // Loop all Clients and check if we need to create a view for it
                        foreach (string clientOtherKey in WorldSocket.Clients.Keys)
                        {
                            WorldClient otherClient = WorldSocket.Clients[clientOtherKey] as WorldClient;
                            if (otherClient != currentClient)
                            {
                                ClientView clientView = currentClient.viewMan.getViewForEntityAndGo(otherClient.playerData.getEntityId(), NumericalUtils.ByteArrayToUint16(otherClient.playerInstance.GetGoid(), 1));

                                // Create
                                Maths  math           = new Maths();
                                double currentPlayerX = 0;
                                double currentPlayerY = 0;
                                double currentPlayerZ = 0;

                                double otherPlayerX = 0;
                                double otherPlayerY = 0;
                                double otherPlayerZ = 0;

                                NumericalUtils.LtVector3dToDoubles(currentClient.playerInstance.Position.getValue(), ref currentPlayerX, ref currentPlayerY, ref currentPlayerZ);
                                NumericalUtils.LtVector3dToDoubles(currentClient.playerInstance.Position.getValue(), ref otherPlayerX, ref otherPlayerY, ref otherPlayerZ);
                                Maths mathUtils        = new Maths();
                                bool  playerIsInCircle = mathUtils.IsInCircle((float)currentPlayerX, (float)currentPlayerZ, (float)otherPlayerX, (float)otherPlayerZ, 5000);
                                if (clientView.viewCreated == false && currentClient.playerData.getDistrictId() == otherClient.playerData.getDistrictId() && otherClient.playerData.getOnWorld() && currentClient.playerData.getOnWorld() && playerIsInCircle)
                                {
                                    // Spawn player
                                    ServerPackets pak = new ServerPackets();
                                    pak.sendSystemChatMessage(currentClient, "Player " + otherClient.playerInstance.GetName() + " with new View ID " + clientView.ViewID + " jacked in", "BROADCAST");
                                    pak.sendPlayerSpawn(currentClient, otherClient, clientView.ViewID);
                                    clientView.spawnId     = currentClient.playerData.spawnViewUpdateCounter;
                                    clientView.viewCreated = true;
                                }


                                if (clientView.viewCreated && !playerIsInCircle)
                                {
                                    // ToDo: delete mob
                                    ServerPackets packets = new ServerPackets();
                                    packets.sendSystemChatMessage(currentClient, "Player " + otherClient.playerInstance.GetName() + " with View ID " + clientView.ViewID + " jacked out!", "MODAL");
                                    packets.sendDeleteViewPacket(currentClient, clientView.ViewID);
                                    currentClient.viewMan.removeViewByViewId(clientView.ViewID);
                                }
                            }
                        }
                    }
                }



                // Spawn/Update for mobs
                int npcCount = WorldSocket.npcs.Count;
                for (int i = 0; i < npcCount; i++)
                {
                    npc thismob = (npc)WorldSocket.npcs[i];

                    lock (WorldSocket.Clients.SyncRoot)
                    {
                        foreach (string clientKey in WorldSocket.Clients.Keys)
                        {
                            // Loop through all clients
                            WorldClient thisclient = WorldSocket.Clients[clientKey] as WorldClient;

                            if (thisclient.Alive == true)
                            {
                                // Check if

                                if (thisclient.playerData.getOnWorld() == true && thisclient.playerData.waitForRPCShutDown == false)
                                {
                                    Maths  math    = new Maths();
                                    double playerX = 0;
                                    double playerY = 0;
                                    double playerZ = 0;
                                    NumericalUtils.LtVector3dToDoubles(thisclient.playerInstance.Position.getValue(), ref playerX, ref playerY, ref playerZ);
                                    Maths mathUtils     = new Maths();
                                    bool  mobIsInCircle = mathUtils.IsInCircle((float)playerX, (float)playerZ, (float)thismob.getXPos(), (float)thismob.getZPos(), 5000);

                                    // ToDo: Check if mob is in circle of player (radian some value that is in a middle range for example 300m)
                                    // Create
                                    ClientView mobView = thisclient.viewMan.getViewForEntityAndGo(thismob.getEntityId(), NumericalUtils.ByteArrayToUint16(thismob.getGoId(), 1));
                                    if (mobView.viewCreated == false && thismob.getDistrict() == thisclient.playerData.getDistrictId() && thisclient.playerData.getOnWorld() && mobIsInCircle)
                                    {
                                        ServerPackets pak = new ServerPackets();
                                        pak.sendSystemChatMessage(thisclient, "Mob with Name " + thismob.getName() + " with new View ID " + mobView.ViewID + " spawned", "BROADCAST");
                                        ServerPackets mobPak = new ServerPackets();
                                        mobPak.spawnMobView(thisclient, thismob, mobView);
                                        mobView.spawnId     = thisclient.playerData.spawnViewUpdateCounter;
                                        mobView.viewCreated = true;
                                    }

                                    // Update Mob
                                    if (mobView.viewCreated == true && thismob.getDistrict() == thisclient.playerData.getDistrictId() && thisclient.playerData.getOnWorld())
                                    {
                                        // ToDo: We need to involve the Statuslist here and we need to move them finaly
                                        if (thismob.getIsDead() == false)
                                        {
                                            updateMob(thisclient, ref thismob, mobView);
                                        }
                                    }

                                    // Mob moves outside - should delete it
                                    if (mobView.viewCreated == true &&
                                        !mobIsInCircle &&
                                        thismob.getDistrict() == thisclient.playerData.getDistrictId())
                                    {
                                        // ToDo: delete mob
                                        ServerPackets packets = new ServerPackets();
                                        packets.sendDeleteViewPacket(thisclient, mobView.ViewID);
                                        packets.sendSystemChatMessage(thisclient, "MobView (" + thismob.getName() + " LVL: " + thismob.getLevel() + " ) with View ID " + mobView.ViewID + " is out of range and is deleted!", "MODAL");
                                        thisclient.viewMan.removeViewByViewId(mobView.ViewID);
                                    }
                                }
                            }
                        }
                    }
                    thismob.updateClient = false;
                }
                Thread.Sleep(500);
            }
        }
Exemplo 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);
            }
        }
Exemplo n.º 21
0
        /**
         * This handles all RPC requests for the client
         */

        public void HandleRpc(int header, ref byte[] rpcData)
        {
            ServerPackets pak = new ServerPackets();

                        #if DEBUG
            pak.sendSystemChatMessage(Store.currentClient, "Handle RPC Client Request Header " + StringUtils.bytesToString_NS(NumericalUtils.int32ToByteArray(header, 0)), "BROADCAST");
                        #endif
            switch (header)
            {
            case (int)RPCRequestHeader.CLIENT_SPAWN_READY:
                new PlayerHandler().processSpawn();
                new PlayerHandler().processAttributes();
                break;

            case (int)RPCRequestHeader.CLIENT_CLOSE_COMBAT:
                                        #if DEBUG
                Output.WriteRpcLog("CLOSE COMBAT REQUEST");
                                        #endif
                new TestUnitHandler().testCloseCombat(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_LEAVE_COMBAT:

                break;

            case (int)RPCRequestHeader.CLIENT_RANGE_COMBAT:
                                #if DEBUG
                Output.WriteRpcLog("RANGE COMBAT REQUEST");
                                        #endif
                new TestUnitHandler().testCloseCombat(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_CHAT:
                new ChatHandler().processChat(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_OBJECTINTERACTION_DYNAMIC:
                new ObjectInteractionHandler().processObjectDynamic(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_OBJECTINTERACTION_STATIC:
                new ObjectInteractionHandler().processObjectStatic(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_JUMP_START:
                //ToDo: Split Jump and Hyperjump
                new AbilityHandler().processHyperJump(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_JUMP_CANCEL:
                // ToDo:
                new AbilityHandler().processHyperJumpCancel(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_TARGET:
                new PlayerHelper().processTargetChange(ref rpcData, Store.currentClient);
                break;

            case (int)RPCRequestHeader.CLIENT_MISSION_INVITE_PLAYER:
                new MissionHandler().processInvitePlayerToMissionTeam(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_MISSION_REQUEST:
                new MissionHandler().processMissionList(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_MISSION_INFO:
                new MissionHandler().processLoadMissionInfo(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_MISSION_ACCEPT:
                new MissionHandler().processMissionaccept(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_MISSION_ABORT:
                new MissionHandler().processAbortMission(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_PARTY_LEAVE:
                break;

            // Team
            case (int)RPCRequestHeader.CLIENT_HANDLE_MISSION_INVITE:
                new TeamHandler().processInviteAnswer(ref rpcData);
                break;

            // Faction and Crews
            case (int)RPCRequestHeader.CREW_INVITE_PLAYER:
                new FCHandler().processInvitePlayerToCrew(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_FACTION_INFO:
                new FCHandler().processLoadFactionName(ref rpcData);
                break;

            // Abilitys
            case (int)RPCRequestHeader.CLIENT_UPGRADE_ABILITY_LEVEL:
                // ToDo: Research and implement^^
                break;

            case (int)RPCRequestHeader.CLIENT_ABILITY_HANDLER:
                new AbilityHandler().processAbility(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_CHANGE_CT:
                // ToDo: Implement Change of CT
                break;

            case (int)RPCRequestHeader.CLIENT_ABILITY_LOADER:
                new PlayerHelper().processLoadAbility(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_HARDLINE_EXIT_LA_CONFIRM:
                new TeleportHandler().processHardlineExitConfirm(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_EXIT_GAME_FINISH:
                new TeleportHandler().processGameFinish();
                break;

            case (int)RPCRequestHeader.CLIENT_READY_WORLDCHANGE:
                new TeleportHandler().processTeleportReset(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_TELEPORT_HL:
                new TeleportHandler().processHardlineTeleport(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_HARDLINE_STATUS_REQUEST:
                new TeleportHandler().processHardlineStatusRequest(ref rpcData);
                break;


            // Inventory
            case (int)RPCRequestHeader.CLIENT_ITEM_MOUNT_RSI:
                new InventoryHandler().processMountItem(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_ITEM_UNMOUNT_RSI:
                new InventoryHandler().processUnmountItem(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_ITEM_MOVE_SLOT:
                new InventoryHandler().processItemMove(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_ITEM_RECYCLE:
                new InventoryHandler().processItemDelete(ref rpcData);
                break;

            // Vendor
            case (int)RPCRequestHeader.CLIENT_VENDOR_BUY:
                new VendorHandler().processBuyItem(ref rpcData);
                break;

            // MarketPlace
            case (int)RPCRequestHeader.CLIENT_MP_OPEN:
                new TestUnitHandler().processMarketTest(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_MP_LIST_ITEMS:
                new MarketPlaceHandler().processMarketplaceList(ref rpcData);
                break;

            // Player

            case (int)RPCRequestHeader.CLIENT_PLAYER_GET_BACKGROUND:
                new PlayerHandler().processGetBackgroundRequest(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_PLAYER_SET_BACKGROUND:
                new PlayerHandler().processSetBackgroundRequest(ref rpcData);
                break;

            // Command Helper
            case (int)RPCRequestHeader.CLIENT_CMD_WHEREAMI:
                new CommandHandler().processWhereamiCommand(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_CMD_WHO:
                new CommandHandler().processWhoCommand(ref rpcData);
                break;

            // Emote and Mood Helpers
            case (int)RPCRequestHeader.CLIENT_CHANGE_MOOD:
                new PlayerHandler().processMood(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_EMOTE:
                new PlayerHandler().processEmote(ref rpcData);
                break;

            case (int)RPCRequestHeader.CLIENT_REGION_LOADED:
                new RegionHandler().processRegionLoaded(ref rpcData);
                //new PlayerInitHelper().processRegionSettings();
                break;

            case (int)RPCRequestHeader.CLIENT_LOOT_ACCEPT:
                new PlayerHandler().processLootAccepted();
                break;


            default:
                //PASS :D
                byte[] headers = NumericalUtils.int32ToByteArray(header, 1);

                                #if DEBUG
                string message = "RPCMAIN : Unknown Header " +
                                 StringUtils.bytesToString_NS(new byte[] { headers[0], headers[1] }) + " \n Content:\n " +
                                 StringUtils.bytesToString_NS(rpcData);
                Output.WriteRpcLog(message);
                                        #endif

                break;
            }
        }