Exemple #1
0
 public PacketIn Decrypt(PacketIn packet)
 {
     byte[] data = packet.ToArray();
     decryption.Process(data, 4, data.Length - 4);
     PacketIn result = new PacketIn(data, 0, data.Length);
     result.Size = result.GetUint32Reversed();
     result.Opcode = result.GetUint32Reversed();
     Console.Write("Dcrptd:");
     for (int i = 0; i < result.ToArray().Length; i++) Console.Write(" "+ result.ToArray()[i]);
     Console.WriteLine();
     return result;
 }
Exemple #2
0
        static public void F_REQUEST_INIT_PLAYER(BaseClient client, PacketIn packet)
        {
            GameClient cclient = client as GameClient;

            Log.Dump("F_REQUEST_INIT_PLAYER", packet.ToArray(), 0, packet.ToArray().Length);

            if (cclient.Plr == null)
                return;

            foreach (Player Obj in cclient.Plr._PlayerRanged)
                Obj.SendMeTo(cclient.Plr);
        }
Exemple #3
0
        public PacketIn Decrypt(PacketIn packet)
        {
            byte[] data = packet.ToArray();
            decryption.Process(data, 4, data.Length - 4);
            PacketIn result = new PacketIn(data, 0, data.Length);

            result.Size   = result.GetUint32Reversed();
            result.Opcode = result.GetUint32Reversed();
            Console.Write("Dcrptd:");
            for (int i = 0; i < result.ToArray().Length; i++)
            {
                Console.Write(" " + result.ToArray()[i]);
            }
            Console.WriteLine();
            return(result);
        }
Exemple #4
0
 public PacketIn Decrypt(PacketIn packet)
 {
     byte[] data = packet.ToArray();
     decryption.Process(data, 4, data.Length - 4);
     PacketIn result = new PacketIn(data, 0, data.Length);
     result.Size = result.GetUint32Reversed();
     result.Opcode = result.GetUint32Reversed();
     Log.Info("[CLIENT POST-ENCRYPT]", this.DumpData(data));
     return result;
 }
Exemple #5
0
        public void SendTCP(PacketOut packet)
        {
            //Fix the packet size
            packet.WritePacketLength();
            packet = Crypt(packet);
            byte[] buf = packet.ToArray(); //packet.WritePacketLength sets the Capacity

            //Send the buffer

            socket.Send(buf);
        }
Exemple #6
0
        public PacketIn Decrypt(PacketIn packet)
        {
            byte[] data = packet.ToArray();
            decryption.Process(data, 4, data.Length - 4);
            PacketIn result = new PacketIn(data, 0, data.Length);

            result.Size   = result.GetUint32Reversed();
            result.Opcode = result.GetUint32Reversed();
            Log.Info("[CLIENT POST-ENCRYPT]", this.DumpData(data));
            return(result);
        }
Exemple #7
0
        private void LogInPacket(PacketIn packet)
        {
            if (_logThread == null)
            {
                _logThread = new Thread(new ThreadStart(PacketLogThread));
                _logThread.Start();
            }

            lock (_packetLog)
            {
                _packetLog.Add(Utils.ToLogHexString((byte)packet.Opcode, false, packet.ToArray()));
            }
        }
Exemple #8
0
        public PacketIn DeCrypt(PacketIn packet)
        {
            if (m_crypts.Count <= 0)
            {
                return(packet);
            }

            ulong opcode   = packet.Opcode;
            ulong size     = packet.Size;
            long  StartPos = packet.Position;

            foreach (KeyValuePair <ICryptHandler, CryptKey[]> Entry in m_crypts)
            {
                try
                {
                    byte[] Buf = new byte[size];

                    long Pos = packet.Position;
                    packet.Read(Buf, 0, (int)Buf.Length);
                    packet.Position = Pos;

                    PacketIn Pack = Entry.Key.Decrypt(Entry.Value[1], Buf);
                    packet.Write(Pack.ToArray(), 0, Pack.ToArray().Length);

                    packet.Opcode = opcode;
                    packet.Size   = size;
                }
                catch (Exception e)
                {
                    Log.Error("Decrypt Error : " + e.ToString());
                    continue;
                }
            }

            packet.Position = StartPos;
            return(packet);
        }
        static public void F_INTERACT(BaseClient client, PacketIn packet)
        {
            GameClient cclient = client as GameClient;

            if (cclient.Plr == null || !cclient.Plr.IsInWorld())
            {
                return;
            }

            Log.Dump("F_INTERACT", packet.ToArray(), 0, packet.ToArray().Length);

            InteractMenu Menu = new InteractMenu();

            Menu.Oid       = packet.GetUint16();
            Menu.Menu      = packet.GetUint16();
            Menu.Page      = packet.GetUint8();
            Menu.Num       = packet.GetUint8();
            Menu.Unk       = packet.GetUint16();
            Menu.SellCount = packet.GetUint16();
            Menu.Count     = packet.GetUint16();

            Object Obj = cclient.Plr.Region.GetObject(Menu.Oid);

            if (Obj == null)
            {
                return;
            }

            if (Obj.GetDistanceTo(cclient.Plr) > 20)
            {
                Log.Error("F_INTERACT", "Distance = " + Obj.GetDistanceTo(cclient.Plr));
                return;
            }

            Obj.SendInteract(cclient.Plr, Menu);
        }
