Exemple #1
0
 public static void SendToEventQueue(ScriptEvent sc_ev)
 {
     lock (eventqueueLock)
     {
         _eventqueue.Enqueue(sc_ev);
     }
 }
Exemple #2
0
        public static ScriptEvent EventQueueDequeue()
        {
            ScriptEvent sc_ev = null;

            lock (eventqueueLock)
            {
                sc_ev = (ScriptEvent)_eventqueue.Dequeue();
            }
            return(sc_ev);
        }
Exemple #3
0
 private void ScriptNetEventBB(NetPacket np)
 {
     if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
     {
         ScriptEvent sc_ev = new ScriptEvent();
         sc_ev.Type = EventType.UDPReceiveBB;
         sc_ev.Variables.Add(new ScriptVariable(np.Sender, "SENDER", Var_Types.STRING, Var_State.PUBLIC));
         sc_ev.Variables.Add(new ScriptVariable((long)np.SenderID, "SENDERID", Var_Types.INT, Var_State.PUBLIC));
         sc_ev.Variables.Add(new ScriptVariable(np.BBuff, "BBUFF", Var_Types.BYTEBUFFER, Var_State.PUBLIC));
         sc_ev.Variables.Add(new ScriptVariable(System.DateTime.Now.Ticks, "TIMESTAMP", Var_Types.INT, Var_State.PUBLIC));
         ScriptEngine.SendToEventQueue(sc_ev);
     }
 }
Exemple #4
0
 private void ScriptNetEvent(NetPacket np)
 {
     if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
     {
         ScriptEvent sc_ev = new ScriptEvent();
         sc_ev.Type = EventType.UDPReceive;
         sc_ev.Variables.Add(new ScriptVariable(np.Sender, "SENDER", Var_Types.STRING, Var_State.PUBLIC));
         sc_ev.Variables.Add(new ScriptVariable((long)np.SenderID, "SENDERID", Var_Types.INT, Var_State.PUBLIC));
         sc_ev.Variables.Add(new ScriptVariable(np.Name, "STRING1", Var_Types.STRING, Var_State.PUBLIC));
         sc_ev.Variables.Add(new ScriptVariable((long)np.Param1, "PARAM1", Var_Types.INT, Var_State.PUBLIC));
         sc_ev.Variables.Add(new ScriptVariable((long)np.Param2, "PARAM2", Var_Types.INT, Var_State.PUBLIC));
         sc_ev.Variables.Add(new ScriptVariable((long)np.Param3, "PARAM3", Var_Types.INT, Var_State.PUBLIC));
         sc_ev.Variables.Add(new ScriptVariable((long)np.Param4, "PARAM4", Var_Types.INT, Var_State.PUBLIC));
         sc_ev.Variables.Add(new ScriptVariable(System.DateTime.Now.Ticks, "TIMESTAMP", Var_Types.INT, Var_State.PUBLIC));
         ScriptEngine.SendToEventQueue(sc_ev);
     }
 }
Exemple #5
0
 private void ScriptNetEvent(NetPacket np)
 {
     if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
     {
         ScriptEvent sc_ev = new ScriptEvent();
         sc_ev.Type = EventType.UDPReceive;
         sc_ev.Variables.Add(new ScriptVariable(np.Sender, "SENDER", Var_Types.STRING, Var_State.PUBLIC));
         sc_ev.Variables.Add(new ScriptVariable((long)np.SenderID, "SENDERID", Var_Types.INT, Var_State.PUBLIC));
         sc_ev.Variables.Add(new ScriptVariable(np.Name, "STRING1", Var_Types.STRING, Var_State.PUBLIC));
         sc_ev.Variables.Add(new ScriptVariable((long)np.Param1, "PARAM1", Var_Types.INT, Var_State.PUBLIC));
         sc_ev.Variables.Add(new ScriptVariable((long)np.Param2, "PARAM2", Var_Types.INT, Var_State.PUBLIC));
         sc_ev.Variables.Add(new ScriptVariable((long)np.Param3, "PARAM3", Var_Types.INT, Var_State.PUBLIC));
         sc_ev.Variables.Add(new ScriptVariable((long)np.Param4, "PARAM4", Var_Types.INT, Var_State.PUBLIC));
         sc_ev.Variables.Add(new ScriptVariable(System.DateTime.Now.Ticks, "TIMESTAMP", Var_Types.INT, Var_State.PUBLIC));
         ScriptEngine.SendToEventQueue(sc_ev);
     }
 }
Exemple #6
0
        public static void MagicSkillCancel(ByteBuffer buff)
        {
            uint _caster = buff.ReadUInt32();

            if (_caster == Globals.gamedata.my_char.ID)
            {
                Globals.gamedata.my_char.ExpiresTime = 1;

                if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
                {
                    ScriptEvent sc_ev = new ScriptEvent();
                    sc_ev.Type = EventType.SkillCanceled;
                    ScriptEngine.SendToEventQueue(sc_ev);
                }

                if (Globals.gamedata.BOT_STATE == BotState.BuffWaiting)
                {
                    Globals.gamedata.my_char.Clear_Botting_Buffing(false);
                }
            }
            else
            {
                if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
                {
                    ScriptEvent sc_ev = new ScriptEvent();
                    sc_ev.Type = EventType.OtherSkillCanceled;
                    sc_ev.Variables.Add(new ScriptVariable((long)_caster, "USER_ID", Var_Types.INT, Var_State.PUBLIC));
                    ScriptEngine.SendToEventQueue(sc_ev);
                }
            }
        }
Exemple #7
0
        public static void MagicSkillLaunched(ByteBuffer buff)
        {
            if (Globals.gamedata.Chron >= Chronicle.CT3_0)
            {
                buff.ReadUInt32();  //00 00 00 00 
            }
            uint _caster = buff.ReadUInt32();
            uint _skillID = buff.ReadUInt32();
            uint _skillLevel = buff.ReadUInt32();
            uint _targetshit = buff.ReadUInt32();//0 = failed
            ArrayList _targets = new ArrayList();

            for (int i = 0; i < _targetshit; i++)
            {
                //more than 1 target id if targetshit > 1
                uint _targetID = buff.ReadUInt32();

                _targets.Add(_targetID);
            }

            /*if (_targetshit == 0)
            {
                //failed or some shit...
                return;
            }*/

            //not setting caster combat to true?
            StopMoveStartCombat(_caster, false);

            if (_caster == Globals.gamedata.my_char.ID)
            {                
                // Globals.gamedata.my_char.HitTime = 0;
                // Globals.l2net_home.Add_Text("MagicSkillLaunched setting hit time to 0 (" + Globals.gamedata.my_char.HitTime + ")", Globals.Cyan, TextType.BOT);

                if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
                {
                    ScriptEvent sc_ev = new ScriptEvent();
                    sc_ev.Type = EventType.SkillLaunched;
                    sc_ev.Variables.Add(new ScriptVariable((long)_skillID, "SKILL_ID", Var_Types.INT, Var_State.PUBLIC));
                    sc_ev.Variables.Add(new ScriptVariable((long)_skillLevel, "SKILL_LEVEL", Var_Types.INT, Var_State.PUBLIC));
                    sc_ev.Variables.Add(new ScriptVariable((long)_targetshit, "TARGET_HIT", Var_Types.INT, Var_State.PUBLIC));
                    ScriptEngine.SendToEventQueue(sc_ev);
                }

                if (Globals.gamedata.BOT_STATE == BotState.BuffWaiting)
                {
                    if (Globals.gamedata.my_char.BuffTarget == 0)
                    {
                        Globals.gamedata.my_char.Clear_Botting_Buffing(true);
                        return;
                    }

                    if (_targets.Contains(Globals.gamedata.my_char.BuffTarget))
                    {
                        //Add_Text("magicskill launched");

                        //launching a magic attack... this is sufficent for having used our skill
                        Globals.gamedata.my_char.Clear_Botting_Buffing(true);
                        return;
                    }
                }
            }
            else
            {
                if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
                {
                    ScriptEvent sc_ev = new ScriptEvent();
                    sc_ev.Type = EventType.OtherSkillLaunched;
                    sc_ev.Variables.Add(new ScriptVariable((long)_caster, "USER_ID", Var_Types.INT, Var_State.PUBLIC));
                    sc_ev.Variables.Add(new ScriptVariable((long)_skillID, "SKILL_ID", Var_Types.INT, Var_State.PUBLIC));
                    sc_ev.Variables.Add(new ScriptVariable((long)_skillLevel, "SKILL_LEVEL", Var_Types.INT, Var_State.PUBLIC));
                    sc_ev.Variables.Add(new ScriptVariable((long)_targetshit, "TARGET_HIT", Var_Types.INT, Var_State.PUBLIC));
                    ScriptEngine.SendToEventQueue(sc_ev);
                }

                //force target for the npc
                foreach (uint _target in _targets)
                {
                    TargetType type = Util.GetType(_target);

                    Globals.NPCLock.EnterReadLock();
                    try
                    {
                        NPCInfo npc = Util.GetNPC(_caster);

                        if (npc != null)
                        {
                            npc.TargetID = _target;
                            npc.CurrentTargetType = type;
                        }
                    }
                    finally
                    {
                        Globals.NPCLock.ExitReadLock();
                    }
                }
                //end of force target for the npc
            }
        }
Exemple #8
0
        public static void EnterCombat(ByteBuffer inp, bool incombat)
        {
            uint _ID = inp.ReadUInt32();
            uint combat;//byte

            if (incombat)
            {
                combat = 1;
            }
            else
            {
                combat = 0;
            }

            TargetType type = Util.GetType(_ID);

            switch (type)
            {
                case TargetType.SELF:
                    Globals.gamedata.my_char.isInCombat = combat;

                    if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
                    {
                        ScriptEvent sc_ev = new ScriptEvent();
                        if (incombat)
                            sc_ev.Type = EventType.SelfEnterCombat;
                        else
                            sc_ev.Type = EventType.SelfLeaveCombat;
                        ScriptEngine.SendToEventQueue(sc_ev);
                    }
                    break;
                case TargetType.MYPET:
                    Globals.gamedata.my_pet.isInCombat = combat;
                    break;
                case TargetType.MYPET1:
                    Globals.gamedata.my_pet1.isInCombat = combat;
                    break;
                case TargetType.MYPET2:
                    Globals.gamedata.my_pet2.isInCombat = combat;
                    break;
                case TargetType.MYPET3:
                    Globals.gamedata.my_pet3.isInCombat = combat;
                    break;
                case TargetType.PLAYER:
                    Globals.PlayerLock.EnterReadLock();
                    try
                    {
                        CharInfo player = Util.GetChar(_ID);

                        if (player != null)
                        {
                            player.isInCombat = combat;
                        }
                    }
                    finally
                    {
                        Globals.PlayerLock.ExitReadLock();
                    }
                    break;
                case TargetType.NPC:
                    Globals.NPCLock.EnterReadLock();
                    try
                    {
                        NPCInfo npc = Util.GetNPC(_ID);

                        if (npc != null)
                        {
                            npc.isInCombat = combat;
                        }
                    }
                    finally
                    {
                        Globals.NPCLock.ExitReadLock();
                    }
                    break;
            }
        }
Exemple #9
0
        public static void SystemMessage(ByteBuffer buffe)
        {
            //64 28 04 00 00 02 00 00 00 01 00 00 00 07 00 00 00 08 00 00 00 10 16 00 00 AC 00 CF 1C 
            //64 5F 00 00 00 02 00 00 00 06 00 00 00 3D 13 00 00 00 00 00 00 01 00 00 00 FA 01 00 00 
            uint type = buffe.ReadUInt32();

            string message = SystemMessageInternal(type, buffe);
            int red = 255;
            int green = 255;
            int blue = 255;

            try
            {
                red = (int)((SystemMsg)Globals.systemmsg[type]).Red;
                green = (int)((SystemMsg)Globals.systemmsg[type]).Green;
                blue = (int)((SystemMsg)Globals.systemmsg[type]).Blue;
            }
            catch
            {
            }

            Globals.l2net_home.Add_Text(message, new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(255, red, green, blue)), TextType.SYSTEM);

            /*if (Globals.gamedata.BOT_STATE == 3)
			{
				if(type == 46)//use skill
				{
					//changing of bot state based on successful skill done elsewhere now
					//Globals.gamedata.my_char.Clear_Botting_Buffing();
				}
				//did our buff fail?... it shouldnt have because of our checks before hand... but just incase
				if(type == 48)//not ready at this time
				{
                    Globals.gamedata.my_char.Clear_Botting_Buffing(false);
				}
				if(type == 50)//target cannot be found
				{
                    Globals.gamedata.my_char.Clear_Botting_Buffing(false);
				}
				if(type == 51)//cannot use skill on self
				{
                    Globals.gamedata.my_char.Clear_Botting_Buffing(false);
				}
				if(type == 113)//cannot use skill unsuitable terms
				{
                    Globals.gamedata.my_char.Clear_Botting_Buffing(false);
				}
				if(type == 181)//cannot see target
				{
                    Globals.gamedata.my_char.Clear_Botting_Buffing(false);
				}
				if(type == 1123)//cannt use skill over weight
				{
                    Globals.gamedata.my_char.Clear_Botting_Buffing(false);
				}
			}*/

            /* Freya:
 * 14:51:47 :[CLIENT DUMP: 38 00 00 00 A0 4F 19 00 93 23 D1 48 //??? 0x38
 * 14:51:47 :[CLIENT DUMP: D0 1A 00 59 07 5C 7B 82 43 A7 A9 6F 20 50 89 5D 62 9B 06 3E 29 04 F0 77 58 1C BE 09 00 2A AD 67 C1 04 43 D9 9D 75 A5 2F 58 12 2A 24 FF BC CF 98 AA 0F FF 9D 0F 31 FD 55 B7 76 F9 EA A7 65 70 EF 64 5F 49 //somethinglong1
 * 14:51:47 :[CLIENT DUMP: CB 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 //GameGuardReply = 0xCB,
*/

            if (type == 0x22  && Globals.gamedata.OOG) //Welcome to the world of Lineage II
            {
                if (Globals.gamedata.Chron >= Chronicle.CT2_5)
                {
                    //ServerPackets.Somethinglong1;
                    ServerPackets.RequestMagicSkillList();
                }

                //request skills
                if (Globals.Got_Skills == false)
                {
                    ServerPackets.RequestSkillList();
                    Globals.Got_Skills = true;
                }
            }

            switch (type)
            {
                case 17:        // Not Enough HP
                case 18:        // Not Enough MP
                case 109:       // Invalid Target                
                case 2156:      // There are not enough necessary items to use the skill
                case 2161:      // There is not enough space to move, the skill cannot be used.
                case 2167:      // A malicious skill cannot be used in a peace zone.
                    Globals.gamedata.my_char.ExpiresTime = 1;
                    break;
                case 139:                    
                    Globals.gamedata.my_char.Resisted = 1;
                    break;
                case 181:       // Cannot See Target
                    Globals.gamedata.my_char.CannotSeeTarget = true;
                    Globals.gamedata.my_char.ExpiresTime = 1;
                    break;
                case 357:       // It has already been spoiled.
                    Globals.gamedata.my_char.TargetSpoiled = true;
                    Globals.gamedata.my_char.ExpiresTime = 1;
                    break;
                case 612:       // The Spoil condition has been activated.
                    Globals.gamedata.my_char.TargetSpoiled = true;
                    break;
                case 1987:
                    if (Globals.ToggleBottingifGMAction)
                    {
                        Globals.l2net_home.Add_Text("Warning, GM performed an action on you!", Globals.Red, TextType.ALL);
                        Globals.l2net_home.Toggle_Botting(1);
                    }
                    break;
            }

            if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
            {
                ScriptEvent sc_ev = new ScriptEvent();
                sc_ev.Type = EventType.SystemMessage;
                sc_ev.Variables.Add(new ScriptVariable((long)type, "MESSAGETYPE", Var_Types.INT, Var_State.PUBLIC));
                sc_ev.Variables.Add(new ScriptVariable(message, "MESSAGE", Var_Types.STRING, Var_State.PUBLIC));
                ScriptEngine.SendToEventQueue(sc_ev);
            }
        }
Exemple #10
0
 private void ScriptNetEventBB(NetPacket np)
 {
     if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
     {
         ScriptEvent sc_ev = new ScriptEvent();
         sc_ev.Type = EventType.UDPReceiveBB;
         sc_ev.Variables.Add(new ScriptVariable(np.Sender, "SENDER", Var_Types.STRING, Var_State.PUBLIC));
         sc_ev.Variables.Add(new ScriptVariable((long)np.SenderID, "SENDERID", Var_Types.INT, Var_State.PUBLIC));
         sc_ev.Variables.Add(new ScriptVariable(np.BBuff, "BBUFF", Var_Types.BYTEBUFFER, Var_State.PUBLIC));
         sc_ev.Variables.Add(new ScriptVariable(System.DateTime.Now.Ticks,"TIMESTAMP",Var_Types.INT, Var_State.PUBLIC));
         ScriptEngine.SendToEventQueue(sc_ev);
     }
 }
