Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Nostale
You last visited: Today at 09:44

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Fix] OpenNos Trade bug

Discussion on [Fix] OpenNos Trade bug within the Nostale forum part of the MMORPGs category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Oct 2018
Posts: 1
Received Thanks: 0
Talking [Fix] OpenNos Trade bug

Hey,
After long researching, i just can't fix the trade on OpenNos.
Im using the Ciapa Cracked SRC, but i just can't fix the trade.
I please u guys to help me, that would be super kind!

PS: Please don't write "LEARN TO CODE" - It's called learning by doing.. ._.
Aruko7 is offline  
Old 10/09/2018, 16:52   #2
 
erixor's Avatar
 
elite*gold: 0
Join Date: Jul 2013
Posts: 408
Received Thanks: 1,067
Coding is learning by doing
erixor is offline  
Old 10/09/2018, 18:41   #3
 
elite*gold: 0
Join Date: Oct 2018
Posts: 10
Received Thanks: 0
send you discord for you help !
SxManuxS is offline  
Old 10/09/2018, 18:54   #4
 
elite*gold: 0
Join Date: Sep 2018
Posts: 12
Received Thanks: 8
Quote:
Originally Posted by SxManuxS View Post
send you discord for you help !
the new dude which says all time send discord for you help lmao
Marshmello* is offline  
Old 10/10/2018, 01:11   #5
 
0Lucifer0's Avatar
 
elite*gold: 0
Join Date: May 2009
Posts: 1,005
Received Thanks: 1,018
Quote:
Originally Posted by Aruko7 View Post
Hey,
After long researching, i just can't fix the trade on OpenNos.
Im using the Ciapa Cracked SRC, but i just can't fix the trade.
I please u guys to help me, that would be super kind!

PS: Please don't write "LEARN TO CODE" - It's called learning by doing.. ._.
This is not doing... when you try to learn math do you ask what’s 2+2 ? No. Also this project is too difficult for you to start with. If you have 0 knowledge try on something really basics. Try to understand the logic behind development. Always start with simple things. If your goal is to fix stuff fast for your server. It won’t happen. It’s like asking please guy I want to pass a PhD tomorrow in quantum physics can you tell me how...
0Lucifer0 is offline  
Old 10/10/2018, 01:59   #6
 
MANUEL PERES's Avatar
 
elite*gold: 0
Join Date: May 2012
Posts: 297
Received Thanks: 74