Exemple #10
0
        public PacketIn Decrypt(PacketIn packet)
        {
            byte[] data = packet.ToArray();
            decryption.Process(data, 4, data.Length - 4);
            PacketIn result = new PacketIn(data, 0, data.Length);
            result.Size = result.GetUint32Reversed();
            result.Opcode = result.GetUint32Reversed();

            /*
            Console.Write("Dcrptd: ");
            for (int i = 0; i < result.ToArray().Length; i++) Console.Write(" "+ result.ToArray()[i]);
            Console.WriteLine();
            */

            Log.Info("[CLIENT POST-ENCRYPT]", this.DumpData(data));

            return result;
        }
Exemple #11
0
        private void onAuthSessionTokenReq(PacketIn packet)
        {
            PacketOut Out = new PacketOut((byte)Opcodes.SMSG_AuthSessionTokenReply);


            AuthSessionTokenReq.Builder authReq = AuthSessionTokenReq.CreateBuilder();
            authReq.MergeFrom(packet.ToArray());

            string session = Encoding.ASCII.GetString(authReq.SessionToken.ToByteArray());

            Log.Trace(session);

            AuthSessionTokenReply.Builder authReply = AuthSessionTokenReply.CreateBuilder();
            authReply.SetResultCode(AuthSessionTokenReply.Types.ResultCode.RES_SUCCESS);


            Out.Write(authReply.Build().ToByteArray());
            SendTCPCuted(Out);
        }
Exemple #12
0
        public void SendCustomPacket(string hexStringBytes)
        {
            try
            {
                hexStringBytes = hexStringBytes.Replace(" ", "");

                byte opcode = Convert.ToByte(hexStringBytes.Substring(0, 2), 16);

                PacketOut packet = new PacketOut(opcode);
                packet.WriteHexStringBytes(hexStringBytes.Remove(0, 2));

                packet.WritePacketLength();
                packet = Crypt(packet);
                byte[] buf = packet.ToArray(); //packet.WritePacketLength sets the Capacity

                socket.Send(buf);
            }
            catch
            {
                Log.Error("SendCustomPacket: Failed to send packet");
            }
        }
Exemple #13
0
        public static void CMSG_AuthSessionTokenReq(BaseClient client, PacketIn packet)
        {
            Log.Debug("LServ", "CMSG_AuthSessionTokenReq");
            Client cclient = (Client)client;

            PacketOut Out = new PacketOut((byte)Opcodes.SMSG_AuthSessionTokenReply);


            AuthSessionTokenReq.Builder authReq = AuthSessionTokenReq.CreateBuilder();
            authReq.MergeFrom(packet.ToArray());

            string session = Encoding.ASCII.GetString(authReq.SessionToken.ToByteArray());

            Log.Debug("AuthSession", "session " + session);
            cclient.Username = "";                                  //username is not important anymore in 1.4.8
            cclient.Token    = session;



            AuthSessionTokenReply.Builder authReply = AuthSessionTokenReply.CreateBuilder();
            authReply.SetResultCode(AuthSessionTokenReply.Types.ResultCode.RES_SUCCESS);


            Out.Write(authReply.Build().ToByteArray());

            cclient.SendTCPCuted(Out);


            /*   //TODO: need auth check
             *
             *  if (Result != AuthResult.AUTH_SUCCESS)
             *      cclient.Disconnect();
             *  else
             *  {
             *      cclient.Username = Username;
             *      cclient.Token = Token;
             *  }*/
        }
Exemple #14
0
        static public void F_PLAYER_STATE2(Connection conn, PacketIn packet)
        {
            Log.DumpHex(packet.ToArray());
            UInt16 unk1         = packet.GetUint16();
            byte   Type         = packet.GetUint8();
            byte   MoveingState = packet.GetUint8(); // ground, jumpstart,jumpend,inair
            byte   unk2         = packet.GetUint8();
            byte   Strafe       = packet.GetUint8();

            UInt16 Heading = packet.GetUint16R();
            UInt16 X       = packet.GetUint16R();
            UInt16 Y       = packet.GetUint16R();
            byte   Unk1    = packet.GetUint8();
            UInt16 Z       = packet.GetUint16R();

            X /= 2;
            Y /= 2;
            Z /= 4;


            if (packet.Size < 10)
            {
                Log.Debug("Player: state refresh");
            }
            else
            {
                if (Type == (byte)MovementTypes.NotMoving)
                {
                    // player not moving or has stopped in position
                    Log.Debug("Player: not moving or has stopped in position " + Type);
                }
                else if (Type == (byte)MovementTypes.GroundForward)
                {
                    // player is moving forward
                    Log.Debug("Player: moving forward " + Type);
                }
                else if (Type == (byte)MovementTypes.GroundBackward)
                {
                    // player is moving backward
                    Log.Debug("Player: moving backward " + Type);
                }
                else if (Type == (byte)MovementTypes.FlyModeForward)
                {
                    // player is using fly mode
                    Log.Debug("Player: flying forward " + Type);
                }
                else if (Type == (byte)MovementTypes.FlyModeBackward)
                {
                    // player is using fly mode
                    Log.Debug("Player: flying backward " + Type);
                }

                GetPosition(X, Y, Z);
            }

            /*try
             * {
             *  long Pos = packet.Position;
             *
             *  PacketOut Out = new PacketOut((byte)Opcodes.F_PLAYER_STATE2);
             *  Out.Write(packet.ToArray(), (int)packet.Position, (int)packet.Size);
             *  Out.WriteByte(0);
             * // Plr.DispatchPacket(Out, false);
             *
             *  packet.Position = Pos;
             * }
             * catch (Exception e)
             * {
             *  Log.Error("F_PLAYER_STATE2", e.ToString());
             * }
             *
             * if (packet.Size < 18)
             * {
             *  Log.Debug("Player: not moving");
             *  Log.DumpHex(packet.ToArray());
             *  return;
             * }
             *
             * UInt16 Key = packet.GetUint16();
             *
             * byte MoveByte = packet.GetUint8();
             * byte UnkByte = packet.GetUint8();
             * byte CombatByte = packet.GetUint8();
             * byte RotateByte = packet.GetUint8();
             *
             * UInt16 Heading = packet.GetUint16R();
             * UInt16 X = packet.GetUint16R();
             * UInt16 Y = packet.GetUint16R();
             * byte Unk1 = packet.GetUint8();
             * UInt16 Z = packet.GetUint16R();
             * byte Unk2 = packet.GetUint8();
             * Log.Debug(string.Format("Player: X={0} Y={1} Z={2}",X,Y,Z));*/
        }