Exemple #11
0
		private void ClientReadThread()
		{
            byte[] buffread = new byte[Globals.BUFFER_MAX];
			byte[] buffpacket;
            byte[] buffpacketin;

			int cnt = 0;
			int size = 0;
            int ggcnt = 0;
            bool forward = true;

			ByteBuffer bbuffer0;
            System.Text.StringBuilder dumpbuilder;

			//Add_Text("Welcome to the game loop",Color.Red);

			try
			{
				while(Globals.gamedata.running && !Globals.gamedata.OOG)
				{
                    cnt += Globals.Game_ClientSocket.Receive(buffread, cnt, Globals.BUFFER_PACKET - cnt, System.Net.Sockets.SocketFlags.None);
					size = System.BitConverter.ToUInt16(buffread,0);

					while(cnt >= size && cnt > 2)
					{
						//if we got partial shit we cant use, read some more until it is full
						while(size > cnt)
						{
                            cnt += Globals.Game_ClientSocket.Receive(buffread, cnt, Globals.BUFFER_PACKET - cnt, System.Net.Sockets.SocketFlags.None);
						}

						buffpacketin = new byte[size - 2];
                        buffpacket = new byte[size - 2];

                        Array.Copy(buffread, 2, buffpacketin, 0, size - 2);

						Globals.gamedata.crypt_clientin.decrypt(buffpacketin);

                        Array.Copy(buffpacketin, 0, buffpacket, 0, size - 2);

                        if (Globals.Mixer != null)
                        {
                            Globals.Mixer.Decrypt0(buffpacket);
                        }
                        if (Globals.pck_thread.pck_recording)
                        {

                            pck_window_dat pck_dat = new pck_window_dat(buffpacket);
                            pck_dat.action = 1;
                            pck_dat.type = 1;
                            pck_dat.time = System.DateTime.Now.TimeOfDay.ToString();
                            Globals.pck_thread.mine_queue.Enqueue(pck_dat);
                             
                        }
#if DEBUG
                        try
                        {
                            //
                           /* if (Globals.pck_thread.pck_recording)
                             {
                            // *                             lock (Globals.pck_thread.lock_obj)
                            // {
                                 pck_window_dat pck_dat = new pck_window_dat(buffpacket);
                                 pck_dat.action = 1;
                                 pck_dat.type = 1;
                                 pck_dat.time = System.DateTime.Now.TimeOfDay.ToString();
                                 Globals.pck_thread.mine_queue.Enqueue(pck_dat);
                             //* }
                             }*/
                            //
                            Globals.clientdataout.WriteLine("packet...-size: " + size.ToString() + " -count:" + cnt.ToString() + " :::time:::" + System.DateTime.Now.TimeOfDay.ToString() + ":::");
                            Globals.clientdataout.WriteLine("-data from client to bot hex-");
                            for (uint i = 0; i < size - 2; i++)
                            {
                                Globals.clientdataout.Write(buffpacket[i].ToString("X2"));
                                Globals.clientdataout.Write(" ");
                            }
                            Globals.clientdataout.WriteLine("");
                            Globals.clientdataout.WriteLine("-data from client to bot string-");
                            for (uint i = 0; i < size - 2; i++)
                            {
                                Globals.clientdataout.Write((char)buffpacket[i]);
                            }
                            Globals.clientdataout.WriteLine("");
                        }
                        catch
                        {
                            //failed to write... oh well
                        }
#endif

                        if (Globals.DumpModeClient)
                        {
                            dumpbuilder = new System.Text.StringBuilder();

                            for (int i = 0; i < size - 2; i++)
                            {
                                dumpbuilder.Append(buffpacket[i].ToString("X2"));
                                dumpbuilder.Append(" ");
                            }
                            Globals.l2net_home.Add_Dump(dumpbuilder.ToString(), false);
                        }

						//shift the data over by size
						for(uint i = 0; i < cnt - size; i ++)
						{
							buffread[i] = buffread[size + i];
						}

						cnt -= size;

						if(buffpacket.Length > 0)
						{
                            forward = true;

                            if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
                            {
                                if ((PClient)buffpacket[0] == PClient.EXPacket)
                                {
                                    if (ScriptEngine.Blocked_ClientPacketsEX.ContainsKey(System.Convert.ToInt32(buffpacket[1])))
                                    {
                                        forward = false;
                                    }

                                    if (ScriptEngine.ClientPacketsEXContainsKey(System.Convert.ToInt32(buffpacket[1])))
                                    {
                                        ByteBuffer bb = new ByteBuffer(buffpacket);

                                        ScriptEvent sc_ev = new ScriptEvent();
                                        sc_ev.Type = EventType.ClientPacketEX;
                                        sc_ev.Type2 = System.Convert.ToInt32(buffpacket[1]);
                                        sc_ev.Variables.Add(new ScriptVariable(bb, "PACKET", Var_Types.BYTEBUFFER, Var_State.PUBLIC));
                                        sc_ev.Variables.Add(new ScriptVariable(System.DateTime.Now.Ticks, "TIMESTAMP", Var_Types.INT, Var_State.PUBLIC));
                                        ScriptEngine.SendToEventQueue(sc_ev);
                                    }
                                }
                                else
                                {
                                    if (ScriptEngine.Blocked_ClientPackets.ContainsKey(System.Convert.ToInt32(buffpacket[0])))
                                    {
                                        forward = false;
                                    }

                                    if (ScriptEngine.ClientPacketsContainsKey(System.Convert.ToInt32(buffpacket[0])))
                                    {
                                        ByteBuffer bb = new ByteBuffer(buffpacket);

                                        ScriptEvent sc_ev = new ScriptEvent();
                                        sc_ev.Type = EventType.ClientPacket;
                                        sc_ev.Type2 = System.Convert.ToInt32(buffpacket[0]);
                                        sc_ev.Variables.Add(new ScriptVariable(bb, "PACKET", Var_Types.BYTEBUFFER, Var_State.PUBLIC));
                                        sc_ev.Variables.Add(new ScriptVariable(System.DateTime.Now.Ticks, "TIMESTAMP", Var_Types.INT, Var_State.PUBLIC));
                                        ScriptEngine.SendToEventQueue(sc_ev);
                                    }
                                }
                            }

							//this is where we would want to handle packets sent by the client
                            switch ((PClient)buffpacket[0])
							{
                                case PClient.AuthLogin://protocol version
                                    int prot = System.BitConverter.ToInt16(buffpacket, 1);
                                    Globals.l2net_home.Add_Text("protocol version: " + prot.ToString(), Globals.Red, TextType.BOT);

                                    if (prot == -2)
                                    {
                                        Globals.l2net_home.Add_Text("-2 protocol... just a ping... we've been had XD...", Globals.Red, TextType.BOT);
                                    }
                                    else
                                    {
                                        //valid protocol...
                                        Globals.l2net_home.Add_Text("valid protocol...", Globals.Red, TextType.BOT);
                                    }
                                    break;
								case PClient.GameGuardReply://gameguard reply
                                    if (Globals.GG_Servermode)
                                    {
                                        if (Globals.GG_QueryReceived)
                                        {
                                            ggcnt++;
                                            if (ggcnt == 1)
                                            {
                                                //GameGuardServer.send_gg_answer(buffpacket, false);
                                                GameGuardServer.SendGGReply(buffpacket);
                                            }
                                            
                                            if (ggcnt == 2)
                                            {
                                                Globals.GG_QueryReceived = false;
                                                //GameGuardServer.send_gg_answer(buffpacket, true);
                                                GameGuardServer.SendGGReply(buffpacket);
                                                ggcnt = 0;
                                            }
                                            forward = false;
                                        }
                                    }
                                    if (Globals.Script_Debugging)
                                    {
                                        string gg = "";

                                        for (int i = 1; i < buffpacket.Length; i++)
                                        {
                                            gg += buffpacket[i].ToString("X2") + " ";
                                        }

                                        Globals.l2net_home.Add_Debug("GameGuard Reply: " + gg);
                                    }
									break;
								case PClient.Say2://say text
									if(Globals.gamedata.OOG == false)
									{
                                        ByteBuffer bbuff = new ByteBuffer(buffpacket);

                                        bbuff.ReadByte();
                                        string start = bbuff.ReadString();
                                        uint type = bbuff.ReadUInt32();
                                        string end = bbuff.ReadString();
                                        
                                        //wanna handle text if prefaced with "-"
                                        //since these are commands to the bot

                                        if (start.StartsWith("--"))
                                        {
                                            forward = false;

                                            start = start.Substring(1, start.Length - 1);

                                            ServerPackets.Send_Text(type, start, end);
                                        }
                                        else if (start.StartsWith("-"))
                                        {
                                            forward = false;

                                            start = start.Substring(1, start.Length - 1);

                                            if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
                                            {
                                                ScriptEvent sc_ev = new ScriptEvent();
                                                sc_ev.Type = EventType.ChatToBot;
                                                sc_ev.Variables.Add(new ScriptVariable((long)type, "MESSAGETYPE", Var_Types.INT, Var_State.PUBLIC));
                                                sc_ev.Variables.Add(new ScriptVariable(end, "TARGETNAME", Var_Types.STRING, Var_State.PUBLIC));
                                                sc_ev.Variables.Add(new ScriptVariable(start, "MESSAGE", Var_Types.STRING, Var_State.PUBLIC));
                                                ScriptEngine.SendToEventQueue(sc_ev);
                                            }
                                        }
									}
									break;
                                case PClient.CharacterSelect:
                                    if ((!Globals.gamedata.OOG) && (!System.String.IsNullOrEmpty(Globals.SecurityPin)) && (Globals.gamedata.SecurityPinOldClient) && (!Globals.gamedata.SecurityPinSent))
                                    {
                                        ServerPackets.RequestSecurityPinWindow();

                                        while (!Globals.gamedata.SecurityPinWindow)
                                        {
                                            System.Threading.Thread.Sleep(100);
                                        }

                                        Globals.l2net_home.Add_Text("Sending security pin: " + Globals.SecurityPin, Globals.Green, TextType.BOT);

                                        ServerPackets.SecurityPin();

                                        while (!Globals.gamedata.SecurityPinOk)
                                        {
                                            System.Threading.Thread.Sleep(100);
                                        }
                                        Globals.l2net_home.Add_Text("Pin OK", Globals.Green, TextType.BOT);
                                        Globals.gamedata.SecurityPinSent = true;
                                    }
                                    break;
							}

                            if (forward)
                            {
                                //send packets from the client right to the server
                                bbuffer0 = new ByteBuffer(buffpacketin);

                                Globals.gamedata.SendToGameServerNF(bbuffer0);
                            }
						}

						if(cnt > 2)
							size = System.BitConverter.ToUInt16(buffread,0);
					}//end of while loop
				}//end of while running
			}
            catch (System.Exception e)
            {
                Globals.l2net_home.Add_Error("crash: ClientReadThread : " + e.Message);
                network_exception();
            }
		}//end of read data
Exemple #12
0
        public static void Load_PartyInfo(ByteBuffer buff)
        {
            Globals.gamedata.PartyLeader = buff.ReadUInt32();
            Globals.gamedata.PartyLoot = buff.ReadUInt32();
            uint cnt = buff.ReadUInt32();

            Globals.PartyLock.EnterWriteLock();
            try
            {
                Globals.gamedata.PartyMembers.Clear();
                Globals.gamedata.PartyCount = cnt;

                for (uint i = 0; i < cnt; i++)
                {
                    PartyMember pmem = new PartyMember();
                    pmem.Load(buff);

                    if (Globals.gamedata.PartyMembers.ContainsKey(pmem.ID))
                    {
                        Globals.gamedata.PartyMembers[pmem.ID] = pmem;
                    }
                    else
                    {
                        Globals.gamedata.PartyMembers.Add(pmem.ID, pmem);
                    }
                }
            }
            finally
            {
                Globals.PartyLock.ExitWriteLock();
            }

            if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
            {
                ScriptEvent sc_ev = new ScriptEvent();
                sc_ev.Type = EventType.JoinParty;
                ScriptEngine.SendToEventQueue(sc_ev);
            }
        }