Code:
  [Packet("exc_list")]
        public void ExchangeList(string packet)
        {
            string[] packetsplit = packet.Split(' ');
            if (!long.TryParse(packetsplit[2], out long gold))
            {
                return;
            }
            if (!long.TryParse(packetsplit[3], out long bankgold))
            {
                return;
            }
            byte[] type = new byte[10], qty = new byte[10];
            short[] slot = new short[10];
            var packetList = string.Empty;

            if (gold < 0 || gold > Session.Character.Gold || bankgold < 0 || bankgold > Session.Account.BankGold || Session.Character.ExchangeInfo == null || Session.Character.ExchangeInfo.ExchangeList.Any())
            {
                return;
            }

            var targetSession = ServerManager.Instance.GetSessionByCharacterId(Session.Character.ExchangeInfo.TargetCharacterId);
            if (Session.Character.HasShopOpened || targetSession != null && targetSession.Character.HasShopOpened)
            {
                closeExchange(Session, targetSession);
                return;
            }

            for (int j = 7, i = 0; j <= packetsplit.Length && i < 10; j += 3, i++)
            {
                byte.TryParse(packetsplit[j - 3], out type[i]);
                short.TryParse(packetsplit[j - 2], out slot[i]);
                byte.TryParse(packetsplit[j - 1], out qty[i]);
                if ((InventoryType)type[i] == InventoryType.Bazaar)
                {
                    closeExchange(Session, targetSession);
                    return;
                }

                var item = Session.Character.Inventory.LoadBySlotAndType(slot[i], (InventoryType)type[i]);
                if (item == null)
                {
                    return;
                }

                if (qty[i] <= 0 || item.Amount < qty[i])
                {
                    return;
                }

                var it = item.DeepCopy();
                if (it.Item.IsTradable && !it.IsBound)
                {
                    it.Amount = qty[i];
                    Session.Character.ExchangeInfo.ExchangeList.Add(it);
                    if (type[i] != 0)
                    {
                        packetList += $"{i}.{type[i]}.{it.ItemVNum}.{qty[i]} ";
                    }
                    else
                    {
                        packetList += $"{i}.{type[i]}.{it.ItemVNum}.{it.Rare}.{it.Upgrade} ";
                    }
                }
                else if (it.IsBound)
                {
                    Session.SendPacket("exc_close 0");
                    Session.CurrentMapInstance?.Broadcast(Session, "exc_close 0", ReceiverType.OnlySomeone,
                        string.Empty, Session.Character.ExchangeInfo.TargetCharacterId);

                    if (targetSession != null)
                    {
                        targetSession.Character.ExchangeInfo = null;
                    }
                    Session.Character.ExchangeInfo = null;
                    return;
                }
            }

            Session.Character.ExchangeInfo.Gold = gold;
            Session.Character.ExchangeInfo.BankGold = bankgold;
            Session.CurrentMapInstance?.Broadcast(Session, $"exc_list 1 {Session.Character.CharacterId} {gold} {bankgold} {packetList}", ReceiverType.OnlySomeone, string.Empty, Session.Character.ExchangeInfo.TargetCharacterId);
            Session.Character.ExchangeInfo.Validate = true;
        }

        /// <summary>
        /// req_exc packet
        /// </summary>
        /// <param name="exchangeRequestPacket"></param>
        public void ExchangeRequest(ExchangeRequestPacket exchangeRequestPacket)
        {
            if (exchangeRequestPacket.CharacterId != 0 && Session.Character.MapInstanceId != ServerManager.Instance.GetProperty<Guid>(exchangeRequestPacket.CharacterId, nameof(Character.MapInstanceId)))
            {
                ServerManager.Instance.SetProperty(exchangeRequestPacket.CharacterId, nameof(Character.ExchangeInfo), null);
                Session.Character.ExchangeInfo = null;
            }
            else
            {
                switch (exchangeRequestPacket.RequestType)
                {
                    case RequestExchangeType.Requested:
                        if (!Session.HasCurrentMapInstance)
                        {
                            return;
                        }

                        var targetSession = Session.CurrentMapInstance.GetSessionByCharacterId(exchangeRequestPacket.CharacterId);
                        if (targetSession == null)
                        {
                            return;
                        }

                        if (targetSession.Character.Group != null && targetSession.Character.Group?.GroupType != GroupType.Group)
                        {
                            Session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("EXCHANGE_NOT_ALLOWED_IN_RAID"), 0));
                            return;
                        }

                        if (Session.Character.Group != null && Session.Character.Group?.GroupType != GroupType.Group)
                        {
                            Session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("EXCHANGE_NOT_ALLOWED_WITH_RAID_MEMBER"), 0));
                            return;
                        }

                        if (Session.Character.IsBlockedByCharacter(exchangeRequestPacket.CharacterId))
                        {
                            Session.SendPacket(UserInterfaceHelper.GenerateInfo(Language.Instance.GetMessageFromKey("BLACKLIST_BLOCKED")));
                            return;
                        }

                        if (Session.Character.Speed == 0 || targetSession.Character.Speed == 0)
                        {
                            Session.Character.ExchangeBlocked = true;
                        }

                        if (targetSession.Character.LastSkillUse.AddSeconds(20) > DateTime.Now || targetSession.Character.LastDefence.AddSeconds(20) > DateTime.Now)
                        {
                            Session.SendPacket(UserInterfaceHelper.GenerateInfo(string.Format(Language.Instance.GetMessageFromKey("PLAYER_IN_BATTLE"), targetSession.Character.Name)));
                            return;
                        }

                        if (Session.Character.LastSkillUse.AddSeconds(20) > DateTime.Now || Session.Character.LastDefence.AddSeconds(20) > DateTime.Now)
                        {
                            Session.SendPacket(UserInterfaceHelper.GenerateInfo(Language.Instance.GetMessageFromKey("IN_BATTLE")));
                            return;
                        }

                        if (Session.Character.HasShopOpened || targetSession.Character.HasShopOpened)
                        {
                            Session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("HAS_SHOP_OPENED"), 10));
                            return;
                        }

                        if (targetSession.Character.ExchangeBlocked)
                        {
                            Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("TRADE_BLOCKED"), 11));
                        }
                        else
                        {
                            if (Session.Character.InExchangeOrTrade || targetSession.Character.InExchangeOrTrade)
                            {
                                Session.SendPacket(UserInterfaceHelper.GenerateModal(Language.Instance.GetMessageFromKey("ALREADY_EXCHANGE"), 0));
                            }
                            else
                            {
                                Session.SendPacket(UserInterfaceHelper.GenerateModal(string.Format(Language.Instance.GetMessageFromKey("YOU_ASK_FOR_EXCHANGE"), targetSession.Character.Name), 0));
                                Session.Character.TradeRequests.Add(targetSession.Character.CharacterId);
                                targetSession.SendPacket(UserInterfaceHelper.GenerateDialog($"#req_exc^2^{Session.Character.CharacterId} #req_exc^5^{Session.Character.CharacterId} {string.Format(Language.Instance.GetMessageFromKey("INCOMING_EXCHANGE"), Session.Character.Name)}"));
                            }
                        }

                        break;

                    case RequestExchangeType.Confirmed: // click Trade button in exchange window
                        if (Session.HasCurrentMapInstance && Session.HasSelectedCharacter
                            && Session.Character.ExchangeInfo != null && Session.Character.ExchangeInfo.TargetCharacterId != Session.Character.CharacterId)
                        {
                            if (!Session.HasCurrentMapInstance)
                            {
                                return;
                            }

                            targetSession = Session.CurrentMapInstance.GetSessionByCharacterId(Session.Character.ExchangeInfo.TargetCharacterId);

                            if (targetSession == null)
                            {
                                return;
                            }

                            if (Session.Character.Group != null && Session.Character.Group?.GroupType != GroupType.Group)
                            {
                                Session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("EXCHANGE_NOT_ALLOWED_IN_RAID"), 0));
                                return;
                            }

                            if (targetSession.Character.Group != null && targetSession.Character.Group?.GroupType != GroupType.Group)
                            {
                                Session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("EXCHANGE_NOT_ALLOWED_WITH_RAID_MEMBER"), 0));
                                return;
                            }

                            if (Session.IsDisposing || targetSession.IsDisposing)
                            {
                                closeExchange(Session, targetSession);
                                return;
                            }

                            lock (targetSession.Character.Inventory)
                            {
                                lock (Session.Character.Inventory)
                                {
                                    var targetExchange = targetSession.Character.ExchangeInfo;
                                    var inventory = targetSession.Character.Inventory;

                                    var gold = targetSession.Character.Gold;
                                    var bankgold = targetSession.Account.BankGold;
                                    var backpack = targetSession.Character.HaveBackpack() ? 1 : 0;
                                    var maxGold = ServerManager.Instance.MaxGold;
                                    var maxBankGold = ServerManager.Instance.MaxBankGold;

                                    if (targetExchange == null || Session.Character.ExchangeInfo == null)
                                    {
                                        return;
                                    }

                                    if (Session.Character.ExchangeInfo.Validate && targetExchange.Validate)
                                    {
                                        Session.Character.ExchangeInfo.Confirm = true;
                                        if (targetExchange.Confirm && Session.Character.ExchangeInfo.Confirm)
                                        {
                                            Session.SendPacket("exc_close 1");
                                            targetSession.SendPacket("exc_close 1");

                                            var [MENTION=1560910]Continue[/MENTION] = true;
                                            var goldmax = false;
                                            if (!Session.Character.Inventory.EnoughPlace(targetExchange.ExchangeList))
                                            {
                                                [MENTION=1560910]Continue[/MENTION] = false;
                                            }

                                             if (!inventory.EnoughPlace(Session.Character.ExchangeInfo.ExchangeList))
                                            {
                                                [MENTION=1560910]Continue[/MENTION] = false;
                                            }

                                            if (Session.Character.ExchangeInfo.Gold + gold > maxGold)
                                            {
                                                goldmax = false;
                                            }
                                            if (Session.Character.ExchangeInfo.BankGold + bankgold > maxBankGold)
                                                goldmax = false;
                                            if (Session.Character.ExchangeInfo.BankGold > Session.Account.BankGold)
                                            {
                                                return;
                                            }

                                            if (Session.Character.ExchangeInfo.Gold > Session.Character.Gold)
                                            {
                                                return;
                                            }



                                            if (targetExchange.BankGold + Session.Character.ExchangeInfo.BankGold > maxBankGold)
                                                goldmax = false;
                                            if (targetExchange.Gold + Session.Character.Gold > maxGold)
                                            {
                                                goldmax = false;
                                            }

                                            if ( [MENTION=1560910]Continue[/MENTION] || goldmax)
                                            {
                                                var message =  [MENTION=1560910]Continue[/MENTION] ? UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0)
                                                    : UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("MAX_GOLD"), 0);
                                                Session.SendPacket(message);
                                                targetSession.SendPacket(message);
                                                closeExchange(Session, targetSession);
                                            }
                                            else
                                            {
                                                if (Session.Character.ExchangeInfo.ExchangeList.Any(ei => !(ei.Item.IsTradable || ei.IsBound)))
                                                {
                                                    Session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("ITEM_NOT_TRADABLE"), 0));
                                                    closeExchange(Session, targetSession);
                                                }
                                                else // all items can be traded
                                                {
                                                    Session.Character.IsExchanging = targetSession.Character.IsExchanging = true;

                                                    // exchange all items from target to source
                                                    exchange(targetSession, Session);

                                                    // exchange all items from source to target
                                                    exchange(Session, targetSession);

                                                    Session.Character.IsExchanging = targetSession.Character.IsExchanging = false;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            Session.SendPacket(UserInterfaceHelper.GenerateInfo(string.Format(Language.Instance.GetMessageFromKey("IN_WAITING_FOR"), targetSession.Character.Name)));
                                        }
                                    }
                                }
                            }
                        }

                        break;

                    case RequestExchangeType.Cancelled: // cancel trade thru exchange window
                        if (Session.HasCurrentMapInstance && Session.Character.ExchangeInfo != null)
                        {
                            targetSession = Session.CurrentMapInstance.GetSessionByCharacterId(Session.Character.ExchangeInfo.TargetCharacterId);
                            closeExchange(Session, targetSession);
                        }

                        break;

                    case RequestExchangeType.List:
                        var otherInExchangeOrTrade = ServerManager.Instance.GetProperty<bool>(exchangeRequestPacket.CharacterId, nameof(Character.InExchangeOrTrade));
                        if (!Session.Character.InExchangeOrTrade || !otherInExchangeOrTrade)
                        {
                            var otherSession = ServerManager.Instance.GetSessionByCharacterId(exchangeRequestPacket.CharacterId);
                            if (exchangeRequestPacket.CharacterId == Session.Character.CharacterId || Session.Character.Speed == 0 || otherSession == null || otherSession.Character.TradeRequests.All(s => s != Session.Character.CharacterId))
                            {
                                return;
                            }

                            if (Session.Character.Group != null && Session.Character.Group?.GroupType != GroupType.Group)
                            {
                                Session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("EXCHANGE_NOT_ALLOWED_IN_RAID"), 0));
                                return;
                            }

                            if (otherSession.Character.Group != null && otherSession.Character.Group?.GroupType != GroupType.Group)
                            {
                                Session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("EXCHANGE_NOT_ALLOWED_WITH_RAID_MEMBER"), 0));
                                return;
                            }

                            Session.SendPacket($"exc_list 1 {exchangeRequestPacket.CharacterId} -1");
                            Session.SendPacket($"gbex {Session.Account.BankGold / 1000} {Session.Character.Gold} 0 0");
                            var exc = new ExchangeInfo
                            {
                                TargetCharacterId = exchangeRequestPacket.CharacterId,
                                Confirm = false
                            };
                            Session.Character.ExchangeInfo = exc;
                            ServerManager.Instance.SetProperty(exchangeRequestPacket.CharacterId, nameof(Character.ExchangeInfo), new ExchangeInfo { TargetCharacterId = Session.Character.CharacterId, Confirm = false });
                            Session.CurrentMapInstance?.Broadcast(Session, $"exc_list 1 {Session.Character.CharacterId} -1", ReceiverType.OnlySomeone, string.Empty, exchangeRequestPacket.CharacterId);
                            ClientSession test = ServerManager.Instance.GetSessionByCharacterId(exchangeRequestPacket.CharacterId);
                            test.SendPacket($"gbex {test.Account.BankGold / 1000} {test.Character.Gold} 0 0");
                        }
                        else
                        {
                            Session.CurrentMapInstance?.Broadcast(Session, UserInterfaceHelper.GenerateModal(Language.Instance.GetMessageFromKey("ALREADY_EXCHANGE"), 0), ReceiverType.OnlySomeone, string.Empty, exchangeRequestPacket.CharacterId);
                        }

                        break;

                    case RequestExchangeType.Declined:
                        ServerManager.Instance.GetProperty<string>(exchangeRequestPacket.CharacterId, nameof(Character.Name));
                        ServerManager.Instance.SetProperty(exchangeRequestPacket.CharacterId, nameof(Character.ExchangeInfo), null);
                        Session.Character.ExchangeInfo = null;
                        Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("YOU_REFUSED"), 10));
                        Session.CurrentMapInstance?.Broadcast(Session, Session.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("EXCHANGE_REFUSED"), Session.Character.Name), 10), ReceiverType.OnlySomeone, string.Empty, exchangeRequestPacket.CharacterId);
                        break;

                    default:
                        Logger.Log.Warn($"Exchange-Request-Type not implemented. RequestType: {exchangeRequestPacket.RequestType})");
                        break;
                }
            }
        }



