Help/visit doesnt work properly

Posts 1–7 of 7 · Page 1 of 1
/visit doesnt work properly
Hello MPGH i have a problem on my server.

I wanna allow my players to use /visit to join eachother in the arena and in the realm
1 huge problem! They can also use /visit to go into vaults of other people this will cause bugs and people can steal items this way.

(players will also buy vault chests for other people and this causes bugged vault u cant enter anymore)

In my code it shows that its possible to make players not able to visit people's vault and guildhalls
But its simply not working not for Vault's and also not for Guildhall..

Can anyone help me out?

 
WorldCommands.cs
Code:
    class VisitCommand : ICommand
    {
        public string Command { get { return "visit"; } }
        public int RequiredRank { get { return 2; } }

        public bool TryJoin(Player player, GlobalPlayerData iPlayerData, World world, Player i)
        {
            if (!iPlayerData.Solo)
            {
                if (!iPlayerData.UsingGroup)
                {
                    player.Client.Reconnect(new ReconnectPacket()
                    {
                        Host = "",
                        Port = 2050,
                        GameId = world.Id,
                        Name = world.Name,
                        Key = Empty<byte>.Array,
                    });
                    return true;
                }
                else
                {
                    foreach (var o in iPlayerData.JGroup)
                    {
                        if (o.Value == player.Client.Account.Name.ToLower())
                        {
                            player.Client.Reconnect(new ReconnectPacket()
                            {
                                Host = "",
                                Port = 2050,
                                GameId = world.Id,
                                Name = world.Name,
                                Key = Empty<byte>.Array,
                            });
                            return true;
                        }
                    }
                    player.SendInfo("Not in " + i.Client.Account.Name + "'s group!");
                    return true;
                }
            }
            else
            {
                player.SendInfo("Player is going solo!");
                return true;
            }
        }

        public void Execute(Player player, string[] args)
        {
            string name = string.Join(" ", args.ToArray()).Trim();
            try
            {
                GlobalPlayerData PlayerData = PlayerDataList.GetData(player.Client.Account.Name);
                foreach (var w in RealmManager.Worlds)
                {
                    World world = w.Value;
                    if (w.Key != 0)
                    {
                        foreach (var i in world.Players)
                        {
                            if (i.Value.Client.Account.Name.ToLower() == name.ToLower())
                            {
                                GlobalPlayerData iPlayerData = PlayerDataList.GetData(i.Value.Client.Account.Name);
                                if (!(player.Client.Account.Rank > 3))
                                {
                                    if (world.Name != "Vault")
                                    {
                                        if (world.Name != "Guild Hall")
                                        {
                                            TryJoin(player, iPlayerData, world, i.Value); return;
                                        }
                                        else
                                        {
                                            if ((world as GuildHall).Guild == player.Guild)
                                            {
                                                TryJoin(player, iPlayerData, world, i.Value); return;
                                            }
                                            else
                                            {
                                                player.SendInfo("Player is in " + i.Value.Guild + "'s guild hall!");
                                                return;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (world.Name == "Vault")
                                        {
                                            player.SendInfo("Player is in Vault!");
                                            return;
                                        }
                                        else if (world.Name == "Guild Hall")
                                        {
                                            player.SendInfo("Player is in Guild Hall!");
                                            return;
                                        }
                                        else
                                        {
                                            if (!iPlayerData.UsingGroup)
                                            {
                                                player.Client.Reconnect(new ReconnectPacket()
                                                {
                                                    Host = "",
                                                    Port = 2050,
                                                    GameId = world.Id,
                                                    Name = i.Value.Name + "'s Vault",
                                                    Key = Empty<byte>.Array,
                                                });
                                                return;
                                            }
                                            else
                                            {
                                                foreach (var o in iPlayerData.JGroup)
                                                {
                                                    if (o.Value == player.Client.Account.Name.ToLower())
                                                    {
                                                        player.Client.Reconnect(new ReconnectPacket()
                                                        {
                                                            Host = "",
                                                            Port = 2050,
                                                            GameId = world.Id,
                                                            Name = i.Value.Name + "'s Vault",
                                                            Key = Empty<byte>.Array,
                                                        });
                                                        return;
                                                    }
                                                }
                                                player.SendInfo("Not in " + i.Value.Client.Account.Name + "'s group!");
                                                return;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    player.Client.Reconnect(new ReconnectPacket()
                                    {
                                        Host = "",
                                        Port = 2050,
                                        GameId = world.Id,
                                        Name = i.Value.Owner.Name,
                                        Key = Empty<byte>.Array,
                                    });
                                    return;
                                }
                            }
                        }
                    }
                }
                player.SendHelp("Use /visit <playername>");
            }
            catch
            {
                player.SendInfo("Unexpected error in command!");
            }
        }
    }


 
Vault.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System****;
using db;
using wServer.realm.entities;
using System.Collections.Concurrent;

namespace wServer.realm.worlds
{
    public class Vault : World
    {
        public Vault(bool isLimbo, ClientProcessor psr = null)
        {
            Id = VAULT_ID;
            Name = "Bank";
            Background = 2;
            if (!(IsLimbo = isLimbo))
            {
                base.FromWorldMap(typeof(RealmManager).Assembly.GetManifestResourceStream("wServer.realm.worlds.vault.wmap"));
                Init(psr);
            }
        }

        ConcurrentDictionary<Tuple<Container, VaultChest>, int> vaultChests = new ConcurrentDictionary<Tuple<Container, VaultChest>, int>();
        ClientProcessor psr;
        Account acc;
        void Init(ClientProcessor psr)
        {
            this.psr = psr;
            this.acc = psr.Account;
            List<IntPoint> vaultChestPosition = new List<IntPoint>();
            IntPoint spawn = new IntPoint(0, 0);

            int w = Map.Width;
            int h = Map.Height;
            for (int y = 0; y < h; y++)
                for (int x = 0; x < w; x++)
                {
                    var tile = Map[x, y];
                    if (tile.Region == TileRegion.Spawn)
                        spawn = new IntPoint(x, y);
                    else if (tile.Region == TileRegion.Vault)
                        vaultChestPosition.Add(new IntPoint(x, y));
                }
            vaultChestPosition.Sort((x, y) => Comparer<int>.Default.Compare(
                (x.X - spawn.X) * (x.X - spawn.X) + (x.Y - spawn.Y) * (x.Y - spawn.Y),
                (y.X - spawn.X) * (y.X - spawn.X) + (y.Y - spawn.Y) * (y.Y - spawn.Y)));

            var chests = psr.Account.Vault.Chests;
            for (int i = 0; i < chests.Count; i++)
            {
                Container con = new Container(0x0504, null, false);
                var inv = chests[i].Items.Select(_ => _ == -1 ? null : (XmlDatas.ItemDescs.ContainsKey((short)_) ? XmlDatas.ItemDescs[(short)_] : null)).ToArray();
                for (int j = 0; j < 8; j++)
                    con.Inventory[j] = inv[j];
                con.Move(vaultChestPosition[0].X + 0.5f, vaultChestPosition[0].Y + 0.5f);
                EnterWorld(con);
                vaultChestPosition.RemoveAt(0);

                vaultChests[new Tuple<Container, VaultChest>(con, chests[i])] = con.UpdateCount;
            }
            foreach (var i in vaultChestPosition)
            {
                SellableObject x = new SellableObject(0x0505);
                x.Move(i.X + 0.5f, i.Y + 0.5f);
                EnterWorld(x);
            }
        }

        public void AddChest(VaultChest chest, Entity original)
        {
            Container con = new Container(0x0504, null, false);
            var inv = chest.Items.Select(_ => _ == -1 ? null : (XmlDatas.ItemDescs.ContainsKey((short)_) ? XmlDatas.ItemDescs[(short)_] : null)).ToArray();
            for (int j = 0; j < 8; j++)
                con.Inventory[j] = inv[j];
            con.Move(original.X, original.Y);
            LeaveWorld(original);
            EnterWorld(con);

            vaultChests[new Tuple<Container, VaultChest>(con, chest)] = con.UpdateCount;
        }
        
        public override World GetInstance(ClientProcessor psr)
        {
            return RealmManager.AddWorld(new Vault(false, psr));
        }

        public override void Tick(RealmTime time)
        {
            base.Tick(time);

            foreach (var i in vaultChests)
            {
                if (i.Key.Item1.UpdateCount > i.Value)
                {
                    try
                    {
                        i.Key.Item2._Items = Utils.GetCommaSepString(i.Key.Item1.Inventory.Take(8).Select(_ => _ == null ? -1 : _.ObjectType).ToArray());
                        new Database().SaveChest(acc, i.Key.Item2);
                        vaultChests[i.Key] = i.Key.Item1.UpdateCount;
                    }
                    catch
                    {
                        //Do NOT make anything happen here..
                        //This catch continues on endlessly
                    }
                }
            }

        }
    }
}


What I want is that players can /visit each other to all zones except the vaults and guidhall.
I could really use some help on this.

Thanks alot
Quote Originally Posted by Mitcheel View Post
Hello MPGH i have a problem on my server.

I wanna allow my players to use /visit to join eachother in the arena and in the realm
1 huge problem! They can also use /visit to go into vaults of other people this will cause bugs and people can steal items this way.

(players will also buy vault chests for other people and this causes bugged vault u cant enter anymore)

In my code it shows that its possible to make players not able to visit people's vault and guildhalls
But its simply not working not for Vault's and also not for Guildhall..

Can anyone help me out?

 
WorldCommands.cs
Code:
    class VisitCommand : ICommand
    {
        public string Command { get { return "visit"; } }
        public int RequiredRank { get { return 2; } }

        public bool TryJoin(Player player, GlobalPlayerData iPlayerData, World world, Player i)
        {
            if (!iPlayerData.Solo)
            {
                if (!iPlayerData.UsingGroup)
                {
                    player.Client.Reconnect(new ReconnectPacket()
                    {
                        Host = "",
                        Port = 2050,
                        GameId = world.Id,
                        Name = world.Name,
                        Key = Empty<byte>.Array,
                    });
                    return true;
                }
                else
                {
                    foreach (var o in iPlayerData.JGroup)
                    {
                        if (o.Value == player.Client.Account.Name.ToLower())
                        {
                            player.Client.Reconnect(new ReconnectPacket()
                            {
                                Host = "",
                                Port = 2050,
                                GameId = world.Id,
                                Name = world.Name,
                                Key = Empty<byte>.Array,
                            });
                            return true;
                        }
                    }
                    player.SendInfo("Not in " + i.Client.Account.Name + "'s group!");
                    return true;
                }
            }
            else
            {
                player.SendInfo("Player is going solo!");
                return true;
            }
        }

        public void Execute(Player player, string[] args)
        {
            string name = string.Join(" ", args.ToArray()).Trim();
            try
            {
                GlobalPlayerData PlayerData = PlayerDataList.GetData(player.Client.Account.Name);
                foreach (var w in RealmManager.Worlds)
                {
                    World world = w.Value;
                    if (w.Key != 0)
                    {
                        foreach (var i in world.Players)
                        {
                            if (i.Value.Client.Account.Name.ToLower() == name.ToLower())
                            {
                                GlobalPlayerData iPlayerData = PlayerDataList.GetData(i.Value.Client.Account.Name);
                                if (!(player.Client.Account.Rank > 3))
                                {
                                    if (world.Name != "Vault")
                                    {
                                        if (world.Name != "Guild Hall")
                                        {
                                            TryJoin(player, iPlayerData, world, i.Value); return;
                                        }
                                        else
                                        {
                                            if ((world as GuildHall).Guild == player.Guild)
                                            {
                                                TryJoin(player, iPlayerData, world, i.Value); return;
                                            }
                                            else
                                            {
                                                player.SendInfo("Player is in " + i.Value.Guild + "'s guild hall!");
                                                return;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (world.Name == "Vault")
                                        {
                                            player.SendInfo("Player is in Vault!");
                                            return;
                                        }
                                        else if (world.Name == "Guild Hall")
                                        {
                                            player.SendInfo("Player is in Guild Hall!");
                                            return;
                                        }
                                        else
                                        {
                                            if (!iPlayerData.UsingGroup)
                                            {
                                                player.Client.Reconnect(new ReconnectPacket()
                                                {
                                                    Host = "",
                                                    Port = 2050,
                                                    GameId = world.Id,
                                                    Name = i.Value.Name + "'s Vault",
                                                    Key = Empty<byte>.Array,
                                                });
                                                return;
                                            }
                                            else
                                            {
                                                foreach (var o in iPlayerData.JGroup)
                                                {
                                                    if (o.Value == player.Client.Account.Name.ToLower())
                                                    {
                                                        player.Client.Reconnect(new ReconnectPacket()
                                                        {
                                                            Host = "",
                                                            Port = 2050,
                                                            GameId = world.Id,
                                                            Name = i.Value.Name + "'s Vault",
                                                            Key = Empty<byte>.Array,
                                                        });
                                                        return;
                                                    }
                                                }
                                                player.SendInfo("Not in " + i.Value.Client.Account.Name + "'s group!");
                                                return;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    player.Client.Reconnect(new ReconnectPacket()
                                    {
                                        Host = "",
                                        Port = 2050,
                                        GameId = world.Id,
                                        Name = i.Value.Owner.Name,
                                        Key = Empty<byte>.Array,
                                    });
                                    return;
                                }
                            }
                        }
                    }
                }
                player.SendHelp("Use /visit <playername>");
            }
            catch
            {
                player.SendInfo("Unexpected error in command!");
            }
        }
    }


 
Vault.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System****;
using db;
using wServer.realm.entities;
using System.Collections.Concurrent;

namespace wServer.realm.worlds
{
    public class Vault : World
    {
        public Vault(bool isLimbo, ClientProcessor psr = null)
        {
            Id = VAULT_ID;
            Name = "Bank";
            Background = 2;
            if (!(IsLimbo = isLimbo))
            {
                base.FromWorldMap(typeof(RealmManager).Assembly.GetManifestResourceStream("wServer.realm.worlds.vault.wmap"));
                Init(psr);
            }
        }

        ConcurrentDictionary<Tuple<Container, VaultChest>, int> vaultChests = new ConcurrentDictionary<Tuple<Container, VaultChest>, int>();
        ClientProcessor psr;
        Account acc;
        void Init(ClientProcessor psr)
        {
            this.psr = psr;
            this.acc = psr.Account;
            List<IntPoint> vaultChestPosition = new List<IntPoint>();
            IntPoint spawn = new IntPoint(0, 0);

            int w = Map.Width;
            int h = Map.Height;
            for (int y = 0; y < h; y++)
                for (int x = 0; x < w; x++)
                {
                    var tile = Map[x, y];
                    if (tile.Region == TileRegion.Spawn)
                        spawn = new IntPoint(x, y);
                    else if (tile.Region == TileRegion.Vault)
                        vaultChestPosition.Add(new IntPoint(x, y));
                }
            vaultChestPosition.Sort((x, y) => Comparer<int>.Default.Compare(
                (x.X - spawn.X) * (x.X - spawn.X) + (x.Y - spawn.Y) * (x.Y - spawn.Y),
                (y.X - spawn.X) * (y.X - spawn.X) + (y.Y - spawn.Y) * (y.Y - spawn.Y)));

            var chests = psr.Account.Vault.Chests;
            for (int i = 0; i < chests.Count; i++)
            {
                Container con = new Container(0x0504, null, false);
                var inv = chests[i].Items.Select(_ => _ == -1 ? null : (XmlDatas.ItemDescs.ContainsKey((short)_) ? XmlDatas.ItemDescs[(short)_] : null)).ToArray();
                for (int j = 0; j < 8; j++)
                    con.Inventory[j] = inv[j];
                con.Move(vaultChestPosition[0].X + 0.5f, vaultChestPosition[0].Y + 0.5f);
                EnterWorld(con);
                vaultChestPosition.RemoveAt(0);

                vaultChests[new Tuple<Container, VaultChest>(con, chests[i])] = con.UpdateCount;
            }
            foreach (var i in vaultChestPosition)
            {
                SellableObject x = new SellableObject(0x0505);
                x.Move(i.X + 0.5f, i.Y + 0.5f);
                EnterWorld(x);
            }
        }

        public void AddChest(VaultChest chest, Entity original)
        {
            Container con = new Container(0x0504, null, false);
            var inv = chest.Items.Select(_ => _ == -1 ? null : (XmlDatas.ItemDescs.ContainsKey((short)_) ? XmlDatas.ItemDescs[(short)_] : null)).ToArray();
            for (int j = 0; j < 8; j++)
                con.Inventory[j] = inv[j];
            con.Move(original.X, original.Y);
            LeaveWorld(original);
            EnterWorld(con);

            vaultChests[new Tuple<Container, VaultChest>(con, chest)] = con.UpdateCount;
        }
        
        public override World GetInstance(ClientProcessor psr)
        {
            return RealmManager.AddWorld(new Vault(false, psr));
        }

        public override void Tick(RealmTime time)
        {
            base.Tick(time);

            foreach (var i in vaultChests)
            {
                if (i.Key.Item1.UpdateCount > i.Value)
                {
                    try
                    {
                        i.Key.Item2._Items = Utils.GetCommaSepString(i.Key.Item1.Inventory.Take(8).Select(_ => _ == null ? -1 : _.ObjectType).ToArray());
                        new Database().SaveChest(acc, i.Key.Item2);
                        vaultChests[i.Key] = i.Key.Item1.UpdateCount;
                    }
                    catch
                    {
                        //Do NOT make anything happen here..
                        //This catch continues on endlessly
                    }
                }
            }

        }
    }
}


What I want is that players can /visit each other to all zones except the vaults and guidhall.
I could really use some help on this.

Thanks alot
As I was the one to add in the fail-safes to the command I might as well help you out.

The problem you're having is you're testing the command on an Admin account most likely. If you look in the code is says
Code:
if (!(player.Client.Account.Rank > 3))
{
    if (world.Name != "Vault")
    {
        if (world.Name != "Guild Hall")
        {
            TryJoin(player, iPlayerData, world, i.Value); return;
        }
        else
        {
            if ((world as GuildHall).Guild == player.Guild)
            {
                TryJoin(player, iPlayerData, world, i.Value); return;
            }
            else
            {
                player.SendInfo("Player is in " + i.Value.Guild + "'s guild hall!");
                return;
            }
        }
    }
    else
    {
        if (world.Name == "Vault")
        {
            player.SendInfo("Player is in Vault!");
            return;
        }
        else if (world.Name == "Guild Hall")
        {
            player.SendInfo("Player is in Guild Hall!");
            return;
        }
        else
        {
            if (!iPlayerData.UsingGroup)
            {
                player.Client.Reconnect(new ReconnectPacket()
                {
                    Host = "",
                    Port = 2050,
                    GameId = world.Id,
                    Name = i.Value.Name + "'s Vault",
                    Key = Empty<byte>.Array,
                });
                return;
            }
            else
            {
                foreach (var o in iPlayerData.JGroup)
                {
                    if (o.Value == player.Client.Account.Name.ToLower())
                    {
                        player.Client.Reconnect(new ReconnectPacket()
                        {
                            Host = "",
                            Port = 2050,
                            GameId = world.Id,
                            Name = i.Value.Name + "'s Vault",
                            Key = Empty<byte>.Array,
                        });
                        return;
                    }
                }
                player.SendInfo("Not in " + i.Value.Client.Account.Name + "'s group!");
                return;
            }
        }
    }
}
else
{
    player.Client.Reconnect(new ReconnectPacket()
    {
        Host = "",
        Port = 2050,
        GameId = world.Id,
        Name = i.Value.Owner.Name,
        Key = Empty<byte>.Array,
    });
    return;
}
That checks your rank and if you're OVER rank 3 (meaning 4 or above) you will connect no matter what. It's a Staff Bypass that I added in to make their job easier.

Simply try it on an un-ranked account and you should be fine.
Yeah what Kithio said. Just change

Code:
if (!(player.Client.Account.Rank > 3))
to something else. This way no one can visit someone elses guild or vault
I already tried that but its not working for me daaamn....

Maybe its because i changed the name Vault to Bank?


ediiittt::

just found out it does work in for the guildhall it has something to do with the bank. I think im able to fix this thanks guys (:

Quote Originally Posted by Mitcheel View Post
I already tried that but its not working for me daaamn....

Maybe its because i changed the name Vault to Bank?
Well then why not just disable /visit from everyone
Its fully working, no need to disable it i had it disabled for a long time. My players wanna do duo arena haha!
Quote Originally Posted by Mitcheel View Post
Its fully working, no need to disable it i had it disabled for a long time. My players wanna do duo arena haha!
If you have any questions about the source you can add me on skype and I can help you out some. I don't have much to do anyway now when school's over.

* Just hit that skype icon under my profile thing on the left and you can add me *
Posts 1–7 of 7 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us