Exemple #1
0
 private void OnGoto(GotoPacket go)
 {
     _net.SendPacket(new GotoAckPacket
     {
         Time = GetTime()
     });
 }
Exemple #2
0
        public void OnNewTick(Client client, Packet packet)
        {
            NewTickPacket ntp = (NewTickPacket)packet;

            if (_enabled && listOfClients[client].Slave)
            {
                // Distance to Master
                double Distance = Math.Sqrt(Math.Pow(master.PlayerData.Pos.X - client.PlayerData.Pos.X, 2) + Math.Pow(master.PlayerData.Pos.Y - client.PlayerData.Pos.Y, 2));
                // Will hold the angle
                float Angle = 0;
                // Get the total milliseconds since the last NewTick
                long timeElapsed = listOfClients[client].sw.ElapsedMilliseconds;
                // This will be used as a multiplier, ive capped it at 250
                timeElapsed = timeElapsed >= 200 ? 200 : timeElapsed;

                // The formula from the client is (MIN_MOVE_SPEED + this.speed_ / 75 * (MAX_MOVE_SPEED - MIN_MOVE_SPEED)) * this.moveMultiplier_
                // this.moveMultiplier_ = the tile movement speed (1 by default)
                // MIN_MOVE_SPEED = 0.004 * this.moveMultiplier_
                // MAX_MOVE_SPEED = 0.0096
                // I dont take into account tile movement speed i justed used the default value of 1
                // I also decreased the max movement speed to avoid disconnect
                float moveMultiplier = GameData.Tiles.ByID(listOfClients[client].CurrentTileType()).Speed;
                float min_speed      = 0.004f * moveMultiplier;
                float speed          = ((min_speed + (client.PlayerData.Speed / 75.0f * (0.007f - min_speed))) * moveMultiplier) * (timeElapsed);
                Console.WriteLine("SW: {0}ms, Dist: {1}, Spd: {2}, TPT: {3}", listOfClients[client].sw.ElapsedMilliseconds, Distance, speed, client.PlayerData.TilesPerTick());

                //speed = client.PlayerData.TilesPerTick();


                Location NewLoc = new Location();
                // Check if the distance to the master is greater then the distance the slave can move
                if (Distance > speed)
                {
                    // Calculate the angle
                    Angle = (float)Math.Atan2(master.PlayerData.Pos.Y - client.PlayerData.Pos.Y, master.PlayerData.Pos.X - client.PlayerData.Pos.X);
                    // Calculate the new location
                    NewLoc.X = client.PlayerData.Pos.X + (float)Math.Cos(Angle) * speed;
                    NewLoc.Y = client.PlayerData.Pos.Y + (float)Math.Sin(Angle) * speed;
                }
                else
                {
                    // Set the move location as the master location
                    NewLoc.X = master.PlayerData.Pos.X;
                    NewLoc.Y = master.PlayerData.Pos.Y;
                }
                // Send the GOTO packet
                GotoPacket go = (GotoPacket)Packet.Create(PacketType.GOTO);
                go.ObjectId = client.ObjectId;
                go.Location = new Location();
                go.Location = NewLoc;
                client.SendToClient(go);
            }

            if (listOfClients[client].Slave)
            {
                // This is used to get the number of milliseconds between each NewTick
                listOfClients[client].UpdateTick();
            }
        }
Exemple #3
0
        public static void SendGoto(this Client client, Location location)
        {
            gotoblocks.Add(client);
            GotoPacket gpacket = Packet.Create <GotoPacket>(PacketType.GOTO);

            gpacket.Location = location;
            gpacket.ObjectId = client.ObjectId;
            client.SendToClient(gpacket);
        }
        public static void JumpUsingGOTO(this Client client, Location target, int msSleep)
        {
            GotoPacket p = Packet.Create <GotoPacket>(PacketType.GOTO);

            p.Location = target;
            p.ObjectId = client.ObjectId;

            client.SendToClient(p);
            Thread.Sleep(msSleep);
        }
