/// <summary> /// Creates a new ESKSequence without special preferences. /// </summary> /// <remarks>No remarks</remarks> public ESKSequence() { pPackets = new Packet[0]; alSymKeys = new ArrayList(); alAsymKeys = new ArrayList(); alAllKeys = new ArrayList(); }
public static void HandleAuthRequest(Packet packet, AuthSession session) { packet.Read<uint>(32); packet.Read<ulong>(64); var loginName = packet.ReadString(); Console.WriteLine($"Account '{loginName}' tries to connect."); //var account = DB.Auth.Single<Account>(a => a.Email == loginName); //if (account != null && account.Online) { var authComplete = new Packet(ServerMessage.AuthComplete); authComplete.Write(0, 32); session.Send(authComplete); var connectToRealm = new Packet(ServerMessage.ConnectToRealm); connectToRealm.Write(BitConverter.ToUInt32(new byte[] { 1, 0, 0, 127 }, 0), 32); connectToRealm.Write(24000, 16); connectToRealm.Write(0, 64); connectToRealm.Write(0, 64); connectToRealm.Write(0, 32); connectToRealm.WriteWString("Multi-Emu"); connectToRealm.Write(0, 2); connectToRealm.Write(0, 21); session.Send(connectToRealm); } }
public Base GetCompletedWork(Guid jobGuid) { if (_ConnectionToManager == null || !_ConnectionToManager.IsConnected()) throw new Exception("Not connected to the manager"); while (true) { Packet p = new Packet(1100); p.Add(jobGuid.ToByteArray(),true); _ConnectionToManager.SendPacket(p); Stopwatch sendTime = new Stopwatch(); sendTime.Start(); while (sendTime.ElapsedMilliseconds < _CommsTimeout) { if (_ConnectionToManager.GetPacketsToProcessCount() > 0) { foreach (Packet packet in _ConnectionToManager.GetPacketsToProcess()) { switch (packet.Type) { case 1101: return null; case 1102: Object[] packetObjects = packet.GetObjects(); BinaryFormatter binaryFormatter = new BinaryFormatter(); return (Base) binaryFormatter.Deserialize(new MemoryStream((Byte[]) packetObjects[0])); } } Thread.Sleep(100); } } if (_ConnectionToManager.IsConnected())_ConnectionToManager.Disconnect(); _ConnectionToManager.Connect(_IpAddress, _Port, 204800); } return null; }
private void _handleAdminShow(Packet pkt) { if (OnAdminHiddenChange == null) return; short id = pkt.GetShort(); OnAdminHiddenChange(id, false); }
public Guid SendJob(Base activity) { if (_ConnectionToManager == null || !_ConnectionToManager.IsConnected()) throw new Exception("Not connected to the manager"); while (true) { BinaryFormatter binaryFormatter = new BinaryFormatter(); MemoryStream datastream = new MemoryStream(); binaryFormatter.Serialize(datastream, activity); Packet p = new Packet(1000); Byte[] data= datastream.ToArray(); p.Add(data,true); _ConnectionToManager.SendPacket(p); Stopwatch sendTime = new Stopwatch(); sendTime.Start(); while (sendTime.ElapsedMilliseconds < _CommsTimeout) { if (_ConnectionToManager.GetPacketsToProcessCount() > 0) { foreach (Guid jobGuid in from packet in _ConnectionToManager.GetPacketsToProcess() where packet.Type == 1001 select new Guid((Byte[]) packet.GetObjects()[0])) { return jobGuid; } } Thread.Sleep(1); } if (_ConnectionToManager.IsConnected()) _ConnectionToManager.Disconnect(); _ConnectionToManager.Connect(_IpAddress, _Port, 20480 * 1024); } throw new Exception("Mananger unavailable or busy"); }
protected override bool OnGetValue(PacketSession session, Packet responsePacket) { object value = session.Server.Vars[Command]; responsePacket.Words.Add(RConDevServer.Protocol.Dice.Battlefield3.Constants.RESPONSE_SUCCESS); responsePacket.Words.Add(Convert.ToString(value)); return true; }
public bool OnCreatingResponse(PacketSession session, Packet requestPacket, Packet responsePacket) { var idTypes = session.Server.IdTypes; if (ValidateRequest(requestPacket)) { var idType = idTypes.FirstOrDefault(x => x.Code == requestPacket.Words[1]); var idValue = requestPacket.Words[2]; var banListItem = session.Server.BanList.FirstOrDefault(x => x.IdType.Code == idType.Code && x.IdValue == idValue); if (banListItem != null) { session.Server.BanList.Remove(banListItem); responsePacket.Words.Add(RConDevServer.Protocol.Dice.Battlefield3.Constants.RESPONSE_SUCCESS); } else { responsePacket.Words.Add(RConDevServer.Protocol.Dice.Battlefield3.Constants.RESPONSE_NOT_FOUND); } } else { responsePacket.Words.Add(RConDevServer.Protocol.Dice.Battlefield3.Constants.RESPONSE_INVALID_ARGUMENTS); } return true; }
/// <summary> /// Initializes new instance of <see cref="UserAuthenticationRequest"/> struct. /// </summary> /// <param name="p"><see cref="Packet"/> to initialize from.</param> public UserAuthenticationRequest( Packet p ) { RequestID = p.ReadLong(); Login = p.ReadString(); Password = p.ReadString(); SessionID = p.ReadInt(); }
public Packet ReadPacket() { if (_reader.PeekChar() < 0) return null; if (Version != 0x0300) { var direction = _reader.ReadByte(); var unixtime = _reader.ReadUInt32(); var tickcount = _reader.ReadUInt32(); var packet = new Packet(); packet.Size = _reader.ReadInt32() - (direction == 0xFF ? 2 : 4); packet.OpcodeNumber = (uint)(direction == 0xFF ? _reader.ReadInt16() : _reader.ReadInt32()); packet.Data = _reader.ReadBytes(packet.Size); return packet; } else { var direction = _reader.ReadUInt32(); var unixtime = _reader.ReadUInt32(); var tickcount = _reader.ReadUInt32(); var packet = new Packet(); var optSize = _reader.ReadInt32(); packet.Size = _reader.ReadInt32() - 4; _reader.ReadBytes(optSize); packet.OpcodeNumber = (uint)_reader.ReadInt32(); packet.Data = _reader.ReadBytes(packet.Size); return packet; } }
/// <summary> /// Prepares skill. /// </summary> /// <param name="creature"></param> /// <param name="skill"></param> /// <param name="packet"></param> /// <returns></returns> public bool Prepare(Creature creature, Skill skill, Packet packet) { Send.SkillInitEffect(creature, "healing"); Send.SkillPrepare(creature, skill.Info.Id, skill.GetCastTime()); return true; }
public bool AccountCreate(string uName, string pass, string realName, string location, string email, string HDDSerial, out AccountReply result) { result = AccountReply.THIS_IS_WRONG; if (!m_client.ConnectedAndInitialized || !Initialized) return false; Packet builder = new Packet(PacketFamily.Account, PacketAction.Create); //eoserv doesn't care... builder.AddShort(1337); builder.AddByte(42); builder.AddBreakString(uName); builder.AddBreakString(pass); builder.AddBreakString(realName); builder.AddBreakString(location); builder.AddBreakString(email); builder.AddBreakString(System.Net.Dns.GetHostName()); builder.AddBreakString(HDDSerial); if (!m_client.SendPacket(builder) || !m_account_responseEvent.WaitOne(Constants.ResponseTimeout)) return false; result = m_account_reply; return true; }
/// <summary> /// Readies the skill. /// </summary> /// <param name="creature"></param> /// <param name="skill"></param> /// <param name="packet"></param> /// <returns></returns> public bool Ready(Creature creature, Skill skill, Packet packet) { Send.UseMotion(creature, 10, 0); Send.SkillReady(creature, skill.Info.Id); return true; }
public void addPacketToQueue(Packet p) { lock (queuedPackets) { queuedPackets.Enqueue(p); } }
public static Packet Compress( Packet p ) { int length; byte[] source = p.Compile( false, out length ); if ( length > 100 && length < 60000 ) { byte[] dest = new byte[(int)(length*1.001)+1]; int destSize = dest.Length; ZLibError error = Compression.Pack( dest, ref destSize, source, length, ZLibQuality.Default ); if ( error != ZLibError.Okay ) { Console.WriteLine( "WARNING: Unable to compress admin packet, zlib error: {0}", error ); return p; } else { return new AdminCompressedPacket( dest, destSize, length ); } } else { return p; } }
public static void AsciiSpeech( Packet p, PacketHandlerEventArgs args ) { // 0, 1, 2 Serial serial = p.ReadUInt32(); // 3, 4, 5, 6 ushort body = p.ReadUInt16(); // 7, 8 MessageType type = (MessageType)p.ReadByte(); // 9 ushort hue = p.ReadUInt16(); // 10, 11 ushort font = p.ReadUInt16(); string name = p.ReadStringSafe( 30 ); string text = p.ReadStringSafe(); if ( World.Player != null && serial == Serial.Zero && body == 0 && type == MessageType.Regular && hue == 0xFFFF && font == 0xFFFF && name == "SYSTEM" ) { args.Block = true; p.Seek( 3, SeekOrigin.Begin ); p.WriteAsciiFixed( "", (int)p.Length-3 ); ClientCommunication.DoFeatures( World.Player.Features ) ; } else { HandleSpeech( p, args, serial, body, type, hue, font, "A", name, text ); if ( !serial.IsValid ) BandageTimer.OnAsciiMessage( text ); } }
public void UnPack(Client client, Packet packet, IEventDispatcher eventDispatcher) { string ip = client.ToString().Split(':')[0]; ushort port = packet.Reader.ReadUInt16(); eventDispatcher.ThrowNewEvent(EventID, new MasterServerDatas {IP = ip, Port = port}); }
public FPSAim(String vcd) { InitializeComponent(); VideoCaptureDevice videoSource = new VideoCaptureDevice(vcd, new Size(320, 240), false); OpenVideoSource(videoSource); redDot.Location = new Point(gridBox.Width / 2 + gridBox.Left, gridBox.Height / 2 + gridBox.Top); servos = new Servos(); redDot.Location = servos.GetPorportionalMathPosition(gridBox.Bounds); redDot.Location = new Point(redDot.Location.X - REDDOT_OFFSET_X, redDot.Location.Y - REDDOT_OFFSET_Y); label1.Text = "(-" + servos.CenterServosPosition.X + "," + servos.CenterServosPosition.Y + ")"; textBoxXServo.Text = servos.ShootingRange.Width.ToString(); textBoxYServo.Text = servos.ShootingRange.Height.ToString(); textBoxXCoord.Text = servos.ServosPosition.X.ToString(); textBoxYCoord.Text = servos.ServosPosition.Y.ToString(); Packet packet = new Packet(servos.CenterServosPosition); packet.setFireOff(); this.sendData(packet); Cursor.Hide(); cursorhidden = true; CoordinateTimer.Start(); //Point camwindowcenter = new Point(gridBox.PointToScreen(new Point(0, 0)).X , gridBox.PointToScreen(new Point(0, 0)).Y ); //Cursor.Position = camwindowcenter; currentX = Cursor.Position.X; currentY = Cursor.Position.Y; lastX = 0; lastY = 0; }
public void Write(Packet packet) { packet.Write(Id, 32); packet.WriteWString(Name); packet.Write(0, 32); packet.Write(0, 32); packet.Write(Type, 2); packet.Write(Status, 3); packet.Write(Population, 3); packet.Write(0, 32); packet.Write(0, 64); packet.Write(0, 64); packet.Write(0, 14); packet.Write(0, 32); packet.WriteWString(""); packet.Write(0, 64); packet.Write(0, 16); packet.Write(0, 16); packet.Write(0, 16); packet.Write(0, 16); }
/// <summary> /// 0: Port /// </summary> /// <param name="w"></param> /// <param name="datas"></param> public void Pack(Writer w, params object[] datas) { var p = new Packet(new PacketHeader {ID = ID}); p.Writer.Write((ushort) datas[0]); p.Write(w); }
public Listening(Gateway.Event.IMediator eventMediator, ITransition transition, Packet.Endpoint.IFactory packetEndpointFactory, Context.IListen context) { _eventMediator = eventMediator; _transition = transition; _packetEndpointFactory = packetEndpointFactory; _context = context; }
public static void HandleGuildInfo(Packet packet) { packet.ReadCString("Name"); packet.ReadTime("Created"); packet.ReadInt32("Number of members"); packet.ReadInt32("Number of accounts"); }
/// <summary> /// Handle ARP packets /// </summary> /// <param name="packet">The EthernetDatagram</param> /// <param name="arp">The ArpDatagram to parse</param> public static void HandleARP(Packet packet, ArpDatagram arp, ref UInt64 frame_id, object[] ctrl) { ListViewItem item = new ListViewItem(frame_id.ToString()); frame_id++; List<string> packet_info = new List<string>(); ListView frames = (ListView)ctrl[0]; EthernetDatagram ethernet = packet.Ethernet; packet_info.Add(packet.Timestamp.ToString("hh:mm:ss.fff tt")); packet_info.Add(arp.SenderProtocolIpV4Address.ToString()); packet_info.Add(arp.TargetProtocolIpV4Address.ToString()); packet_info.Add(ethernet.Source.ToString()); packet_info.Add(ethernet.Destination.ToString()); packet_info.Add("ARP"); packet_info.Add(arp.Length.ToString()); // update UI if (item != null) { item.SubItems.AddRange(packet_info.ToArray()); object[] param = new object[2]; param[0] = frames; object[] o = new object[3]; o[0] = item; o[1] = ctrl[1]; o[2] = packet; param[1] = o; frames.BeginInvoke(new ParserHelper.UIHandlerEx(ParserHelper.UpdateFrameUI), param); } }
protected override bool OnGetValue(PacketSession session, Packet responsePacket) { bool isRanked = session.Server.ServerInfo.IsRanked; responsePacket.Words.Add(RConDevServer.Protocol.Dice.Battlefield3.Constants.RESPONSE_SUCCESS); responsePacket.Words.Add(Convert.ToString(isRanked)); return true; }
private static void IncomingDataTask(object tuple) { Socket cSocket = ((Tuple<Socket, Input>)tuple).Item1; Input input = ((Tuple<Socket, Input>)tuple).Item2; byte[] buffer; int readBytes; try { while (true) { buffer = new byte[cSocket.SendBufferSize]; readBytes = cSocket.Receive(buffer); if (readBytes > 0) { Packet packet = new Packet(buffer); DataManager(packet, input); } } } catch (SocketException) { lock (Server.clientsLock) { Server.clients.Remove(Server.clients.Last((c) => { return c.clientSocket == cSocket; })); } Server.Informer.AddEventInformation("A client disconnected"); } }
public Packet ReadPacket() { if (_readPackets >= _packets.Count) { return null; } var element = _packets[_readPackets]; var data = element.InnerText; var len = data.Length / 2; var bytes = new byte[len]; for (var i = 0; i < len; ++i) { var pos = i * 2; var str = data[pos].ToString(); str += data[pos + 1]; bytes[i] = byte.Parse(str, System.Globalization.NumberStyles.HexNumber); } var packet = new Packet(); packet.Size = len; packet.Code = (OpCodes)Convert.ToInt32(element.Attributes["opcode"].Value); packet.Data = bytes; _readPackets++; return packet; }
public void DeserializeServerOriginatedPacketResponseTest() { var expectedPacket = new Packet(PacketOrigin.Server, true, 458, new List<string>() { "OK", "21", "test" }); var packetBytes = Convert.FromBase64String("ygEAwCMAAAADAAAAAgAAAE9LAAIAAAAyMQAEAAAAdGVzdAA="); var deserializedPackets = this.serializer.Deserialize(packetBytes).ToArray(); Assert.AreEqual(expectedPacket, deserializedPackets[0], "Deserializing Server Packet Response not successful"); }
public void DeserializeServerOriginatedPacketTest() { var expectedPacket = new Packet(PacketOrigin.Server, false, 458, new List<string>() {"listPlayers", "all"}); var packetBytes = Convert.FromBase64String("ygEAgCQAAAACAAAACwAAAGxpc3RQbGF5ZXJzAAMAAABhbGwA"); var deserializedPackets = this.serializer.Deserialize(packetBytes).ToArray(); Assert.AreEqual(expectedPacket, deserializedPackets[0], "Deserializing Server Packet not successful"); }
public static Parser CreateParser(Packet packet) { Type type; if (Parsers.TryGetValue(packet.Code, out type)) { var parser = (Parser) Activator.CreateInstance(type); parser.Initialize(packet); parser.Parse(); parser.CheckPacket(); return parser; } MethodInfo mi; if (MethodParsers.TryGetValue(packet.Code, out mi)) { Type createdType = mi.IsStatic ? typeof (Parser) : mi.DeclaringType; var parserObj = (Parser) Activator.CreateInstance(createdType); parserObj.Initialize(packet); var args = new object[mi.GetParameters().Length]; if (args.Length > 0) args[0] = parserObj; // pass the Parser object as a parameter for compatibility try { mi.Invoke(parserObj, args); } catch (Exception e) { if (e.InnerException != null) e = e.InnerException; parserObj.WriteLine("ERROR: Parsing failed with exception " + e); } parserObj.CheckPacket(); return parserObj; } return UnknownParser; }
//**CONFIRMED public static Packet GetPackage(int shipNumber) { SetShipSubPacket ssp = new SetShipSubPacket(shipNumber); ShipActionPacket sap = new ShipActionPacket(ssp); Packet p = new Packet(sap); return p; }
public static void SendHighscore(string name, int score) { ip = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 5000); serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); Console.WriteLine("Sending..."); try { serverSocket.Connect(ip); } catch { Console.WriteLine("Failed to connect to host server."); return; } Packet sendPacket = new Packet(); sendPacket.sendName = name; sendPacket.sendScore = score; serverSocket.Send(sendPacket.ToByteArray()); serverSocket.Close(); }
public static void HandlePetCastSpell(Packet packet) { var guid1 = new byte[8]; var guid2 = new byte[8]; var guid3 = new byte[8]; var guid4 = new byte[8]; var petGuid = new byte[8]; var transportGUID = new byte[8]; var guid20 = new byte[8]; var bit388 = false; var bit389 = false; var bit412 = false; var hasUnkMovementField = false; var hasTransport = false; var hasTransportTime2 = false; var hasTransportTime3 = false; var hasMovementFlags = false; var hasMovementFlags2 = false; var hasFallDirection = false; var hasFallData = false; var hasPitch = false; var hasOrientation = false; var hasSplineElevation = false; var hasTimestamp = false; var targetString = 0u; var hasDestLocation = packet.ReadBit(); // v2 + 112 petGuid[7] = packet.ReadBit(); var hasMissileSpeed = !packet.ReadBit(); var hasSrcLocation = packet.ReadBit(); // v2 + 80 petGuid[1] = packet.ReadBit(); var archeologyCounter = packet.ReadBits(2); // v2 + 424 var hasTargetMask = !packet.ReadBit(); // v2 + 32 petGuid[4] = packet.ReadBit(); packet.ReadBit(); petGuid[6] = packet.ReadBit(); var hasTargetString = !packet.ReadBit(); // v2 + 120 packet.ReadBit(); var hasMovement = packet.ReadBit(); // v2 + 416 var hasCastFlags = !packet.ReadBit(); // v2 + 28 var hasSpellId = !packet.ReadBit(); // v2 + 20 petGuid[0] = packet.ReadBit(); petGuid[5] = packet.ReadBit(); petGuid[2] = packet.ReadBit(); for (var i = 0; i < archeologyCounter; ++i) { packet.ReadBits("archeologyType", 2, i); } petGuid[3] = packet.ReadBit(); var hasGlyphIndex = !packet.ReadBit(); // v2 + 24 var hasCastCount = !packet.ReadBit(); // v2 + 16 var hasElevation = !packet.ReadBit(); var unkMovementLoopCounter = 0u; if (hasMovement) { hasOrientation = !packet.ReadBit(); hasSplineElevation = !packet.ReadBit(); bit388 = packet.ReadBit(); // v2 + 388 guid20[5] = packet.ReadBit(); // v2 + 261 guid20[7] = packet.ReadBit(); // v2 + 263 hasMovementFlags2 = !packet.ReadBit(); hasTimestamp = !packet.ReadBit(); // v2 + bit272 hasFallData = packet.ReadBit(); hasMovementFlags = !packet.ReadBit(); // v2 + 264 hasUnkMovementField = !packet.ReadBit(); // v2 + 408 if (hasMovementFlags) { packet.ReadBits("hasMovementFlags", 30); } bit389 = packet.ReadBit(); // v2 + 389 guid20[6] = packet.ReadBit(); // v2 + 263 hasTransport = packet.ReadBit(); // v2 + 344 guid20[0] = packet.ReadBit(); // v2 + 263 unkMovementLoopCounter = packet.ReadBits(22); if (hasTransport) { hasTransportTime2 = packet.ReadBit(); // v2 + 332 hasTransportTime3 = packet.ReadBit(); // v2 + 340 transportGUID[5] = packet.ReadBit(); // v2 + 300 transportGUID[6] = packet.ReadBit(); // v2 + 302 transportGUID[4] = packet.ReadBit(); // v2 + 301 transportGUID[0] = packet.ReadBit(); // v2 + 296 transportGUID[1] = packet.ReadBit(); // v2 + 297 transportGUID[2] = packet.ReadBit(); // v2 + 2980 transportGUID[7] = packet.ReadBit(); // v2 + 303 transportGUID[3] = packet.ReadBit(); // v2 + 299 } guid20[1] = packet.ReadBit(); // v2 + 257 if (hasMovementFlags2) { packet.ReadBits("hasMovementFlags2", 13); } guid20[3] = packet.ReadBit(); // v2 + 259 guid20[2] = packet.ReadBit(); // v2 + 258 bit412 = packet.ReadBit(); // v2 + 412 hasPitch = !packet.ReadBit(); guid20[4] = packet.ReadBit(); // v2 + 260 if (hasFallData) { hasFallDirection = packet.ReadBit(); } } if (hasDestLocation) { packet.StartBitStream(guid2, 2, 0, 1, 4, 5, 6, 3, 7); } if (hasCastFlags) { packet.ReadBits("hasCastFlags", 5); } packet.StartBitStream(guid1, 2, 4, 7, 0, 6, 1, 5, 3); if (hasTargetMask) { packet.ReadEnum <TargetFlag>("Target Flags", 20); } if (hasTargetString) { targetString = packet.ReadBits("hasTargetString", 7); } if (hasSrcLocation) { packet.StartBitStream(guid4, 2, 0, 3, 1, 6, 7, 4, 5); } packet.StartBitStream(guid3, 6, 0, 3, 4, 2, 1, 5, 7); //resetbitreader packet.ReadXORBytes(petGuid, 2, 6, 3); for (var i = 0; i < archeologyCounter; ++i) { packet.ReadUInt32("unk1", i); // +4 packet.ReadUInt32("unk2", i); // +8 } packet.ReadXORBytes(petGuid, 1, 7, 0, 4, 5); if (hasDestLocation) { packet.ReadXORByte(guid2, 4); packet.ReadXORByte(guid2, 1); packet.ReadXORByte(guid2, 7); packet.ReadSingle("Position Z"); packet.ReadSingle("Position Y"); packet.ReadXORByte(guid2, 6); packet.ReadXORByte(guid2, 3); packet.ReadSingle("Position X"); packet.ReadXORByte(guid2, 2); packet.ReadXORByte(guid2, 5); packet.ReadXORByte(guid2, 0); packet.WriteGuid("Guid2", guid2); } if (hasMovement) { if (hasPitch) { packet.ReadSingle("Pitch"); // v2 + 352 } if (hasTransport) { if (hasTransportTime3) { packet.ReadInt32("hasTransportTime3"); } if (hasTransportTime2) { packet.ReadInt32("hasTransportTime2"); } packet.ReadByte("Transport Seat"); // v2 + 320 packet.ReadSingle("O"); // v2 + 304 packet.ReadSingle("Z"); // v2 + 312 packet.ReadXORByte(transportGUID, 2); // v2 + 298 packet.ReadInt32("Transport Time"); // v2 + 324 packet.ReadXORByte(transportGUID, 3); // v2 + 299 packet.ReadSingle("X"); // v2 + 308 packet.ReadXORByte(transportGUID, 6); // v2 + 302 packet.ReadXORByte(transportGUID, 5); // v2 + 301 packet.ReadXORByte(transportGUID, 7); // v2 + 303 packet.ReadXORByte(transportGUID, 0); // v2 + 296 packet.ReadSingle("Y"); // v2 + 316 packet.ReadXORByte(transportGUID, 4); // v2 + 300 packet.ReadXORByte(transportGUID, 1); // v2 + 297 packet.WriteGuid("Transport GUID", transportGUID); } if (hasUnkMovementField) { packet.ReadInt32("Int408"); // v2 + 408 } for (var i = 0; i < unkMovementLoopCounter; ++i) { packet.ReadInt32("MovementLoopCounter", i); } packet.ReadXORByte(guid20, 3); // v2 + 260 if (hasOrientation) { packet.ReadSingle("Orientation"); // v2 + 288 } packet.ReadXORByte(guid20, 5); // v2 + 256 if (hasFallData) { packet.ReadSingle("Z Speed"); if (hasFallDirection) { packet.ReadSingle("CosAngle"); packet.ReadSingle("XY Speed"); packet.ReadSingle("SinAngle"); } packet.ReadInt32("FallTime"); } if (hasTimestamp) { packet.ReadInt32("hasTimestamp"); // v2 + 288 } packet.ReadXORByte(guid20, 6); // v2 + 262 packet.ReadSingle("Position X"); // v2 + 276 packet.ReadXORByte(guid20, 1); // v2 + 257 packet.ReadSingle("Position Z"); // v2 + 284 packet.ReadXORByte(guid20, 2); // v2 + 258 packet.ReadXORByte(guid20, 7); // v2 + 260 packet.ReadXORByte(guid20, 0); // v2 + 256 packet.ReadSingle("Position Y"); // v2 + 280 packet.ReadXORByte(guid20, 4); // v2 + 260 if (hasSplineElevation) { packet.ReadSingle("SplineElevation"); // v2 + 384 } packet.WriteGuid("Guid20", guid20); } if (hasSrcLocation) { packet.ReadXORByte(guid4, 3); packet.ReadXORByte(guid4, 4); packet.ReadXORByte(guid4, 2); packet.ReadXORByte(guid4, 1); packet.ReadXORByte(guid4, 0); packet.ReadXORByte(guid4, 7); packet.ReadSingle("Position Z"); packet.ReadXORByte(guid4, 6); packet.ReadXORByte(guid4, 5); packet.ReadSingle("Position X"); packet.ReadSingle("Position Y"); packet.WriteGuid("Guid4", guid4); } if (hasMissileSpeed) { packet.ReadSingle("missileSpeed"); } packet.ParseBitStream(guid1, 1, 2, 5, 7, 4, 6, 3, 0); packet.WriteGuid("Guid1", guid1); packet.ParseBitStream(guid3, 1, 5, 7, 3, 0, 2, 4, 6); packet.WriteGuid("Guid3", guid3); if (hasElevation) { packet.ReadSingle("hasElevation"); } if (hasCastCount) { packet.ReadByte("Cast Count"); } if (hasTargetString) { packet.ReadWoWString("TargetString", targetString); } if (hasGlyphIndex) { packet.ReadInt32("hasGlyphIndex"); } if (hasSpellId) { packet.ReadEntry <Int32>(StoreNameType.Spell, "Spell ID"); } packet.WriteGuid("PetGuid", petGuid); }
/// <summary> /// Send packet /// </summary> /// <param name="p">Packet</param> public void Send(Packet p) { _Device.SendPacket(p); }
/// <summary> /// Store result on desktop. /// </summary> /// <param name="packet">Packet of data to store.</param> /// <param name="async">Store the packet asyncronously to speed up the thread.</param> /// <remarks>Async creates crashes in Mono 3.10 if the thread disappears before the upload is complete so it is disabled for now.</remarks> public void StoreResult(Packet packet, bool async = false) { // Do nothing. }
/// <summary> /// Process an incoming packet. /// </summary> bool ProcessPacket(Buffer buffer, IPEndPoint ip) { BinaryReader reader = buffer.BeginReading(); Packet request = (Packet)reader.ReadByte(); switch (request) { case Packet.RequestPing: { BeginSend(Packet.ResponsePing); EndSend(ip); break; } case Packet.RequestAddServer: { if (reader.ReadUInt16() != GameServer.gameID) { return(false); } ServerList.Entry ent = new ServerList.Entry(); ent.ReadFrom(reader); if (ent.externalAddress.Address.Equals(IPAddress.None) || ent.externalAddress.Address.Equals(IPAddress.IPv6None)) { ent.externalAddress = ip; } mList.Add(ent, mTime); #if STANDALONE Tools.Print(ip + " added a server (" + ent.internalAddress + ", " + ent.externalAddress + ")"); #endif return(true); } case Packet.RequestRemoveServer: { if (reader.ReadUInt16() != GameServer.gameID) { return(false); } IPEndPoint internalAddress, externalAddress; Tools.Serialize(reader, out internalAddress); Tools.Serialize(reader, out externalAddress); if (externalAddress.Address.Equals(IPAddress.None) || externalAddress.Address.Equals(IPAddress.IPv6None)) { externalAddress = ip; } RemoveServer(internalAddress, externalAddress); #if STANDALONE Tools.Print(ip + " removed a server (" + internalAddress + ", " + externalAddress + ")"); #endif return(true); } case Packet.RequestServerList: { if (reader.ReadUInt16() != GameServer.gameID) { return(false); } mList.WriteTo(BeginSend(Packet.ResponseServerList)); EndSend(ip); return(true); } } return(false); }
public static void HandleLfgQuickJoinAutoAcceptRequests(Packet packet) { packet.ReadBit("AutoAccept"); }
public static AudioOutputChannel Create(Core.ChannelManager channelManager, Packet request, Packet response) { return(new AudioOutputChannel(channelManager)); }
/// <summary> /// Sends TradeComplete to creature's client. /// </summary> /// <param name="creature"></param> public static void TradeComplete(Creature creature) { var packet = new Packet(Op.TradeComplete, creature.EntityId); creature.Client.Send(packet); }
public override void Broadcast(Packet packet, Entity source, bool sendToSource = true, int range = -1) { Log.Warning("Broadcast in Limbo from source."); Log.Debug(Environment.StackTrace); }
private Packet?FilterServerPackets(Packet rawPacket) { var discardCurrentPacket = false; if (rawPacket.Id == PacketDefinitions.GeneralInformationPacket.Id && rawPacket.Payload[4] == 8) { var packet = new SetMapPacket(); packet.Deserialize(rawPacket); player.MapId = packet.MapId; } if (rawPacket.Id != PacketDefinitions.CharacterMoveAck.Id) { return(rawPacket); } if (player.WalkRequestQueue.TryDequeue(out var walkRequest)) { try { if (walkRequest.IssuedByProxy) { client.PauseClient(PauseClientChoice.Pause); client.DrawGamePlayer(player.PlayerId, player.BodyType, player.Location, player.Direction, player.MovementType, player.Color); foreach (var mobile in UO.Mobiles) { if (mobile.Id != player.PlayerId) { UO.Client.ObjectInfo(mobile.Id, mobile.Type, mobile.Location, mobile.Color); } } client.PauseClient(PauseClientChoice.Resume); discardCurrentPacket = true; } if (player.Direction != walkRequest.Direction) { player.Direction = walkRequest.Direction; } else { player.Location = player.Location.LocationInDirection(walkRequest.Direction); } if (gameObjects[player.PlayerId] is Mobile updatedMobile) { gameObjects.UpdateObject(updatedMobile.UpdateLocation(player.Location, player.Direction, player.MovementType)); } } finally { OnWalkRequestDequeued(); } } eventJournalSource.Publish(new PlayerMoveAcceptedEvent()); return(discardCurrentPacket ? (Packet?)null : rawPacket); }
public static void HandlePetSpells(Packet packet) { var guid = new byte[8]; guid[7] = packet.ReadBit(); guid[4] = packet.ReadBit(); var bits44 = (int)packet.ReadBits(21); var bits28 = (int)packet.ReadBits(22); guid[2] = packet.ReadBit(); var bits10 = (int)packet.ReadBits(20); guid[5] = packet.ReadBit(); guid[3] = packet.ReadBit(); guid[6] = packet.ReadBit(); guid[0] = packet.ReadBit(); guid[1] = packet.ReadBit(); const int maxCreatureSpells = 10; var spells = new List <uint>(maxCreatureSpells); for (var i = 0; i < maxCreatureSpells; i++) // Read pet/vehicle spell ids { var spell16 = packet.ReadUInt16(); var spell8 = packet.ReadByte(); var spellId = spell16 + (spell8 << 16); var slot = packet.ReadByte(); if (spellId <= 4) { packet.AddValue("Action", spellId, i); } else { packet.AddValue("Spell", StoreGetters.GetName(StoreNameType.Spell, spellId), i); } } for (var i = 0; i < bits10; ++i) { packet.ReadInt32("Int14", i); packet.ReadInt32("Int14", i); packet.ReadInt16("Int14", i); packet.ReadInt32("Int14", i); } packet.ReadXORByte(guid, 2); for (var i = 0; i < bits28; ++i) { packet.ReadInt32("IntED", i); } packet.ReadXORByte(guid, 7); packet.ReadXORByte(guid, 0); packet.ReadXORByte(guid, 3); packet.ReadInt16("Family"); for (var i = 0; i < bits44; ++i) { packet.ReadInt32("Int48", i); packet.ReadByte("Byte48", i); packet.ReadInt32("Int48", i); } packet.ReadInt16("Int40"); packet.ReadXORByte(guid, 1); packet.ReadXORByte(guid, 4); packet.ReadXORByte(guid, 6); packet.ReadInt32("Int24"); packet.ReadXORByte(guid, 5); packet.ReadInt32("Int20"); packet.WriteGuid("Guid", guid); }
public void ItemMagnet(ChannelClient client, Packet packet) { var creature = client.GetCreatureSafe(packet.Id); Send.MsgBox(creature, Localization.Get("Not supported yet.")); }
public override void Broadcast(Packet packet) { Log.Warning("Broadcast in Limbo."); Log.Debug(Environment.StackTrace); }
public void UseItem(ChannelClient client, Packet packet) { var entityId = packet.GetLong(); var creature = client.GetCreatureSafe(packet.Id); // Check states if (creature.IsDead) { Log.Warning("Player '{0}' tried to use item while being dead.", creature.Name); goto L_Fail; } // Check lock if (!creature.Can(Locks.UseItem)) { Log.Debug("UseItem locked for '{0}'.", creature.Name); goto L_Fail; } // Get item var item = creature.Inventory.GetItem(entityId); if (item == null) { goto L_Fail; } // Meta Data Scripts var gotMetaScript = false; { // Sealed books if (item.MetaData1.Has("MGCWRD") && item.MetaData1.Has("MGCSEL")) { var magicWords = item.MetaData1.GetString("MGCWRD"); try { var sms = new MagicWordsScript(magicWords); sms.Run(creature, item); gotMetaScript = true; } catch (Exception ex) { Log.Exception(ex, "Problem while running magic words script '{0}'", magicWords); Send.ServerMessage(creature, Localization.Get("Unimplemented item.")); goto L_Fail; } } } // Aura Scripts if (!gotMetaScript) { // Get script var script = ChannelServer.Instance.ScriptManager.ItemScripts.Get(item.Info.Id); if (script == null) { Log.Unimplemented("Item script for '{0}' not found.", item.Info.Id); Send.ServerMessage(creature, Localization.Get("This item isn't implemented yet.")); goto L_Fail; } // Run script try { script.OnUse(creature, item); } catch (NotImplementedException) { Log.Unimplemented("UseItem: Item OnUse method for '{0}'.", item.Info.Id); Send.ServerMessage(creature, Localization.Get("This item isn't implemented completely yet.")); goto L_Fail; } } ChannelServer.Instance.Events.OnPlayerUsesItem(creature, item); // Decrease item count if (item.Data.Consumed) { creature.Inventory.Decrement(item); ChannelServer.Instance.Events.OnPlayerRemovesItem(creature, item.Info.Id, 1); } // Break seal after use if (item.MetaData1.Has("MGCSEL")) { item.MetaData1.Remove("MGCWRD"); item.MetaData1.Remove("MGCSEL"); Send.ItemUpdate(creature, item); } // Mandatory stat update Send.StatUpdate(creature, StatUpdateType.Private, Stat.Life, Stat.LifeInjured, Stat.Mana, Stat.Stamina, Stat.Hunger); Send.StatUpdate(creature, StatUpdateType.Public, Stat.Life, Stat.LifeInjured); Send.UseItemR(creature, true, item.Info.Id); return; L_Fail: Send.UseItemR(creature, false, 0); }
private static MovementInfo ReadMovementUpdateBlock547(ref Packet packet, Guid guid, int index) { var moveInfo = new MovementInfo(); var hasUnkDword676 = packet.ReadBit(); var hasVehicleData = packet.ReadBit("Has Vehicle Data", index); var hasUnkDword1044 = packet.ReadBit(); var hasGameObjectRotation = packet.ReadBit("Has GameObject Rotation", index); packet.ReadBit("unk byte0", index); var living = packet.ReadBit("Living", index); var hasUnkLargeBlock = packet.ReadBit("Has Unk Large Block", index); packet.ReadBit("Unk Byte2", index); var hasUnkLargeBlock2 = packet.ReadBit("Has Unk Large Block2", index); packet.ReadBit("Self", index); packet.ReadBit("Unk Byte681", index); packet.ReadBit("Unk Byte1", index); var hasGameObjectPosition = packet.ReadBit("Has GameObject Position", index); var transport = packet.ReadBit("Has Transport Data", index); var hasAnimKits = packet.ReadBit("Has AnimKits", index); var hasStationaryPosition = packet.ReadBit("Has Stationary Position", index); var hasAttackingTarget = packet.ReadBit("Has Attacking Target", index); var unkLoopCounter = packet.ReadBits("Unknown array size", 22, index); var hasUnkString = packet.ReadBit("Has Unknown String", index); var hasTransportFrames = packet.ReadBit("Has Transport Frames", index); uint transportFramesCount = 0; uint UnkStringLen = 0; //int IsLivingUnkCountLoop = 0; uint IsLivingUnkCounter = 0; var hasOrientation = false; var guid2 = new byte[8]; var hasPitch = false; var hasFallData = false; var hasSplineElevation = false; var hasTransportData = false; var hasTimestamp = false; var hasMovementCounter = false; var transportGuid = new byte[8]; var hasTransportTime2 = false; var hasTransportTime3 = false; var bit216 = false; var hasSplineStartTime = false; var splineCount = 0u; var splineType = SplineType.Stop; var facingTargetGuid = new byte[8]; var hasSplineVerticalAcceleration = false; var hasSplineUnkPart = false; var hasFallDirection = false; var goTransportGuid = new byte[8]; var hasGOTransportTime2 = false; var hasGOTransportTime3 = false; var attackingTargetGuid = new byte[8]; var SplineFacingTargetGuid = new byte[8]; var hasAnimKit1 = false; var hasAnimKit2 = false; var hasAnimKit3 = false; bool[] UnkLargeBlockBits = new bool[13]; uint[] UnkLargeBlockCount = new uint[3]; if (hasTransportFrames) { transportFramesCount = packet.ReadBits("Transport Frames Count", 22, index); } if (hasGameObjectPosition) { goTransportGuid[3] = packet.ReadBit(); goTransportGuid[5] = packet.ReadBit(); goTransportGuid[2] = packet.ReadBit(); goTransportGuid[1] = packet.ReadBit(); goTransportGuid[4] = packet.ReadBit(); hasGOTransportTime3 = packet.ReadBit(); hasGOTransportTime2 = packet.ReadBit(); goTransportGuid[0] = packet.ReadBit(); goTransportGuid[6] = packet.ReadBit(); goTransportGuid[7] = packet.ReadBit(); } if (living) { hasTransportData = packet.ReadBit("Has Transport Data", index); if (hasTransportData) { transportGuid[4] = packet.ReadBit(); transportGuid[0] = packet.ReadBit(); transportGuid[5] = packet.ReadBit(); transportGuid[2] = packet.ReadBit(); transportGuid[3] = packet.ReadBit(); hasTransportTime2 = packet.ReadBit(); transportGuid[7] = packet.ReadBit(); transportGuid[6] = packet.ReadBit(); transportGuid[1] = packet.ReadBit(); hasTransportTime3 = packet.ReadBit(); } hasPitch = !packet.ReadBit("Lacks pitch", index); packet.ReadBit("Has MovementInfo spline", index); packet.ReadBits("IsLicingUnkLoop", 19, index); guid2[1] = packet.ReadBit(); var hasExtraMovementFlags = !packet.ReadBit(); /*var v37 = IsLivingUnkCountLoop == 0; * * if (!v37) * { * for (int i = 0; i < IsLivingUnkCountLoop; ++i) * { * packet.ReadBits("Unk DWORD24 Loop1", 2, index, (int)i); * } * }*/ packet.ReadBit("Unk Bit from movementInfo", index); hasSplineElevation = !packet.ReadBit("Lacks spline elevation", index); if (hasExtraMovementFlags) { moveInfo.FlagsExtra = packet.ReadEnum <MovementFlagExtra>("Extra Movement Flags", 13, index); } hasOrientation = !packet.ReadBit("Lacks orientation", index); hasTimestamp = !packet.ReadBit("Has Timestamp", index); var hasMovementFlags = !packet.ReadBit(); hasMovementCounter = !packet.ReadBit("Has Movement Counter", index); guid2[2] = packet.ReadBit(); guid2[6] = packet.ReadBit(); hasFallData = packet.ReadBit("Has Fall Data", index); guid2[5] = packet.ReadBit(); guid2[4] = packet.ReadBit(); guid2[0] = packet.ReadBit(); if (hasMovementFlags) { moveInfo.Flags = (WowPacketParser.Enums.MovementFlag)packet.ReadEnum <MovementFlag>("Movement Flags", 30, index); } packet.ReadBit("Unk byte164", index); if (hasFallData) { hasFallDirection = packet.ReadBit("Has Fall Direction", index); } packet.ReadBits("Is Living Unk Counter", 22, index); guid2[7] = packet.ReadBit(); moveInfo.HasSplineData = packet.ReadBit("Has Spline Data", index); guid2[3] = packet.ReadBit(); if (moveInfo.HasSplineData) { bit216 = packet.ReadBit("Has extended spline data", index); if (bit216) { packet.ReadBits("Unk bits", 2, index); hasSplineStartTime = packet.ReadBit("Has spline start time", index); splineCount = packet.ReadBits("Spline Waypoints", 22, index); packet.ReadEnum <SplineFlag434>("Spline flags", 25, index); hasSplineVerticalAcceleration = packet.ReadBit("Has spline vertical acceleration", index); hasSplineUnkPart = packet.ReadBit(); if (hasSplineUnkPart) { packet.ReadBits("Unk word300", 2, index); //unk word300 packet.ReadBits("Unk dword284", 21, index); //unk dword284 } } } } if (hasUnkLargeBlock2) { UnkLargeBlockBits[0] = packet.ReadBit(); UnkLargeBlockBits[1] = packet.ReadBit(); packet.ReadBit("Unk Byte256", index); packet.ReadBit("Unk Byte257", index); UnkLargeBlockBits[4] = packet.ReadBit(); packet.ReadBit("Unk Byte254", index); UnkLargeBlockBits[6] = packet.ReadBit(); packet.ReadBit("Unk Byte255", index); UnkLargeBlockBits[8] = packet.ReadBit(); if (UnkLargeBlockBits[8]) { UnkLargeBlockCount[0] = packet.ReadBits(21); UnkLargeBlockCount[1] = packet.ReadBits(21); } UnkLargeBlockBits[9] = packet.ReadBit(); if (UnkLargeBlockBits[9]) { UnkLargeBlockCount[2] = packet.ReadBits(20); } UnkLargeBlockBits[10] = packet.ReadBit(); packet.ReadBit("Unk Byte258", index); UnkLargeBlockBits[12] = packet.ReadBit(); } if (hasAttackingTarget) { attackingTargetGuid = packet.StartBitStream(4, 6, 3, 5, 0, 2, 7, 1); } if (hasAnimKits) { hasAnimKit2 = !packet.ReadBit(); hasAnimKit3 = !packet.ReadBit(); hasAnimKit1 = !packet.ReadBit(); } if (hasUnkString) { UnkStringLen = packet.ReadBits(7); } packet.ResetBitReader(); // Reading data for (var i = 0u; i < unkLoopCounter; ++i) { packet.ReadUInt32("Unk UInt32", index, (int)i); } if (hasUnkLargeBlock2) { if (UnkLargeBlockBits[10]) { packet.ReadSingle("Unk Float 234", index); packet.ReadSingle("Unk Float 238", index); } if (UnkLargeBlockBits[8]) { for (uint i = 0; i < UnkLargeBlockCount[1]; ++i) { packet.ReadSingle("Unk Float Loop1", index); packet.ReadSingle("Unk Float1 Loop1", index); } packet.ReadSingle("Unk Float 27C", index); for (uint i = 0; i < UnkLargeBlockCount[0]; ++i) { packet.ReadSingle("Unk Float Loop0", index); packet.ReadSingle("Unk Float1 Loop0", index); } packet.ReadSingle("Unk Float 280", index); } if (UnkLargeBlockBits[1]) { packet.ReadSingle("Unk Float 244", index); packet.ReadSingle("Unk Float 250", index); packet.ReadSingle("Unk Float 254", index); packet.ReadSingle("Unk Float 248", index); packet.ReadSingle("Unk Float 240", index); packet.ReadSingle("Unk Float 24C", index); } packet.ReadInt32("Unk DWORD 520", index); if (UnkLargeBlockBits[9]) { for (uint i = 0; i < UnkLargeBlockCount[2]; ++i) { packet.ReadSingle("Unk Float Loop2", index); packet.ReadSingle("Unk Float1 Loop2", index); packet.ReadSingle("Unk Float2 Loop2", index); } } if (UnkLargeBlockBits[12]) { packet.ReadInt32("Unk DWORD 540", index); } if (UnkLargeBlockBits[6]) { packet.ReadInt32("Unk DWORD 532", index); } if (UnkLargeBlockBits[0]) { packet.ReadInt32("Unk DWORD 556", index); } if (UnkLargeBlockBits[4]) { packet.ReadInt32("Unk DWORD 548", index); } } if (living) { if (hasFallData) { if (hasFallDirection) { packet.ReadSingle("Jump Sin", index); packet.ReadSingle("Jump Cos", index); packet.ReadSingle("Jump XY Speed", index); } packet.ReadSingle("Fall Z Speed", index); packet.ReadUInt32("Time Fallen", index); } if (moveInfo.HasSplineData) { if (bit216) { packet.ReadSingle("Spline Duration Multiplier Next", index); for (var i = 0u; i < splineCount; ++i) { var wp = new Vector3 { Z = packet.ReadSingle(), X = packet.ReadSingle(), Y = packet.ReadSingle(), }; packet.WriteLine("[{0}][{1}] Spline Waypoint: {2}", index, i, wp); } splineType = packet.ReadEnum <SplineType>("Spline Type", TypeCode.Byte, index); packet.ReadSingle("Spline Duration Multiplier", index); //unk part goes here if (splineType == SplineType.FacingSpot) { var point = new Vector3 { X = packet.ReadSingle(), Z = packet.ReadSingle(), Y = packet.ReadSingle(), }; packet.WriteLine("[{0}] Facing Spot: {1}", index, point); } if (hasSplineVerticalAcceleration) { packet.ReadSingle("Spline Vertical Acceleration", index); } if (splineType == SplineType.FacingAngle) { packet.ReadSingle("Facing Angle", index); } packet.ReadUInt32("Spline Full Time", index); if (hasSplineStartTime) { packet.ReadUInt32("Spline Start time", index); } packet.ReadUInt32("Spline Time", index); } packet.ReadUInt32("Spline Id", index); var endPoint = new Vector3 { Z = packet.ReadSingle(), X = packet.ReadSingle(), Y = packet.ReadSingle(), }; packet.WriteLine("[{0}] Spline Endpoint: {1}", index, endPoint); } moveInfo.Position.Z = packet.ReadSingle(); /*if (IsLivingUnkCountLoop > 0) * { * for (int i = 0; i < IsLivingUnkCountLoop; ++i) * { * packet.ReadSingle("Unk Float14", index, (int)i); * packet.ReadInt32("Unk DWORD10", index, (int)i); * packet.ReadInt32("Unk DWORD0", index, (int)i); * packet.ReadSingle("Unk FloatC", index, (int)i); * packet.ReadSingle("Unk Float4", index, (int)i); * packet.ReadSingle("Unk Float8", index, (int)i); * } * }*/ moveInfo.Position.Y = packet.ReadSingle(); packet.ReadSingle("Fly Speed", index); packet.ReadXORByte(guid2, 6); packet.ReadSingle("FlyBack Speed", index); if (hasTransportData) { packet.ReadXORByte(transportGuid, 7); packet.ReadXORByte(transportGuid, 4); if (hasTransportTime3) { packet.ReadUInt32("Transport Time 3", index); } packet.ReadUInt32("Transport Time", index); if (hasTransportTime2) { packet.ReadUInt32("Transport Time 2", index); } moveInfo.TransportOffset.O = packet.ReadSingle(); moveInfo.TransportOffset.X = packet.ReadSingle(); packet.ReadXORByte(transportGuid, 6); packet.ReadXORByte(transportGuid, 3); packet.ReadXORByte(transportGuid, 2); moveInfo.TransportOffset.Z = packet.ReadSingle(); moveInfo.TransportOffset.Y = packet.ReadSingle(); packet.ReadSByte("Transport Seat", index); packet.ReadXORByte(transportGuid, 1); packet.ReadXORByte(transportGuid, 0); packet.ReadXORByte(transportGuid, 5); moveInfo.TransportGuid = new Guid(BitConverter.ToUInt64(transportGuid, 0)); packet.WriteLine("[{0}] Transport GUID {1}", index, moveInfo.TransportGuid); packet.WriteLine("[{0}] Transport Position: {1}", index, moveInfo.TransportOffset); } moveInfo.Position.X = packet.ReadSingle(); packet.ReadXORByte(guid2, 2); if (hasPitch) { packet.ReadSingle("Pitch", index); } packet.ReadSingle("Swim Speed", index); packet.ReadXORByte(guid2, 1); packet.ReadSingle("RunBack Speed", index); packet.ReadSingle("SwimBack Speed", index); packet.ReadXORByte(guid2, 5); if (hasSplineElevation) { packet.ReadSingle("Spline Elevation", index); } if (hasMovementCounter) { packet.ReadUInt32("Movement Counter", index); } moveInfo.RunSpeed = packet.ReadSingle("Run Speed", index) / 7.0f; packet.ReadXORByte(guid2, 7); moveInfo.WalkSpeed = packet.ReadSingle("Walk Speed", index) / 2.5f; packet.ReadSingle("Pitch Rate", index); if (IsLivingUnkCounter > 0) { for (uint i = 0; i < IsLivingUnkCounter; ++i) { packet.ReadUInt32("Unk DWORD148", index, (int)i); } } if (hasTimestamp) { packet.ReadUInt32("Timestamp", index); } packet.ReadXORByte(guid2, 4); packet.ReadXORByte(guid2, 0); if (hasOrientation) { moveInfo.Orientation = packet.ReadSingle(); } packet.WriteLine("[{0}] GUID 2: {1}", index, new Guid(BitConverter.ToUInt64(guid2, 0))); packet.WriteLine("[{0}] Position: {1}", index, moveInfo.Position); packet.WriteLine("[{0}] Orientation: {1}", index, moveInfo.Orientation); } if (hasAttackingTarget) { packet.ParseBitStream(attackingTargetGuid, 5, 1, 2, 0, 3, 4, 6, 7); packet.WriteGuid("Attacking Target GUID", attackingTargetGuid, index); } if (hasStationaryPosition) { moveInfo.Orientation = packet.ReadSingle("Stationary Orientation", index); moveInfo.Position = packet.ReadVector3("Stationary Position", index); } if (hasGameObjectPosition) { packet.ReadByte("GO Transport Seat", index); moveInfo.TransportOffset.X = packet.ReadSingle(); packet.ReadXORByte(goTransportGuid, 1); packet.ReadXORByte(goTransportGuid, 0); packet.ReadXORByte(goTransportGuid, 2); packet.ReadXORByte(goTransportGuid, 6); packet.ReadXORByte(goTransportGuid, 5); packet.ReadXORByte(goTransportGuid, 4); if (hasGOTransportTime3) { packet.ReadUInt32("GO Transport Time 3", index); } packet.ReadXORByte(goTransportGuid, 7); moveInfo.TransportOffset.O = packet.ReadSingle(); moveInfo.TransportOffset.Z = packet.ReadSingle(); moveInfo.TransportOffset.Y = packet.ReadSingle(); if (hasGOTransportTime2) { packet.ReadUInt32("GO Transport Time 2", index); } packet.ReadXORByte(goTransportGuid, 3); packet.ReadUInt32("GO Transport Time", index); moveInfo.TransportGuid = new Guid(BitConverter.ToUInt64(goTransportGuid, 0)); packet.WriteLine("[{0}] GO Transport GUID {1}", index, moveInfo.TransportGuid); packet.WriteLine("[{0}] GO Transport Position: {1}", index, moveInfo.TransportOffset); } if (transport) { packet.ReadUInt32("Transport path timer", index); } if (hasUnkDword676) { packet.ReadUInt32("Unk DWORD676", index); } if (hasUnkString) { packet.ReadWoWString("Unk String", UnkStringLen, index); } if (hasGameObjectRotation) { packet.ReadPackedQuaternion("GameObject Rotation", index); } if (hasVehicleData) { moveInfo.VehicleId = packet.ReadUInt32("Vehicle Id", index); packet.ReadSingle("Vehicle Orientation", index); } if (hasUnkDword1044) { packet.ReadUInt32("Unk DWORD1044", index); } if (hasAnimKits) { if (hasAnimKit1) { packet.ReadUInt16("Anim Kit 1", index); } if (hasAnimKit2) { packet.ReadUInt16("Anim Kit 2", index); } if (hasAnimKit3) { packet.ReadUInt16("Anim Kit 3", index); } } /*if (bit456) * { * // float[] arr = new float[16]; * // ordering: 13, 4, 7, 15, BYTE, 10, 11, 3, 5, 14, 6, 1, 8, 12, 0, 2, 9 * packet.ReadBytes(4 * 16 + 1); * }*/ if (living && moveInfo.HasSplineData && bit216) { if (splineType == SplineType.FacingTarget) { SplineFacingTargetGuid = packet.StartBitStream(6, 7, 3, 0, 5, 1, 4, 2); packet.ParseBitStream(SplineFacingTargetGuid, 4, 2, 5, 6, 0, 7, 1, 3); packet.WriteGuid("Spline Facing Target GUID", SplineFacingTargetGuid, index); } } return(moveInfo); }
private void SendResources(Session session, Packet packet) { uint cityId; uint objectId; string targetCityName; Resource resource; bool actuallySend; try { cityId = packet.GetUInt32(); objectId = packet.GetUInt32(); targetCityName = packet.GetString().Trim(); resource = new Resource(packet.GetInt32(), packet.GetInt32(), packet.GetInt32(), packet.GetInt32()); actuallySend = packet.GetByte() == 1; } catch (Exception) { ReplyError(session, packet, Error.Unexpected); return; } uint targetCityId; if (!world.Cities.FindCityId(targetCityName, out targetCityId)) { ReplyError(session, packet, Error.CityNotFound); return; } if (cityId == targetCityId) { ReplyError(session, packet, Error.ActionSelf); return; } var hasCity = locker.Lock(session.Player) .Do(() => session.Player.GetCity(cityId) != null); if (!hasCity) { ReplyError(session, packet, Error.Unexpected); return; } Dictionary <uint, ICity> cities; locker.Lock(out cities, cityId, targetCityId).Do(() => { if (cities == null) { ReplyError(session, packet, Error.Unexpected); return; } ICity city = cities[cityId]; IStructure structure; if (!city.TryGetStructure(objectId, out structure)) { ReplyError(session, packet, Error.Unexpected); } var action = actionFactory.CreateResourceSendActiveAction(cityId, objectId, targetCityId, resource); // If actually send then we perform the action, otherwise, we send the player information about the trade. if (actuallySend) { Error ret = city.Worker.DoActive(structureCsvFactory.GetActionWorkerType(structure), structure, action, structure.Technologies); if (ret != 0) { ReplyError(session, packet, ret); } else { ReplySuccess(session, packet); } } else { var reply = new Packet(packet); reply.AddString(cities[targetCityId].Owner.Name); reply.AddInt32(action.CalculateTradeTime(structure, cities[targetCityId])); session.Write(reply); } }); }
public void DyePaletteReq(ChannelClient client, Packet packet) { var creature = client.GetCreatureSafe(packet.Id); Send.DyePaletteReqR(creature, 0, 0, 0, 0); }
/// <summary> /// Sends TouchMimicR to creature's client. /// </summary> /// <param name="creature"></param> public static void TouchMimicR(Creature creature) { var packet = new Packet(Op.TouchMimicR, creature.EntityId); creature.Client.Send(packet); }
public void ItemMove(ChannelClient client, Packet packet) { var entityId = packet.GetLong(); var untrustedSource = (Pocket)packet.GetByte(); // Discard this, NA does too var target = (Pocket)packet.GetByte(); var unk = packet.GetByte(); var targetX = packet.GetByte(); var targetY = packet.GetByte(); // Get creature var creature = client.GetCreatureSafe(packet.Id); // Get item var item = creature.Inventory.GetItemSafe(entityId); var source = item.Info.Pocket; // Check lock if ((source.IsEquip() || target.IsEquip()) && !creature.Can(Locks.ChangeEquipment)) { Log.Debug("ChangeEquipment locked for '{0}'.", creature.Name); goto L_Fail; } // Check bag if (item.IsBag && target.IsBag() && !ChannelServer.Instance.Conf.World.Bagception) { Send.ServerMessage(creature, Localization.Get("Item bags can't be stored inside other bags.")); goto L_Fail; } // Check TwinSword feature if (target == creature.Inventory.LeftHandPocket && !item.IsShieldLike && creature.RightHand != null && !AuraData.FeaturesDb.IsEnabled("TwinSword")) { // TODO: Is this message sufficient? Do we need a better one? // Do we need one at all? Or would that confuse people even more? Send.Notice(creature, NoticeType.MiddleSystem, Localization.Get("The Dual Wielding feature hasn't been enabled yet.")); goto L_Fail; } // Stop moving when changing weapons if ((target >= Pocket.RightHand1 && target <= Pocket.Magazine2) || (source >= Pocket.RightHand1 && source <= Pocket.Magazine2)) { creature.StopMove(); } // Try to move item if (!creature.Inventory.Move(item, target, targetX, targetY)) { goto L_Fail; } // Give Ranged Attack when equipping a (cross)bow if (target.IsEquip() && (item.HasTag("/bow/|/crossbow/")) && !creature.Skills.Has(SkillId.RangedAttack)) { creature.Skills.Give(SkillId.RangedAttack, SkillRank.Novice); } // Give Playing Instrument when equipping an instrument if (target.IsEquip() && (item.HasTag("/instrument/")) && !creature.Skills.Has(SkillId.PlayingInstrument)) { creature.Skills.Give(SkillId.PlayingInstrument, SkillRank.Novice); } // Inform about temp moves (items in temp don't count for quest objectives?) if (source == Pocket.Temporary && target == Pocket.Cursor) { ChannelServer.Instance.Events.OnPlayerReceivesItem(creature, item.Info.Id, item.Info.Amount); } Send.ItemMoveR(creature, true); return; L_Fail: Send.ItemMoveR(creature, false); }
/// <summary> /// Broadcasts IsNowDead in range of creature. /// </summary> /// <remarks> /// Creature isn't targetable anymore after this. /// </remarks> /// <param name="creature"></param> public static void IsNowDead(Creature creature) { var packet = new Packet(Op.IsNowDead, creature.EntityId); creature.Region.Broadcast(packet, creature); }
/// <summary> /// Broadcasts CombatActionPack in range of pack's attacker. /// </summary> /// <param name="pack"></param> public static void CombatAction(CombatActionPack pack) { var attackerPos = pack.Attacker.GetPosition(); var packet = new Packet(Op.CombatActionPack, MabiId.Broadcast); packet.PutInt(pack.Id); packet.PutInt(pack.PrevId); packet.PutByte(pack.Hit); packet.PutByte((byte)pack.Type); packet.PutByte(pack.Flags); if ((pack.Flags & 1) == 1) { packet.PutInt(pack.BlockedByShieldPosX); packet.PutInt(pack.BlockedByShieldPosY); packet.PutLong(pack.ShieldCasterId); } // Actions packet.PutInt(pack.Actions.Count); Packet actionPacket = null; foreach (var action in pack.Actions) { var pos = action.Creature.GetPosition(); if (actionPacket == null) { actionPacket = new Packet(Op.CombatAction, action.Creature.EntityId); } else { actionPacket.Clear(Op.CombatAction, action.Creature.EntityId); } actionPacket.PutInt(pack.Id); actionPacket.PutLong(action.Creature.EntityId); actionPacket.PutByte((byte)action.Flags); actionPacket.PutShort(action.Stun); actionPacket.PutUShort((ushort)action.SkillId); actionPacket.PutUShort((ushort)action.SecondarySkillId); // Official name for CombatAction is CombatScene, and both Actions are Combatant. // Official client distinguish between Attacker and Defender simply by checking Flags. tachiorz // AttackerAction //if ((action.Flags & CombatActionFlags.Attacker) != 0) if (action.Category == CombatActionCategory.Attack) { var aAction = action as AttackerAction; actionPacket.PutLong(aAction.TargetId); actionPacket.PutUInt((uint)aAction.Options); actionPacket.PutByte(aAction.UsedWeaponSet); actionPacket.PutByte(aAction.WeaponParameterType); // !aAction.Has(AttackerOptions.KnockBackHit2) ? 2 : 1)); // ? actionPacket.PutInt(pos.X); actionPacket.PutInt(pos.Y); if ((aAction.Options & AttackerOptions.Dashed) != 0) { actionPacket.PutFloat(0); // DashedPosX actionPacket.PutFloat(0); // DashedPosY actionPacket.PutUInt(0); // DashDelay } if ((aAction.Options & AttackerOptions.PhaseAttack) != 0) { actionPacket.PutByte(aAction.Phase); } if ((aAction.Options & AttackerOptions.UseEffect) != 0) { actionPacket.PutLong(aAction.PropId); } } // TargetAction //if ((action.Flags & CombatActionFlags.TakeHit) != 0) else if (action.Category == CombatActionCategory.Target && !action.Is(CombatActionType.None)) { var tAction = action as TargetAction; // Target used Defense or Counter if ((action.Flags & CombatActionType.Attacker) != 0) { actionPacket.PutLong(tAction.Attacker.EntityId); actionPacket.PutInt(0); // attacker Options actionPacket.PutByte(tAction.UsedWeaponSet); actionPacket.PutByte(tAction.WeaponParameterType); actionPacket.PutInt(pos.X); actionPacket.PutInt(pos.Y); } actionPacket.PutUInt((uint)tAction.Options); actionPacket.PutFloat(tAction.Damage); actionPacket.PutFloat(tAction.Wound); actionPacket.PutInt((int)tAction.ManaDamage); actionPacket.PutFloat(attackerPos.X - pos.X); actionPacket.PutFloat(attackerPos.Y - pos.Y); if (tAction.IsKnockBack) { actionPacket.PutFloat(pos.X); actionPacket.PutFloat(pos.Y); // [190200, NA203 (22.04.2015)] { actionPacket.PutInt(0); } } if ((tAction.Options & TargetOptions.MultiHit) != 0) { actionPacket.PutUInt(0); // MultiHitDamageCount actionPacket.PutUInt(0); // MultiHitDamageShowTime } actionPacket.PutByte((byte)tAction.EffectFlags); actionPacket.PutInt(tAction.Delay); actionPacket.PutLong(tAction.Attacker.EntityId); } packet.PutBin(actionPacket); } pack.Attacker.Region.Broadcast(packet, pack.Attacker); }
void HandleSendGarbage(Socket socket, Packet packet, params object[] args) { int payload = Convert.ToInt32((double)args[0]); SpawnGarbage(payload); }
/// <summary> /// Sends ChangeStanceRequestR to creature's client. /// </summary> /// <param name="creature"></param> public static void ChangeStanceRequestR(Creature creature) { var packet = new Packet(Op.ChangeStanceRequestR, creature.EntityId); creature.Client.Send(packet); }
public static void AssertPacket(Packet p, int length, int priority) { Assert.AreEqual(p.Data.Payload.Length, length); Assert.AreEqual(p.Data.ID, priority); }
/// <summary> /// Broadcasts SetFinisher2 in range of creature. /// </summary> /// <remarks> /// Purpose unknown, sent shortly after SetFinisher. /// </remarks> /// <param name="creature"></param> public static void SetFinisher2(Creature creature) { var packet = new Packet(Op.SetFinisher2, creature.EntityId); creature.Region.Broadcast(packet, creature); }
private void ProcessIncoming(object state) { NetPeer myPeer = (NetPeer)state; NetIncomingMessage myMessage = myPeer.ReadMessage(); switch (myMessage.MessageType) { case NetIncomingMessageType.Error: break; case NetIncomingMessageType.StatusChanged: switch ((NetConnectionStatus)myMessage.ReadByte()) { case NetConnectionStatus.None: break; case NetConnectionStatus.InitiatedConnect: break; case NetConnectionStatus.ReceivedInitiation: break; case NetConnectionStatus.RespondedAwaitingApproval: break; case NetConnectionStatus.RespondedConnect: break; case NetConnectionStatus.Connected: isConnected = true; OnConnect?.Invoke(); break; case NetConnectionStatus.Disconnecting: break; case NetConnectionStatus.Disconnected: isConnected = false; myTimer = new Timer(new TimerCallback(AttemptToReconnect), this, 0, 500); OnDisconnect?.Invoke(); break; } int i = 0; break; case NetIncomingMessageType.UnconnectedData: break; case NetIncomingMessageType.ConnectionApproval: break; case NetIncomingMessageType.Data: myStream.Write(myMessage.Data, 0, myMessage.Data.Length); myStream.Position = 0; Packet myPacket = (Packet)mySendFormatter.Deserialize(myStream); myStream.SetLength(0); PacketFactory.SetProcessor(myPacket); myPacket.Process(); break; case NetIncomingMessageType.Receipt: break; case NetIncomingMessageType.DiscoveryRequest: break; case NetIncomingMessageType.DiscoveryResponse: break; case NetIncomingMessageType.VerboseDebugMessage: break; case NetIncomingMessageType.DebugMessage: break; case NetIncomingMessageType.WarningMessage: Debug.WriteLine(myMessage.ReadString()); break; case NetIncomingMessageType.ErrorMessage: break; case NetIncomingMessageType.NatIntroductionSuccess: break; case NetIncomingMessageType.ConnectionLatencyUpdated: break; } myPeer.Recycle(myMessage); }
/// <summary> /// Создать экземпляр чанка файла из полученного пакета /// </summary> /// <param name="packet">Пакет</param> /// <returns></returns> public static FileChunk ReadPacket(Packet packet) { return(new FileChunk(packet.PullInt(), packet.PullBytes()).Sended()); }
public void CombatAttack(ChannelClient client, Packet packet) { var targetEntityId = packet.GetLong(); // This string is in the standard CombatAttack packet, // but the purpose is unknown, and it's not in all CombatAttack // packets. if (packet.Peek() == PacketElementType.String) { var unkString = packet.GetString(); if (!string.IsNullOrWhiteSpace(unkString)) { Log.Info("CombatAttack: Non-empty string, please report this message to the development team. String: " + unkString); } } var creature = client.GetCreature(packet.Id); // Despawning a pet while it's attacking can make the client // send another attack packet while the creature has already // been removed on the server. Using GetCreatureSafe can // kick players. if (creature == null) { return; } // Check lock if (!creature.Can(Locks.Attack)) { Log.Debug("Attack locked for '{0}'.", creature.Name); goto L_End; } // Check target var target = creature.Region.GetCreature(targetEntityId); if (target == null || !creature.CanTarget(target)) { goto L_End; } // Check Stun if (creature.IsStunned) { goto L_End; } // Get skill var skill = creature.Skills.ActiveSkill; if (skill == null && (skill = creature.Skills.Get(SkillId.CombatMastery)) == null) { Log.Warning("CombatAttack: Creature '{0}' doesn't have Combat Mastery.", creature.Name); goto L_End; } // Get handler var skillHandler = ChannelServer.Instance.SkillManager.GetHandler <ISkillHandler>(skill.Info.Id); if (skillHandler == null) { Log.Unimplemented("CombatAttack: Skill handler or interface for '{0}'.", skill.Info.Id); Send.ServerMessage(creature, "This combat skill isn't implemented yet."); goto L_End; } var handler = skillHandler as ICombatSkill; if (handler == null) { // Skill exists, but doesn't seem to be a combat skill, ignore. // Example: Clicking a monster while Healing is active. goto L_End; } try { var result = handler.Use(creature, skill, targetEntityId); if (result == CombatSkillResult.Okay) { Send.CombatAttackR(creature, true); skill.State = SkillState.Used; creature.Regens.Remove("ActiveSkillWait"); } else if (result == CombatSkillResult.OutOfRange) { Send.CombatAttackR(creature, target); } else { Send.CombatAttackR(creature, false); } return; } catch (NotImplementedException) { Log.Unimplemented("CombatAttack: Skill use method for '{0}'.", skill.Info.Id); Send.ServerMessage(creature, "This combat skill isn't implemented completely yet."); } L_End: Send.CombatAttackR(creature, false); }
public void RequestRebirth(ChannelClient client, Packet packet) { var unkLong = packet.GetLong(); var resetAge = packet.GetBool(); short age = 0; if (resetAge) { age = packet.GetShort(); } var resetLevel = packet.GetBool(); var resetGender = packet.GetBool(); var race = 0; if (resetGender) { race = packet.GetInt(); } var skinColor = packet.GetByte(); var hairItemId = packet.GetInt(); var hairColor = packet.GetByte(); var eyeType = packet.GetShort(); var eyeColor = packet.GetByte(); var mouthType = packet.GetByte(); var faceItemId = packet.GetInt(); var location = (RebirthLocation)packet.GetByte(); var talent = packet.GetByte(); // Get required data var creature = client.GetCreatureSafe(packet.Id); var hair = creature.Inventory.GetItemAt(Pocket.Hair, 0, 0); var face = creature.Inventory.GetItemAt(Pocket.Face, 0, 0); var hairItemData = AuraData.ItemDb.Find(hairItemId); var faceItemData = AuraData.ItemDb.Find(faceItemId); // Check age if (resetAge && (age < 10 || age > 17 || age > creature.Age)) { throw new SevereViolation("Player tried to rebirth with invalid age ({0}).", age); } // Check race, the new one would be the same as the old one, // if you remove the last number (1 for female, 2 for male). if (resetGender && (creature.RaceId & ~3) != (race & ~3)) { throw new SevereViolation("Player tried to rebirth with invalid race ({0}).", race); } // Check hair if (hairItemData == null || (hairItemData.Type != ItemType.Hair && hairItemData.Type != ItemType.Face)) { throw new SevereViolation("Player tried to rebirth with invalid hair ({0}).", hairItemId); } // Check face if (faceItemData == null || (faceItemData.Type != ItemType.Face && faceItemData.Type != ItemType.Hair)) { throw new SevereViolation("Player tried to rebirth with invalid face ({0}).", faceItemId); } // Check location if (location < RebirthLocation.Last || location > RebirthLocation.Iria) { throw new SevereViolation("Player tried to rebirth with invalid location ({0}).", location); } // Reset age if (resetAge) { creature.Age = age; creature.Height = Math.Min(1.0f, 1.0f / 7.0f * (age - 10.0f)); // 0 ~ 1.0 } // Reset level and stats if (resetLevel) { creature.Level = 1; creature.Exp = 0; var ageStats = AuraData.StatsBaseDb.Find(creature.RaceId, creature.Age); creature.LifeMaxBase = ageStats.Life; creature.ManaMaxBase = ageStats.Mana; creature.StaminaMaxBase = ageStats.Stamina; creature.StrBase = ageStats.Str; creature.IntBase = ageStats.Int; creature.DexBase = ageStats.Dex; creature.WillBase = ageStats.Will; creature.LuckBase = ageStats.Luck; creature.FullHeal(); } // Reset body creature.EyeType = eyeType; creature.EyeColor = eyeColor; creature.MouthType = mouthType; creature.SkinColor = skinColor; creature.Weight = 1; creature.Upper = 1; creature.Lower = 1; // Update face face.Info.Id = faceItemId; face.Info.Color1 = skinColor; // Update hair hair.Info.Id = hairItemId; hair.Info.Color1 = hairColor + 0x10000000u; // Reset LastX times var player = (PlayerCreature)creature; player.LastAging = DateTime.Now; player.LastRebirth = DateTime.Now; player.RebirthCount++; // Location switch (location) { // Tir beginner area case RebirthLocation.Tir: creature.SetLocation(125, 21489, 76421); break; // Iria beginner area (Rano) // (TODO: Disable pre-G4?) case RebirthLocation.Iria: creature.SetLocation(3001, 164533, 161862); break; } // Just rebirthed switch (usage?) creature.Activate(CreatureStates.JustRebirthed); // Success Send.RequestRebirthR(creature, true); }
public void M2C_ROOM(Packet packet) { ConstructRoom(packet.s_datas [0]); }
public void UnkCombat(ChannelClient client, Packet packet) { var creature = client.GetCreatureSafe(packet.Id); Send.UnkCombatR(creature); }