Exemple #13
0
        public static void Revive(uint id)
        {
            TargetType type = Util.GetType(id);

            switch (type)
            {
                case TargetType.SELF:
                    //alive again
                    Globals.l2net_home.Hide_Dead();

                    Globals.gamedata.my_char.isAlikeDead = 0;

                    if (Globals.gamedata.yesno_state == 5)
                    {
                        Globals.l2net_home.Hide_YesNo();
                    }

                    if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
                    {
                        ScriptEvent sc_ev = new ScriptEvent();
                        sc_ev.Type = EventType.SelfRez;
                        ScriptEngine.SendToEventQueue(sc_ev);
                    }
                    break;
                case TargetType.MYPET:
                    Globals.gamedata.my_pet.isAlikeDead = 0;
                    break;
                case TargetType.MYPET1:
                    Globals.gamedata.my_pet1.isAlikeDead = 0;
                    break;
                case TargetType.MYPET2:
                    Globals.gamedata.my_pet2.isAlikeDead = 0;
                    break;
                case TargetType.MYPET3:
                    Globals.gamedata.my_pet3.isAlikeDead = 0;
                    break;
                case TargetType.PLAYER:
                    Globals.PlayerLock.EnterReadLock();
                    try
                    {
                        CharInfo player = Util.GetChar(id);

                        if (player != null)
                        {
                            player.isAlikeDead = 0;
                        }
                    }
                    finally
                    {
                        Globals.PlayerLock.ExitReadLock();
                    }
                    break;
                case TargetType.NPC:
                    Globals.NPCLock.EnterReadLock();
                    try
                    {
                        NPCInfo npc = Util.GetNPC(id);

                        if (npc != null)
                        {
                            npc.isAlikeDead = 0;
                        }
                    }
                    finally
                    {
                        Globals.NPCLock.ExitReadLock();
                    }
                    break;
            }
        }
        private static void HandlePackets()
        {
            ByteBuffer buffe;
            uint b0 = 0, b1 = 0;//byte
            string last_p = "";//, last_p2 = "";

            while (Globals.gamedata.GetCount_DataToBot() > 0)
            {
                try
                {
                    //buffe = null;

                    Globals.GameReadQueueLock.EnterWriteLock();
                    try
                    {
                        buffe = (ByteBuffer)Globals.gamedata.gamereadqueue.Dequeue();
                    }
                    catch (System.Exception e)
                    {
                        Globals.l2net_home.Add_Error("Packet Error Reading Queue : " + e.Message);
                        break;
                    }
                    finally
                    {
                        Globals.GameReadQueueLock.ExitWriteLock();
                    }

                    //buffe contains unencoded data
                    b0 = buffe.ReadByte();
                    //last_p2 = last_p;
                    last_p = b0.ToString("X2");

                    //do we have an event for this packet?
                    if (ScriptEngine.ServerPacketsContainsKey((int)b0))
                    {
                        ScriptEvent sc_ev = new ScriptEvent();
                        sc_ev.Type = EventType.ServerPacket;
                        sc_ev.Type2 = (int)b0;
                        sc_ev.Variables.Add(new ScriptVariable(buffe, "PACKET", Var_Types.BYTEBUFFER, Var_State.PUBLIC));
                        sc_ev.Variables.Add(new ScriptVariable(System.DateTime.Now.Ticks, "TIMESTAMP", Var_Types.INT, Var_State.PUBLIC));
                        ScriptEngine.SendToEventQueue(sc_ev);
                    }

                    switch ((PServer)b0)
                    {
                        case PServer.MTL:
                            ClientPackets.MoveToLocation(buffe);
                            break;
                        case PServer.NS:
                            ClientPackets.NPCSay(buffe);
                            break;
                        case PServer.CI:
                            ClientPackets.CharInfo(buffe);
                            break;
                        case PServer.RelationChanged:
                            ClientPackets.RelationChanged(buffe);
                            break;
                        case PServer.UI:
                            ClientPackets.UserInfo(buffe);
                            break;
                        case PServer.Attack:
                            ClientPackets.Attack_Packet(buffe);
                            break;
                        case PServer.Die:
                            ClientPackets.Die_Packet(buffe);
                            break;
                        case PServer.Revive:
                            ClientPackets.Revive(buffe.ReadUInt32());
                            break;
                        case PServer.ChangeMoveType:
                            ClientPackets.ChangeMoveType(buffe);
                            break;
                        case PServer.ChangeWaitType:
                            ClientPackets.ChangeWaitType(buffe);
                            break;
                        case PServer.AttackDeadTarget:
                            ClientPackets.AttackCanceled_Packet(buffe);
                            break;
                        case PServer.SpawnItem://add item (to ground)
                            ClientPackets.AddItem(buffe);
                            break;
                        case PServer.DropItem:
                            ClientPackets.ItemDrop(buffe);
                            break;
                        case PServer.GetItem:
                            ClientPackets.Get_Item(buffe);
                            break;
                        case PServer.StatusUpdate:
                            ClientPackets.StatusUpdate(buffe);
                            break;
                        case PServer.NpcHtmlMessage:
                            NPC_Chat.Npc_Chat(buffe);
                            break;
                        case PServer.BuyList: //Buylist
                            ClientPackets.BuyList(buffe);
                            break;
                        case PServer.DeleteObject:
                            ClientPackets.DeleteItem(buffe);
                            break;
                        case PServer.CharacterSelectionInfo:
                            Globals.login_window.CharList(buffe);
                            //this is the list of chars
                            //not handled by ig

                            //need to handle this packet here and not on the oog login
                            //on ig, the list will just show up, then disappear on 0x15 CharSelected so its all good
                            break;
                        case PServer.CharSelected:
                            ClientPackets.CharSelected(buffe);
                            break;
                        case PServer.NpcInfo:
                            ClientPackets.NPCInfo(buffe);
                            break;
                        case PServer.ServerObjectInfo:
                            ClientPackets.ServerObjectInfo(buffe);
                            break;
                        case PServer.StaticObject:
                            ClientPackets.StaticObjectInfo(buffe);
                            break;
                        case PServer.ItemList:
                            ClientPackets.ItemList(buffe);
                            break;
                        case PServer.SunRise:
                            Globals.l2net_home.Add_Text("[The sun has just risen]", Globals.Gray, TextType.SYSTEM);
                            break;
                        case PServer.SunSet:
                            Globals.l2net_home.Add_Text("[The sun has just set]", Globals.Gray, TextType.SYSTEM);
                            break;
                        case PServer.TradeStart:
                            break;
                        case PServer.TradeDone:
                            try
                            {
                                Globals.tradewindow.Close();
                            }
                            catch
                            {
                                //trade window is not opened.
                            }
                            break;
                        case PServer.ActionFailed:
                            //l2j is ghei and throws this packet at us a lot
                            // (Freya) Retail also causes this packet to be sent before any Attack or skill use that requires CTRL
                            break;
                        case PServer.InventoryUpdate:
                            AddInfo.Inventory_Update(buffe);
                            break;
                        case PServer.TeleportToLocation:
                            ClientPackets.Teleport(buffe);
                            break;
                        case PServer.MyTargetSelected:
                            ClientPackets.MyTargetSelected(buffe);
                            break;
                        case PServer.TargetSelected:
                            ClientPackets.TargetSelected(buffe, true);
                            break;
                        case PServer.TargetUnselected:
                            ClientPackets.TargetSelected(buffe, false);
                            break;
                        case PServer.AutoAttackStart:
                            //4bytes target id
                            ClientPackets.EnterCombat(buffe, true);
                            break;
                        case PServer.AutoAttackStop:
                            //4bytes target id
                            ClientPackets.EnterCombat(buffe, false);
                            break;
                        case PServer.SocialAction:
                            ClientPackets.Social_Action(buffe);
                            break;
                        case PServer.AskJoinPledge:
                            ClientPackets.RequestJoinClan(buffe);
                            break;
                        case PServer.AskJoinParty:
                            ClientPackets.RequestJoinParty(buffe);
                            break;
                        case PServer.TradeRequest:
                            ClientPackets.TradeRequest(buffe);
                            break;
                        case PServer.ShortCutRegister:
                            ClientPackets.Load_Shortcut(buffe);
                            break;
                        case PServer.ShortCutInit:
                            ClientPackets.Load_Shortcuts(buffe);
                            break;
                        case PServer.StopMove:
                            ClientPackets.StopMove(buffe);
                            break;
                        case PServer.MagicSkillUser:
                            ClientPackets.MagicSkillUser(buffe);
                            break;
                        case PServer.MagicSkillCancelId:
                            //4bytes - ID of caster that canceled
                            ClientPackets.MagicSkillCancel(buffe);
                            break;
                        case PServer.CreatureSay:
                            ClientPackets.OtherMessage(buffe);
                            break;
                        case PServer.PartySmallWindowAll:
                            if (Globals.gamedata.yesno_state == 1)
                                Globals.l2net_home.Hide_YesNo();
                            ClientPackets.Load_PartyInfo(buffe);
                            AddInfo.Set_PartyVisible();
                            AddInfo.Set_PartyInfo();
                            break;
                        case PServer.PartySmallWindowAdd:
                            if (Globals.gamedata.yesno_state == 1)
                                Globals.l2net_home.Hide_YesNo();
                            ClientPackets.Add_PartyInfo(buffe);
                            AddInfo.Set_PartyVisible();
                            AddInfo.Set_PartyInfo();
                            break;
                        case PServer.PartySmallWindowDeleteAll:
                            ClientPackets.Delete_Party();
                            AddInfo.Set_PartyVisible();
                            AddInfo.Set_PartyInfo();
                            break;
                        case PServer.PartySmallWindowDelete:
                            ClientPackets.Delete_PartyInfo(buffe);
                            AddInfo.Set_PartyVisible();
                            AddInfo.Set_PartyInfo();
                            break;
                        case PServer.PartySmallWindowUpdate:
                            ClientPackets.Update_PartyInfo(buffe);
                            AddInfo.Set_PartyInfo();
                            break;
                        case PServer.PledgeShowMemberListAll:
                            ClientPackets.PledgeShowMemberListAll(buffe);
                            break;
                        case PServer.PledgeShowMemberListUpdate:
                            ClientPackets.PledgeShowMemberListUpdate(buffe);
                            break;
                        case PServer.PledgeShowMemberListAdd:
                            //changes the clan status of one char... need to update/add as needed
                            ClientPackets.PledgeShowMemberListAdd(buffe);
                            break;
                        case PServer.PledgeShowMemberListDelete:
                            ClientPackets.PledgeShowMemberListDelete(buffe);
                            break;
                        case PServer.PledgeShowInfoUpdate:
                            ClientPackets.PledgeShowInfoUpdate(buffe);
                            break;
                        case PServer.PledgeShowMemberListDeleteAll:
                            ClientPackets.PledgeShowMemberListDeleteAll(buffe);
                            break;
                        case PServer.AbnormalStatusUpdate:
                            ClientPackets.LoadBuffList(buffe);
                            break;
                        case PServer.PartySpelled:
                            ClientPackets.PartySpelled(buffe);
                            break;
                        case PServer.ShortBuffStatusUpdate:
                            ClientPackets.UpdateBuff(buffe);
                            break;
                        case PServer.SkillList:
                            ClientPackets.SkillList(buffe);
                            break;
                        case PServer.SkillCoolTime:
                            ClientPackets.SkillCoolTime(buffe);
                            break;
                        case PServer.RestartResponse:
                            ClientPackets.RestartResponse(buffe);
                            break;
                        case PServer.MoveToPawn:
                            ClientPackets.MoveToPawn(buffe);
                            break;
                        case PServer.ValidateLocation:
                            ClientPackets.Validate_Location(buffe, false);
                            //int id
                            //int rotation
                            break;
                        case PServer.SystemMessage:
                            ClientPackets.SystemMessage(buffe);
                            break;
                        case PServer.PledgeCrest:
                            ClientPackets.PledgeCrest(buffe);
                            break;
                        case PServer.PledgeInfo:
                            ClientPackets.PledgeInfo(buffe);
                            break;
                        case PServer.ValidateLocationInVehicle:
                            ClientPackets.Validate_Location(buffe, true);
                            break;
                        case PServer.MagicSkillLaunched:
                            ClientPackets.MagicSkillLaunched(buffe);
                            //Validate_Location(buffe,false);
                            break;
                        case PServer.FriendAddRequest:
                            ClientPackets.RequestJoinFriend(buffe);
                            break;
                        case PServer.LogOutOk:
                            //ok time to end
                            Globals.gamedata.running = false;
                            Globals.l2net_home.KillEverything();
                            break;
                        case PServer.PartyMemberPosition:
                            ClientPackets.Set_PartyLocations(buffe);
                            break;
                        case PServer.AskJoinAlly:
                            ClientPackets.RequestJoinAlly(buffe);
                            break;
                        case PServer.AllianceCrest:
                            ClientPackets.AllyCrest(buffe);
                            break;
                        case PServer.Earthquake:
                            //x,y,z,power,duration
                            Globals.l2net_home.Add_Text("[Earthquake at X:" + buffe.ReadInt32().ToString() + " Y:" + buffe.ReadInt32().ToString() + " Z:" + buffe.ReadInt32().ToString() + " Of Power:" + buffe.ReadInt32().ToString() + " For:" + buffe.ReadInt32().ToString() + "]", Globals.Gray, TextType.SYSTEM);
                            break;
                        case PServer.PledgeStatusChanged:
                            ClientPackets.ClanStatusChanged(buffe);
                            break;
                        case PServer.Dice:
                            ClientPackets.Dice(buffe);
                            break;
                        case PServer.HennaInfo:
                            ClientPackets.Set_Henna_Info(buffe);
                            break;
                        case PServer.ConfirmDlg:
                            ClientPackets.RequestReply(buffe);
                            break;
                        case PServer.SSQInfo://SignSky:
                            ClientPackets.SevenSignSky(buffe);
                            break;
                        case PServer.GameGuardQuery:
                            ClientPackets.GameGuardReply(buffe);
                            break;
                        case PServer.L2FriendSay:
                            ClientPackets.Get_Friend_Message(buffe);
                            break;
                        case PServer.EtcStatusUpdate:
                            ClientPackets.EtcStatusUpdate(buffe);
                            break;
                        case PServer.PetStatusShow:
                            ClientPackets.PetStatusShow(buffe);
                            break;
                        case PServer.PetInfo:
                            ClientPackets.PetInfo(buffe);
                            break;
                        case PServer.PetStatusUpdate:
                            ClientPackets.PetStatusUpdate(buffe);
                            break;
                        case PServer.PetDelete:
                            ClientPackets.PetDelete(buffe);
                            break;
                        case PServer.PetItemList:
                            ClientPackets.PetItemList(buffe);
                            if (Globals.petwindow != null)
                            {
                                Globals.petwindow.fill_pet_inventory();
                            }
                            break;
                        case PServer.PetInventoryUpdate:
                            AddInfo.PetInventory_Update(buffe);
                            if (Globals.petwindow != null)
                            {
                                Globals.petwindow.fill_pet_inventory();
                            }
                            break;
                        case PServer.NetPing:
                            ClientPackets.NetPing(buffe);
                            break;



                        case PServer.EXPacket:
                            b1 = buffe.ReadUInt16();
                            //buffe.ReadByte();

                            last_p = last_p + " " + b1.ToString("X2");

                            //do we have an event for this packet?
                            if (ScriptEngine.ServerPacketsEXContainsKey((int)b1))
                            {
                                ScriptEvent sc_ev = new ScriptEvent();
                                sc_ev.Type = EventType.ServerPacketEX;
                                sc_ev.Type2 = (int)b1;
                                sc_ev.Variables.Add(new ScriptVariable(buffe, "PACKET", Var_Types.BYTEBUFFER, Var_State.PUBLIC));
                                sc_ev.Variables.Add(new ScriptVariable(System.DateTime.Now.Ticks, "TIMESTAMP", Var_Types.INT, Var_State.PUBLIC));
                                ScriptEngine.SendToEventQueue(sc_ev);
                            }
                            //Globals.l2net_home.Add_Text(last_p);
                            switch ((PServerEX)b1)
                            {
                                /*case PServerEX.ExPledgeCrestLarge:
                                    //https://www.l2jserver.com/trac/browser/trunk/L2_GameServer_It/java/net/sf/l2j/gameserver/serverpackets/ExPledgeCrestLarge.java
                                    break;*/
                                case PServerEX.ExMailArrived:
                                    Globals.l2net_home.Add_Text("[Mail has arrived]");
                                    VoicePlayer.PlaySound(8);
                                    break;
                                case PServerEX.ExSetCompassZoneCode:
                                    ClientPackets.ExSetCompassZoneCode(buffe);
                                    break;
                                case PServerEX.ExShowScreenMessage:
                                    ClientPackets.ExShowScreenMessage(buffe);
                                    break;
                                case PServerEX.ExQuestHTML:
                                    if (Globals.gamedata.Chron >= Chronicle.CT2_3)
                                    {
                                        NPC_Chat.Npc_Chat(buffe);
                                    }
                                    break;
                                case PServerEX.ExSendUIEventPacket:
                                    if (Globals.gamedata.Chron >= Chronicle.CT3_2)
                                    {
                                        NPC_Chat.Npc_Chat(buffe);
                                    }
                                    break;
                                case PServerEX.ExQuestItemList:
                                    if (Globals.gamedata.Chron >= Chronicle.CT2_5)
                                    {
                                        ClientPackets.ExQuestItemList(buffe);
                                    }
                                    break;
                                case PServerEX.ExVitalityUpdate:
                                    if (Globals.gamedata.Chron >= Chronicle.CT2_1)
                                    {
                                        ClientPackets.ExVitalityUpdate(buffe);
                                    }
                                    break;
                                case PServerEX.ExShowReceivedPostList:
                                    ClientPackets.Load_ReceivedMails(buffe);
                                    break;
                                case PServerEX.ExShowSecurityPinWindow:
                                    Globals.gamedata.SecurityPinWindow = true;
                                    if ((!Globals.OOG) && (!System.String.IsNullOrEmpty(Globals.SecurityPin)) && (!Globals.gamedata.SecurityPinOldClient))
                                    {
                                        System.Threading.Thread.Sleep(3000);
                                        ServerPackets.SecurityPin();
                                        Globals.gamedata.SecurityPinSent = true;
                                    }
                                    break;
                                case PServerEX.ExSecurityPinCorrect:
                                    Globals.gamedata.SecurityPinOk = true;
                                    break;
                                case PServerEX.ExAcquireSkillInfo:
                                    ClientPackets.ExAcquireSkillInfo(buffe);
                                    break;
                                case PServerEX.ExNewSkillToLearnByLevelup:
                                    //Glory days
                                    ClientPackets.ExAcquireSkillInfo(buffe);
                                    break;
                                case PServerEX.ExtargetBuffs:
                                    ClientPackets.Extargetbuffs(buffe);
                                    break;
                                case PServerEX.ExPartyPetWindowAdd:
                                    ClientPackets.ExPartyPetWindowAdd(buffe);
                                    break;
                                case PServerEX.ExPartyPetWindowDelete:
                                    ClientPackets.ExPartyPetWindowDelete(buffe);
                                    break;
                                case PServerEX.ExNpcInfo:
                                    ClientPackets.ExNPCInfo(buffe);
                                    break;
                                case PServerEX.ExUserinfoItems:
                                    ClientPackets.ExUserInfoItems(buffe);
                                    break;
                                case PServerEX.ExUserinfoStats:
                                    ClientPackets.ExUserInfoStats(buffe);
                                    break;
                                case PServerEX.ExUserInfo:
                                    ClientPackets.EXUserInfo(buffe);
                                    break;
                            }
                            break;
                    }//end of switch on packet type

                }
                catch (System.Exception e)
                {
                    //Globals.l2net_home.Add_Error("Packet Error: " + last_p + " Previous Packet: " + last_p2 + " : " + e.Message);
                    Globals.l2net_home.Add_Error("Packet Error: " + last_p + " :: " + e.Message);
                }
            }//end of loop to handle queue data
        }//end of HandlePackets
Exemple #15
0
        private void Call_Event(ScriptEventCaller evn_call, ScriptEvent pop_event)
        {
            if (evn_call == null)
            {
                return;
            }
            //is the file loaded?
            if (!Files.ContainsKey(evn_call.File))
            {
                System.IO.StreamReader filein = new System.IO.StreamReader(evn_call.File);
                ScriptFile sf = new ScriptFile();
                sf.Name = evn_call.File;
                sf.ReadScript(filein);
                filein.Close();

                Files.Add(sf.Name, sf);
            }
            //find the function
            int dest_line = Get_Function_Line(evn_call.Function, evn_call.File);
            if (dest_line == -1)
            {
                ScriptEngine.Script_Error("EVENT CALLER: FUNCTION DOES NOT EXIST : " + evn_call.File + " : " + evn_call.Function);
                Globals.gamedata.CurrentScriptState = ScriptState.Error;
                return;
            }

            //create a new thread at the function...
            ScriptThread scr_thread = new ScriptThread();
            scr_thread.Current_File = evn_call.File;
            scr_thread.Line_Pos = dest_line + 1;

            VariableList stack_bottom = new VariableList();
            //copy the variables over
            foreach (ScriptVariable svar in pop_event.Variables)
            {
                stack_bottom.Add_Variable(svar);
            }
            scr_thread._stack.Add(stack_bottom);
            scr_thread.ID = GetUniqueThreadID();
            Threads.Add(scr_thread.ID, scr_thread);
        }