Exemple #5
0
        public void OnGoto(Client client, Packet packet)
        {
            GotoPacket gotop = (GotoPacket)packet;

            if (_enabled && listOfClients[client].Slave)
            {
                // Send our own GOTOACK when we get a GOTO from the server
                GotoAckPacket gotoack = (GotoAckPacket)Packet.Create(PacketType.GOTOACK);
                gotoack.Time = client.Time;
                client.SendToServer(gotoack);
            }
        }
        protected override bool Process(Player player, RealmTime time, string[] args)
        {
            if (player.Owner is Vault || player.Owner is PetYard)
            {
                player.SendInfo("You cant summon in this world.");
                return(false);
            }
            foreach (KeyValuePair <string, Client> i in player.Manager.Clients)
            {
                if (i.Value.Player.Name.EqualsIgnoreCase(args[0]))
                {
                    Packet pkt;
                    if (i.Value.Player.Owner == player.Owner)
                    {
                        i.Value.Player.Move(player.X, player.Y);
                        pkt = new GotoPacket
                        {
                            ObjectId = i.Value.Player.Id,
                            Position = new Position(player.X, player.Y)
                        };
                        i.Value.Player.UpdateCount++;
                        player.SendInfo("Player summoned!");
                    }
                    else
                    {
                        pkt = new ReconnectPacket
                        {
                            GameId      = player.Owner.Id,
                            Host        = "",
                            IsFromArena = false,
                            Key         = player.Owner.PortalKey,
                            KeyTime     = -1,
                            Name        = player.Owner.Name,
                            Port        = -1
                        };
                        player.SendInfo("Player will connect to you now!");
                    }

                    i.Value.SendPacket(pkt);

                    return(true);
                }
            }
            player.SendError(string.Format("Player '{0}' could not be found!", args));
            return(false);
        }
Exemple #7
0
 protected override bool Process(Player player, RealmTime time, string[] args)
 {
     foreach (KeyValuePair <string, Client> i in player.Manager.Clients)
     {
         if (i.Value.Player.Owner is PetYard || i.Value.Player.Owner is Vault)
         {
             player.SendInfo("You cant visit players in that world.");
             return(false);
         }
     }
     foreach (KeyValuePair <string, Client> i in player.Manager.Clients)
     {
         if (i.Value.Player.Name.EqualsIgnoreCase(args[0]))
         {
             Packet pkt;
             if (i.Value.Player.Owner == player.Owner)
             {
                 player.Move(i.Value.Player.X, i.Value.Player.Y);
                 pkt = new GotoPacket
                 {
                     ObjectId = player.Id,
                     Position = new Position(i.Value.Player.X, i.Value.Player.Y)
                 };
                 i.Value.Player.UpdateCount++;
                 player.SendInfo("Player already in world.");
             }
             else
             {
                 player.Client.Reconnect(new ReconnectPacket
                 {
                     GameId      = i.Value.Player.Owner.Id,
                     Host        = "",
                     IsFromArena = false,
                     Key         = Empty <byte> .Array,
                     KeyTime     = -1,
                     Name        = i.Value.Player.Owner.Name,
                     Port        = -1
                 });
                 player.SendInfo("You are visiting " + i.Value.Player.Owner.Id);
             }
             return(true);
         }
     }
     player.SendError(string.Format("Player '{0}' could not be found!", args));
     return(false);
 }
        protected override Tuple <bool, string> Process(Player player, RealmTime time, string[] args)
        {
            if (player.Owner is Vault || player.Owner is PetYard)
            {
                return(Tuple.Create(false, "You cannot summon players to this world"));
            }

            foreach (KeyValuePair <string, Client> i in player.Manager.Clients)
            {
                if (i.Value.Player.Name.EqualsIgnoreCase(args[0]))
                {
                    Packet pkt;
                    if (i.Value.Player.Owner == player.Owner)
                    {
                        i.Value.Player.Move(player.X, player.Y);
                        pkt = new GotoPacket
                        {
                            ObjectId = i.Value.Player.Id,
                            Position = new Position(player.X, player.Y)
                        };
                        i.Value.Player.UpdateCount++;
                    }
                    else
                    {
                        pkt = new ReconnectPacket
                        {
                            GameId      = player.Owner.Id,
                            Host        = "",
                            IsFromArena = false,
                            Key         = player.Owner.PortalKey,
                            KeyTime     = -1,
                            Name        = player.Owner.Name,
                            Port        = -1
                        };
                    }

                    i.Value.SendPacket(pkt);
                    return(Tuple.Create(true, "Player summoned!"));
                }
            }
            return(Tuple.Create(false, $"Player '{args[0]}' could not be found!"));
        }
