Converts secure trade packets (#329)

This commit is contained in:
Kamron Batman 2020-11-29 22:20:10 -08:00 committed by GitHub
parent 77f665502b
commit 8c4c30da7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 184 additions and 184 deletions

View file

@ -0,0 +1,117 @@
/*************************************************************************
* ModernUO *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: OutgoingSecureTradePackets.cs *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
using System.Buffers;
using Server.Items;
namespace Server.Network
{
public enum TradeFlag : byte
{
Display,
Close,
Update,
UpdateGold,
UpdateLedger
}
public static class OutgoingSecureTradePackets
{
public static void SendDisplaySecureTrade(
this NetState ns, Mobile them, Container first, Container second, string name
)
{
if (ns == null || !ns.GetSendBuffer(out var buffer))
{
return;
}
var writer = new CircularBufferWriter(buffer);
writer.Write((byte)0x6F); // Packet ID
writer.Write((ushort)47); // Length
writer.Write((byte)TradeFlag.Display);
writer.Write(them.Serial);
writer.Write(first.Serial);
writer.Write(second.Serial);
writer.Write(true);
writer.WriteAscii(name ?? "", 30);
ns.Send(ref buffer, writer.Position);
}
public static void SendCloseSecureTrade(this NetState ns, Container cont)
{
if (ns == null || !ns.GetSendBuffer(out var buffer))
{
return;
}
var writer = new CircularBufferWriter(buffer);
writer.Write((byte)0x6F); // Packet ID
writer.Write((ushort)8); // Length
writer.Write((byte)TradeFlag.Close);
writer.Write(cont.Serial);
ns.Send(ref buffer, writer.Position);
}
public static void SendUpdateSecureTrade(this NetState ns, Container cont, bool first, bool second) =>
ns.SendUpdateSecureTrade(cont, TradeFlag.Update, first ? 1 : 0, second ? 1 : 0);
public static void SendUpdateSecureTrade(this NetState ns, Container cont, TradeFlag flag, int first, int second)
{
if (ns == null || !ns.GetSendBuffer(out var buffer))
{
return;
}
var writer = new CircularBufferWriter(buffer);
writer.Write((byte)0x6F); // Packet ID
writer.Write((ushort)16); // Length
writer.Write((byte)flag);
writer.Write(cont.Serial);
writer.Write(first);
writer.Write(second);
ns.Send(ref buffer, writer.Position);
}
public static void SendSecureTradeEquip(this NetState ns, Item item, Mobile m)
{
if (ns == null || !ns.GetSendBuffer(out var buffer))
{
return;
}
var writer = new CircularBufferWriter(buffer);
writer.Write((byte)0x25); // Packet ID
writer.Write(item.Serial);
writer.Write((short)item.ItemID);
writer.Write((byte)0);
writer.Write((short)item.Amount);
writer.Write((short)item.X);
writer.Write((short)item.Y);
if (ns.ContainerGridLines)
{
writer.Write((byte)0);
}
writer.Write(m.Serial);
writer.Write((short)item.Hue);
ns.Send(ref buffer, writer.Position);
}
}
}

View file

@ -1,109 +0,0 @@
/*************************************************************************
* ModernUO *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: SecureTradePackets.cs *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
using Server.Items;
namespace Server.Network
{
public sealed class DisplaySecureTrade : Packet
{
public DisplaySecureTrade(Mobile them, Container first, Container second, string name)
: base(0x6F)
{
name ??= "";
EnsureCapacity(18 + name.Length);
Stream.Write((byte)0); // Display
Stream.Write(them.Serial);
Stream.Write(first.Serial);
Stream.Write(second.Serial);
Stream.Write(true);
Stream.WriteAsciiFixed(name, 30);
}
}
public sealed class CloseSecureTrade : Packet
{
public CloseSecureTrade(Container cont)
: base(0x6F)
{
EnsureCapacity(8);
Stream.Write((byte)1); // Close
Stream.Write(cont.Serial);
}
}
public enum TradeFlag : byte
{
Display = 0x0,
Close = 0x1,
Update = 0x2,
UpdateGold = 0x3,
UpdateLedger = 0x4
}
public sealed class UpdateSecureTrade : Packet
{
public UpdateSecureTrade(Container cont, bool first, bool second)
: this(cont, TradeFlag.Update, first ? 1 : 0, second ? 1 : 0)
{
}
public UpdateSecureTrade(Container cont, TradeFlag flag, int first, int second)
: base(0x6F)
{
EnsureCapacity(17);
Stream.Write((byte)flag);
Stream.Write(cont.Serial);
Stream.Write(first);
Stream.Write(second);
}
}
public sealed class SecureTradeEquip : Packet
{
public SecureTradeEquip(Item item, Mobile m) : base(0x25, 20)
{
Stream.Write(item.Serial);
Stream.Write((short)item.ItemID);
Stream.Write((byte)0);
Stream.Write((short)item.Amount);
Stream.Write((short)item.X);
Stream.Write((short)item.Y);
Stream.Write(m.Serial);
Stream.Write((short)item.Hue);
}
}
public sealed class SecureTradeEquip6017 : Packet
{
public SecureTradeEquip6017(Item item, Mobile m) : base(0x25, 21)
{
Stream.Write(item.Serial);
Stream.Write((short)item.ItemID);
Stream.Write((byte)0);
Stream.Write((short)item.Amount);
Stream.Write((short)item.X);
Stream.Write((short)item.Y);
Stream.Write((byte)0); // Grid Location?
Stream.Write(m.Serial);
Stream.Write((short)item.Hue);
}
}
}