Exemple #16
0
        public static void Send_Text(int index, string total_text)
        {
            //did they even say anything?
            if (total_text.Length == 0)
                return;

            bool ok = false;
            string start = "";
            uint type = 0;
            string end = "";
            int marker;

            //change the first thing if needed
            if (index == 0)
            {
                switch (total_text[0])
                {
                    case '!'://shout
                        index = 1;
                        total_text = total_text.Substring(1, total_text.Length - 1);
                        break;
                    case '"'://tell
                        index = 2;
                        total_text = total_text.Substring(1, total_text.Length - 1);
                        break;
                    case '+'://trade
                        index = 8;
                        total_text = total_text.Substring(1, total_text.Length - 1);
                        break;
                    case '#'://party
                        index = 3;
                        total_text = total_text.Substring(1, total_text.Length - 1);
                        break;
                    case '@'://clan
                        index = 4;
                        total_text = total_text.Substring(1, total_text.Length - 1);
                        break;
                    case '$'://ally
                        index = 9;
                        total_text = total_text.Substring(1, total_text.Length - 1);
                        break;
                    case '%'://hero
                        index = 17;
                        total_text = total_text.Substring(1, total_text.Length - 1);
                        break;
                    case '&'://reply to gm
                        index = 7;
                        total_text = total_text.Substring(1, total_text.Length - 1);
                        break;
                    case '/'://run command
                        ServerPackets.Run_Command(total_text);
                        index = -1;
                        break;
                }
            }

            if (total_text.Length > Globals.MAX_MESSAGE_LEN)
            {
                total_text = total_text.Substring(0, Globals.MAX_MESSAGE_LEN);
            }

            switch (index)
            {
                case 0://all 0x00
                    type = 0x00;
                    start = total_text;
                    ok = true;
                    break;
                case 1://shout 0x01
                    type = 0x01;
                    start = total_text;
                    ok = true;
                    break;
                case 2://tell player 0x02
                    type = 0x02;
                    string inp = total_text;

                    marker = inp.IndexOf(' ');
                    try
                    {
                        end = inp.Substring(0, marker);
                    }
                    catch
                    {
                        end = "";
                    }
                    inp = inp.Remove(0, marker + 1);
                    start = inp;
                    ok = true;
                    break;
                case 3://party 0x03
                    type = 0x03;
                    start = total_text;
                    ok = true;
                    break;
                case 4://clan 0x04
                    type = 0x04;
                    start = total_text;
                    ok = true;
                    break;
                case 5://from gm 0x05
                    Globals.l2net_home.Add_Text("GM only tell -no message sent]", Globals.Red, TextType.ALL);
                    break;
                case 6://reply to petition from 0x06
                    type = 0x06;
                    start = total_text;
                    ok = true;
                    break;
                case 7://petition from gm 0x07
                    Globals.l2net_home.Add_Text("GM only chat in petition box -no message sent]", Globals.Red, TextType.ALL);
                    break;
                case 8://trade 0x08
                    type = 0x08;
                    start = total_text;
                    ok = true;
                    break;
                case 9://alliance 0x09
                    type = 0x09;
                    start = total_text;
                    ok = true;
                    break;
                case 10://announcement 0x0A
                    Globals.l2net_home.Add_Text("announcement -no message sent]", Globals.Red, TextType.ALL);
                    break;
                case 11://crash client 0x0B
                    Globals.l2net_home.Add_Text("boat message -no message sent]", Globals.Red, TextType.SYSTEM);
                    break;
                case 12://fake1 0x0C
                    Globals.l2net_home.Add_Text("bad -no message sent]", Globals.Red, TextType.BOT);
                    break;
                case 13://fake2 0x0D
                    Globals.l2net_home.Add_Text("bad -no message sent]", Globals.Red, TextType.BOT);
                    break;
                case 14://fake3 0x0E
                    Globals.l2net_home.Add_Text("bad -no message sent]", Globals.Red, TextType.BOT);
                    break;
                case 15://party room all 0x0F
                    Globals.l2net_home.Add_Text("text to party room members -no message sent]", Globals.Red, TextType.PARTY);
                    break;
                case 16://party room commander 0x10
                    type = 0x10;
                    start = total_text;
                    ok = true;
                    break;
                case 17://hero 0x11
                    type = 0x11;
                    start = total_text;
                    ok = true;
                    break;
            }

            if (!ok)
            {
                return;
            }

            if (start.StartsWith("--"))
            {
                start = start.Substring(1, start.Length - 1);

                ServerPackets.Send_Text(type, start, end);
            }
            else if (start.StartsWith("-"))
            {
                start = start.Substring(1, start.Length - 1);

                if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
                {
                    ScriptEvent sc_ev = new ScriptEvent();
                    sc_ev.Type = EventType.ChatToBot;
                    sc_ev.Variables.Add(new ScriptVariable((long)type, "MESSAGETYPE", Var_Types.INT, Var_State.PUBLIC));
                    sc_ev.Variables.Add(new ScriptVariable(end, "TARGETNAME", Var_Types.STRING, Var_State.PUBLIC));
                    sc_ev.Variables.Add(new ScriptVariable(start, "MESSAGE", Var_Types.STRING, Var_State.PUBLIC));
                    ScriptEngine.SendToEventQueue(sc_ev);
                }
            }
            else
            {
                //need to build a packet and send it out
                ServerPackets.Send_Text(type, start, end);
            }
        }
Exemple #17
0
 public static void SendToEventQueue(ScriptEvent sc_ev)
 {
     lock (eventqueueLock)
     {
         _eventqueue.Enqueue(sc_ev);
     }
 }
Exemple #18
0
        public static void MagicSkillUser(ByteBuffer buff)
        {
           if (Globals.gamedata.Chron >= Chronicle.CT3_0)
            {
                /*god packet
                  * 48 
                     00 00 00 00 // null
                     0B AA C0 4E //char id
                     0B AA C0 4E //targetid
                     00 //null
                     C0 04 00 00 //skill id
                     01 00 00 00 // lvl ?
                     8D 10 00 00 //hit time ?(4237)
                     FF FF FF FF 
                     B8 0B 00 00 // Reuse ?(3000)?
                     CB 41 FE FF //x
                     6E CF 03 00 //y
                     E8 F8 FF FF //z
                     00 00 00 00 // null
                     CB 41 FE FF //tar x
                     6E CF 03 00 //tar y
                     E8 F8 FF FF //tar z
                  * 
                  * 
                  **/
                buff.ReadUInt32(); // 48 00 00 00 00 43 28 01 48 43 28 01 48 00 FF 07 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3F 41 FE FF 79 DE 03 00 00 FA FF FF 00 00 00 00 3F 41 FE FF 79 DE 03 00 00 FA FF FF 
            }
            uint _caster = buff.ReadUInt32();
            uint _target = buff.ReadUInt32();
            if (Globals.gamedata.Chron >= Chronicle.CT3_0)
            {
                buff.ReadByte();
            }
            uint _skillid = buff.ReadUInt32();
            uint _skilllevel = buff.ReadUInt32();
            uint _hittime = buff.ReadUInt32();
            if (Globals.gamedata.Chron >= Chronicle.CT3_0)
            {
                int _baseSkillID = buff.ReadInt32(); //FF FF FF FF

                if (_baseSkillID > 0)
                    _skillid = (uint)_baseSkillID;

            }
            int _delay = buff.ReadInt32();
            //4 bytescha.getX();
            //4 bytes cha.getY();
            //4 bytes cha.getZ();
            //00 00 00 00

            //not setting caster combat to true?
            StopMoveStartCombat(_caster, false);

            if (_caster == Globals.gamedata.my_char.ID)
            {                
                Globals.gamedata.my_char.Resisted = 0;
                
                // Globals.gamedata.my_char.ExpiresTime = ((1000 + _hittime) * TimeSpan.TicksPerMillisecond) + System.DateTime.Now.Ticks;
                Globals.gamedata.my_char.ExpiresTime = ((_hittime) * TimeSpan.TicksPerMillisecond) + System.DateTime.Now.Ticks;
                
                if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
                {
                    ScriptEvent sc_ev = new ScriptEvent();
                    sc_ev.Type = EventType.SkillUsed;
                    sc_ev.Variables.Add(new ScriptVariable((long)_target, "SKILL_TARGET_ID", Var_Types.INT, Var_State.PUBLIC));
                    sc_ev.Variables.Add(new ScriptVariable((long)_skillid, "SKILL_ID", Var_Types.INT, Var_State.PUBLIC));
                    sc_ev.Variables.Add(new ScriptVariable((long)_skilllevel, "SKILL_LEVEL", Var_Types.INT, Var_State.PUBLIC));
                    sc_ev.Variables.Add(new ScriptVariable((long)_hittime, "HIT_TIME", Var_Types.INT, Var_State.PUBLIC));
                    sc_ev.Variables.Add(new ScriptVariable((long)_delay, "DELAY", Var_Types.INT, Var_State.PUBLIC));
                    ScriptEngine.SendToEventQueue(sc_ev);
                }

                //we cast the skill... let's set our reuse timer...

                Globals.SkillListLock.EnterReadLock();
                try
                {                    
                    if (Globals.gamedata.skills.ContainsKey(_skillid))
                    {
                        ((UserSkill)Globals.gamedata.skills[_skillid]).LastTime = System.DateTime.Now;                     
                        ((UserSkill)Globals.gamedata.skills[_skillid]).NextTime = System.DateTime.Now.AddMilliseconds(_delay);                        
                    }
                }
                finally
                {
                    Globals.SkillListLock.ExitReadLock();
                }
            }
            else
            {
                TargetType type = Util.GetType(_target);

                //force target for the npc
                Globals.NPCLock.EnterReadLock();
                try
                {
                    NPCInfo npc = Util.GetNPC(_caster);

                    if (npc != null)
                    {
                        npc.TargetID = _target;
                        npc.CurrentTargetType = type;
                    }
                }
                finally
                {
                    Globals.NPCLock.ExitReadLock();
                }
                //end of force target for the npc

                if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
                {
                    ScriptEvent sc_ev = new ScriptEvent();
                    sc_ev.Type = EventType.OtherSkillUsed;
                    sc_ev.Variables.Add(new ScriptVariable((long)_caster, "USER_ID", Var_Types.INT, Var_State.PUBLIC));
                    sc_ev.Variables.Add(new ScriptVariable((long)_target, "SKILL_TARGET_ID", Var_Types.INT, Var_State.PUBLIC));
                    sc_ev.Variables.Add(new ScriptVariable((long)_skillid, "SKILL_ID", Var_Types.INT, Var_State.PUBLIC));
                    sc_ev.Variables.Add(new ScriptVariable((long)_skilllevel, "SKILL_LEVEL", Var_Types.INT, Var_State.PUBLIC));
                    sc_ev.Variables.Add(new ScriptVariable((long)_hittime, "HIT_TIME", Var_Types.INT, Var_State.PUBLIC));
                    sc_ev.Variables.Add(new ScriptVariable((long)_delay, "DELAY", Var_Types.INT, Var_State.PUBLIC));
                    ScriptEngine.SendToEventQueue(sc_ev);
                }
            }
        }
Exemple #19
0
        public static void PartySpelled(ByteBuffer buff)
        {

            /*
            	protected final void writeImpl()
	            {
		            writeC(0xf4);
		            writeD(_activeChar instanceof L2SummonInstance ? 2 : _activeChar instanceof L2PetInstance ? 1 : 0);
		            writeD(_activeChar.getObjectId());
		            writeD(_effects.size());
		            for (Effect temp : _effects)
		            {
			            writeD(temp._skillId);
			            writeH(temp._dat);
			            writeD(temp._duration / 1000);
		            }
		
	            }
            */

            uint update_type = buff.ReadUInt32();
            uint update_object = buff.ReadUInt32();
            int update_count = buff.ReadInt32();
            int skill_duration = 0;
            uint skill_id = 0;

            try
            {
                if (Globals.gamedata.PartyMembers.ContainsKey(update_object))
                {
                    PartyMember ph = null;
                    CharInfo ch;
                    Globals.PlayerLock.EnterReadLock();
                    try
                    {
                        ph = Util.GetCharParty(update_object);
                        ch = Util.GetChar(update_object);
                    }
                    finally
                    {
                        Globals.PlayerLock.ExitReadLock();
                    }

                    Globals.PlayerLock.EnterWriteLock();
                    try
                    {
                        if (ph != null)
                        {
                            ph.my_buffs.Clear();

                            for (int i = 0; i < update_count; i++)
                            {
                                skill_id = buff.ReadUInt32();
                                buff.ReadInt16();
                                skill_duration = buff.ReadInt32();
                                Add_PartyBuff(update_object, skill_id, skill_duration, ph);
                            }

                            if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
                            {

                                Script_ClassData cd = new Script_ClassData();
                                cd.Name = "PLAYER";
                                cd._Variables.Add("ID", new ScriptVariable((long)ph.ID, "ID", Var_Types.INT, Var_State.PUBLIC));
                                cd._Variables.Add("NAME", new ScriptVariable(ph.Name, "NAME", Var_Types.STRING, Var_State.PUBLIC));

                                cd._Variables.Add("CLASS", new ScriptVariable((long)ph.Class, "CLASS", Var_Types.INT, Var_State.PUBLIC));
                                cd._Variables.Add("LEVEL", new ScriptVariable((long)ph.Level, "LEVEL", Var_Types.INT, Var_State.PUBLIC));

                                cd._Variables.Add("HP", new ScriptVariable((long)ph.Cur_HP, "HP", Var_Types.INT, Var_State.PUBLIC));
                                cd._Variables.Add("MAX_HP", new ScriptVariable((long)ph.Max_HP, "MAX_HP", Var_Types.INT, Var_State.PUBLIC));
                                cd._Variables.Add("MP", new ScriptVariable((long)ph.Cur_MP, "MP", Var_Types.INT, Var_State.PUBLIC));
                                cd._Variables.Add("MAX_MP", new ScriptVariable((long)ph.Max_MP, "MAX_MP", Var_Types.INT, Var_State.PUBLIC));
                                cd._Variables.Add("CP", new ScriptVariable((long)ph.Cur_CP, "CP", Var_Types.INT, Var_State.PUBLIC));
                                cd._Variables.Add("MAX_CP", new ScriptVariable((long)ph.Max_CP, "MAX_CP", Var_Types.INT, Var_State.PUBLIC));

                                try
                                {
                                    System.Collections.SortedList buffs = new System.Collections.SortedList();
                                    foreach (CharBuff _buff in ph.my_buffs.Values)
                                    {
                                        Script_ClassData ncd = new Script_ClassData();
                                        ncd.Name = "EFFECT";
                                        ncd._Variables.Add("ID", new ScriptVariable((long)_buff.ID, "ID", Var_Types.INT, Var_State.PUBLIC));
                                        ncd._Variables.Add("LEVEL", new ScriptVariable((long)_buff.SkillLevel, "LEVEL", Var_Types.INT, Var_State.PUBLIC));
                                        ncd._Variables.Add("DURATION", new ScriptVariable((long)_buff.ExpiresTime, "DURATION", Var_Types.INT, Var_State.PUBLIC));
                                        ncd._Variables.Add("NAME", new ScriptVariable(Util.GetSkillName(_buff.ID, _buff.SkillLevel), "NAME", Var_Types.STRING, Var_State.PUBLIC));
                                        ScriptVariable nsv = new ScriptVariable(ncd, "EFFECT", Var_Types.CLASS, Var_State.PUBLIC);

                                        buffs.Add(_buff.ID.ToString(), nsv);
                                    }

                                    cd._Variables.Add("EFFECTS", new ScriptVariable((System.Collections.SortedList)buffs, "EFFECTS", Var_Types.SORTEDLIST, Var_State.PUBLIC));
                                }
                                catch
                                {
                                    System.Collections.SortedList empty = new System.Collections.SortedList();
                                    cd._Variables.Add("EFFECTS", new ScriptVariable((System.Collections.SortedList)empty, "EFFECTS", Var_Types.SORTEDLIST, Var_State.PUBLIC));
                                }


                                if (ch == null)
                                {
                                    cd._Variables.Add("X", new ScriptVariable((long)ph.X, "X", Var_Types.INT, Var_State.PUBLIC));
                                    cd._Variables.Add("Y", new ScriptVariable((long)ph.Y, "Y", Var_Types.INT, Var_State.PUBLIC));
                                    cd._Variables.Add("Z", new ScriptVariable((long)ph.Z, "Z", Var_Types.INT, Var_State.PUBLIC));

                                    cd._Variables.Add("TITLE", new ScriptVariable("", "TITLE", Var_Types.STRING, Var_State.PUBLIC));
                                    cd._Variables.Add("CLAN", new ScriptVariable(0L, "CLAN", Var_Types.INT, Var_State.PUBLIC));
                                    cd._Variables.Add("ALLY", new ScriptVariable(0L, "ALLY", Var_Types.INT, Var_State.PUBLIC));

                                    cd._Variables.Add("RACE", new ScriptVariable(0L, "RACE", Var_Types.INT, Var_State.PUBLIC));
                                    cd._Variables.Add("SEX", new ScriptVariable(0L, "SEX", Var_Types.INT, Var_State.PUBLIC));

                                    cd._Variables.Add("PVPFLAG", new ScriptVariable(0L, "PVPFLAG", Var_Types.INT, Var_State.PUBLIC));
                                    cd._Variables.Add("KARMA", new ScriptVariable(0L, "KARMA", Var_Types.INT, Var_State.PUBLIC));

                                    cd._Variables.Add("ATTACK_SPEED", new ScriptVariable(0L, "ATTACK_SPEED", Var_Types.INT, Var_State.PUBLIC));
                                    cd._Variables.Add("CAST_SPEED", new ScriptVariable(0L, "CAST_SPEED", Var_Types.INT, Var_State.PUBLIC));
                                    cd._Variables.Add("RUN_SPEED", new ScriptVariable(0L, "RUN_SPEED", Var_Types.INT, Var_State.PUBLIC));

                                    cd._Variables.Add("TARGET_ID", new ScriptVariable(0L, "TARGET_ID", Var_Types.INT, Var_State.PUBLIC));

                                    cd._Variables.Add("DEST_X", new ScriptVariable(0L, "DEST_X", Var_Types.INT, Var_State.PUBLIC));
                                    cd._Variables.Add("DEST_Y", new ScriptVariable(0L, "DEST_Y", Var_Types.INT, Var_State.PUBLIC));
                                    cd._Variables.Add("DEST_Z", new ScriptVariable(0L, "DEST_Z", Var_Types.INT, Var_State.PUBLIC));

                                    cd._Variables.Add("LOOKS_DEAD", new ScriptVariable(0L, "LOOKS_DEAD", Var_Types.INT, Var_State.PUBLIC));
                                    cd._Variables.Add("IN_COMBAT", new ScriptVariable(0L, "IN_COMBAT", Var_Types.INT, Var_State.PUBLIC));
                                    //cd._Variables.Add("EFFECTS", new ScriptVariable((System.Collections.SortedList)pl.my_buffs, "EFFECTS", Var_Types.SORTEDLIST, Var_State.PUBLIC));
                                }
                                else
                                {
                                    cd._Variables.Add("X", new ScriptVariable((long)ch.X, "X", Var_Types.INT, Var_State.PUBLIC));
                                    cd._Variables.Add("Y", new ScriptVariable((long)ch.Y, "Y", Var_Types.INT, Var_State.PUBLIC));
                                    cd._Variables.Add("Z", new ScriptVariable((long)ch.Z, "Z", Var_Types.INT, Var_State.PUBLIC));

                                    cd._Variables.Add("TITLE", new ScriptVariable(ch.Title, "TITLE", Var_Types.STRING, Var_State.PUBLIC));
                                    cd._Variables.Add("CLAN", new ScriptVariable((long)ch.ClanID, "CLAN", Var_Types.INT, Var_State.PUBLIC));
                                    cd._Variables.Add("ALLY", new ScriptVariable((long)ch.AllyID, "ALLY", Var_Types.INT, Var_State.PUBLIC));

                                    cd._Variables.Add("RACE", new ScriptVariable((long)ch.Race, "RACE", Var_Types.INT, Var_State.PUBLIC));
                                    cd._Variables.Add("SEX", new ScriptVariable((long)ch.Sex, "SEX", Var_Types.INT, Var_State.PUBLIC));

                                    cd._Variables.Add("PVPFLAG", new ScriptVariable((long)ch.PvPFlag, "PVPFLAG", Var_Types.INT, Var_State.PUBLIC));
                                    cd._Variables.Add("KARMA", new ScriptVariable((long)ch.Karma, "KARMA", Var_Types.INT, Var_State.PUBLIC));

                                    cd._Variables.Add("ATTACK_SPEED", new ScriptVariable((long)(ch.PatkSpeed * ch.AttackSpeedMult), "ATTACK_SPEED", Var_Types.INT, Var_State.PUBLIC));
                                    cd._Variables.Add("CAST_SPEED", new ScriptVariable((long)ch.MatkSpeed, "CAST_SPEED", Var_Types.INT, Var_State.PUBLIC));
                                    cd._Variables.Add("RUN_SPEED", new ScriptVariable((long)(ch.RunSpeed * ch.MoveSpeedMult), "RUN_SPEED", Var_Types.INT, Var_State.PUBLIC));

                                    cd._Variables.Add("TARGET_ID", new ScriptVariable((long)ch.TargetID, "TARGET_ID", Var_Types.INT, Var_State.PUBLIC));

                                    cd._Variables.Add("DEST_X", new ScriptVariable((long)ch.Dest_X, "DEST_X", Var_Types.INT, Var_State.PUBLIC));
                                    cd._Variables.Add("DEST_Y", new ScriptVariable((long)ch.Dest_Y, "DEST_Y", Var_Types.INT, Var_State.PUBLIC));
                                    cd._Variables.Add("DEST_Z", new ScriptVariable((long)ch.Dest_Z, "DEST_Z", Var_Types.INT, Var_State.PUBLIC));

                                    cd._Variables.Add("LOOKS_DEAD", new ScriptVariable((long)ch.isAlikeDead, "LOOKS_DEAD", Var_Types.INT, Var_State.PUBLIC));
                                    cd._Variables.Add("IN_COMBAT", new ScriptVariable((long)ch.isInCombat, "IN_COMBAT", Var_Types.INT, Var_State.PUBLIC));
                                    //cd._Variables.Add("EFFECTS", new ScriptVariable((System.Collections.SortedList)pl.my_buffs, "EFFECTS", Var_Types.SORTEDLIST, Var_State.PUBLIC));
                                }

                                ScriptEvent sc_ev = new ScriptEvent();
                                sc_ev.Type = EventType.PartyEffect;
                                sc_ev.Variables.Add(new ScriptVariable(cd, "PARTYMEMBER", Var_Types.CLASS, Var_State.PUBLIC));
                                ScriptEngine.SendToEventQueue(sc_ev);
                            }
                        }
                    }
                    finally
                    {
                        Globals.PlayerLock.ExitWriteLock();
                    }
                }
            }
            finally
            {
                
            }
        }