Exemple #9
0
        public override bool Handle(Player player)
        {
            foreach (KeyValuePair <string, Client> i in player.Manager.Clients)
            {
                if (i.Value.Player.Name.EqualsIgnoreCase(Arguments[0]))
                {
                    Packet pkt;
                    if (i.Value.Player.Owner == player.Owner)
                    {
                        i.Value.Player.Move(player.X, player.Y);
                        pkt = new GotoPacket
                        {
                            ObjectId = i.Value.Player.Id,
                            Position = new Position(player.X, player.Y)
                        };
                        i.Value.Player.UpdateCount++;
                        player.SendInfo("Player summoned!");
                    }
                    else
                    {
                        pkt = new ReconnectPacket
                        {
                            GameId      = player.Owner.Id,
                            Host        = "",
                            IsFromArena = false,
                            Key         = player.Owner.PortalKey,
                            KeyTime     = -1,
                            Name        = player.Owner.Name,
                            Port        = -1
                        };
                        player.SendInfo("Player will connect to you now!");
                    }

                    i.Value.SendPacket(pkt);

                    return(true);
                }
            }
            player.SendError(string.Format("Player '{0}' could not be found!", Arguments));
            return(false);
        }
        protected override Tuple <bool, string> Process(Player player, RealmTime time, string[] args)
        {
            foreach (KeyValuePair <string, Client> i in player.Manager.Clients)
            {
                if (i.Value.Player.Owner is PetYard || i.Value.Player.Owner is Vault) //Use this if you don't want people visiting those worlds
                {
                    return(Tuple.Create(false, $"You cant visit players in world: {i.Value.Player.Owner}"));
                }

                if (i.Value.Player.Name.EqualsIgnoreCase(args[0]))
                {
                    Packet pkt;
                    if (i.Value.Player.Owner == player.Owner)
                    {
                        player.Move(i.Value.Player.X, i.Value.Player.Y);
                        pkt = new GotoPacket
                        {
                            ObjectId = player.Id,
                            Position = new Position(i.Value.Player.X, i.Value.Player.Y)
                        };
                        i.Value.Player.UpdateCount++;
                    }
                    else
                    {
                        player.Client.Reconnect(new ReconnectPacket
                        {
                            GameId      = i.Value.Player.Owner.Id,
                            Host        = "",
                            IsFromArena = false,
                            Key         = Empty <byte> .Array,
                            KeyTime     = -1,
                            Name        = i.Value.Player.Owner.Name,
                            Port        = -1
                        });
                    }
                    return(Tuple.Create(true, "You are visiting " + i.Value.Player.Owner.Id));
                }
            }
            return(Tuple.Create(false, $"Player '{args[0]}' could not be found!"));
        }