Exemple #15
0
        static public void F_PLAYER_STATE2(BaseClient client, PacketIn packet)
        {
            GameClient cclient = client as GameClient;

            if (cclient.Plr == null || !cclient.Plr.IsInWorld())
            {
                return;
            }

            Player Plr = cclient.Plr;

            long Pos = packet.Position;

            PacketOut Out = new PacketOut((byte)Opcodes.F_PLAYER_STATE2);

            Out.Write(packet.ToArray(), (int)packet.Position, (int)packet.Size);
            Out.WriteByte(0);
            Plr.DispatchPacket(Out, false);

            packet.Position = Pos;

            UInt16 Key = packet.GetUint16();

            byte Type         = packet.GetUint8();
            byte MoveingState = packet.GetUint8();
            byte CombatByte   = packet.GetUint8();
            byte Strafe       = packet.GetUint8();

            UInt16 Heading = packet.GetUint16R();
            UInt16 X       = packet.GetUint16R();
            UInt16 Y       = packet.GetUint16R();
            byte   Unk1    = packet.GetUint8();
            UInt16 Z       = packet.GetUint16R();

            if (packet.Size < 10)
            {
                return;
            }

            Heading /= 8;
            X       /= 2;
            Y       /= 2;
            Z       /= 2;

            if (Type != (byte)MovementTypes.NotMoving)
            {
                Plr.IsMoving = true;
            }
            else
            {
                Plr.IsMoving = false;
            }

            //Log.Success("Movement Before ", X + "," + Y + "," + Z);
            if (CombatByte >= 50 && CombatByte < 0x92 || CombatByte == 0xDF)
            {
                if (Plr.LastCX != 0 && Plr.LastCY != 0)
                {
                    if (Plr.LastCX > 12288 && X < 4096)
                    {
                        Plr.SetOffset((ushort)(Plr.XOffset + 1), Plr.YOffset);
                    }
                    else if (X > 12288 && Plr.LastCX < 4096)
                    {
                        Plr.SetOffset((ushort)(Plr.XOffset - 1), Plr.YOffset);
                    }

                    if (Plr.LastCY > 24576 && Y < 8192)
                    {
                        Plr.SetOffset(Plr.XOffset, (ushort)(Plr.YOffset + 1));
                    }
                    else if (Y > 24576 && Plr.LastCY < 8192)
                    {
                        Plr.SetOffset(Plr.XOffset, (ushort)(Plr.YOffset - 1));
                    }
                }

                Plr.LastCX = X;
                Plr.LastCY = Y;

                X        = Plr.Zone.CalculCombat(X, Plr.XOffset, true);
                Y        = Plr.Zone.CalculCombat(Y, Plr.YOffset, false);
                Heading /= 2;
                Z       += 32768;
                Z       /= 4;
                Z       /= 2;
            }
            else
            {
                if (Plr.LastX != 0 && Plr.LastY != 0)
                {
                    if (Plr.LastX > 24576 && X < 4096)
                    {
                        Plr.SetOffset((ushort)(Plr.XOffset + 1), Plr.YOffset);
                    }
                    else if (Plr.LastX < 4096 && X > 24576)
                    {
                        Plr.SetOffset((ushort)(Plr.XOffset - 1), Plr.YOffset);
                    }

                    if (Plr.LastY > 24576 && Y < 4096)
                    {
                        Plr.SetOffset(Plr.XOffset, (ushort)(Plr.YOffset + 1));
                    }
                    else if (Plr.LastY < 4096 && Y > 24576)
                    {
                        Plr.SetOffset(Plr.XOffset, (ushort)(Plr.YOffset - 1));
                    }
                }

                Plr.LastX = X;
                Plr.LastY = Y;

                X  = Plr.Zone.CalculPin(X, Plr.XOffset, true);
                Y  = Plr.Zone.CalculPin(Y, Plr.YOffset, false);
                Z /= 2;
            }

            if (Plr.IsInWorld() && Plr.Zone.ZoneId == 161)
            {
                Z += 16384;
            }

            //Log.Success("Movement after", "X=" + X + ",Y=" + Y + ",Z=" + Z + "," + Type + "," + Unk1 + "," + CombatByte);
            Plr.SetPosition(X, Y, Z, Heading);
        }
        public static void F_PLAYER_STATE2(BaseClient client, PacketIn packet)
        {
            GameClient cclient = (GameClient)client;

            Player player = cclient.Plr;

            if (player == null || !player.IsInWorld())
            {
                return;
            }



            bool skipSend = false;

            long pos = packet.Position;

            //Comments below are for testing State2

            //byte[] data = packet.ToArray();
            PacketOut Out = new PacketOut((byte)Opcodes.F_PLAYER_STATE2, (int)packet.Size + 1);

            //Out.Write(data, (int)packet.Position, (int)packet.Size); // instead of the line below for testing
            Out.Write(packet.ToArray(), (int)packet.Position, (int)packet.Size);
            Out.WriteByte(0);

/*
 #if DEBUG
 *          State2 stateTest = new State2();
 *          stateTest.Read(data, data.Length);
 *          Log.Info("state2.HasEnemyTarget", stateTest.HasEnemyTarget.ToString());
 *          Log.Info("state2.FreeFall", stateTest.FreeFall.ToString());
 *          Log.Info("state2.Falltime", stateTest.FallTime.ToString());
 #endif
 */
//End of the testing of state2

            packet.Position = pos;

            byte[] data = packet.ToArray();

            // Experimental throttling if too many players in range. This can be overridden later if the position update's forced
            if (player.PlayersInRange.Count > 150 && TCPManager.GetTimeStampMS() - player.LastStateRecvTime < 200)
            {
                skipSend = true;
            }

            ushort currentHeading = player.Heading;

            if (packet.Size > 9 && packet.Size < 18)
            {
                long state  = System.Net.IPAddress.NetworkToHostOrder(BitConverter.ToInt64(data, 2));
                long state2 = System.Net.IPAddress.NetworkToHostOrder(BitConverter.ToInt64(data, 10));

                ushort x = ((ushort)(((state2 >> 56 & 0x1) << 15) | ((state >> 0 & 0xFF) << 7) | ((state >> 9 & 0x7F))));
                ushort y = ((ushort)(((state2 >> 40 & 0x1) << 15) | ((state2 >> 48 & 0xFF) << 7) | ((state2 >> 57 & 0x7F))));
                ushort z = ((ushort)(((state2 >> 16 & 0x3) << 14) | ((state2 >> 24 & 0xFF) << 6) | ((state2 >> 34 & 0x3F))));

                ushort direction  = ((ushort)(((state >> 16 & 0x7F) << 5) | ((state >> 27 & 0x1F))));
                ushort zoneID     = ((byte)(((state2 >> 32 & 0x1) << 7) | ((state2 >> 41 & 0x7F))));
                bool   grounded   = ((((state >> 8 & 0x1))) == 1);
                byte   fallState  = ((byte)(((state >> 40 & 0x1F))));
                bool   walking    = ((((state >> 48 & 0x1))) == 1);
                bool   moving     = ((((state >> 49 & 0x1))) == 1);
                bool   notMoving  = ((((state >> 63 & 0x1))) == 1);
                byte   groundtype = ((byte)(((state2 >> 82 & 0x1F))));

                //Hack Zone ID should be ushort but we only read a byte
                if (cclient.Plr.ZoneId > 255)
                {
                    zoneID = (ushort)Utils.setBit(zoneID, 8, true);
                }

                //hardcode to not allow players into gunbad in case we miss to invalidate the zone on push
#if (!DEBUG)
                /*
                 * if (zoneID == 60 && player.Client.IsPlaying())
                 * {
                 *  if (player.Realm == Realms.REALMS_REALM_DESTRUCTION)
                 *      player.Teleport(161, 439815, 134493, 16865, 0);
                 *
                 *  else if (player.Realm == Realms.REALMS_REALM_ORDER)
                 *      player.Teleport(162, 124084, 130213, 12572, 0);
                 * }
                 */

                if (zoneID == 111 && player.Client.IsPlaying())
                {
                    if (player.Realm == Realms.REALMS_REALM_DESTRUCTION)
                    {
                        player.Teleport(202, 1411789, 1454421, 3516, 0);
                    }

                    else if (player.Realm == Realms.REALMS_REALM_ORDER)
                    {
                        player.Teleport(202, 1449783, 1459746, 3549, 0);
                    }
                }
#endif

                //stop players from getting stuck below the world like below IC
                if (player.Z < 150 && !player.IsDead && player.Client.IsPlaying())
                {
                    player.SendClientMessage("You have fallen through the floor, instead of falling and getting stuck somewhere you get terminated.", ChatLogFilters.CHATLOGFILTERS_CSR_TELL_RECEIVE);
                    player.Terminate();
                }

                //lets move players instantly, if they are in a void (even staff)
                if ((zoneID == 0 && player.ZoneId.HasValue) && player.Client.IsPlaying())
                {
                    player.SendClientMessage("You managed to go outside of the worlds boundries, as such you have been forcefully moved to your capital", ChatLogFilters.CHATLOGFILTERS_CSR_TELL_RECEIVE);
                    if (player.Realm == Realms.REALMS_REALM_DESTRUCTION)
                    {
                        player.Teleport(161, 439815, 134493, 16865, 0);
                    }



                    else if (player.Realm == Realms.REALMS_REALM_ORDER)
                    {
                        player.Teleport(162, 124084, 130213, 12572, 0);
                    }
                }


                //player should not be able to cast while in the air.
                if (!grounded)
                {
                    if (player.AbtInterface.GetAbiityProcessor() != null && player.AbtInterface.GetAbiityProcessor().HasInfo() && player.AbtInterface.GetAbiityProcessor().AbInfo.Entry != 8090 && player.AbtInterface.GetAbiityProcessor().AbInfo.Entry != 9393)
                    {
                        player.AbtInterface.Cancel(true);
                    }
                }

                if (fallState != 31 || ((moving || walking || !notMoving || !grounded) && player.Speed > 0))
                {
                    player.IsMoving = true;
                }
                else
                {
                    player.IsMoving = false;
                }

                if (!player.WasGrounded)
                {
                    if (grounded)
                    {
                        player.CalculateFallDamage();
                        player.AirCount          = -1;
                        player.ForceSendPosition = true;
                    }
                }

                player.WasGrounded = grounded;

                if (!grounded)
                {
                    player.FallState = fallState;
                }

                // Throttle pure rotation updates.
                if (player.X == x && player.Y == y && player.Z == z && TCPManager.GetTimeStampMS() - player.LastStateRecvTime < 150)
                {
                    if (player.AirCount == -1)
                    {
                        player.AirCount = 0;
                    }
                    else
                    {
                        skipSend = true;
                    }
                }

                if (player.IsStaggered || player.IsDisabled)
                {
                    direction = currentHeading;
                }

                player.SetPosition(x, y, z, direction, zoneID);

                //solid, exclude any zones that has to use a hardcode lava to not disable the damage instantly
                if (groundtype == 0)
                {
                    //release lava damage
                    if (_lavaBuffs.ContainsKey(player) && (zoneID != 190 || zoneID != 197))
                    {
                        _lavaBuffs[player].BuffHasExpired = true;
                        _lavaBuffs.Remove(player);
                    }
                }
                //shallow water 1, have no use for it atm, shallow sludge 7

                /*
                 * if (groundtype == 1 || groundtype == 7)
                 * {
                 *
                 * }*/

                //deep water 17 in current implementation should be 2 by londos decode, deep sludge 23
                if (groundtype == 17 || groundtype == 23)
                {
                    player.Dismount();
                }

                //lava
                long Now = TCPManager.GetTimeStampMS();
                if (groundtype == 3 || groundtype == 19) //19 is deep lava
                {
                    player.Dismount();
                    if (!player.IsDead)
                    {
                        //do lava dmg
                        if (_lavatimer < Now)
                        {
                            player.BuffInterface.QueueBuff(new BuffQueueInfo(player, player.Level, AbilityMgr.GetBuffInfo(14430), AddLavaBuff));
                            _lavatimer = Now + 1000;
                            player.ResetMorale();
                        }
                    }
                }

                //instadeath

                if (groundtype == 5 || groundtype == 21) //should be 4 according to londos notes 5=lotd shallow water 21=lotd deep water
                {
                    if (!player.IsDead)
                    {
                        Log.Texte("groundstate instadeath: ", player.Name + " managed to trigger groundtype instadeath in zone: " + player.ZoneId, ConsoleColor.Yellow);
                        player.SendClientMessage("You have managed to trigger the instadeath code from river mortis, please screenshot your death and send to the devs on the bugtracker", ChatLogFilters.CHATLOGFILTERS_CSR_TELL_RECEIVE);
                        player.Terminate();
                    }
                }

                //bright wizard colleage lava
                if (zoneID == 197)
                {
                    if (!player.IsDead && player.Z <= 23791)
                    {
                        if (_lavatimer < Now)
                        {
                            player.BuffInterface.QueueBuff(new BuffQueueInfo(player, player.Level, AbilityMgr.GetBuffInfo(14430), AddLavaBuff));
                            _lavatimer = Now + 1000;
                            player.ResetMorale();
                        }
                    }
                    else
                    {
                        if (_lavaBuffs.ContainsKey(player))
                        {
                            _lavaBuffs[player].BuffHasExpired = true;
                            _lavaBuffs.Remove(player);
                        }
                    }
                }
                if (zoneID == 190)
                {
                    if (!player.IsDead && player.Z <= 7806)
                    {
                        if (_lavatimer < Now)
                        {
                            player.BuffInterface.QueueBuff(new BuffQueueInfo(player, player.Level, AbilityMgr.GetBuffInfo(14430), AddLavaBuff));
                            _lavatimer = Now + 1000;
                            player.ResetMorale();
                        }
                    }
                    else
                    {
                        if (_lavaBuffs.ContainsKey(player))
                        {
                            _lavaBuffs[player].BuffHasExpired = true;
                            _lavaBuffs.Remove(player);
                        }
                    }
                }

                if (player.Zone.Info.Illegal && player.GmLevel < 1)
                {
                    if (!player.IsDead && player.BuffInterface.GetBuff(27960, player) == null)
                    {
                        player.BuffInterface.QueueBuff(new BuffQueueInfo(player, player.Level, AbilityMgr.GetBuffInfo(27960)));
                    }
                }
                else if (!player.Zone.Info.Illegal)
                {
                    if (player.BuffInterface.GetBuff(27960, player) != null)
                    {
                        player.BuffInterface.RemoveBuffByEntry(27960);
                    }
                }

                if (player.ForceSendPosition)
                {
                    skipSend = false;
                    player.ForceSendPosition = false;
                }

                //gunbad has low points where we want to kill the player
                if (zoneID == 60 && player.Z < 17900)
                {
                    player.Terminate();
                }
            }

            #region Long seems to be when the player has a hostile target
            else if (packet.Size > 17)
            {
                long state  = System.Net.IPAddress.NetworkToHostOrder(BitConverter.ToInt64(data, 2));
                long state2 = System.Net.IPAddress.NetworkToHostOrder(BitConverter.ToInt64(data, 10));

                ushort x          = ((ushort)(((state2 >> 56 & 0x3) << 14) | ((state >> 0 & 0xFF) << 6) | ((state >> 10 & 0x3F))));
                ushort y          = ((ushort)(((state2 >> 40 & 0x3) << 14) | ((state2 >> 48 & 0xFF) << 6) | ((state2 >> 58 & 0x3F))));
                ushort z          = ((ushort)(((state2 >> 16 & 0x7) << 12) | ((state2 >> 24 & 0xFF) << 4) | ((state2 >> 36 & 0x0F))));
                byte   zoneID     = ((byte)(((state2 >> 34 & 0x1) << 7) | ((state2 >> 32 & 0x3) << 5) | ((state2 >> 43 & 0x1F))));
                ushort direction  = ((ushort)(((state >> 16 & 0xFF) << 4) | ((state >> 28 & 0x0F))));
                bool   grounded   = ((((state >> 9 & 0x1))) == 1);
                bool   walking    = ((((state >> 48 & 0x1))) == 1);
                bool   moving     = ((((state >> 49 & 0x1))) == 1);
                bool   notMoving  = ((((state >> 63 & 0x1))) == 1);
                byte   fallState  = ((byte)(((state >> 40 & 0x1F))));
                byte   groundtype = ((byte)(((state2 >> 73 & 0x1F))));

                if (fallState != 31 || ((moving || walking || !notMoving || !grounded) && player.Speed > 0))
                {
                    player.IsMoving = true;
                }
                else
                {
                    player.IsMoving = false;
                }

                //stop players from getting stuck below the world like below IC
                if (player.Z < 150 && !player.IsDead && player.Client.IsPlaying())
                {
                    player.SendClientMessage("You have fallen through the floor, instead of falling and getting stuck somewhere you get terminated.", ChatLogFilters.CHATLOGFILTERS_CSR_TELL_RECEIVE);
                    player.Terminate();
                }
                //hardcode to not allow players into gunbad in case we miss to invalidate the zone on push
#if (!DEBUG)
                /*
                 * if (zoneID == 60 && player.Client.IsPlaying())
                 * {
                 *  if (player.Realm == Realms.REALMS_REALM_DESTRUCTION)
                 *      player.Teleport(161, 439815, 134493, 16865, 0);
                 *
                 *  else if (player.Realm == Realms.REALMS_REALM_ORDER)
                 *      player.Teleport(162, 124084, 130213, 12572, 0);
                 * }
                 */
#endif

                //lets move players instantly, if they are in a void (even staff)
                if ((zoneID == 0 && player.ZoneId.HasValue) && player.Client.IsPlaying())
                {
                    player.SendClientMessage("You managed to go outside of the worlds boundries, as such you have been forcefully moved to your capital", ChatLogFilters.CHATLOGFILTERS_CSR_TELL_RECEIVE);
                    if (player.Realm == Realms.REALMS_REALM_DESTRUCTION)
                    {
                        player.Teleport(161, 439815, 134493, 16865, 0);
                    }

                    else if (player.Realm == Realms.REALMS_REALM_ORDER)
                    {
                        player.Teleport(162, 124084, 130213, 12572, 0);
                    }
                }

                //player should not be able to cast while in the air.
                if (!grounded)
                {
                    player.AbtInterface.Cancel(true);
                }

                if (!player.WasGrounded)
                {
                    if (grounded)
                    {
                        player.CalculateFallDamage();
                        player.AirCount          = -1;
                        player.ForceSendPosition = true;
                    }
                }

                player.WasGrounded = grounded;
                if (!grounded)
                {
                    player.FallState = fallState;
                }

                if (player.IsStaggered || player.IsDisabled)
                {
                    direction = currentHeading;
                }

                player.SetPosition(x, y, z, direction, zoneID);

                //solid, exclude any zones that has to use a hardcode lava to not disable the damage instantly
                if (groundtype == 0)
                {
                    //release lava damage
                    if (_lavaBuffs.ContainsKey(player) && (zoneID != 190 || zoneID != 197))
                    {
                        _lavaBuffs[player].BuffHasExpired = true;
                        _lavaBuffs.Remove(player);
                    }
                }
                //shallow water 1, have no use for it atm... shallow sludge 7

                /*
                 * if (groundtype == 1 || groundtype == 7)
                 * {
                 *
                 * }*/

                //deep water 17 in current implementation should be 2 by londos decode, deep sludge 23
                if (groundtype == 17 || groundtype == 23)
                {
                    player.Dismount();
                }

                //lava
                long Now = TCPManager.GetTimeStampMS();
                if (groundtype == 3 || groundtype == 19) //19 is deep lava
                {
                    player.Dismount();
                    if (!player.IsDead)
                    {
                        //do lava dmg
                        if (_lavatimer < Now)
                        {
                            player.BuffInterface.QueueBuff(new BuffQueueInfo(player, player.Level, AbilityMgr.GetBuffInfo(14430), AddLavaBuff));
                            _lavatimer = Now + 1000;
                            player.ResetMorale();
                        }
                    }
                }

                //instadeath

                if (groundtype == 5 || groundtype == 21) //should be 4 according to londos notes 5=lotd shallow water 21=lotd deep water
                {
                    if (!player.IsDead)
                    {
                        Log.Texte("groundstate instadeath: ", player.Name + " managed to trigger groundtype instadeath in zone: " + player.ZoneId, ConsoleColor.Yellow);
                        player.SendClientMessage("You have managed to trigger the instadeath code from river mortis, please screenshot your death and send to the devs on the bugtracker", ChatLogFilters.CHATLOGFILTERS_CSR_TELL_RECEIVE);

                        player.Terminate();
                    }
                }

                //bright wizard colleage lava
                if (zoneID == 197)
                {
                    if (!player.IsDead && player.Z <= 23791)
                    {
                        if (_lavatimer < Now)
                        {
                            player.BuffInterface.QueueBuff(new BuffQueueInfo(player, player.Level, AbilityMgr.GetBuffInfo(14430), AddLavaBuff));
                            _lavatimer = Now + 1000;
                            player.ResetMorale();
                        }
                    }
                    else
                    {
                        if (_lavaBuffs.ContainsKey(player))
                        {
                            _lavaBuffs[player].BuffHasExpired = true;
                            _lavaBuffs.Remove(player);
                        }
                    }
                }
                if (zoneID == 190)
                {
                    if (!player.IsDead && player.Z <= 7806)
                    {
                        if (_lavatimer < Now)
                        {
                            player.BuffInterface.QueueBuff(new BuffQueueInfo(player, player.Level, AbilityMgr.GetBuffInfo(14430), AddLavaBuff));
                            _lavatimer = Now + 1000;
                            player.ResetMorale();
                        }
                    }
                    else
                    {
                        if (_lavaBuffs.ContainsKey(player))
                        {
                            _lavaBuffs[player].BuffHasExpired = true;
                            _lavaBuffs.Remove(player);
                        }
                    }
                }

                if (player.Zone.Info.Illegal && player.GmLevel == 0)
                {
                    if (!player.IsDead && player.BuffInterface.GetBuff(27960, player) == null)
                    {
                        player.BuffInterface.QueueBuff(new BuffQueueInfo(player, player.Level, AbilityMgr.GetBuffInfo(27960)));
                    }
                }
                else if (!player.Zone.Info.Illegal)
                {
                    if (player.BuffInterface.GetBuff(27960, player) != null)
                    {
                        player.BuffInterface.RemoveBuffByEntry(27960);
                    }
                }

                if (player.ForceSendPosition)
                {
                    skipSend = false;
                    player.ForceSendPosition = false;
                }

                //gunbad has low points where we want to kill the player
                if (zoneID == 60 && player.Z < 17900)
                {
                    player.Terminate();
                }
            }

            #endregion

            // Packets not conforming to the above are sent at 500ms intervals when the player is still.
            // I don't know their function, but it appears they're of no interest to the client.
            else
            {
                skipSend = true;
                player.ForceSendPosition = true;
            }

            // TODO: Conditional dispatch for Player State 2
            if (skipSend)
            {
                return;
            }
            player.SendCounter++;
            //player.DebugMessage("F_PLAYER_STATE2: "+ (TCPManager.GetTimeStampMS() - player.LastStateRecvTime));
            player.DispatchPacket(Out, false, true);
            player.LastStateRecvTime = TCPManager.GetTimeStampMS();
        }