Exemple #20
0
        public static void TargetSelected(ByteBuffer buff, bool type)
        {
            uint _ID = 0;
            uint _targetID = 0;
            int _x = 0;
            int _y = 0;
            int _z = 0;
            string _targeter_name = "";
            int _targeter_war = 0;

            bool targeter_is_player = true;

            _ID = buff.ReadUInt32();

            TargetType targeter_type = Util.GetType(_ID);

            try
            {
                if (type)
                {
                    //target selected
                    _targetID = buff.ReadUInt32();
                    _x = buff.ReadInt32();
                    _y = buff.ReadInt32();
                    _z = buff.ReadInt32();
                    buff.ReadInt32();//0x00 ?

                    TargetType target_type = Util.GetType(_targetID);

                    //active follow attack targeting
                    if (!Globals.picking_up_items)
                    {
                        if (Globals.gamedata.DoTargeting(_ID, _targetID))
                        {
                            if (_targetID != 0)
                            {
                                //lets target it
                                ServerPackets.Target(_targetID, _x, _y, _z, false);

                                //instant attack
                                if (Globals.gamedata.botoptions.ActiveFollowAttackInstant == 1)
                                {
                                    if (Globals.gamedata.Control)
                                    {
                                        ServerPackets.Force_Attack(_targetID, Util.Float_Int32(_x), Util.Float_Int32(_y), Util.Float_Int32(_z), Globals.gamedata.Shift);
                                    }
                                    else
                                    {
                                        ServerPackets.ClickOBJ(_targetID, false, Globals.gamedata.Shift);
                                    }
                                }
                            }
                        }
                    }

                    //set the targetid of the targeter
                    switch (targeter_type)
                    {
                        case TargetType.SELF:
                            Set_Target_Data(_targetID);
                            AddInfo.Set_Target_HP();
                            _targeter_name = Globals.gamedata.my_char.Name;
                            _targeter_war = 0;
                            if (Globals.gamedata.BOT_STATE == BotState.Attacking || Globals.gamedata.BOT_STATE == BotState.FinishedBuffing)
                                Globals.gamedata.BOT_STATE = BotState.Nothing;
                            break;
                        case TargetType.MYPET:
                            Globals.gamedata.my_pet.TargetID = _targetID;
                            Globals.gamedata.my_pet.CurrentTargetType = target_type;
                            _targeter_name = Globals.gamedata.my_pet.Name;
                            _targeter_war = 0;
                            break;
                        case TargetType.MYPET1:
                            Globals.gamedata.my_pet1.TargetID = _targetID;
                            Globals.gamedata.my_pet1.CurrentTargetType = target_type;
                            _targeter_name = Globals.gamedata.my_pet1.Name;
                            _targeter_war = 0;
                            break;
                        case TargetType.MYPET2:
                            Globals.gamedata.my_pet2.TargetID = _targetID;
                            Globals.gamedata.my_pet2.CurrentTargetType = target_type;
                            _targeter_name = Globals.gamedata.my_pet2.Name;
                            _targeter_war = 0;
                            break;
                        case TargetType.MYPET3:
                            Globals.gamedata.my_pet3.TargetID = _targetID;
                            Globals.gamedata.my_pet3.CurrentTargetType = target_type;
                            _targeter_name = Globals.gamedata.my_pet3.Name;
                            _targeter_war = 0;
                            break;
                        case TargetType.PLAYER:
                            Globals.PlayerLock.EnterReadLock();
                            try
                            {
                                CharInfo player = Util.GetChar(_ID);

                                if (player != null)
                                {
                                    player.TargetID = _targetID;
                                    player.CurrentTargetType = target_type;
                                    _targeter_name = player.Name;
                                    _targeter_war = player.WarState;
                                }
                            }
                            finally
                            {
                                Globals.PlayerLock.ExitReadLock();
                            }
                            break;
                        case TargetType.NPC:
                            Globals.NPCLock.EnterReadLock();
                            try
                            {
                                NPCInfo npc = Util.GetNPC(_ID);

                                if (npc != null)
                                {
                                    npc.TargetID = _targetID;
                                    npc.CurrentTargetType = target_type;
                                    targeter_is_player = false;
                                    _targeter_name = npc.Name;
                                    _targeter_war = 0;
                                }
                            }
                            finally
                            {
                                Globals.NPCLock.ExitReadLock();
                            }

                            try
                            {
                                if (Globals.gamedata.botoptions.OnlyPickMine == 1 && Globals.gamedata.botoptions.Pickup == 1)
                                {
                                    try
                                    {
                                        Globals.MobListLock.EnterWriteLock();
                                        if ((_targetID == Globals.gamedata.my_char.ID) || (_targetID == Globals.gamedata.my_pet.ID) || (_targetID == Globals.gamedata.my_pet1.ID) || (_targetID == Globals.gamedata.my_pet2.ID) || (_targetID == Globals.gamedata.my_pet3.ID))
                                        {
                                            Globals.gamedata.MobList.Add(_ID);
#if DEBUG
                                            Globals.l2net_home.Add_Text("Adding npc to moblist(self or summon): " + _ID, Globals.Green, TextType.SYSTEM);
#endif
                                        }
                                        else
                                        {
                                            foreach (PartyMember pmem in Globals.gamedata.PartyMembers.Values)
                                            {
                                                if ((_targetID == pmem.ID) || (_targetID == pmem.petID) || (_targetID == pmem.pet1ID) || (_targetID == pmem.pet2ID) || (_targetID == pmem.pet3ID))
                                                {
                                                    Globals.gamedata.MobList.Add(_ID);
#if DEBUG
                                                    Globals.l2net_home.Add_Text("Adding npc to moblist(partymember/summon): " + _ID, Globals.Green, TextType.SYSTEM);
#endif
                                                }
                                            }

                                        }

                                        //cleanup old mobs... get the last 75 mobs and save to new array
                                        if (Globals.gamedata.MobList.Count > 350)
                                        {
                                            //System.Collections.ArrayList tmparr = new System.Collections.ArrayList();
                                            //int count = Globals.gamedata.MobList.Count;
                                            //for (int i = 0; i < 75; i++)
                                            //{
                                            //    tmparr.Add(Globals.gamedata.MobList[count - (1 + i)]);
                                            //}
                                            //Globals.gamedata.MobList = tmparr;

                                            //Oddi: Remove first 275 elements in list.

                                            Globals.gamedata.MobList.RemoveRange(0, 225);
                                            #if DEBUG
                                            Globals.l2net_home.Add_Text("resizing array: " + Globals.gamedata.MobList.Count, Globals.Green, TextType.SYSTEM);
                                            #endif

                                        }
                                    }
                                    finally
                                    {
                                        Globals.MobListLock.ExitWriteLock();
                                    }
                                }
                                    
                            }
                            catch(Exception e)
                            {
                                Globals.l2net_home.Add_Error("Error with moblist adding or resizing " + e.Message);
                            }
                            break;
                    }
                }
                else
                {
                    //target unselected
                    _x = buff.ReadInt32();
                    _y = buff.ReadInt32();
                    _z = buff.ReadInt32();
                    buff.ReadInt32();//0x00 ?

                    //active follow attack targeting
                    if (Globals.gamedata.DoTargeting(_ID, _targetID))
                    {
#if DEBUG
                                                    Globals.l2net_home.Add_Text("Canceleling target from Clientpackets: ", Globals.Blue, TextType.SYSTEM);
#endif
                        //cancel target
                        ServerPackets.Send_CancelTarget();
                    }

                    switch (targeter_type)
                    {
                        case TargetType.SELF:
                            Set_Target_Data(0);
                            AddInfo.Set_Target_HP();
                            _targeter_name = Globals.gamedata.my_char.Name;
                            _targeter_war = 0;
                            if (Globals.gamedata.BOT_STATE == BotState.Attacking)
                                Globals.gamedata.BOT_STATE = BotState.Nothing;
                            break;
                        case TargetType.MYPET:
                            Globals.gamedata.my_pet.TargetID = 0;
                            Globals.gamedata.my_pet.CurrentTargetType = TargetType.NONE;
                            _targeter_name = Globals.gamedata.my_pet.Name;
                            _targeter_war = 0;
                            break;
                        case TargetType.MYPET1:
                            Globals.gamedata.my_pet1.TargetID = 0;
                            Globals.gamedata.my_pet1.CurrentTargetType = TargetType.NONE;
                            _targeter_name = Globals.gamedata.my_pet1.Name;
                            _targeter_war = 0;
                            break;
                        case TargetType.MYPET2:
                            Globals.gamedata.my_pet2.TargetID = 0;
                            Globals.gamedata.my_pet2.CurrentTargetType = TargetType.NONE;
                            _targeter_name = Globals.gamedata.my_pet2.Name;
                            _targeter_war = 0;
                            break;
                        case TargetType.MYPET3:
                            Globals.gamedata.my_pet3.TargetID = 0;
                            Globals.gamedata.my_pet3.CurrentTargetType = TargetType.NONE;
                            _targeter_name = Globals.gamedata.my_pet3.Name;
                            _targeter_war = 0;
                            break;
                        case TargetType.PLAYER:
                            Globals.PlayerLock.EnterReadLock();
                            try
                            {
                                CharInfo player = Util.GetChar(_ID);

                                if (player != null)
                                {
                                    player.TargetID = 0;
                                    player.CurrentTargetType = TargetType.NONE;
                                    _targeter_name = player.Name;
                                    _targeter_war = player.WarState;
                                }
                            }
                            finally
                            {
                                Globals.PlayerLock.ExitReadLock();
                            }
                            break;
                        case TargetType.NPC:
                            Globals.NPCLock.EnterReadLock();
                            try
                            {
                                NPCInfo npc = Util.GetNPC(_ID);

                                if (npc != null)
                                {
                                    npc.TargetID = 0;
                                    npc.CurrentTargetType = TargetType.NONE;
                                    targeter_is_player = false;
                                    _targeter_name = npc.Name;
                                    _targeter_war = 0;
                                }
                            }
                            finally
                            {
                                Globals.NPCLock.ExitReadLock();
                            }
                            break;
                    }
                }
            }
            finally
            {
                if (_targetID == Globals.gamedata.my_char.ID)
                {
                    if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
                    {
                        ScriptEvent sc_ev = new ScriptEvent();
                        if (type)
                            sc_ev.Type = EventType.SelfTargeted;
                        else
                            sc_ev.Type = EventType.SelfUnTargeted;
                        sc_ev.Variables.Add(new ScriptVariable((long)_ID, "TARGETER_ID", Var_Types.INT, Var_State.PUBLIC));
                        sc_ev.Variables.Add(new ScriptVariable((long)_x, "TARGETER_X", Var_Types.INT, Var_State.PUBLIC));
                        sc_ev.Variables.Add(new ScriptVariable((long)_y, "TARGETER_Y", Var_Types.INT, Var_State.PUBLIC));
                        sc_ev.Variables.Add(new ScriptVariable((long)_z, "TARGETER_Z", Var_Types.INT, Var_State.PUBLIC));
                        sc_ev.Variables.Add(new ScriptVariable(targeter_is_player ? 1L : 0L, "TARGETER_IS_PLAYER", Var_Types.INT, Var_State.PUBLIC));
                        sc_ev.Variables.Add(new ScriptVariable(_targeter_name, "TARGETER_NAME", Var_Types.STRING, Var_State.PUBLIC));
                        sc_ev.Variables.Add(new ScriptVariable((long)_targeter_war, "TARGETER_WARSTATE", Var_Types.INT, Var_State.PUBLIC));
                        ScriptEngine.SendToEventQueue(sc_ev);
                    }
                }
            }
        }
Exemple #21
0
        public static void UpdateBuff(ByteBuffer buff)
        {
            uint skill_id = buff.ReadUInt32();
            uint skill_level = buff.ReadUInt32(); // maybe it iwll fix it
            int skill_duration = buff.ReadInt32();

            Globals.MyBuffsListLock.EnterWriteLock();
            try
            {
                //need to see if the buff exists in our list...
                //if so, update the remaining time
                //otherwise, add the buff
                if (Globals.gamedata.mybuffs.ContainsKey(skill_id))
                {
                    CharBuff cb = (CharBuff)Globals.gamedata.mybuffs[skill_id];
                    cb.SkillLevel = skill_level;
                    if (skill_duration == -1)
                    {
                        //remove the buff
                        //Globals.gamedata.mybuffs.Remove(skill_id);


                        //toggle buff
                        cb.ExpiresTime = -1;
                        cb.EFFECT_TIME = -1;
                    }
                    else
                    {
                        cb.EFFECT_TIME = skill_duration;
                        cb.ExpiresTime = System.DateTime.Now.AddSeconds(skill_duration).Ticks;
                    }
                }
                else
                {
                    CharBuff cb = new CharBuff();
                    cb.ID = skill_id;
                    cb.SkillLevel = skill_level;
                    if (skill_duration == -1)
                    {
                        //toggle buff

                        cb.ExpiresTime = -1;
                        cb.EFFECT_TIME = -1;
                        Globals.gamedata.mybuffs.Add(cb.ID, cb);
                    }
                    else
                    {
                        cb.EFFECT_TIME = skill_duration;
                        cb.ExpiresTime = System.DateTime.Now.AddSeconds(skill_duration).Ticks;
                        Globals.gamedata.mybuffs.Add(cb.ID, cb);
                    }
                }
                if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
                {
                    SortedList _mybuff = new SortedList();
                    if (Globals.gamedata.mybuffs.Count > 0)
                    {
                        foreach (CharBuff _buff in Globals.gamedata.mybuffs.Values)
                        {
                            Script_ClassData cd = new Script_ClassData();
                            cd.Name = "EFFECT";
                            cd._Variables.Add("ID", new ScriptVariable((long)_buff.ID, "ID", Var_Types.INT, Var_State.PUBLIC));
                            cd._Variables.Add("LEVEL", new ScriptVariable((long)_buff.SkillLevel, "LEVEL", Var_Types.INT, Var_State.PUBLIC));
                            cd._Variables.Add("DURATION", new ScriptVariable((long)_buff.ExpiresTime, "DURATION", Var_Types.INT, Var_State.PUBLIC));
                            cd._Variables.Add("EFFECT_TIME", new ScriptVariable((long)_buff.EFFECT_TIME, "EFFECT_TIME", Var_Types.INT, Var_State.PUBLIC));
                            cd._Variables.Add("NAME", new ScriptVariable(Util.GetSkillName(_buff.ID, _buff.SkillLevel), "NAME", Var_Types.STRING, Var_State.PUBLIC));
                            ScriptVariable sv = new ScriptVariable(cd, "EFFECT", Var_Types.CLASS, Var_State.PUBLIC);
                            _mybuff.Add(_buff.ID.ToString(), sv);
                        }
                    }
                    ScriptEvent sc_ev = new ScriptEvent();
                    sc_ev.Type = EventType.CharEffect;
                    sc_ev.Variables.Add(new ScriptVariable(_mybuff, "EFFECTLIST", Var_Types.SORTEDLIST, Var_State.PUBLIC));
                    ScriptEngine.SendToEventQueue(sc_ev);
                }
            }
            finally
            {
                Globals.MyBuffsListLock.ExitWriteLock();
            }
        }