Exemple #11
0
        public override bool Handle(Player player)
        {
            foreach (KeyValuePair <string, Client> i in player.Manager.Clients)
            {
                if (i.Value.Player.Name.EqualsIgnoreCase(Arguments[0]))
                {
                    Packet pkt;
                    if (i.Value.Player.Owner == player.Owner)
                    {
                        player.Move(i.Value.Player.X, i.Value.Player.Y);
                        pkt = new GotoPacket
                        {
                            ObjectId = player.Id,
                            Position = new Position(i.Value.Player.X, i.Value.Player.Y)
                        };
                        i.Value.Player.UpdateCount++;
                        player.SendInfo("He is here already. git fast.");
                    }
                    else
                    {
                        player.Client.Reconnect(new ReconnectPacket()
                        {
                            GameId      = i.Value.Player.Owner.Id,
                            Host        = "",
                            IsFromArena = false,
                            Key         = Empty <byte> .Array,
                            KeyTime     = -1,
                            Name        = i.Value.Player.Owner.Name,
                            Port        = -1,
                        });
                        player.SendInfo("You are visiting " + i.Value.Player.Owner.Id + " now");
                    }

                    return(true);
                }
            }
            player.SendError(string.Format("Player '{0}' could not be found!", Arguments));
            return(false);
        }
Exemple #12
0
        private async void MoveToRealms(Client client, bool realmChosen = false)
        {
            if (client == null)
            {
                Log("No client passed to MoveToRealms.");
                return;
            }
            Location target = config.RealmLocation;

            if (client.PlayerData == null)
            {
                await Task.Delay(5);

                MoveToRealms(client);
                return;
            }

            if (target_ != null)
            {
                target = target_;
            }
            var healthPercentage = (float)client.PlayerData.Health / (float)client.PlayerData.MaxHealth;

            if (healthPercentage < 0.95f && currentMapName == "Nexus")
            {
                target = config.FountainLocation;
            }

            bestName = "";
            if ((client.PlayerData.Pos.Y <= config.RealmLocation.Y + 1f && client.PlayerData.Pos.Y != 0) || realmChosen)
            {
                if (portals.Count != 0)
                {
                    bool hasNoPreferredRealm = true;
                    if (!string.IsNullOrEmpty(preferredRealmName))
                    {
                        if (portals.Exists(ptl => string.Compare(ptl.Name, preferredRealmName, true) == 0))
                        {
                            hasNoPreferredRealm = false;
                            Portal preferred = portals.Single(ptl => string.Compare(ptl.Name, preferredRealmName, true) == 0);
                            target      = preferred.Location;
                            bestName    = preferred.Name;
                            realmChosen = true;
                        }
                        else
                        {
                            client.Notify(preferredRealmName + " not found. Choosing new realm");
                            Log("The realm \"" + preferredRealmName + "\" was not found. Choosing the best realm instead...");
                            preferredRealmName = null;
                        }
                    }

                    if (hasNoPreferredRealm)
                    {
                        int bestCount = 0;
                        if (portals.Where(ptl => ptl.PlayerCount == 85).Count() > 1)
                        {
                            foreach (Portal ptl in portals.Where(ptl => ptl.PlayerCount == 85))
                            {
                                int count = playerPositions.Values.Where(plr => plr.Position.DistanceSquaredTo(ptl.Location) <= 4).Count();
                                if (count > bestCount)
                                {
                                    bestCount   = count;
                                    bestName    = ptl.Name;
                                    target      = ptl.Location;
                                    realmChosen = true;
                                }
                            }
                        }
                        else
                        {
                            Portal ptl = portals.OrderByDescending(prtl => prtl.PlayerCount).First();
                            target      = ptl.Location;
                            bestName    = ptl.Name;
                            realmChosen = true;
                        }
                    }
                }
                else if (target_ != null)
                {
                    target = target_;
                }
                else
                {
                    target = config.RealmLocation;
                }
            }

            CalculateMovement(client, target, 0.5f);

            if (client.PlayerData.Pos.DistanceTo(target) < 1f && portals.Count != 0)
            {
                if (client.PlayerData.Pos.DistanceTo(target) <= client.PlayerData.TilesPerTick() && client.PlayerData.Pos.DistanceTo(target) > 0.01f)
                {
                    if (client.Connected)
                    {
                        ResetAllKeys();
                        GotoPacket gotoPacket = Packet.Create(PacketType.GOTO) as GotoPacket;
                        gotoPacket.Location = target;
                        gotoPacket.ObjectId = client.ObjectId;
                        blockNextAck        = true;
                        client.SendToClient(gotoPacket);
                    }
                }
                if (client.State.LastRealm?.Name.Contains(bestName) ?? false)
                {
                    Log("Last realm is still the best realm. Sending reconnect.");
                    if (client.ConnectTo(client.State.LastRealm))
                    {
                        gotoRealm = false;
                        return;
                    }
                }

                Log("Attempting connection.");
                gotoRealm = false;
                AttemptConnection(client, portals.OrderBy(ptl => ptl.Location.DistanceSquaredTo(client.PlayerData.Pos)).First().ObjectId);
            }
            await Task.Delay(5);

            if (gotoRealm)
            {
                MoveToRealms(client, realmChosen);
            }
            else
            {
                Log("Stopped moving to realm.");
            }
        }
