public static ByteArrayToUint16 ( byte data, int reversed ) : |
||
data | byte | |
reversed | int | |
return |
public void processTeamInviteAnswer(ref byte[] packet) { // read the important things byte[] unknownUint16_1 = new byte[2]; byte[] sizeString = new byte[2]; ArrayUtils.copyTo(packet, 3, unknownUint16_1, 0, 2); ArrayUtils.copyTo(packet, 7, sizeString, 0, 2); UInt16 sizeCharName = NumericalUtils.ByteArrayToUint16(sizeString, 1); byte[] characterNameBytes = new byte[sizeCharName]; ArrayUtils.copyTo(packet, 9, characterNameBytes, 0, sizeCharName); string characterName = StringUtils.charBytesToString(characterNameBytes); // if it is 0 - then he has accepted the request - otherwise decline and ..we dont care if (NumericalUtils.ByteArrayToUint16(unknownUint16_1, 1) == 0) { lock (WorldSocket.missionTeams) { foreach (MissionTeam team in WorldSocket.missionTeams) { if (team.characterMasterName.Equals(characterName)) { team.addMember(StringUtils.charBytesToString_NZ(Store.currentClient.playerInstance.CharacterName.getValue())); } } } } }
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); }
public void processLoadAbility(ref byte[] packet) { // read the values from the packet PacketReader reader = new PacketReader(packet); UInt32 staticObjectID = reader.readUInt32(1); UInt16 unloadFlag = reader.readUInt16(1); UInt16 loadFlag = reader.readUInt16(1); UInt16 countAbilities = reader.readUInt16(1); int pointer = 11; // Start at index 11 List <UInt16> abilitySlots = new List <UInt16>(); for (int i = 1; i <= countAbilities; i++) { // This must be looped byte[] slotByteID = new byte[2]; ArrayUtils.copyTo(packet, pointer, slotByteID, 0, 2); pointer = pointer + 2; byte[] abilityByteID = new byte[2]; ArrayUtils.copyTo(packet, pointer, abilityByteID, 0, 2); pointer = pointer + 4; byte[] abilityByteLevel = new byte[2]; ArrayUtils.copyTo(packet, pointer, abilityByteLevel, 0, 2); pointer = pointer + 3; UInt16 slotID = NumericalUtils.ByteArrayToUint16(slotByteID, 1); UInt16 AbilityID = NumericalUtils.ByteArrayToUint16(abilityByteID, 1); UInt16 AbilityLevel = NumericalUtils.ByteArrayToUint16(abilityByteLevel, 1); PacketContent pak = new PacketContent(); if (unloadFlag > 0) { pak.addUint16((UInt16)RPCResponseHeaders.SERVER_ABILITY_UNLOAD, 0); pak.addByteArray(abilityByteID); } else { pak.addUint16((UInt16)RPCResponseHeaders.SERVER_ABILITY_LOAD, 0); pak.addByteArray(abilityByteID); pak.addByteArray(abilityByteLevel); pak.addByteArray(slotByteID); } abilitySlots.Add(slotID); Store.currentClient.messageQueue.addRpcMessage(pak.returnFinalPacket()); } if (unloadFlag > 0) { Store.dbManager.WorldDbHandler.updateAbilityLoadOut(abilitySlots, 0); } else { Store.dbManager.WorldDbHandler.updateAbilityLoadOut(abilitySlots, 1); } }
public void processMissionList(ref byte[] packet) { new TeamHandler().checkAndCreateMissionTeam(Store.currentClient); byte[] contactBytes = { packet[0], packet[1] }; UInt16 contactId = NumericalUtils.ByteArrayToUint16(contactBytes, 1); uint orgID = packet[2]; ServerPackets pak = new ServerPackets(); pak.sendMissionList(contactId, orgID, Store.currentClient); }
public void processSetBackgroundRequest(ref byte[] packetData) { UInt16 backgroundSize = NumericalUtils.ByteArrayToUint16(new byte[] { packetData[3], packetData[4] }, 1); byte[] backgroundBytes = new byte[backgroundSize - 1]; ArrayUtils.copy(packetData, 5, backgroundBytes, 0, backgroundSize - 1); string backgroundText = StringUtils.charBytesToString(backgroundBytes); Store.dbManager.WorldDbHandler.setBackground(backgroundText); }
public UInt16 readUInt16(int reversed) { UInt16 value = 0; // ToDo: implement value = NumericalUtils.ByteArrayToUint16(new byte[] { packetData[offset], packetData[offset + 1] }, reversed); offset = offset + 2; return(value); }
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"); }
public void processItemMove(ref byte[] packet) { byte[] sourceSlot = { packet[0], packet[1] }; byte[] destSlot = { packet[2], packet[3] }; UInt16 fromSlot = NumericalUtils.ByteArrayToUint16(sourceSlot, 1); UInt16 toSlot = NumericalUtils.ByteArrayToUint16(destSlot, 1); Store.dbManager.WorldDbHandler.updateInventorySlot(fromSlot, toSlot); ServerPackets pak = new ServerPackets(); pak.sendInventoryItemMove(fromSlot, toSlot, Store.currentClient); }
public void processMissionaccept(ref byte[] packet) { byte[] contactBytes = { packet[0], packet[1] }; UInt16 contactId = NumericalUtils.ByteArrayToUint16(contactBytes, 1); ushort missionId = packet[2]; Output.WriteRpcLog("Mission Accept Data:" + StringUtils.bytesToString(packet)); ServerPackets pak = new ServerPackets(); pak.sendMissionAccept(Store.currentClient, contactId, missionId); pak.sendSetMissionObjective(1, 0, "This is the test Mission, mate", Store.currentClient); pak.sendSetMissionObjective(2, 0, "Success", Store.currentClient); //pak.sendSetMissionObjective(3, 2, "Failed Remain", Store.currentClient); //pak.sendSetMissionObjective(4, 3, "Failed Clear", Store.currentClient); }
public void AddWorldObjectToWorldServer(StaticWorldObject worldObject) { UInt16 typeId = NumericalUtils.ByteArrayToUint16(worldObject.type, 1); switch (typeId) { case 6568: Subway subway = new Subway(worldObject); Subways.Add(subway); WorldSocket.subways.Add(subway); WorldSocket.gameServerEntities.Add(subway); subway.StartCountdown(); break; } }
public int parseAttributes(ref byte[] buffer, int _offset) { int offset = _offset; byte flag = 0x00; flag = BufferHandler.readByte(ref buffer, ref offset); byte[] stateData = new byte[buffer.Length - offset + 2]; ArrayUtils.copy(buffer, offset - 2, stateData, 0, buffer.Length - offset + 2); //Flag Bits{0,0,0,0,Vector3f Position Update, Yaw Update,Animation Update, AttributesPacked Update?} switch (flag) { case 0x02: Action.setValue(BufferHandler.readBytes(ref buffer, ref offset, Action.getSize())); break; case 0x04: YawInterval.setValue(BufferHandler.readBytes(ref buffer, ref offset, YawInterval.getSize())); break; case 0x08: double x = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref offset, 4), 1); double y = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref offset, 4), 1); double z = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref offset, 4), 1); Position.setValue(NumericalUtils.doublesToLtVector3d(x, y, z)); break; case 0x0e: // UInt16 unknown + LtVector3f UInt16 unknown = NumericalUtils.ByteArrayToUint16(BufferHandler.readBytes(ref buffer, ref offset, 2), 1); float xPos = NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref offset, 4), 1); float yPos = NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref offset, 4), 1); float zPos = NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref offset, 4), 1); Position.setValue(NumericalUtils.doublesToLtVector3d((double)xPos, (double)yPos, (double)zPos)); break; } // TODO: update player attribute packets someday (announce it to my spawners) Store.world.sendViewPacketToAllPlayers(stateData, Store.currentClient.playerData.getCharID(), NumericalUtils.ByteArrayToUint16(Store.currentClient.playerInstance.GetGoid(), 1), Store.currentClient.playerData.getEntityId()); return(offset); }
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; } }
// This is for team and crew invites public void processInviteAnswer(ref byte[] packet) { // read the important things byte[] maybeType = new byte[2]; byte[] sizeString = new byte[2]; ArrayUtils.copyTo(packet, 3, maybeType, 0, 2); ArrayUtils.copyTo(packet, 7, sizeString, 0, 2); UInt16 sizeCharName = NumericalUtils.ByteArrayToUint16(sizeString, 1); byte[] characterNameBytes = new byte[sizeCharName]; ArrayUtils.copyTo(packet, 9, characterNameBytes, 0, sizeCharName); string characterName = StringUtils.charBytesToString(characterNameBytes); // if it is 0 - then he has accepted the request - otherwise decline and ..we dont care switch (NumericalUtils.ByteArrayToUint16(maybeType, 1)) { // Team Invites case 0: lock (WorldSocket.missionTeams) { foreach (MissionTeam team in WorldSocket.missionTeams) { if (team.characterMasterName.Equals(characterName)) { team.addMember(StringUtils.charBytesToString_NZ(Store.currentClient.playerInstance.CharacterName.getValue())); } } } break; // Crew Invites case 2: // ToDo: add to Crew and maybe to faction (if crew is part of faction) // ToDo: Generate Repsonse for all connected crew mates and the new member // ToDo: add to crew and figure out the responses that are necessary (like crew message , player update etc.) // ToDo: for this the "2_player_action" logs could be useful. break; } }
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(); }
private void charNameRequest(byte[] packet, NetworkStream client) { // Get the handle text byte[] handleSize = new byte[2]; handleSize[0] = packet[5]; handleSize[1] = packet[6]; int size = (int)NumericalUtils.ByteArrayToUint16(handleSize, 1); byte[] handleB = new byte[size - 1]; ArrayUtils.copy(packet, 7, handleB, 0, size - 1); string handleBStr = StringUtils.bytesToString_NS(handleB); // Handle as "414141" string handleStr = StringUtils.charBytesToString(handleB); // Handle as "AAA" // Process DB to answer the client - we directly create the character UInt32 dbResult = Store.dbManager.MarginDbHandler.getNewCharnameID(handleStr, userID); // Add the new charId so that we can work with it // Create the answer string nameRequestResponse = ""; if (dbResult == 0) { nameRequestResponse += "0b0f00010000110000000000000000"; nameRequestResponse += StringUtils.bytesToString_NS(handleSize); nameRequestResponse += handleBStr + "00"; } else { newCharID = dbResult; nameRequestResponse += "0b0f0000000000"; nameRequestResponse += StringUtils.bytesToString_NS(NumericalUtils.uint32ToByteArray((UInt32)dbResult, 1)); nameRequestResponse += "0000000000"; nameRequestResponse += StringUtils.bytesToString_NS(handleSize); nameRequestResponse += handleBStr + "00"; } Output.writeToLogForConsole(nameRequestResponse); sendMarginData(nameRequestResponse, client); }
// Return all the values in an ArrayList, not just the decrypted packet public ArrayList decrypt(byte[] encryptedData, int length) { ArrayList response = new ArrayList(); UInt16 pss = 0; UInt16 cseq = 0; UInt16 sseq = 0; int decryptedSize = EnigmaLib.worldDecrypt(encryptedData, innerBuffer, length, ref pss, ref cseq, ref sseq); /* * If decrypted size is -1337 then it was a CRC in packet <> CRC of packet Exception * */ if (decryptedSize == -1337) { Output.WriteLine("Oh oh, CRC didnt matched in this packet"); } // This hexsize throws exceptions ...so we will use the decryptedSize - 10 (same value) byte[] hexSize = new byte[2]; hexSize [0] = innerBuffer[4]; hexSize [1] = innerBuffer[5]; UInt16 size = NumericalUtils.ByteArrayToUint16(hexSize, 1); size -= 4; // remove the 4 seq data bytes from size byte[] data = new byte[size]; ArrayUtils.copy(innerBuffer, 14, data, 0, decryptedSize - 10); // Should do a fast copy method for this, if not done already response.Add(data); response.Add(pss); response.Add(cseq); response.Add(sseq); return(response); }
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; } }
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; } } } } } } }
private static void CleanDeadPlayers(ArrayList deadPlayers) { foreach (string key in deadPlayers) { WorldClient deadClient = WorldSocket.Clients[key] as WorldClient; foreach (string client in WorldSocket.Clients.Keys) { WorldClient otherclient = WorldSocket.Clients[client] as WorldClient; ClientView view = otherclient.viewMan.getViewForEntityAndGo(deadClient.playerData.getEntityId(), NumericalUtils.ByteArrayToUint16(deadClient.playerInstance.GetGoid(), 1)); ServerPackets pak = new ServerPackets(); pak.sendDeleteViewPacket(otherclient, view.ViewID); Store.margin.removeClientsByCharId(otherclient.playerData.getCharID()); } // Views are now deleted to other players // ToDo: Cleanup Missions (kill all running missions the player have) // ToDo: Cleanup Teams (if your mission team has more than one player, you need to announce an update for the mission team to your mates) // ToDo: Announce friendlists from other users that you are going offline (just collect all players whohave this client in list and send the packet) // ToDo: Finally save the current character Data to the Database^^ Output.WriteLine("Removed inactive Client with Key " + key); lock (WorldSocket.Clients.SyncRoot) { WorldSocket.Clients.Remove(key); } } }
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); } } } } } }
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; } }
public void processTarget(ref byte[] packet) { byte[] viewBytes = { packet[0], packet[1] }; UInt16 viewID = NumericalUtils.ByteArrayToUint16(viewBytes, 1); }
public void SendViewUpdateToClientsWhoHasSpawnedView(PacketContent packet, Mob mob) { lock (Clients.SyncRoot) { foreach (string clientKey in Clients.Keys) { WorldClient client = Clients[clientKey] as WorldClient; ClientView mobView = client.viewMan.getViewForEntityAndGo(mob.getEntityId(), NumericalUtils.ByteArrayToUint16(mob.getGoId(), 1)); if (mobView.viewCreated == true && mob.getDistrict() == client.playerData.getDistrictId() && client.playerData.getOnWorld()) { ServerPackets pak = new ServerPackets(); pak.SendNpcUpdateData(mobView.ViewID, client, packet.returnFinalPacket()); } } } }
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; } }
private void createCharacterRSI(byte[] packet, NetworkStream client) { // Instance the Data Loader DataLoader ItemLoader = DataLoader.getInstance(); isNewCreatedChar = true; string debugHexPacket = StringUtils.bytesToString_NS(packet); // lets read the values // the IDs for the Appeareance is always uint16 goID byte[] bodyTypeIDByte = new byte[4]; byte[] professionByte = new byte[4]; byte[] facialdetailBytes = new byte[4]; byte[] facialdetailColorBytes = new byte[4]; byte[] hairBytes = new byte[4]; byte[] hairColorBytes = new byte[4]; byte[] skintoneBytes = new byte[4]; byte[] tatooBytes = new byte[4]; byte[] headIDBytes = new byte[4]; // Clothing byte[] shirtIDBytes = new byte[4]; byte[] pantsIDBytes = new byte[4]; byte[] outerwearIDBytes = new byte[4]; byte[] hatIDBytes = new byte[4]; byte[] eyewearIDBytes = new byte[4]; byte[] footwearIDBytes = new byte[4]; byte[] glovesIDBytes = new byte[4]; //byte[] legginsIDBytes = new byte[4]; // RSI ArrayUtils.copy(packet, 3, skintoneBytes, 0, 2); // Done! ArrayUtils.copy(packet, 7, bodyTypeIDByte, 0, 2); // Done! ArrayUtils.copy(packet, 15, hairBytes, 0, 2); // Done! ArrayUtils.copy(packet, 19, hairColorBytes, 0, 2); // Done! ArrayUtils.copy(packet, 23, tatooBytes, 0, 2); // Done! ArrayUtils.copy(packet, 27, headIDBytes, 0, 2); ArrayUtils.copy(packet, 31, facialdetailBytes, 0, 2); ArrayUtils.copy(packet, 35, facialdetailColorBytes, 0, 2); ArrayUtils.copy(packet, 67, professionByte, 0, 2); UInt16 body = 0; UInt16 gender = 0; UInt32 bodyTypeId = NumericalUtils.ByteArrayToUint32(bodyTypeIDByte, 1); UInt16 hairId = NumericalUtils.ByteArrayToUint16(hairBytes, 1); UInt16 haircolor = NumericalUtils.ByteArrayToUint16(hairColorBytes, 1); UInt16 tattoo = NumericalUtils.ByteArrayToUint16(tatooBytes, 1); UInt16 facialDetailColor = NumericalUtils.ByteArrayToUint16(facialdetailColorBytes, 1); UInt16 skintone = NumericalUtils.ByteArrayToUint16(skintoneBytes, 1); UInt16 headID = NumericalUtils.ByteArrayToUint16(headIDBytes, 1); // Get Values by "NewRSI" IDs NewRSIItem hairItem = ItemLoader.getNewRSIItemByTypeAndID("HAIR", hairId); NewRSIItem bodyItem = ItemLoader.getNewRSIItemByTypeAndID("BODY", (ushort)bodyTypeId); NewRSIItem headItem = ItemLoader.getNewRSIItemByTypeAndID("HEAD", headID); Store.dbManager.MarginDbHandler.updateRSIValue("body", bodyItem.internalId.ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("sex", bodyItem.gender.ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("face", headItem.internalId.ToString(), newCharID); // ToDo: Store.dbManager.MarginDbHandler.updateRSIValue("hair", hairItem.internalId.ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("haircolor", haircolor.ToString(), newCharID); // ToDo: check if it is correct Store.dbManager.MarginDbHandler.updateRSIValue("tattoo", tattoo.ToString(), newCharID); // ToDo: Store.dbManager.MarginDbHandler.updateRSIValue("facialdetailcolor", facialDetailColor.ToString(), newCharID); // ToDo: Store.dbManager.MarginDbHandler.updateRSIValue("skintone", skintone.ToString(), newCharID); // Clothing Items // ToDo: GLOVES ARE MISSING! ArrayUtils.copy(packet, 43, shirtIDBytes, 0, 2); ArrayUtils.copy(packet, 47, glovesIDBytes, 0, 2); ArrayUtils.copy(packet, 55, pantsIDBytes, 0, 2); ArrayUtils.copy(packet, 51, outerwearIDBytes, 0, 2); ArrayUtils.copy(packet, 34, hatIDBytes, 0, 2); ArrayUtils.copy(packet, 39, eyewearIDBytes, 0, 2); ArrayUtils.copy(packet, 63, footwearIDBytes, 0, 2); ClothingItem shirt = ItemLoader.getItemValues(NumericalUtils.ByteArrayToUint16(shirtIDBytes, 1)); ClothingItem pants = ItemLoader.getItemValues(NumericalUtils.ByteArrayToUint16(pantsIDBytes, 1)); ClothingItem outerwear = ItemLoader.getItemValues(NumericalUtils.ByteArrayToUint16(outerwearIDBytes, 1)); ClothingItem hat = ItemLoader.getItemValues(NumericalUtils.ByteArrayToUint16(hatIDBytes, 1)); ClothingItem eyewear = ItemLoader.getItemValues(NumericalUtils.ByteArrayToUint16(eyewearIDBytes, 1)); ClothingItem footwear = ItemLoader.getItemValues(NumericalUtils.ByteArrayToUint16(footwearIDBytes, 1)); ClothingItem gloves = ItemLoader.getItemValues(NumericalUtils.ByteArrayToUint16(glovesIDBytes, 1)); Store.dbManager.MarginDbHandler.updateRSIValue("hat", hat.getModelId().ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("shirt", shirt.getModelId().ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("shirtcolor", shirt.getModelId().ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("coat", outerwear.getModelId().ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("coatcolor", outerwear.getModelId().ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("pants", pants.getModelId().ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("pantscolor", pants.getModelId().ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("shoes", pants.getModelId().ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("shoecolor", pants.getModelId().ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("glasses", pants.getModelId().ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("glassescolor", pants.getModelId().ToString(), newCharID); // ToDO: Figre out the ITem Slots for "currentlyWearing" Items and add the ITems correctly to the Inventory // FirstName UInt16 currentOffset = 79; byte[] firstNameLenBytes = new byte[2]; ArrayUtils.copy(packet, currentOffset, firstNameLenBytes, 0, 2); UInt16 firstNameLen = NumericalUtils.ByteArrayToUint16(firstNameLenBytes, 1); currentOffset += 2; byte[] firstNameBytes = new byte[NumericalUtils.ByteArrayToUint16(firstNameLenBytes, 1) - 1]; ArrayUtils.copy(packet, currentOffset, firstNameBytes, 0, firstNameLen - 1); string firstNameString = StringUtils.charBytesToString(firstNameBytes); currentOffset += firstNameLen; // LastName byte[] lastNameLenBytes = new byte[2]; ArrayUtils.copy(packet, currentOffset, lastNameLenBytes, 0, 2); UInt16 lastNameLen = NumericalUtils.ByteArrayToUint16(lastNameLenBytes, 1); currentOffset += 2; byte[] lastNameBytes = new byte[NumericalUtils.ByteArrayToUint16(lastNameLenBytes, 1) - 1]; ArrayUtils.copy(packet, currentOffset, lastNameBytes, 0, lastNameLen - 1); string lastNameString = StringUtils.charBytesToString(lastNameBytes); currentOffset += lastNameLen; // Description byte[] descriptionLenBytes = new byte[2]; ArrayUtils.copy(packet, currentOffset, descriptionLenBytes, 0, 2); UInt16 descriptionLen = NumericalUtils.ByteArrayToUint16(descriptionLenBytes, 1); currentOffset += 2; byte[] descriptionBytes = new byte[NumericalUtils.ByteArrayToUint16(descriptionLenBytes, 1) - 1]; ArrayUtils.copy(packet, currentOffset, descriptionBytes, 0, descriptionLen - 1); string descriptionString = StringUtils.charBytesToString(descriptionBytes); currentOffset += lastNameLen; // Update Characters values Store.dbManager.MarginDbHandler.updateCharacter(firstNameString, lastNameString, descriptionString, newCharID); // Add the Basic Abilitys... Store.dbManager.MarginDbHandler.addAbility(-2147481600, 0, newCharID, 1, 1); Store.dbManager.MarginDbHandler.addAbility(-2147367936, 1, newCharID, 1, 1); Store.dbManager.MarginDbHandler.addAbility(-2147294208, 2, newCharID, 0, 1); Store.dbManager.MarginDbHandler.addAbility(-2147281920, 3, newCharID, 0, 0); Store.dbManager.MarginDbHandler.addAbility(-2147280896, 4, newCharID, 0, 0); Store.dbManager.MarginDbHandler.addAbility(-2147437568, 5, newCharID, 1, 1); Store.dbManager.MarginDbHandler.addAbility(-2147425280, 6, newCharID, 0, 0); Store.dbManager.MarginDbHandler.addAbility(-2147404800, 7, newCharID, 0, 0); Store.dbManager.MarginDbHandler.addAbility(-2147445760, 8, newCharID, 0, 0); Store.dbManager.MarginDbHandler.addAbility(-2146493440, 9, newCharID, 0, 0); Store.dbManager.MarginDbHandler.addAbility(-2146453504, 10, newCharID, 1, 0); // we have all created - lets load the charData loadCharacter(packet, client, this.newCharID); }
public void sendSpawnStaticObject(WorldClient client, GameObject creationObjectData, UInt64 entityID) { ClientView staticObjectView = client.viewMan.getViewForEntityAndGo(entityID, NumericalUtils.ByteArrayToUint16(creationObjectData.GetGoid(), 1)); if (staticObjectView.viewCreated == false) { PacketContent pak = new PacketContent(); pak.addUint16(1, 1); pak.addByteArray(Store.world.objMan.GenerateCreationPacket(creationObjectData, 0x0000, client.playerData.assignSpawnIdCounter()).getBytes()); pak.addUint16(staticObjectView.ViewID, 1); pak.addByte(0x00); client.messageQueue.addObjectMessage(pak.returnFinalPacket(), false); client.FlushQueue(); staticObjectView.viewCreated = true; } }
private void createCharacterRSI(byte[] packet, NetworkStream client) { // Instance the Data Loader DataLoader itemLoader = DataLoader.getInstance(); isNewCreatedChar = true; string debugHexPacket = StringUtils.bytesToString_NS(packet); // ToDo: Replace all with Packet Reader Instance PacketReader reader = new PacketReader(packet); reader.incrementOffsetByValue(3); UInt16 body = 0; UInt16 gender = 0; UInt16 skintone = reader.readUInt16(1); reader.setOffsetOverrideValue(7); UInt16 bodyTypeId = reader.readUInt16(1); reader.setOffsetOverrideValue(15); UInt16 hairId = reader.readUInt16(1); reader.setOffsetOverrideValue(19); UInt16 haircolor = reader.readUInt16(1); reader.setOffsetOverrideValue(23); UInt16 tattoo = reader.readUInt16(1); reader.setOffsetOverrideValue(27); UInt16 headId = reader.readUInt16(1); reader.setOffsetOverrideValue(31); UInt16 facialDetail = reader.readUInt16(1); reader.setOffsetOverrideValue(35); // ToDo: it has a bug - figure out correct position UInt16 facialDetailColor = reader.readUInt16(1); // ToDo: Remove this when facialDetailColor is parsed properly facialDetailColor = 0; reader.setOffsetOverrideValue(67); UInt16 profession = reader.readUInt16(1); // lets read the values // the IDs for the Appeareance is always uint16 goID // Extra Hint: there are no leggins in Char Creation Process reader.setOffsetOverrideValue(35); UInt16 hatId = reader.readUInt16(1); reader.setOffsetOverrideValue(39); UInt16 eyewearId = reader.readUInt16(1); reader.setOffsetOverrideValue(43); UInt16 shirtId = reader.readUInt16(1); reader.setOffsetOverrideValue(47); UInt16 glovesId = reader.readUInt16(1); reader.setOffsetOverrideValue(51); UInt16 outerwearId = reader.readUInt16(1); reader.setOffsetOverrideValue(55); UInt16 pantsId = reader.readUInt16(1); reader.setOffsetOverrideValue(63); UInt16 footwearId = reader.readUInt16(1); // Get Values by "NewRSI" IDs NewRSIItem hairItem = itemLoader.getNewRSIItemByTypeAndID("HAIR", hairId); NewRSIItem bodyItem = itemLoader.getNewRSIItemByTypeAndID("BODY", (ushort)bodyTypeId); NewRSIItem headItem = itemLoader.getNewRSIItemByTypeAndID("HEAD", headId); Store.dbManager.MarginDbHandler.updateRSIValue("body", bodyItem.internalId.ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("sex", bodyItem.gender.ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("face", headItem.internalId.ToString(), newCharID); // ToDo: Store.dbManager.MarginDbHandler.updateRSIValue("hair", hairItem.internalId.ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("haircolor", haircolor.ToString(), newCharID); // ToDo: check if it is correct Store.dbManager.MarginDbHandler.updateRSIValue("tattoo", tattoo.ToString(), newCharID); // ToDo: Store.dbManager.MarginDbHandler.updateRSIValue("facialdetail", facialDetail.ToString(), newCharID); // ToDo: Store.dbManager.MarginDbHandler.updateRSIValue("facialdetailcolor", facialDetailColor.ToString(), newCharID); // ToDo: Store.dbManager.MarginDbHandler.updateRSIValue("skintone", skintone.ToString(), newCharID); // Clothing Items ClothingItem shirt = itemLoader.getItemValues(shirtId); ClothingItem pants = itemLoader.getItemValues(pantsId); ClothingItem outerwear = itemLoader.getItemValues(outerwearId); ClothingItem hat = itemLoader.getItemValues(hatId); ClothingItem eyewear = itemLoader.getItemValues(eyewearId); ClothingItem footwear = itemLoader.getItemValues(footwearId); ClothingItem gloves = itemLoader.getItemValues(glovesId); Store.dbManager.MarginDbHandler.updateRSIValue("hat", hat.getModelId().ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("shirt", shirt.getModelId().ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("shirtcolor", shirt.getColorId().ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("coat", outerwear.getModelId().ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("coatcolor", outerwear.getColorId().ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("pants", pants.getModelId().ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("pantscolor", pants.getColorId().ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("shoes", footwear.getModelId().ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("shoecolor", footwear.getColorId().ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("glasses", eyewear.getModelId().ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("glassescolor", eyewear.getColorId().ToString(), newCharID); Store.dbManager.MarginDbHandler.updateRSIValue("gloves", gloves.getModelId().ToString(), newCharID); Store.dbManager.MarginDbHandler.AddItemToSlot(hatId, 0x61, newCharID); Store.dbManager.MarginDbHandler.AddItemToSlot(eyewearId, 0x62, newCharID); Store.dbManager.MarginDbHandler.AddItemToSlot(shirtId, 0x63, newCharID); Store.dbManager.MarginDbHandler.AddItemToSlot(glovesId, 0x64, newCharID); Store.dbManager.MarginDbHandler.AddItemToSlot(outerwearId, 0x65, newCharID); Store.dbManager.MarginDbHandler.AddItemToSlot(pantsId, 0x66, newCharID); Store.dbManager.MarginDbHandler.AddItemToSlot(footwearId, 0x68, newCharID); // FirstName UInt16 currentOffset = 79; byte[] firstNameLenBytes = new byte[2]; ArrayUtils.copy(packet, currentOffset, firstNameLenBytes, 0, 2); UInt16 firstNameLen = NumericalUtils.ByteArrayToUint16(firstNameLenBytes, 1); currentOffset += 2; byte[] firstNameBytes = new byte[NumericalUtils.ByteArrayToUint16(firstNameLenBytes, 1) - 1]; ArrayUtils.copy(packet, currentOffset, firstNameBytes, 0, firstNameLen - 1); string firstNameString = StringUtils.charBytesToString(firstNameBytes); currentOffset += firstNameLen; // LastName byte[] lastNameLenBytes = new byte[2]; ArrayUtils.copy(packet, currentOffset, lastNameLenBytes, 0, 2); UInt16 lastNameLen = NumericalUtils.ByteArrayToUint16(lastNameLenBytes, 1); currentOffset += 2; byte[] lastNameBytes = new byte[NumericalUtils.ByteArrayToUint16(lastNameLenBytes, 1) - 1]; ArrayUtils.copy(packet, currentOffset, lastNameBytes, 0, lastNameLen - 1); string lastNameString = StringUtils.charBytesToString(lastNameBytes); currentOffset += lastNameLen; // Description byte[] descriptionLenBytes = new byte[2]; ArrayUtils.copy(packet, currentOffset, descriptionLenBytes, 0, 2); UInt16 descriptionLen = NumericalUtils.ByteArrayToUint16(descriptionLenBytes, 1); currentOffset += 2; byte[] descriptionBytes = new byte[NumericalUtils.ByteArrayToUint16(descriptionLenBytes, 1) - 1]; ArrayUtils.copy(packet, currentOffset, descriptionBytes, 0, descriptionLen - 1); string descriptionString = StringUtils.charBytesToString(descriptionBytes); currentOffset += lastNameLen; // Update Characters values Store.dbManager.MarginDbHandler.updateCharacter(firstNameString, lastNameString, descriptionString, newCharID); // Add the Basic Abilitys... addStartAbilitys(newCharID); // we have all created - lets load the charData loadCharacter(packet, client, this.newCharID); }
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); } }
public int parseAttributes(ref byte[] buffer, int _offset) { _offset++; byte flag = 0x00; flag = BufferHandler.readByte(ref buffer, ref _offset); byte[] stateData = new byte[buffer.Length - _offset + 2]; ArrayUtils.copy(buffer, _offset - 2, stateData, 0, buffer.Length - _offset + 2); //Flag Bits{0,0,0,0,Vector3f Position Update, Yaw Update,Animation Update, AttributesPacked Update?} double x = 0; double y = 0; double z = 0; switch (flag) { case 0x02: Action.setValue(BufferHandler.readBytes(ref buffer, ref _offset, Action.getSize())); break; case 0x04: YawInterval.setValue(BufferHandler.readBytes(ref buffer, ref _offset, YawInterval.getSize())); break; case 0x08: x = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1); y = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1); z = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1); Position.setValue(NumericalUtils.doublesToLtVector3d(x, y, z)); break; case 0x0a: YawInterval.setValue(BufferHandler.readByte(ref buffer, ref _offset)); x = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1); y = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1); z = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1); Position.setValue(NumericalUtils.doublesToLtVector3d(x, y, z)); break; case 0x0e: // UInt16 unknown + LtVector3f UInt16 unknown = NumericalUtils.ByteArrayToUint16(BufferHandler.readBytes(ref buffer, ref _offset, 2), 1); x = NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1); y = NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1); z = NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1); Position.setValue(NumericalUtils.doublesToLtVector3d(x, y, z)); break; default: // ToDo: we need a proper way to proove if there is a 00 00 04 somewhere (and if set the offset to it) // If this doesnt match we need to write this somewhere... string message = "RPCMAIN : Unknown Client 03 Request Packet \r\n" + "Flag: " + flag + "\r\n " + "Content: \n" + StringUtils.bytesToString(stateData) + "\r\n"; Output.WriteClientViewRequestLog(message); // ...and we dont want to crash so we just say "offset is full packet" _offset = buffer.Length - 1; break; } // TODO: update player attribute packets someday (announce it to my spawners) Store.world.sendViewPacketToAllPlayers(stateData, Store.currentClient.playerData.getCharID(), NumericalUtils.ByteArrayToUint16(Store.currentClient.playerInstance.GetGoid(), 1), Store.currentClient.playerData.getEntityId()); return(_offset); }
public List <StaticWorldObject> findObjectsBySectorWorldRangeAndType(float x, float z, uint metrId, UInt16 typeId) { IEnumerable <StaticWorldObject> staticWorldObjectsIenumerator = WorldObjectsDB.Where(w => w.metrId == metrId && NumericalUtils.ByteArrayToUint16(w.type, 1) == typeId && mathUtils.IsInCircle(x, z, (float)w.pos_x, (float)w.pos_z, 5000)); List <StaticWorldObject> TempStaticWorldObjects = staticWorldObjectsIenumerator.ToList(); return(TempStaticWorldObjects); }