Exemple #22
0
        public static void Delete_Party()
        {
            //def need a writer lock here
            Globals.PartyLock.EnterWriteLock();
            try
            {
                Globals.gamedata.PartyMembers.Clear();
                Globals.gamedata.PartyCount = 0;
            }
            finally
            {
                Globals.PartyLock.ExitWriteLock();
            }

            if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
            {
                ScriptEvent sc_ev = new ScriptEvent();
                sc_ev.Type = EventType.LeaveParty;
                ScriptEngine.SendToEventQueue(sc_ev);
            }
        }
        private static void HandlePackets()
        {
            ByteBuffer buffe;
            uint       b0 = 0, b1 = 0; //byte
            string     last_p = "";    //, last_p2 = "";

            while (Globals.gamedata.GetCount_DataToBot() > 0)
            {
                try
                {
                    //buffe = null;

                    Globals.GameReadQueueLock.EnterWriteLock();
                    try
                    {
                        buffe = (ByteBuffer)Globals.gamedata.gamereadqueue.Dequeue();
                    }
                    catch (System.Exception e)
                    {
                        Globals.l2net_home.Add_Error("Packet Error Reading Queue : " + e.Message);
                        break;
                    }
                    finally
                    {
                        Globals.GameReadQueueLock.ExitWriteLock();
                    }

                    //buffe contains unencoded data
                    b0 = buffe.ReadByte();
                    //last_p2 = last_p;
                    last_p = b0.ToString("X2");

                    //do we have an event for this packet?
                    if (ScriptEngine.ServerPacketsContainsKey((int)b0))
                    {
                        ScriptEvent sc_ev = new ScriptEvent();
                        sc_ev.Type  = EventType.ServerPacket;
                        sc_ev.Type2 = (int)b0;
                        sc_ev.Variables.Add(new ScriptVariable(buffe, "PACKET", Var_Types.BYTEBUFFER, Var_State.PUBLIC));
                        sc_ev.Variables.Add(new ScriptVariable(System.DateTime.Now.Ticks, "TIMESTAMP", Var_Types.INT, Var_State.PUBLIC));
                        ScriptEngine.SendToEventQueue(sc_ev);
                    }

                    switch ((PServer)b0)
                    {
                    case PServer.MTL:
                        ClientPackets.MoveToLocation(buffe);
                        break;

                    case PServer.NS:
                        ClientPackets.NPCSay(buffe);
                        break;

                    case PServer.CI:
                        ClientPackets.CharInfo(buffe);
                        break;

                    case PServer.RelationChanged:
                        ClientPackets.RelationChanged(buffe);
                        break;

                    case PServer.UI:
                        ClientPackets.UserInfo(buffe);
                        break;

                    case PServer.Attack:
                        ClientPackets.Attack_Packet(buffe);
                        break;

                    case PServer.Die:
                        ClientPackets.Die_Packet(buffe);
                        break;

                    case PServer.Revive:
                        ClientPackets.Revive(buffe.ReadUInt32());
                        break;

                    case PServer.ChangeMoveType:
                        ClientPackets.ChangeMoveType(buffe);
                        break;

                    case PServer.ChangeWaitType:
                        ClientPackets.ChangeWaitType(buffe);
                        break;

                    case PServer.AttackDeadTarget:
                        ClientPackets.AttackCanceled_Packet(buffe);
                        break;

                    case PServer.SpawnItem:    //add item (to ground)
                        ClientPackets.AddItem(buffe);
                        break;

                    case PServer.DropItem:
                        ClientPackets.ItemDrop(buffe);
                        break;

                    case PServer.GetItem:
                        ClientPackets.Get_Item(buffe);
                        break;

                    case PServer.StatusUpdate:
                        ClientPackets.StatusUpdate(buffe);
                        break;

                    case PServer.NpcHtmlMessage:
                        NPC_Chat.Npc_Chat(buffe);
                        break;

                    case PServer.BuyList:     //Buylist
                        ClientPackets.BuyList(buffe);
                        break;

                    case PServer.DeleteObject:
                        ClientPackets.DeleteItem(buffe);
                        break;

                    case PServer.CharacterSelectionInfo:
                        Globals.login_window.CharList(buffe);
                        //this is the list of chars
                        //not handled by ig

                        //need to handle this packet here and not on the oog login
                        //on ig, the list will just show up, then disappear on 0x15 CharSelected so its all good
                        break;

                    case PServer.CharSelected:
                        ClientPackets.CharSelected(buffe);
                        break;

                    case PServer.NpcInfo:
                        ClientPackets.NPCInfo(buffe);
                        break;

                    case PServer.ServerObjectInfo:
                        ClientPackets.ServerObjectInfo(buffe);
                        break;

                    case PServer.StaticObject:
                        ClientPackets.StaticObjectInfo(buffe);
                        break;

                    case PServer.ItemList:
                        ClientPackets.ItemList(buffe);
                        break;

                    case PServer.SunRise:
                        Globals.l2net_home.Add_Text("[The sun has just risen]", Globals.Gray, TextType.SYSTEM);
                        break;

                    case PServer.SunSet:
                        Globals.l2net_home.Add_Text("[The sun has just set]", Globals.Gray, TextType.SYSTEM);
                        break;

                    case PServer.TradeStart:
                        break;

                    case PServer.TradeDone:
                        try
                        {
                            Globals.tradewindow.Close();
                        }
                        catch
                        {
                            //trade window is not opened.
                        }
                        break;

                    case PServer.ActionFailed:
                        //l2j is ghei and throws this packet at us a lot
                        // (Freya) Retail also causes this packet to be sent before any Attack or skill use that requires CTRL
                        break;

                    case PServer.InventoryUpdate:
                        AddInfo.Inventory_Update(buffe);
                        break;

                    case PServer.TeleportToLocation:
                        ClientPackets.Teleport(buffe);
                        break;

                    case PServer.MyTargetSelected:
                        ClientPackets.MyTargetSelected(buffe);
                        break;

                    case PServer.TargetSelected:
                        ClientPackets.TargetSelected(buffe, true);
                        break;

                    case PServer.TargetUnselected:
                        ClientPackets.TargetSelected(buffe, false);
                        break;

                    case PServer.AutoAttackStart:
                        //4bytes target id
                        ClientPackets.EnterCombat(buffe, true);
                        break;

                    case PServer.AutoAttackStop:
                        //4bytes target id
                        ClientPackets.EnterCombat(buffe, false);
                        break;

                    case PServer.SocialAction:
                        ClientPackets.Social_Action(buffe);
                        break;

                    case PServer.AskJoinPledge:
                        ClientPackets.RequestJoinClan(buffe);
                        break;

                    case PServer.AskJoinParty:
                        ClientPackets.RequestJoinParty(buffe);
                        break;

                    case PServer.TradeRequest:
                        ClientPackets.TradeRequest(buffe);
                        break;

                    case PServer.ShortCutRegister:
                        ClientPackets.Load_Shortcut(buffe);
                        break;

                    case PServer.ShortCutInit:
                        ClientPackets.Load_Shortcuts(buffe);
                        break;

                    case PServer.StopMove:
                        ClientPackets.StopMove(buffe);
                        break;

                    case PServer.MagicSkillUser:
                        ClientPackets.MagicSkillUser(buffe);
                        break;

                    case PServer.MagicSkillCancelId:
                        //4bytes - ID of caster that canceled
                        ClientPackets.MagicSkillCancel(buffe);
                        break;

                    case PServer.CreatureSay:
                        ClientPackets.OtherMessage(buffe);
                        break;

                    case PServer.PartySmallWindowAll:
                        if (Globals.gamedata.yesno_state == 1)
                        {
                            Globals.l2net_home.Hide_YesNo();
                        }
                        ClientPackets.Load_PartyInfo(buffe);
                        AddInfo.Set_PartyVisible();
                        AddInfo.Set_PartyInfo();
                        break;

                    case PServer.PartySmallWindowAdd:
                        if (Globals.gamedata.yesno_state == 1)
                        {
                            Globals.l2net_home.Hide_YesNo();
                        }
                        ClientPackets.Add_PartyInfo(buffe);
                        AddInfo.Set_PartyVisible();
                        AddInfo.Set_PartyInfo();
                        break;

                    case PServer.PartySmallWindowDeleteAll:
                        ClientPackets.Delete_Party();
                        AddInfo.Set_PartyVisible();
                        AddInfo.Set_PartyInfo();
                        break;

                    case PServer.PartySmallWindowDelete:
                        ClientPackets.Delete_PartyInfo(buffe);
                        AddInfo.Set_PartyVisible();
                        AddInfo.Set_PartyInfo();
                        break;

                    case PServer.PartySmallWindowUpdate:
                        ClientPackets.Update_PartyInfo(buffe);
                        AddInfo.Set_PartyInfo();
                        break;

                    case PServer.PledgeShowMemberListAll:
                        ClientPackets.PledgeShowMemberListAll(buffe);
                        break;

                    case PServer.PledgeShowMemberListUpdate:
                        ClientPackets.PledgeShowMemberListUpdate(buffe);
                        break;

                    case PServer.PledgeShowMemberListAdd:
                        //changes the clan status of one char... need to update/add as needed
                        ClientPackets.PledgeShowMemberListAdd(buffe);
                        break;

                    case PServer.PledgeShowMemberListDelete:
                        ClientPackets.PledgeShowMemberListDelete(buffe);
                        break;

                    case PServer.PledgeShowInfoUpdate:
                        ClientPackets.PledgeShowInfoUpdate(buffe);
                        break;

                    case PServer.PledgeShowMemberListDeleteAll:
                        ClientPackets.PledgeShowMemberListDeleteAll(buffe);
                        break;

                    case PServer.AbnormalStatusUpdate:
                        ClientPackets.LoadBuffList(buffe);
                        break;

                    case PServer.PartySpelled:
                        ClientPackets.PartySpelled(buffe);
                        break;

                    case PServer.ShortBuffStatusUpdate:
                        ClientPackets.UpdateBuff(buffe);
                        break;

                    case PServer.SkillList:
                        ClientPackets.SkillList(buffe);
                        break;

                    case PServer.SkillCoolTime:
                        ClientPackets.SkillCoolTime(buffe);
                        break;

                    case PServer.RestartResponse:
                        ClientPackets.RestartResponse(buffe);
                        break;

                    case PServer.MoveToPawn:
                        ClientPackets.MoveToPawn(buffe);
                        break;

                    case PServer.ValidateLocation:
                        ClientPackets.Validate_Location(buffe, false);
                        //int id
                        //int rotation
                        break;

                    case PServer.SystemMessage:
                        ClientPackets.SystemMessage(buffe);
                        break;

                    case PServer.PledgeCrest:
                        ClientPackets.PledgeCrest(buffe);
                        break;

                    case PServer.PledgeInfo:
                        ClientPackets.PledgeInfo(buffe);
                        break;

                    case PServer.ValidateLocationInVehicle:
                        ClientPackets.Validate_Location(buffe, true);
                        break;

                    case PServer.MagicSkillLaunched:
                        ClientPackets.MagicSkillLaunched(buffe);
                        //Validate_Location(buffe,false);
                        break;

                    case PServer.FriendAddRequest:
                        ClientPackets.RequestJoinFriend(buffe);
                        break;

                    case PServer.LogOutOk:
                        //ok time to end
                        Globals.gamedata.running = false;
                        Globals.l2net_home.KillEverything();
                        break;

                    case PServer.PartyMemberPosition:
                        ClientPackets.Set_PartyLocations(buffe);
                        break;

                    case PServer.AskJoinAlly:
                        ClientPackets.RequestJoinAlly(buffe);
                        break;

                    case PServer.AllianceCrest:
                        ClientPackets.AllyCrest(buffe);
                        break;

                    case PServer.Earthquake:
                        //x,y,z,power,duration
                        Globals.l2net_home.Add_Text("[Earthquake at X:" + buffe.ReadInt32().ToString() + " Y:" + buffe.ReadInt32().ToString() + " Z:" + buffe.ReadInt32().ToString() + " Of Power:" + buffe.ReadInt32().ToString() + " For:" + buffe.ReadInt32().ToString() + "]", Globals.Gray, TextType.SYSTEM);
                        break;

                    case PServer.PledgeStatusChanged:
                        ClientPackets.ClanStatusChanged(buffe);
                        break;

                    case PServer.Dice:
                        ClientPackets.Dice(buffe);
                        break;

                    case PServer.HennaInfo:
                        ClientPackets.Set_Henna_Info(buffe);
                        break;

                    case PServer.ConfirmDlg:
                        ClientPackets.RequestReply(buffe);
                        break;

                    case PServer.SSQInfo:    //SignSky:
                        ClientPackets.SevenSignSky(buffe);
                        break;

                    case PServer.GameGuardQuery:
                        ClientPackets.GameGuardReply(buffe);
                        break;

                    case PServer.L2FriendSay:
                        ClientPackets.Get_Friend_Message(buffe);
                        break;

                    case PServer.EtcStatusUpdate:
                        ClientPackets.EtcStatusUpdate(buffe);
                        break;

                    case PServer.PetStatusShow:
                        ClientPackets.PetStatusShow(buffe);
                        break;

                    case PServer.PetInfo:
                        ClientPackets.PetInfo(buffe);
                        break;

                    case PServer.PetStatusUpdate:
                        ClientPackets.PetStatusUpdate(buffe);
                        break;

                    case PServer.PetDelete:
                        ClientPackets.PetDelete(buffe);
                        break;

                    case PServer.PetItemList:
                        ClientPackets.PetItemList(buffe);
                        if (Globals.petwindow != null)
                        {
                            Globals.petwindow.fill_pet_inventory();
                        }
                        break;

                    case PServer.PetInventoryUpdate:
                        AddInfo.PetInventory_Update(buffe);
                        if (Globals.petwindow != null)
                        {
                            Globals.petwindow.fill_pet_inventory();
                        }
                        break;

                    case PServer.NetPing:
                        ClientPackets.NetPing(buffe);
                        break;



                    case PServer.EXPacket:
                        b1 = buffe.ReadUInt16();
                        //buffe.ReadByte();

                        last_p = last_p + " " + b1.ToString("X2");

                        //do we have an event for this packet?
                        if (ScriptEngine.ServerPacketsEXContainsKey((int)b1))
                        {
                            ScriptEvent sc_ev = new ScriptEvent();
                            sc_ev.Type  = EventType.ServerPacketEX;
                            sc_ev.Type2 = (int)b1;
                            sc_ev.Variables.Add(new ScriptVariable(buffe, "PACKET", Var_Types.BYTEBUFFER, Var_State.PUBLIC));
                            sc_ev.Variables.Add(new ScriptVariable(System.DateTime.Now.Ticks, "TIMESTAMP", Var_Types.INT, Var_State.PUBLIC));
                            ScriptEngine.SendToEventQueue(sc_ev);
                        }
                        //Globals.l2net_home.Add_Text(last_p);
                        switch ((PServerEX)b1)
                        {
                        /*case PServerEX.ExPledgeCrestLarge:
                         *  //https://www.l2jserver.com/trac/browser/trunk/L2_GameServer_It/java/net/sf/l2j/gameserver/serverpackets/ExPledgeCrestLarge.java
                         *  break;*/
                        case PServerEX.ExMailArrived:
                            Globals.l2net_home.Add_Text("[Mail has arrived]");
                            VoicePlayer.PlaySound(8);
                            break;

                        case PServerEX.ExSetCompassZoneCode:
                            ClientPackets.ExSetCompassZoneCode(buffe);
                            break;

                        case PServerEX.ExShowScreenMessage:
                            ClientPackets.ExShowScreenMessage(buffe);
                            break;

                        case PServerEX.ExQuestHTML:
                            if (Globals.gamedata.Chron >= Chronicle.CT2_3)
                            {
                                NPC_Chat.Npc_Chat(buffe);
                            }
                            break;

                        case PServerEX.ExSendUIEventPacket:
                            if (Globals.gamedata.Chron >= Chronicle.CT3_2)
                            {
                                NPC_Chat.Npc_Chat(buffe);
                            }
                            break;

                        case PServerEX.ExQuestItemList:
                            if (Globals.gamedata.Chron >= Chronicle.CT2_5)
                            {
                                ClientPackets.ExQuestItemList(buffe);
                            }
                            break;

                        case PServerEX.ExVitalityUpdate:
                            if (Globals.gamedata.Chron >= Chronicle.CT2_1)
                            {
                                ClientPackets.ExVitalityUpdate(buffe);
                            }
                            break;

                        case PServerEX.ExShowReceivedPostList:
                            ClientPackets.Load_ReceivedMails(buffe);
                            break;

                        case PServerEX.ExShowSecurityPinWindow:
                            Globals.gamedata.SecurityPinWindow = true;
                            if ((!Globals.OOG) && (!System.String.IsNullOrEmpty(Globals.SecurityPin)) && (!Globals.gamedata.SecurityPinOldClient))
                            {
                                System.Threading.Thread.Sleep(3000);
                                ServerPackets.SecurityPin();
                                Globals.gamedata.SecurityPinSent = true;
                            }
                            break;

                        case PServerEX.ExSecurityPinCorrect:
                            Globals.gamedata.SecurityPinOk = true;
                            break;

                        case PServerEX.ExAcquireSkillInfo:
                            ClientPackets.ExAcquireSkillInfo(buffe);
                            break;

                        case PServerEX.ExNewSkillToLearnByLevelup:
                            //Glory days
                            ClientPackets.ExAcquireSkillInfo(buffe);
                            break;

                        case PServerEX.ExtargetBuffs:
                            ClientPackets.Extargetbuffs(buffe);
                            break;

                        case PServerEX.ExPartyPetWindowAdd:
                            ClientPackets.ExPartyPetWindowAdd(buffe);
                            break;

                        case PServerEX.ExPartyPetWindowDelete:
                            ClientPackets.ExPartyPetWindowDelete(buffe);
                            break;

                        case PServerEX.ExNpcInfo:
                            ClientPackets.ExNPCInfo(buffe);
                            break;

                        case PServerEX.ExUserinfoItems:
                            ClientPackets.ExUserInfoItems(buffe);
                            break;

                        case PServerEX.ExUserinfoStats:
                            ClientPackets.ExUserInfoStats(buffe);
                            break;

                        case PServerEX.ExUserInfo:
                            ClientPackets.EXUserInfo(buffe);
                            break;
                        }
                        break;
                    }//end of switch on packet type
                }
                catch (System.Exception e)
                {
                    //Globals.l2net_home.Add_Error("Packet Error: " + last_p + " Previous Packet: " + last_p2 + " : " + e.Message);
                    Globals.l2net_home.Add_Error("Packet Error: " + last_p + " :: " + e.Message);
                }
            } //end of loop to handle queue data
        }     //end of HandlePackets