Code:
using System.Collections.Generic;

namespace OpenNos.GameObject
{
    public class ExchangeInfo
    {
        #region Instantiation

        public ExchangeInfo()
        {
            Confirm = false;
            Gold = 0;
            BankGold = 0;
            TargetCharacterId = -1;
            ExchangeList = new List<ItemInstance>();
            Validate = false;
        }

        #endregion

        #region Properties

        public bool Confirm { get; set; }

        public List<ItemInstance> ExchangeList { get; set; }

        public long Gold { get; set; }

        public long BankGold { get; set; }

        public long TargetCharacterId { get; set; }

        public bool Validate { get; set; }

        #endregion
    }
}



Code:
 public void SetProperty(long charId, string property, object value)
        {
            var session = GetSessionByCharacterId(charId);
            if (session == null)
            {
                return;
            }

            var propertyinfo = session.Character.GetType().GetProperty(property);
            propertyinfo?.SetValue(session.Character, value, null);
        }

        public T GetProperty<T>(string charName, string property)
        {
            var session = Sessions.FirstOrDefault(s => s.Character != null && s.Character.Name.Equals(charName));
            if (session == null)
            {
                return default(T);
            }

            return (T)session.Character.GetType().GetProperties().Single(pi => pi.Name == property).GetValue(session.Character, null);
        }

        public T GetProperty<T>(long charId, string property)
        {
            var session = GetSessionByCharacterId(charId);
            if (session == null)
            {
                return default(T);
            }

            return (T)session.Character.GetType().GetProperties().Single(pi => pi.Name == property).GetValue(session.Character, null);
        }