Exemple #13
0
        private void proxy_Move(Client client, Packet real_packet)
        {
            MovePacket packet = (MovePacket)real_packet;

            if (Master == null)
            {
                Time[client] = packet.Time;

                return;
            }

            if (Master != client)
            {
                if (client.PlayerData.Pos.DistanceTo(Master.PlayerData.Pos) > 2)
                {
                    if (TeleportState[client] > 1)
                    {
                        TeleportState[client]--;
                    }
                    else if (TeleportState[client] == 0)
                    {
                        TeleportPacket tp = (TeleportPacket)TeleportPacket.Create(PacketType.TELEPORT);

                        tp.ObjectId = Master.ObjectId;

                        client.SendToServer(tp);

                        TeleportState[client] = 10000 / 200;
                    }

                    /*Master.SendToClient(
                     *  PluginUtils.CreateNotification(Master.ObjectId,
                     *  "Player " + client.PlayerData.Name +
                     *  " is too far away from you to reposition!")
                     *  );*/

                    return;
                }

                // TODO: fix?

                /*
                 * if (packet.Records.Length == 0)
                 *  return;
                 *
                 * double angle = 180 / Math.PI * Math.Atan2(packet.NewPosition.Y - packet.Records[0].Y,
                 *  packet.NewPosition.X - packet.Records[0].X);
                 * if (angle % 90 == 0)
                 * {
                 */

                if (packet.Records.Length > 0 &&
                    packet.Records[0].X == packet.NewPosition.X &&
                    packet.Records[0].Y == packet.NewPosition.Y)
                {
                    GotoQueue.Add(client);
                }
            }
            else
            {
                while (GotoQueue.Count > 0)
                {
                    Client c = GotoQueue[0];
                    GotoQueue.RemoveAt(0);

                    GotoPacket gotop = (GotoPacket)GotoPacket.Create(PacketType.GOTO);

                    gotop.Location = new Location();

                    gotop.Location.X = Master.PlayerData.Pos.X;
                    gotop.Location.Y = Master.PlayerData.Pos.Y;

                    /*
                     * {
                     *  double rads = Math.PI / 180 * angle;
                     *
                     *  Location MasterRotated = RotateVector(Master.PlayerData.Pos, -rads);
                     *  Location MeRotated = RotateVector(packet.NewPosition, -rads);
                     *  MasterRotated.X -= MeRotated.X;
                     *  MasterRotated.Y = 0;
                     *
                     *  Location Rotated = RotateVector(MasterRotated, rads);
                     *
                     *  if (Math.Abs(Rotated.X + Rotated.Y) < 0.04)
                     *      return;
                     *
                     *  gotop.Location.X = packet.NewPosition.X - Rotated.X;
                     *  gotop.Location.Y = packet.NewPosition.Y - Rotated.Y;
                     * }
                     */
                    gotop.ObjectId = c.ObjectId;

                    c.SendToClient(gotop);


                    GotoSkipList[c].Add(1);
                }
            }
        }