Exemple #24
0
        public static void Die_Packet(ByteBuffer inp)
        {
            uint dead_id = inp.ReadUInt32();
            uint toVillage = inp.ReadUInt32();
            uint toClanHall = inp.ReadUInt32();
            uint toCastle = inp.ReadUInt32();
            uint toSiegeHQ = inp.ReadUInt32();
            uint sweep = inp.ReadUInt32();
            uint toFortress = inp.ReadUInt32();
            //25, 4bytes access level

            if (Globals.gamedata.my_char.ID == dead_id)
            {
                Globals.l2net_home.DeadButtons(toVillage, toClanHall, toCastle, toSiegeHQ, toFortress);
                Globals.l2net_home.Show_Dead();

                if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
                {
                    ScriptEvent sc_ev = new ScriptEvent();
                    sc_ev.Type = EventType.SelfDie;
                    ScriptEngine.SendToEventQueue(sc_ev);
                }
            }

            if (Globals.gamedata.my_char.TargetID == dead_id)
            {
                /*
                if (sweep == 1 && Globals.gamedata.botoptions.AutoSweep == 1)
                {
                    ServerPackets.Try_Use_Skill(Globals.Skill_SWEEP, false, false);
                }*/

                if (Globals.gamedata.BOT_STATE == BotState.Attacking)
                {
                    Globals.gamedata.BOT_STATE = BotState.Nothing;
                }

                if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
                {
                    ScriptEvent sc_ev = new ScriptEvent();
                    sc_ev.Type = EventType.TargetDie;
                    sc_ev.Variables.Add(new ScriptVariable((long)sweep, "TARGET_BLUE", Var_Types.INT, Var_State.PUBLIC));
                    ScriptEngine.SendToEventQueue(sc_ev);
                }
            }

            TargetType type = Util.GetType(dead_id);

            switch (type)
            {
                case TargetType.SELF:
                    Globals.gamedata.my_char.Dest_X = Util.Float_Int32(Globals.gamedata.my_char.X);
                    Globals.gamedata.my_char.Dest_Y = Util.Float_Int32(Globals.gamedata.my_char.Y);
                    Globals.gamedata.my_char.Dest_Z = Util.Float_Int32(Globals.gamedata.my_char.Z);
                    Globals.gamedata.my_char.Moving = false;
                    Globals.gamedata.my_char.isAlikeDead = 1;
                    break;
                case TargetType.MYPET:
                    Globals.gamedata.my_pet.Dest_X = Util.Float_Int32(Globals.gamedata.my_pet.X);
                    Globals.gamedata.my_pet.Dest_Y = Util.Float_Int32(Globals.gamedata.my_pet.Y);
                    Globals.gamedata.my_pet.Dest_Z = Util.Float_Int32(Globals.gamedata.my_pet.Z);
                    Globals.gamedata.my_pet.Moving = false;
                    Globals.gamedata.my_pet.isAlikeDead = 1;
                    break;
                case TargetType.MYPET1:
                    Globals.gamedata.my_pet1.Dest_X = Util.Float_Int32(Globals.gamedata.my_pet1.X);
                    Globals.gamedata.my_pet1.Dest_Y = Util.Float_Int32(Globals.gamedata.my_pet1.Y);
                    Globals.gamedata.my_pet1.Dest_Z = Util.Float_Int32(Globals.gamedata.my_pet1.Z);
                    Globals.gamedata.my_pet1.Moving = false;
                    Globals.gamedata.my_pet1.isAlikeDead = 1;
                    break;
                case TargetType.MYPET2:
                    Globals.gamedata.my_pet2.Dest_X = Util.Float_Int32(Globals.gamedata.my_pet2.X);
                    Globals.gamedata.my_pet2.Dest_Y = Util.Float_Int32(Globals.gamedata.my_pet2.Y);
                    Globals.gamedata.my_pet2.Dest_Z = Util.Float_Int32(Globals.gamedata.my_pet2.Z);
                    Globals.gamedata.my_pet2.Moving = false;
                    Globals.gamedata.my_pet2.isAlikeDead = 1;
                    break;
                case TargetType.MYPET3:
                    Globals.gamedata.my_pet3.Dest_X = Util.Float_Int32(Globals.gamedata.my_pet3.X);
                    Globals.gamedata.my_pet3.Dest_Y = Util.Float_Int32(Globals.gamedata.my_pet3.Y);
                    Globals.gamedata.my_pet3.Dest_Z = Util.Float_Int32(Globals.gamedata.my_pet3.Z);
                    Globals.gamedata.my_pet3.Moving = false;
                    Globals.gamedata.my_pet3.isAlikeDead = 1;
                    break;
                case TargetType.PLAYER:
                    Globals.PlayerLock.EnterReadLock();
                    try
                    {
                        CharInfo player = Util.GetChar(dead_id);

                        if (player != null)
                        {
                            player.Dest_X = player.X;
                            player.Dest_Y = player.Y;
                            player.Dest_Z = player.Z;
                            player.Moving = false;
                            player.isAlikeDead = 1;
                        }
                    }//unlock
                    finally
                    {
                        Globals.PlayerLock.ExitReadLock();
                    }
                    break;
                case TargetType.NPC:
                    Globals.NPCLock.EnterReadLock();
                    try
                    {
                        NPCInfo npc = Util.GetNPC(dead_id);

                        if (npc != null)
                        {
                            try
                            {
                                Globals.MobListLock.EnterWriteLock();
                                if ((npc.ID == Globals.gamedata.my_char.TargetID) || (npc.ID == Globals.gamedata.my_pet.TargetID) || (npc.ID == Globals.gamedata.my_pet1.TargetID) || (npc.ID == Globals.gamedata.my_pet2.TargetID) || (npc.ID == Globals.gamedata.my_pet3.TargetID))
                                {
                                    Globals.gamedata.MobList.Add(npc.ID);
#if DEBUG
                                    Globals.l2net_home.Add_Text("Adding npc to moblist(npc dead): " + npc.ID, Globals.Green, TextType.SYSTEM);
#endif
                                }
                            }
                            finally
                            {
                                Globals.MobListLock.ExitWriteLock();
                            }

                            npc.Dest_X = npc.X;
                            npc.Dest_Y = npc.Y;
                            npc.Dest_Z = npc.Z;
                            npc.Moving = false;
                            npc.TargetID = 0;
                            npc.CurrentTargetType = TargetType.NONE;
                            npc.isAlikeDead = 1;
                            if (sweep == 1)
                                npc.IsSpoiled = true;
                        }
                        if (Globals.gamedata.botoptions.Cancel_Target == 1)
                        {
                            ServerPackets.Send_CancelTarget();
                        }
                    }//unlock
                    finally
                    {
                        Globals.NPCLock.ExitReadLock();
                    }
                    break;
            }
        }
Exemple #25
0
		public void SendToGameServer(ByteBuffer buff)
		{
            uint b0 = 0, b1 = 0;//byte
            bool expacket = false;
            try
            {
                b0 = buff.GetByte(0);
                b1 = buff.GetByte(1);
            }
            catch
            {

            }

            if (b0 == System.Convert.ToUInt32(PClient.EXPacket))
                expacket = true;

            //do we have an event for this packet?
            if (ScriptEngine.SelfPacketsContainsKey((int)b0))
            {
                ScriptEvent sc_ev = new ScriptEvent();
                sc_ev.Type = EventType.SelfPacket;
                sc_ev.Type2 = (int)b0;
                sc_ev.Variables.Add(new ScriptVariable(buff, "PACKET", Var_Types.BYTEBUFFER, Var_State.PUBLIC));
                sc_ev.Variables.Add(new ScriptVariable(System.DateTime.Now.Ticks, "TIMESTAMP", Var_Types.INT, Var_State.PUBLIC));
                ScriptEngine.SendToEventQueue(sc_ev);
            }

            if (expacket && ScriptEngine.SelfPacketsEXContainsKey((int)b1))
            {
                ScriptEvent sc_ev = new ScriptEvent();
                sc_ev.Type = EventType.SelfPacketEX;
                sc_ev.Type2 = (int)b1;
                sc_ev.Variables.Add(new ScriptVariable(buff, "PACKET", Var_Types.BYTEBUFFER, Var_State.PUBLIC));
                sc_ev.Variables.Add(new ScriptVariable(System.DateTime.Now.Ticks, "TIMESTAMP", Var_Types.INT, Var_State.PUBLIC));
                ScriptEngine.SendToEventQueue(sc_ev);
            }

            if (ScriptEngine.Blocked_SelfPackets.ContainsKey((int)b0) || (expacket && ScriptEngine.Blocked_SelfPacketsEX.ContainsKey((int)b1)))
            {
                //blocked packet... do nothing
            }
            else
            {
                if (Globals.Mixer != null)
                {
                    Globals.Mixer.Encrypt0(buff);
                }

                Globals.GameSendQueueLock.EnterWriteLock();
                try
                {
                    Globals.gamedata.gamesendqueue.Enqueue(buff);
                }
                finally
                {
                    Globals.GameSendQueueLock.ExitWriteLock();
                }

                if (Globals.gamethread.sendthread.ThreadState == System.Threading.ThreadState.WaitSleepJoin)
                {
                    try
                    {
                        Globals.gamethread.sendthread.Interrupt();
                    }
                    catch (System.Threading.ThreadInterruptedException)
                    {
                        //everything worked perfect
                    }
                    catch
                    {
                        Globals.l2net_home.Add_Error("SendToGameServer error");
                    }
                }
            }
		}
Exemple #26
0
        public static void LoadBuffList(ByteBuffer buff)
        {
            int cnt = buff.ReadInt16();

            Globals.MyBuffsListLock.EnterWriteLock();
            try
            {
                //duration in seconds
                Globals.gamedata.mybuffs.Clear();

                for (int i = 0; i < cnt; i++)
                {
                    Add_Buff(buff);
                }

                if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
                {
                    SortedList _mybuff = new SortedList();
                    if (Globals.gamedata.mybuffs.Count > 0)
                    {
                        foreach (CharBuff _buff in Globals.gamedata.mybuffs.Values)
                        {
                            Script_ClassData cd = new Script_ClassData();
                            cd.Name = "EFFECT";
                            cd._Variables.Add("ID", new ScriptVariable((long)_buff.ID, "ID", Var_Types.INT, Var_State.PUBLIC));
                            cd._Variables.Add("LEVEL", new ScriptVariable((long)_buff.SkillLevel, "LEVEL", Var_Types.INT, Var_State.PUBLIC));
                            cd._Variables.Add("DURATION", new ScriptVariable((long)_buff.ExpiresTime, "DURATION", Var_Types.INT, Var_State.PUBLIC));
                            cd._Variables.Add("EFFECT_TIME", new ScriptVariable((long)_buff.EFFECT_TIME, "EFFECT_TIME", Var_Types.INT, Var_State.PUBLIC));
                            cd._Variables.Add("NAME", new ScriptVariable(Util.GetSkillName(_buff.ID, _buff.SkillLevel), "NAME", Var_Types.STRING, Var_State.PUBLIC));
                            ScriptVariable sv = new ScriptVariable(cd, "EFFECT", Var_Types.CLASS, Var_State.PUBLIC);
                            _mybuff.Add(_buff.ID.ToString(), sv);
                        }
                    }
                    ScriptEvent sc_ev = new ScriptEvent();
                    sc_ev.Type = EventType.CharEffect;
                    sc_ev.Variables.Add(new ScriptVariable(_mybuff, "EFFECTLIST", Var_Types.SORTEDLIST, Var_State.PUBLIC));
                    ScriptEngine.SendToEventQueue(sc_ev);
                }

            }
            finally
            {
                Globals.MyBuffsListLock.ExitWriteLock();
            }
        }
Exemple #27
0
        public static void OtherMessage(ByteBuffer buffe)
        {
            uint data1 = buffe.ReadUInt32();//objid - mob that said it
            uint data2 = buffe.ReadUInt32();//type of message

            //offset = 9;
            string from = buffe.ReadString();
            if (Globals.gamedata.Chron >= Chronicle.CT2_6)
            {
                buffe.ReadUInt32();
            }
            string text = buffe.ReadString();

            if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
            {
                ScriptEvent sc_ev = new ScriptEvent();
                sc_ev.Type = EventType.Chat;
                sc_ev.Variables.Add(new ScriptVariable((long)data1, "SENDERID", Var_Types.INT, Var_State.PUBLIC));
                sc_ev.Variables.Add(new ScriptVariable((long)data2, "MESSAGETYPE", Var_Types.INT, Var_State.PUBLIC));
                sc_ev.Variables.Add(new ScriptVariable(from, "SENDERNAME", Var_Types.STRING, Var_State.PUBLIC));
                sc_ev.Variables.Add(new ScriptVariable(text, "MESSAGE", Var_Types.STRING, Var_State.PUBLIC));
                ScriptEngine.SendToEventQueue(sc_ev);
            }

            string message = from + ": " + text;

            switch (data2)
            {
                case 0x00://local
                    if (Globals.gamedata.alertoptions.beepon_whitechat)
                    {
                        VoicePlayer.PlayAlarm();
                    }
                    Globals.l2net_home.Add_Text(message, Globals.White, TextType.LOCAL);

                    if ((Globals.gamedata.LocalChatQueue.Count < 4) && Globals.gamedata.autoreply && (data1 != Globals.gamedata.my_char.ID))
                    {
                        Globals.gamedata.LocalChatQueue.Enqueue(message); //Max 3 messages at a time
                    }

                    break;
                case 0x01://shout
                    Globals.l2net_home.Add_Text(message, new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(((System.Byte)(253)), ((System.Byte)(100)), ((System.Byte)(0)))), TextType.LOCAL);
                    break;
                case 0x02://tell
                    if (Globals.gamedata.alertoptions.beepon_privatemessage)
                    {
                        VoicePlayer.PlayAlarm();
                    }
                    Globals.l2net_home.Add_Text(message, Globals.Tell_Brush, TextType.ALL);

                    if ((Globals.gamedata.PrivateMsgQueue.Count < 4)&& Globals.gamedata.autoreplyPM && (data1 != Globals.gamedata.my_char.ID))
                    {
                        Globals.gamedata.PrivateMsgQueue.Enqueue(message);
                    }
                    break;
                case 0x03://party
                    Globals.l2net_home.Add_Text(message, Globals.Party_Brush, TextType.PARTY);
                    break;
                case 0x04://clan
                    Globals.l2net_home.Add_Text(message, Globals.Clan_Brush, TextType.CLAN);
                    break;
                case 0x05://gm msg
                    Globals.l2net_home.Add_Text("GM MSG: " + message, Globals.Red, TextType.ALL);
                    break;
                case 0x06://gm petition text
                    Globals.l2net_home.Add_Text("GM PETITION: " + message, Globals.Red, TextType.ALL);
                    break;
                case 0x07://gm petition reply
                    Globals.l2net_home.Add_Text("GM PETITION REPLY: " + message, Globals.Red, TextType.ALL);
                    break;
                case 0x08://trade
                    Globals.l2net_home.Add_Text(message, Globals.Trade_Brush, TextType.TRADE);
                    break;
                case 0x09://ally
                    Globals.l2net_home.Add_Text(message, Globals.Ally_Brush, TextType.ALLY);
                    break;
                case 0x0A://anouncement
                    Globals.l2net_home.Add_Text(message, Globals.Announcement_Brush, TextType.ALL);
                    break;
                case 0x0B://crash
                    //Globals.l2net_home.Add_Text("Boat Message: " + message, Globals.Red, TextType.SYSTEM); //Disabled, boat message is bugged anyway...
                    break;
                case 0x0C://fake1
                    Globals.l2net_home.Add_Text("FAKE1: " + message, Globals.Red, TextType.ALL);
                    break;
                case 0x0D://fake2
                    Globals.l2net_home.Add_Text("FAKE2: " + message, Globals.Red, TextType.ALL);
                    break;
                case 0x0E://fake3
                    Globals.l2net_home.Add_Text("FAKE3: " + message, Globals.Red, TextType.ALL);
                    break;
                case 0x0F://party room all
                    Globals.l2net_home.Add_Text(message, Globals.Salmon, TextType.PARTY);
                    break;
                case 0x10://party room commander
                    Globals.l2net_home.Add_Text(message, Globals.Yellow, TextType.PARTY);
                    break;
                case 0x11://hero
                    Globals.l2net_home.Add_Text(message, Globals.Cyan, TextType.HERO);
                    break;
                case 0x12://Announcement 2
                    Globals.l2net_home.Add_Text(message, Globals.Announcement_Brush, TextType.SYSTEM);
                    break;
                case 0x14://territory battle
                    Globals.l2net_home.Add_Text(message, Globals.Gold, TextType.SYSTEM);
                    break;
                default:
                    Globals.l2net_home.Add_Text("0x" + data2.ToString("X2") + ": " + message, Globals.Red, TextType.BOT);
                    break;
            }
        }