Exemple #17
0
        static public void F_PLAYER_STATE2(BaseClient client, PacketIn packet)
        {
            GameClient cclient = client as GameClient;

            if (cclient.Plr == null || !cclient.Plr.IsInWorld())
            {
                return;
            }

            Player Plr = cclient.Plr;

            long Pos = packet.Position;

            PacketOut Out = new PacketOut((byte)Opcodes.F_PLAYER_STATE2);

            Out.Write(packet.ToArray(), (int)packet.Position, (int)packet.Size);
            Out.WriteByte(0);
            Plr.DispatchPacket(Out, false);

            packet.Position = Pos;

            UInt16 Key = packet.GetUint16();

            byte Type         = packet.GetUint8();
            byte MoveingState = packet.GetUint8();
            byte CombatByte   = packet.GetUint8();
            byte Strafe       = packet.GetUint8();

            UInt16 Heading = packet.GetUint16R();
            UInt16 X       = packet.GetUint16R();
            UInt16 Y       = packet.GetUint16R();
            byte   Unk1    = packet.GetUint8();
            UInt16 Z       = packet.GetUint16R();
            byte   zmod    = packet.GetUint8();

            //Log.Success("zMod ",""+zmod);
            // zmod is somewhat strange what i found out so far
            // z mod is 255 while standing
            // z mod is 0 while running and z is below 65535
            // z mod is 1 while running and z is above 65535
            // z mod can be  113 / 97 / 115 / 99 while running and z is below 65535 and enemy in target
            // z mod is 99 / 100 / 116  while running and z is above 65535 and enemy in target

            // z mod is 4 while running in water
            // z mod is 68 while swimming in water
            // z mod is ticking with 255 7 times then 68 while standing in deep water
            // z mod is 12 while running in water (that should lower your health / kill you and reduce movement speed)
            // z mod is ticking with 255 7 times then 12 while standing in lava

            if (packet.Size < 10)
            {
                return;
            }

            int z_temp = Z;

            Heading /= 8;
            X       /= 2;
            Y       /= 2;

            // z update if z is higher then 65535
            if (zmod != 0 && zmod != 97 && zmod != 113 && zmod != 99 && zmod != 115)
            {
                z_temp += 65535;
            }

            if (Type != (byte)MovementTypes.NotMoving)
            {
                Plr.IsMoving = true;
            }
            else
            {
                Plr.IsMoving = false;
            }

            //Log.Success("Movement Before ", X + "," + Y + "," + Z);
            if (CombatByte >= 50 && CombatByte < 0x92 || CombatByte == 0xDF)
            {
                if (Plr.LastCX != 0 && Plr.LastCY != 0)
                {
                    if (Plr.LastCX > 12288 && X < 4096)
                    {
                        Plr.SetOffset((ushort)(Plr.XOffset + 1), Plr.YOffset);
                    }
                    else if (X > 12288 && Plr.LastCX < 4096)
                    {
                        Plr.SetOffset((ushort)(Plr.XOffset - 1), Plr.YOffset);
                    }

                    if (Plr.LastCY > 24576 && Y < 8192)
                    {
                        Plr.SetOffset(Plr.XOffset, (ushort)(Plr.YOffset + 1));
                    }
                    else if (Y > 24576 && Plr.LastCY < 8192)
                    {
                        Plr.SetOffset(Plr.XOffset, (ushort)(Plr.YOffset - 1));
                    }
                }

                Plr.LastCX = X;
                Plr.LastCY = Y;

                X = Plr.Zone.CalculCombat(X, Plr.XOffset, true);
                Y = Plr.Zone.CalculCombat(Y, Plr.YOffset, false);

                Heading /= 2;
                z_temp  /= 16;

                // combat offset z
                if (Plr._ZoneMgr.ZoneId == 161 || Plr._ZoneMgr.ZoneId == 162)
                {
                    z_temp += 12288;
                }
                else
                {
                    z_temp += 4096;
                }
            }
            else
            {
                if (Plr.LastX != 0 && Plr.LastY != 0)
                {
                    if (Plr.LastX > 24576 && X < 4096)
                    {
                        Plr.SetOffset((ushort)(Plr.XOffset + 1), Plr.YOffset);
                    }
                    else if (Plr.LastX < 4096 && X > 24576)
                    {
                        Plr.SetOffset((ushort)(Plr.XOffset - 1), Plr.YOffset);
                    }

                    if (Plr.LastY > 24576 && Y < 4096)
                    {
                        Plr.SetOffset(Plr.XOffset, (ushort)(Plr.YOffset + 1));
                    }
                    else if (Plr.LastY < 4096 && Y > 24576)
                    {
                        Plr.SetOffset(Plr.XOffset, (ushort)(Plr.YOffset - 1));
                    }
                }

                Plr.LastX = X;
                Plr.LastY = Y;

                X       = Plr.Zone.CalculPin(X, Plr.XOffset, true);
                Y       = Plr.Zone.CalculPin(Y, Plr.YOffset, false);
                z_temp /= 4;
            }

            //  if (Plr.IsInWorld() && Plr.Zone.ZoneId == 161)
            //      Z += 16384;

            //Log.Success("Movement after", "X=" + X + ",Y=" + Y + ",Z=" + Z + ",ztemp = " + z_temp + "," + Type + "," + Unk1 + "," + CombatByte);
            Plr.SetPosition(X, Y, (ushort)z_temp, Heading);
        }
        static public void F_PLAYER_STATE2(BaseClient client, PacketIn packet)
        {
            GameClient cclient = client as GameClient;

            if (cclient.Plr == null || !cclient.Plr.IsInWorld())
            {
                return;
            }

            Player Plr = cclient.Plr;

            try
            {
                long Pos = packet.Position;

                PacketOut Out = new PacketOut((byte)Opcodes.F_PLAYER_STATE2);
                Out.Write(packet.ToArray(), (int)packet.Position, (int)packet.Size);
                Out.WriteByte(0);
                Plr.DispatchPacket(Out, false);

                packet.Position = Pos;
            }
            catch (Exception e)
            {
                Log.Error("F_PLAYER_STATE2", e.ToString());
            }

            if (packet.Size < 18)
            {
                Plr.IsMoving = false;
                return;
            }

            UInt16 Key = packet.GetUint16();

            byte MoveByte   = packet.GetUint8();
            byte UnkByte    = packet.GetUint8();
            byte CombatByte = packet.GetUint8();
            byte RotateByte = packet.GetUint8();

            UInt16 Heading = packet.GetUint16R();
            UInt16 X       = packet.GetUint16R();
            UInt16 Y       = packet.GetUint16R();
            byte   Unk1    = packet.GetUint8();
            UInt16 Z       = packet.GetUint16R();
            byte   Unk2    = packet.GetUint8();

            Heading /= 8;
            X       /= 2;
            Y       /= 2;
            Z       /= 2;

            if (CombatByte >= 50 && CombatByte < 0x92 || CombatByte == 0xDF)
            {
                if (Plr.LastCX != 0 && Plr.LastCY != 0)
                {
                    if (Plr.LastCX > 12288 && X < 4096)
                    {
                        Plr.SetOffset((ushort)(Plr.XOffset + 1), Plr.YOffset);
                    }
                    else if (X > 12288 && Plr.LastCX < 4096)
                    {
                        Plr.SetOffset((ushort)(Plr.XOffset - 1), Plr.YOffset);
                    }

                    if (Plr.LastCY > 24576 && Y < 8192)
                    {
                        Plr.SetOffset(Plr.XOffset, (ushort)(Plr.YOffset + 1));
                    }
                    else if (Y > 24576 && Plr.LastCY < 8192)
                    {
                        Plr.SetOffset(Plr.XOffset, (ushort)(Plr.YOffset - 1));
                    }
                }

                Plr.LastCX = X;
                Plr.LastCY = Y;

                X        = Plr.Zone.CalculCombat(X, Plr.XOffset, true);
                Y        = Plr.Zone.CalculCombat(Y, Plr.YOffset, false);
                Heading /= 2;
                Z       += 32768;
                Z       /= 4;
            }
            else
            {
                if (Plr.LastX != 0 && Plr.LastY != 0)
                {
                    if (Plr.LastX > 24576 && X < 4096)
                    {
                        Plr.SetOffset((ushort)(Plr.XOffset + 1), Plr.YOffset);
                    }
                    else if (Plr.LastX < 4096 && X > 24576)
                    {
                        Plr.SetOffset((ushort)(Plr.XOffset - 1), Plr.YOffset);
                    }

                    if (Plr.LastY > 24576 && Y < 4096)
                    {
                        Plr.SetOffset(Plr.XOffset, (ushort)(Plr.YOffset + 1));
                    }
                    else if (Plr.LastY < 4096 && Y > 24576)
                    {
                        Plr.SetOffset(Plr.XOffset, (ushort)(Plr.YOffset - 1));
                    }
                }

                Plr.LastX = X;
                Plr.LastY = Y;

                X = Plr.Zone.CalculPin(X, Plr.XOffset, true);
                Y = Plr.Zone.CalculPin(Y, Plr.YOffset, false);
            }

            Plr.SetPosition(X, Y, Z, Heading);
        }