MANUEL PERES is offline  
Reply

Tags
opennos, trade bug


Similar Threads Similar Threads
OpenNos "The project 'OpenNos.Login' failed to build."
06/19/2019 - Nostale - 11 Replies
Hello! When I put in update-database in Visual Studio I get the 'The project 'OpenNos.Login' failed to build.' error. I already did what was on the troubleshoot before I put it in. I've been at this for hours and I can't figure it out. Can someone help me please?
[OpenNos] ¿How to select the project OpenNos.DAL.EF?
05/04/2018 - Nostale - 4 Replies
Hello, I have a problem with my visual studio 2017, it turns out that to be able to give the update-database command I must have the project OpenNos.DAL.EF But the thing is that in my visual studio there is no option to select the project ... I need help!:D:D
[opennos]The project 'OpenNos.Login' failed to build.
08/03/2017 - Nostale - 9 Replies
Hello I have a problem with the package manager console to run the update- database command to opennos soon as I executes the command, he said: The project ' opennos.login ' failed to build What to do? I made the updates to Microsoft Visual Studio thank you ..
[04.09.13] GigaByte v2.6 [FIX, FIX, FIX, FIX AND FIX]
09/11/2013 - WarRock Hacks, Bots, Cheats & Exploits - 79 Replies
http://www.elitepvpers.com/forum/warrock-hacks-bot s-cheats-exploits/2843300-11-09-gigabyte-public-v2 -7-a.html



All times are GMT +1. The time now is 09:45.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.