Exemple #28
0
        private void ClientReadThread()
        {
            byte[] buffread = new byte[Globals.BUFFER_MAX];
            byte[] buffpacket;
            byte[] buffpacketin;

            int  cnt     = 0;
            int  size    = 0;
            int  ggcnt   = 0;
            bool forward = true;

            ByteBuffer bbuffer0;

            System.Text.StringBuilder dumpbuilder;

            Globals.l2net_home.Add_Text("Welcome to the game loop", Globals.Red, TextType.BOT);

            try
            {
                while (Globals.gamedata.running && !Globals.gamedata.OOG)
                {
                    cnt += Globals.Game_ClientSocket.Receive(buffread, cnt, Globals.BUFFER_PACKET - cnt, System.Net.Sockets.SocketFlags.None);
                    size = System.BitConverter.ToUInt16(buffread, 0);

                    while (cnt >= size && cnt > 2)
                    {
                        //if we got partial shit we cant use, read some more until it is full
                        while (size > cnt)
                        {
                            cnt += Globals.Game_ClientSocket.Receive(buffread, cnt, Globals.BUFFER_PACKET - cnt, System.Net.Sockets.SocketFlags.None);
                        }

                        buffpacketin = new byte[size - 2];
                        buffpacket   = new byte[size - 2];

                        Array.Copy(buffread, 2, buffpacketin, 0, size - 2);

                        Globals.gamedata.crypt_clientin.decrypt(buffpacketin);

                        Array.Copy(buffpacketin, 0, buffpacket, 0, size - 2);

                        if (Globals.Mixer != null)
                        {
                            Globals.Mixer.Decrypt0(buffpacket);
                        }
                        if (Globals.pck_thread.pck_recording)
                        {
                            pck_window_dat pck_dat = new pck_window_dat(buffpacket);
                            pck_dat.action = 1;
                            pck_dat.type   = 1;
                            pck_dat.time   = System.DateTime.Now.TimeOfDay.ToString();
                            Globals.pck_thread.mine_queue.Enqueue(pck_dat);
                        }
#if DEBUG
                        try
                        {
                            //

                            /* if (Globals.pck_thread.pck_recording)
                             * {
                             * // *                             lock (Globals.pck_thread.lock_obj)
                             * // {
                             *    pck_window_dat pck_dat = new pck_window_dat(buffpacket);
                             *    pck_dat.action = 1;
                             *    pck_dat.type = 1;
                             *    pck_dat.time = System.DateTime.Now.TimeOfDay.ToString();
                             *    Globals.pck_thread.mine_queue.Enqueue(pck_dat);
                             * //* }
                             * }*/
                            //
                            Globals.clientdataout.WriteLine("packet...-size: " + size.ToString() + " -count:" + cnt.ToString() + " :::time:::" + System.DateTime.Now.TimeOfDay.ToString() + ":::");
                            Globals.clientdataout.WriteLine("-data from client to bot hex-");
                            for (uint i = 0; i < size - 2; i++)
                            {
                                Globals.clientdataout.Write(buffpacket[i].ToString("X2"));
                                Globals.clientdataout.Write(" ");
                            }
                            Globals.clientdataout.WriteLine("");
                            Globals.clientdataout.WriteLine("-data from client to bot string-");
                            for (uint i = 0; i < size - 2; i++)
                            {
                                Globals.clientdataout.Write((char)buffpacket[i]);
                            }
                            Globals.clientdataout.WriteLine("");
                        }
                        catch
                        {
                            //failed to write... oh well
                        }
#endif

                        if (Globals.DumpModeClient)
                        {
                            dumpbuilder = new System.Text.StringBuilder();

                            for (int i = 0; i < size - 2; i++)
                            {
                                dumpbuilder.Append(buffpacket[i].ToString("X2"));
                                dumpbuilder.Append(" ");
                            }
                            Globals.l2net_home.Add_Dump(dumpbuilder.ToString(), false);
                        }

                        //shift the data over by size
                        for (uint i = 0; i < cnt - size; i++)
                        {
                            buffread[i] = buffread[size + i];
                        }

                        cnt -= size;

                        if (buffpacket.Length > 0)
                        {
                            forward = true;

                            if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
                            {
                                if ((PClient)buffpacket[0] == PClient.EXPacket)
                                {
                                    if (ScriptEngine.Blocked_ClientPacketsEX.ContainsKey(System.Convert.ToInt32(buffpacket[1])))
                                    {
                                        forward = false;
                                    }

                                    if (ScriptEngine.ClientPacketsEXContainsKey(System.Convert.ToInt32(buffpacket[1])))
                                    {
                                        ByteBuffer bb = new ByteBuffer(buffpacket);

                                        ScriptEvent sc_ev = new ScriptEvent();
                                        sc_ev.Type  = EventType.ClientPacketEX;
                                        sc_ev.Type2 = System.Convert.ToInt32(buffpacket[1]);
                                        sc_ev.Variables.Add(new ScriptVariable(bb, "PACKET", Var_Types.BYTEBUFFER, Var_State.PUBLIC));
                                        sc_ev.Variables.Add(new ScriptVariable(System.DateTime.Now.Ticks, "TIMESTAMP", Var_Types.INT, Var_State.PUBLIC));
                                        ScriptEngine.SendToEventQueue(sc_ev);
                                    }
                                }
                                else
                                {
                                    if (ScriptEngine.Blocked_ClientPackets.ContainsKey(System.Convert.ToInt32(buffpacket[0])))
                                    {
                                        forward = false;
                                    }

                                    if (ScriptEngine.ClientPacketsContainsKey(System.Convert.ToInt32(buffpacket[0])))
                                    {
                                        ByteBuffer bb = new ByteBuffer(buffpacket);

                                        ScriptEvent sc_ev = new ScriptEvent();
                                        sc_ev.Type  = EventType.ClientPacket;
                                        sc_ev.Type2 = System.Convert.ToInt32(buffpacket[0]);
                                        sc_ev.Variables.Add(new ScriptVariable(bb, "PACKET", Var_Types.BYTEBUFFER, Var_State.PUBLIC));
                                        sc_ev.Variables.Add(new ScriptVariable(System.DateTime.Now.Ticks, "TIMESTAMP", Var_Types.INT, Var_State.PUBLIC));
                                        ScriptEngine.SendToEventQueue(sc_ev);
                                    }
                                }
                            }

                            //this is where we would want to handle packets sent by the client
                            switch ((PClient)buffpacket[0])
                            {
                            case PClient.AuthLogin:    //protocol version
                                int prot = System.BitConverter.ToInt16(buffpacket, 1);
                                Globals.l2net_home.Add_Text("protocol version: " + prot.ToString(), Globals.Red, TextType.BOT);

                                if (prot == -2)
                                {
                                    Globals.l2net_home.Add_Text("-2 protocol... just a ping... we've been had XD...", Globals.Red, TextType.BOT);
                                }
                                else
                                {
                                    //valid protocol...
                                    Globals.l2net_home.Add_Text("valid protocol...", Globals.Red, TextType.BOT);
                                }
                                break;

                            case PClient.GameGuardReply:                                    //gameguard reply
                                if (Globals.GG_Servermode)
                                {
                                    if (Globals.GG_QueryReceived)
                                    {
                                        ggcnt++;
                                        if (ggcnt == 1)
                                        {
                                            //GameGuardServer.send_gg_answer(buffpacket, false);
                                            GameGuardServer.SendGGReply(buffpacket);
                                        }

                                        if (ggcnt == 2)
                                        {
                                            Globals.GG_QueryReceived = false;
                                            //GameGuardServer.send_gg_answer(buffpacket, true);
                                            GameGuardServer.SendGGReply(buffpacket);
                                            ggcnt = 0;
                                        }
                                        forward = false;
                                    }
                                }
                                if (Globals.Script_Debugging)
                                {
                                    string gg = "";

                                    for (int i = 1; i < buffpacket.Length; i++)
                                    {
                                        gg += buffpacket[i].ToString("X2") + " ";
                                    }

                                    Globals.l2net_home.Add_Debug("GameGuard Reply: " + gg);
                                }
                                break;

                            case PClient.Say2:                                    //say text
                                if (Globals.gamedata.OOG == false)
                                {
                                    ByteBuffer bbuff = new ByteBuffer(buffpacket);

                                    bbuff.ReadByte();
                                    string start = bbuff.ReadString();
                                    uint   type  = bbuff.ReadUInt32();
                                    string end   = bbuff.ReadString();

                                    //wanna handle text if prefaced with "-"
                                    //since these are commands to the bot

                                    if (start.StartsWith("--"))
                                    {
                                        forward = false;

                                        start = start.Substring(1, start.Length - 1);

                                        ServerPackets.Send_Text(type, start, end);
                                    }
                                    else if (start.StartsWith("-"))
                                    {
                                        forward = false;

                                        start = start.Substring(1, start.Length - 1);

                                        if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
                                        {
                                            ScriptEvent sc_ev = new ScriptEvent();
                                            sc_ev.Type = EventType.ChatToBot;
                                            sc_ev.Variables.Add(new ScriptVariable((long)type, "MESSAGETYPE", Var_Types.INT, Var_State.PUBLIC));
                                            sc_ev.Variables.Add(new ScriptVariable(end, "TARGETNAME", Var_Types.STRING, Var_State.PUBLIC));
                                            sc_ev.Variables.Add(new ScriptVariable(start, "MESSAGE", Var_Types.STRING, Var_State.PUBLIC));
                                            ScriptEngine.SendToEventQueue(sc_ev);
                                        }
                                    }
                                }
                                break;

                            case PClient.CharacterSelect:
                                if ((!Globals.gamedata.OOG) && (!System.String.IsNullOrEmpty(Globals.SecurityPin)) && (Globals.gamedata.SecurityPinOldClient) && (!Globals.gamedata.SecurityPinSent))
                                {
                                    ServerPackets.RequestSecurityPinWindow();

                                    while (!Globals.gamedata.SecurityPinWindow)
                                    {
                                        System.Threading.Thread.Sleep(100);
                                    }

                                    Globals.l2net_home.Add_Text("Sending security pin: " + Globals.SecurityPin, Globals.Green, TextType.BOT);

                                    ServerPackets.SecurityPin();

                                    while (!Globals.gamedata.SecurityPinOk)
                                    {
                                        System.Threading.Thread.Sleep(100);
                                    }
                                    Globals.l2net_home.Add_Text("Pin OK", Globals.Green, TextType.BOT);
                                    Globals.gamedata.SecurityPinSent = true;
                                }
                                break;
                            }

                            if (forward)
                            {
                                //send packets from the client right to the server
                                bbuffer0 = new ByteBuffer(buffpacketin);

                                Globals.gamedata.SendToGameServerNF(bbuffer0);
                            }
                        }

                        if (cnt > 2)
                        {
                            size = System.BitConverter.ToUInt16(buffread, 0);
                        }
                    }            //end of while loop
                }                //end of while running
            }
            catch (System.Exception e)
            {
                Globals.l2net_home.Add_Error("crash: ClientReadThread : " + e.Message);
                network_exception();
            }
        } //end of read data
Exemple #29
0
        public static void StopMove(ByteBuffer buffe)
        {
            uint data1 = buffe.ReadUInt32();
            int dx = buffe.ReadInt32();
            int dy = buffe.ReadInt32();
            int dz = buffe.ReadInt32();
            int dh = buffe.ReadInt32();

            TargetType type = Util.GetType(data1);

            switch (type)
            {
                case TargetType.SELF:
                    Globals.gamedata.my_char.Moving = false;
                    Globals.gamedata.my_char.MoveTarget = 0;
                    Globals.gamedata.my_char.MoveTargetType = TargetType.NONE;
                    Globals.gamedata.my_char.X = dx;
                    Globals.gamedata.my_char.Y = dy;
                    Globals.gamedata.my_char.Z = dz;
                    Globals.gamedata.my_char.Dest_X = dx;
                    Globals.gamedata.my_char.Dest_Y = dy;
                    Globals.gamedata.my_char.Dest_Z = dz;
                    Globals.gamedata.my_char.Heading = dh;
                    //Globals.gamedata.my_char.Clear_Botting_Buffing(false);

                    // More smarts for USE_SKILL_SMART
                    // This is one of the scenarios that would normally
                    // cause USE_SKILL_SMART to sleep forever unless we react by setting HitTime to 1.
                    Globals.gamedata.my_char.ExpiresTime = 1;
                    // Globals.l2net_home.Add_Text("StopMove setting ExpiresTime to 1 (" + Globals.gamedata.my_char.ExpiresTime + ")", Globals.Cyan, TextType.BOT);

                    if (Globals.gamedata.CurrentScriptState == ScriptState.Running)
                    {
                        ScriptEvent sc_ev = new ScriptEvent();
                        sc_ev.Type = EventType.SelfStopMove;
                        ScriptEngine.SendToEventQueue(sc_ev);
                    }
                    break;
                case TargetType.MYPET:
                    Globals.gamedata.my_pet.Moving = false;
                    Globals.gamedata.my_pet.MoveTarget = 0;
                    Globals.gamedata.my_pet.MoveTargetType = TargetType.NONE;
                    Globals.gamedata.my_pet.X = dx;
                    Globals.gamedata.my_pet.Y = dy;
                    Globals.gamedata.my_pet.Z = dz;
                    Globals.gamedata.my_pet.Dest_X = dx;
                    Globals.gamedata.my_pet.Dest_Y = dy;
                    Globals.gamedata.my_pet.Dest_Z = dz;
                    Globals.gamedata.my_pet.Heading = dh;
                    break;
                case TargetType.MYPET1:
                    Globals.gamedata.my_pet1.Moving = false;
                    Globals.gamedata.my_pet1.MoveTarget = 0;
                    Globals.gamedata.my_pet1.MoveTargetType = TargetType.NONE;
                    Globals.gamedata.my_pet1.X = dx;
                    Globals.gamedata.my_pet1.Y = dy;
                    Globals.gamedata.my_pet1.Z = dz;
                    Globals.gamedata.my_pet1.Dest_X = dx;
                    Globals.gamedata.my_pet1.Dest_Y = dy;
                    Globals.gamedata.my_pet1.Dest_Z = dz;
                    Globals.gamedata.my_pet1.Heading = dh;
                    break;
                case TargetType.MYPET2:
                    Globals.gamedata.my_pet2.Moving = false;
                    Globals.gamedata.my_pet2.MoveTarget = 0;
                    Globals.gamedata.my_pet2.MoveTargetType = TargetType.NONE;
                    Globals.gamedata.my_pet2.X = dx;
                    Globals.gamedata.my_pet2.Y = dy;
                    Globals.gamedata.my_pet2.Z = dz;
                    Globals.gamedata.my_pet2.Dest_X = dx;
                    Globals.gamedata.my_pet2.Dest_Y = dy;
                    Globals.gamedata.my_pet2.Dest_Z = dz;
                    Globals.gamedata.my_pet2.Heading = dh;
                    break;
                case TargetType.MYPET3:
                    Globals.gamedata.my_pet3.Moving = false;
                    Globals.gamedata.my_pet3.MoveTarget = 0;
                    Globals.gamedata.my_pet3.MoveTargetType = TargetType.NONE;
                    Globals.gamedata.my_pet3.X = dx;
                    Globals.gamedata.my_pet3.Y = dy;
                    Globals.gamedata.my_pet3.Z = dz;
                    Globals.gamedata.my_pet3.Dest_X = dx;
                    Globals.gamedata.my_pet3.Dest_Y = dy;
                    Globals.gamedata.my_pet3.Dest_Z = dz;
                    Globals.gamedata.my_pet3.Heading = dh;
                    break;
                case TargetType.PLAYER:
                    Globals.PlayerLock.EnterReadLock();
                    try
                    {
                        CharInfo player = Util.GetChar(data1);

                        if (player != null)
                        {
                            player.Moving = false;
                            player.MoveTarget = 0;
                            player.MoveTargetType = TargetType.NONE;
                            player.X = dx;
                            player.Y = dy;
                            player.Z = dz;
                            player.Dest_X = dx;
                            player.Dest_Y = dy;
                            player.Dest_Z = dz;
                            player.Heading = dh;
                        }
                    }
                    finally
                    {
                        Globals.PlayerLock.ExitReadLock();
                    }
                    break;
                case TargetType.NPC:
                    Globals.NPCLock.EnterReadLock();
                    try
                    {
                        NPCInfo npc = Util.GetNPC(data1);

                        if (npc != null)
                        {
                            npc.Moving = false;
                            npc.MoveTarget = 0;
                            npc.MoveTargetType = TargetType.NONE;
                            npc.X = dx;
                            npc.Y = dy;
                            npc.Z = dz;
                            npc.Dest_X = dx;
                            npc.Dest_Y = dy;
                            npc.Dest_Z = dz;
                            npc.Heading = dh;
                        }
                    }
                    finally
                    {
                        Globals.NPCLock.ExitReadLock();
                    }
                    break;
            }
        }