PRODUCTION-201610052203-260805057 - Trading

May 1, 2015
470
154
Alright, everything seems to be sorted now but the trading doesn't work?
I've tried everything I could think of.
Once and item is added and both users accept the trade just sits there and does nothing.
Thanks
 

JayC

Well-Known Member
Aug 8, 2013
5,505
1,401
Code:
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using Plus.HabboHotel.Rooms.Trading;
using Plus.HabboHotel.Items;

namespace Plus.Communication.Packets.Outgoing.Inventory.Trading
{
class TradingUpdateComposer : ServerPacket
{
public TradingUpdateComposer(Trade Trade) : base(ServerPacketHeader.TradingUpdateMessageComposer)
{

if (Trade.Users.Count() < 2)
return;

var User1 = Trade.Users.First();
var User2 = Trade.Users.Last();

base.WriteInteger(User1.GetClient().GetHabbo().Id);
SerializeUserItems(User1);

base.WriteInteger(0);
base.WriteInteger(0);
base.WriteInteger(1);

SerializeUserItems(User2);

base.WriteInteger(0);
base.WriteInteger(0);

/*base.WriteInteger(User.GetClient().GetHabbo().Id);
base.WriteInteger(User.OfferedItems.Count);

foreach (Item Item in User.OfferedItems.ToList())
{
base.WriteInteger(Item.Id);
base.WriteString(Item.GetBaseItem().Type.ToString().ToLower());
base.WriteInteger(Item.Id);
base.WriteInteger(Item.Data.SpriteId);
base.WriteInteger(0);//Not sure.
if (Item.LimitedNo > 0)
{
base.WriteBoolean(false);//Stackable
base.WriteInteger(256);
base.WriteString("");
base.WriteInteger(Item.LimitedNo);
base.WriteInteger(Item.LimitedTot);
}
else
{
base.WriteBoolean(true);//Stackable
base.WriteInteger(0);
base.WriteString("");
}

base.WriteInteger(0);
base.WriteInteger(0);
base.WriteInteger(0);

if (Item.GetBaseItem().Type == 's')
base.WriteInteger(0);

base.WriteInteger(0);
base.WriteInteger(0);
base.WriteInteger(-1);*/
}
private void SerializeUserItems(TradeUser User)
{
base.WriteInteger(User.OfferedItems.Count);//While
foreach (Item Item in User.OfferedItems.ToList())
{
base.WriteInteger(Item.Id);
base.WriteString(Item.Data.Type.ToString().ToUpper());
base.WriteInteger(Item.Id);
base.WriteInteger(Item.Data.SpriteId);
base.WriteInteger(1);
base.WriteBoolean(true);

//Func called _SafeStr_15990
base.WriteInteger(0);
base.WriteString("");

//end Func called
base.WriteInteger(0);
base.WriteInteger(0);
base.WriteInteger(0);
if (Item.Data.Type.ToString().ToUpper() == "S")
base.WriteInteger(0);
}
//End of while
}
}
}
 

Sledmore

Chaturbate Livestreamer
Staff member
FindRetros Moderator
Jul 24, 2010
5,199
3,934
I'm curious why you have another method in there when it isn't needed? The disconnections are due to invalid packet structure.

The issue here is one of the packets are wrong - the accept & confirm have the same headers.

TradingAcceptMessageComposer
TradingConfirmedMessageComposer

Should be the same packet ID value. So one of those is wrong, simply test both to see which is correct.

As for your TradingUpdateComposer that is very wrong, you should never break/return mid structure.

PHP:
if (Trade.Users.Count() < 2)
return;

Needs removing for a start.

PHP:
   class TradingUpdateComposer : ServerPacket
    {
        public TradingUpdateComposer(Trade Trade)
            : base(ServerPacketHeader.TradingUpdateMessageComposer)
        {
            foreach (TradeUser User in Trade.Users.ToList())
            {
                base.WriteInteger(User.GetClient().GetHabbo().Id);
                base.WriteInteger(User.OfferedItems.Count);

                foreach (Item Item in User.OfferedItems.ToList())
                {
                    base.WriteInteger(Item.Id);
                    base.WriteString(Item.GetBaseItem().Type.ToString().ToLower());
                    base.WriteInteger(Item.Id);
                    base.WriteInteger(Item.Data.SpriteId);
                    base.WriteInteger(0);//Not sure.

                    base.WriteBoolean(true);//Stackable
                    base.WriteInteger(0);
                    base.WriteString("");

                    base.WriteInteger(0);
                    base.WriteInteger(0);
                    base.WriteInteger(0);

                    if (Item.GetBaseItem().Type == 's')
                        base.WriteInteger(0);
                }

                base.WriteInteger(User.OfferedItems.Count);//Item Count
                base.WriteInteger(0);//Value of the items.
            }
        }
    }

Is what it should be.
 
May 1, 2015
470
154
The trade shows the amount of
Items, but once I accept on both trades it still just sits there.
The packet Id for both of those is 2457, are those correct? I have no idea.
 

JayC

Well-Known Member
Aug 8, 2013
5,505
1,401
I'm curious why you have another method in there when it isn't needed? The disconnections are due to invalid packet structure.

The issue here is one of the packets are wrong - the accept & confirm have the same headers.

TradingAcceptMessageComposer
TradingConfirmedMessageComposer

Should be the same packet ID value. So one of those is wrong, simply test both to see which is correct.

As for your TradingUpdateComposer that is very wrong, you should never break/return mid structure.

PHP:
if (Trade.Users.Count() < 2)
return;

Needs removing for a start.

PHP:
   class TradingUpdateComposer : ServerPacket
    {
        public TradingUpdateComposer(Trade Trade)
            : base(ServerPacketHeader.TradingUpdateMessageComposer)
        {
            foreach (TradeUser User in Trade.Users.ToList())
            {
                base.WriteInteger(User.GetClient().GetHabbo().Id);
                base.WriteInteger(User.OfferedItems.Count);

                foreach (Item Item in User.OfferedItems.ToList())
                {
                    base.WriteInteger(Item.Id);
                    base.WriteString(Item.GetBaseItem().Type.ToString().ToLower());
                    base.WriteInteger(Item.Id);
                    base.WriteInteger(Item.Data.SpriteId);
                    base.WriteInteger(0);//Not sure.

                    base.WriteBoolean(true);//Stackable
                    base.WriteInteger(0);
                    base.WriteString("");

                    base.WriteInteger(0);
                    base.WriteInteger(0);
                    base.WriteInteger(0);

                    if (Item.GetBaseItem().Type == 's')
                        base.WriteInteger(0);
                }

                base.WriteInteger(User.OfferedItems.Count);//Item Count
                base.WriteInteger(0);//Value of the items.
            }
        }
    }

Is what it should be.
I got this class from a release, and I didn't even read that was there lmao I am removing that now- It was on the newest production release.
 

Users who are viewing this thread

Top