Esempio n. 1
0
 internal void CraftingRecipeSelected(Game game, int x, int y, int z, IntRef recipe)
 {
     if (recipe == null)
     {
         return;
     }
     game.SendPacketClient(ClientPackets.Craft(x, y, z, recipe.value));
 }
Esempio n. 2
0
        /*public static void PlayerMovement(bool[] inputs)
         * {
         *  using (var packet = new Packet((int) ClientPackets.playerMovement))
         *  {
         *      packet.Write(inputs.Length);
         *      for (int i = 0; i < inputs.Length; i++)
         *      {
         *          packet.Write(inputs[i]);
         *      }
         *      packet.Write(GameManager.players[Client.Instance.myId].transform.rotation);
         *
         *      SendUDPData(packet);
         *  }
         * }*/

        public static void SendStruct <TStruct>(ref TStruct tstruct, ClientPackets packetId, Client.TCP tcp)
            where TStruct : struct, IPacketSerializable
        {
            using (var packet = new Packet((int)packetId))
            {
                tstruct.WriteToPacket(packet);
                SendTCPData(packet, tcp);
            }
        }
Esempio n. 3
0
        public CharacterInfo(ClientPackets.NewCharacter p, MirConnection c)
        {
            Name = p.Name;
            Class = p.Class;
            Gender = p.Gender;

            CreationIP = c.IPAddress;
            CreationDate = SMain.Envir.Now;
        }
Esempio n. 4
0
 public override void OnKeyDown(Game game, KeyEventArgs args)
 {
     for (int i = 0; i < game.dialogsCount; i++)
     {
         if (game.dialogs[i] == null)
         {
             continue;
         }
         game.dialogs[i].screen.OnKeyDown(game, args);
     }
     if (game.guistate == GuiState.Normal)
     {
         if (args.GetKeyCode() == game.GetKey(GlKeys.Escape))
         {
             for (int i = 0; i < game.dialogsCount; i++)
             {
                 if (game.dialogs[i] == null)
                 {
                     continue;
                 }
                 VisibleDialog d = game.dialogs[i];
                 if (d.value.IsModal != 0)
                 {
                     game.dialogs[i] = null;
                     return;
                 }
             }
             game.ShowEscapeMenu();
             args.SetHandled(true);
             return;
         }
     }
     if (game.guistate == GuiState.ModalDialog)
     {
         if (//args.GetKeyCode() == game.GetKey(GlKeys.B) ||
             args.GetKeyCode() == game.GetKey(GlKeys.Escape))
         {
             for (int i = 0; i < game.dialogsCount; i++)
             {
                 if (game.dialogs[i] == null)
                 {
                     continue;
                 }
                 if (game.dialogs[i].value.IsModal != 0)
                 {
                     game.dialogs[i] = null;
                 }
             }
             game.SendPacketClient(ClientPackets.DialogClick("Esc", new string[0], 0));
             game.GuiStateBackToGame();
             args.SetHandled(true);
         }
         return;
     }
 }
Esempio n. 5
0
        public AccountInfo(C.NewAccount p)
        {
            AccountID = p.AccountID;
            Password = p.Password;
            UserName = p.UserName;
            SecretQuestion = p.SecretQuestion;
            SecretAnswer = p.SecretAnswer;
            EMailAddress = p.EMailAddress;

            BirthDate = p.BirthDate;
            CreationDate = SMain.Envir.Now;
        }
Esempio n. 6
0
    public override void OnNewFrame(Game game, NewFrameEventArgs args)
    {
        if (game.spawned && ((game.platform.TimeMillisecondsFromStart() - game.lastpositionsentMilliseconds) > 100))
        {
            game.lastpositionsentMilliseconds = game.platform.TimeMillisecondsFromStart();

            game.SendPacketClient(ClientPackets.PositionAndOrientation(game, game.LocalPlayerId,
                                                                       game.player.position.x, game.player.position.y, game.player.position.z,
                                                                       game.player.position.rotx, game.player.position.roty, game.player.position.rotz,
                                                                       game.localstance));
        }
    }
            /// <summary>Prepares received data to be used by the appropriate packet handler methods.</summary>
            /// <param name="_data">The recieved data.</param>
            private bool HandleData(byte[] _data)
            {
                int _packetLength = 0;

                receivedData.SetBytes(_data);

                if (receivedData.UnreadLength() >= 4)
                {
                    // If client's received data contains a packet
                    _packetLength = receivedData.ReadInt();
                    if (_packetLength <= 0)
                    {
                        // If packet contains no data
                        return(true); // Reset receivedData instance to allow it to be reused
                    }
                }

                while (_packetLength > 0 && _packetLength <= receivedData.UnreadLength())
                {
                    // While packet contains data AND packet data length doesn't exceed the length of the packet we're reading
                    byte[] _packetBytes = receivedData.ReadBytes(_packetLength);
                    ThreadManager.ExecuteOnMainThread(() =>
                    {
                        using (Packet _packet = new Packet(_packetBytes))
                        {
                            ClientPackets _packetId = (ClientPackets)_packet.ReadInt();
                            PacketHandler.PacketHandlers[_packetId](id, _packet); // Call appropriate method to handle the packet
                        }
                    });

                    _packetLength = 0; // Reset packet length
                    if (receivedData.UnreadLength() >= 4)
                    {
                        // If client's received data contains another packet
                        _packetLength = receivedData.ReadInt();
                        if (_packetLength <= 0)
                        {
                            // If packet contains no data
                            return(true); // Reset receivedData instance to allow it to be reused
                        }
                    }
                }

                if (_packetLength <= 1)
                {
                    return(true); // Reset receivedData instance to allow it to be reused
                }

                return(false);
            }
    public override void OnNewFrameFixed(Game game, NewFrameEventArgs args)
    {
        Packet_Item activeitem  = game.d_Inventory.RightHand[game.ActiveMaterial];
        int         activeblock = 0;

        if (activeitem != null)
        {
            activeblock = activeitem.BlockId;
        }
        if (activeblock != PreviousActiveMaterialBlock)
        {
            game.SendPacketClient(ClientPackets.ActiveMaterialSlot(game.ActiveMaterial));
        }
        PreviousActiveMaterialBlock = activeblock;
    }
            /// <summary>Prepares received data to be used by the appropriate packet handler methods.</summary>
            /// <param name="_packetData">The packet containing the recieved data.</param>
            public void HandleData(Packet _packetData)
            {
                int _packetLength = _packetData.ReadInt();

                byte[] _packetBytes = _packetData.ReadBytes(_packetLength);

                ThreadManager.ExecuteOnMainThread(() =>
                {
                    using (Packet _packet = new Packet(_packetBytes))
                    {
                        ClientPackets _packetId = (ClientPackets)_packet.ReadInt();
                        PacketHandler.PacketHandlers[_packetId](id, _packet); // Call appropriate method to handle the packet
                    }
                });
            }
Esempio n. 10
0
 public override void OnKeyPress(Game game, KeyPressEventArgs args)
 {
     if (game.guistate != GuiState.ModalDialog &&
         game.guistate != GuiState.Normal)
     {
         return;
     }
     if (game.IsTyping)
     {
         // Do not handle key presses when chat is opened
         return;
     }
     for (int i = 0; i < game.dialogsCount; i++)
     {
         if (game.dialogs[i] == null)
         {
             continue;
         }
         game.dialogs[i].screen.OnKeyPress(game, args);
     }
     for (int k = 0; k < game.dialogsCount; k++)
     {
         if (game.dialogs[k] == null)
         {
             continue;
         }
         VisibleDialog d = game.dialogs[k];
         for (int i = 0; i < d.value.WidgetsCount; i++)
         {
             Packet_Widget w = d.value.Widgets[i];
             if (w == null)
             {
                 continue;
             }
             // Only typeable characters are handled by KeyPress (for special characters use KeyDown)
             string valid = "abcdefghijklmnopqrstuvwxyz1234567890\t ";
             if (game.platform.StringContains(valid, game.CharToString(w.ClickKey)))
             {
                 if (args.GetKeyChar() == w.ClickKey)
                 {
                     game.SendPacketClient(ClientPackets.DialogClick(w.Id, new string[0], 0));
                     return;
                 }
             }
         }
     }
 }
Esempio n. 11
0
 public override void OnButton(MenuWidget w)
 {
     if (w.isbutton)
     {
         string[] textValues = new string[WidgetCount];
         for (int i = 0; i < WidgetCount; i++)
         {
             string s = widgets[i].text;
             if (s == null)
             {
                 s = "";
             }
             textValues[i] = s;
         }
         game.SendPacketClient(ClientPackets.DialogClick(w.id, textValues, WidgetCount));
     }
 }
Esempio n. 12
0
    void SendRequest(NetClient client)
    {
        //Create request packet
        Packet_Client pp = ClientPackets.ServerQuery();

        //Serialize packet
        CitoMemoryStream ms = new CitoMemoryStream();

        Packet_ClientSerializer.Serialize(ms, pp);
        byte[] data = ms.ToArray();

        //Send packet to server
        INetOutgoingMessage msg = new INetOutgoingMessage();

        msg.Write(data, ms.Length());
        client.SendMessage(msg, MyNetDeliveryMethod.ReliableOrdered);
    }
Esempio n. 13
0
 private void RegisterResponse(ClientPackets packet)
 {
     if (!this.IsDisposed)
     {
         if (packet == ClientPackets.RegisterAccept)
         {
             if (MessageBox.Show(Program.LanguageManager.Translation.RegistMsb4) == System.Windows.Forms.DialogResult.OK)
             {
                 DialogResult = System.Windows.Forms.DialogResult.OK;
             }
         }
         else if (packet == ClientPackets.RegisterFailed)
         {
             MessageBox.Show(Program.LanguageManager.Translation.RegistMsb5);
         }
     }
 }
Esempio n. 14
0
 void UpdateEntityHit(Game game)
 {
     //Only single hit when mouse clicked
     if (game.currentlyAttackedEntity != -1 && game.mouseLeft)
     {
         for (int i = 0; i < game.clientmodsCount; i++)
         {
             if (game.clientmods[i] == null)
             {
                 continue;
             }
             OnUseEntityArgs args = new OnUseEntityArgs();
             args.entityId = game.currentlyAttackedEntity;
             game.clientmods[i].OnHitEntity(game, args);
         }
         game.SendPacketClient(ClientPackets.HitEntity(game.currentlyAttackedEntity));
     }
 }
        private static void AcceptCallback(IAsyncResult ar)
        {
            Socket socket = _serverSocket.EndAccept(ar);

            _serverSocket.BeginAccept(new AsyncCallback(AcceptCallback), null);

            byte[] tempData = new byte[1024];
            socket.ReceiveTimeout = (int)Constants.CONNECT_TIMEOUT * 1000;

            try {
                PacketBuffer buffer = new PacketBuffer();
                buffer.WriteServerPacket(ServerPackets.SAskIfClientOrServer);
                SendDataTo(socket, buffer.ToArray());
                buffer.Dispose();

                socket.Receive(tempData);

                PacketBuffer  receivedbuffer = new PacketBuffer(tempData);
                ClientPackets packet         = receivedbuffer.ReadClientPacket();
                string        key            = receivedbuffer.ReadString();
                int           index          = receivedbuffer.ReadInteger();

                if (packet != ClientPackets.CSendKey)
                {
                    throw new Exception("Wrong packet sent to server.");
                }

                if (key == ServerHandleNetworkData.masterServerKey)
                {
                    ConnectMatchServer(socket, index);
                }
                else if (key == ServerHandleNetworkData.clientKey)
                {
                    ConnectPlayer(socket);
                }
                else
                {
                    throw new Exception("Wrong key sent to server.");
                }
            } catch {
                socket.Close();
            }
        }
Esempio n. 16
0
 public override void OnKeyPress(Game game, KeyPressEventArgs args)
 {
     if (game.guistate != GuiState.ModalDialog &&
         game.guistate != GuiState.Normal)
     {
         return;
     }
     for (int i = 0; i < game.dialogsCount; i++)
     {
         if (game.dialogs[i] == null)
         {
             continue;
         }
         game.dialogs[i].screen.OnKeyPress(game, args);
     }
     for (int k = 0; k < game.dialogsCount; k++)
     {
         if (game.dialogs[k] == null)
         {
             continue;
         }
         VisibleDialog d = game.dialogs[k];
         for (int i = 0; i < d.value.WidgetsCount; i++)
         {
             Packet_Widget w = d.value.Widgets[i];
             if (w == null)
             {
                 continue;
             }
             string valid = (StringTools.StringAppend(game.platform, "abcdefghijklmnopqrstuvwxyz1234567890\t ", game.CharToString(27)));
             if (game.platform.StringContains(valid, game.CharToString(w.ClickKey)))
             {
                 if (args.GetKeyChar() == w.ClickKey)
                 {
                     game.SendPacketClient(ClientPackets.DialogClick(w.Id, new string[0], 0));
                     return;
                 }
             }
         }
     }
 }
Esempio n. 17
0
        private void LoginResponse(ClientPackets type, LoginData data)
        {
            if (type == ClientPackets.Banned)
            {
                if (ResetTimeout != null)
                    ResetTimeout();
                MessageBox.Show("You are banned.");
            }
            else if (type == ClientPackets.LoginFailed)
            {
                if (ResetTimeout != null)
                    ResetTimeout();
                MessageBox.Show("Incorrect Password or Username.");
            }
            else
            {
                _userInfo.Username = _username;
                _userInfo.LoginKey = data.LoginKey.ToString();
                _userInfo.Rank = data.UserRank;

                if (NotifyLogin != null)
                    NotifyLogin();
            }
        }
Esempio n. 18
0
    public override void OnKeyDown(Game game, KeyEventArgs args)
    {
        if (!(game.guistate == GuiState.Normal && game.GuiTyping == TypingState.None))
        {
            //Do nothing when in dialog or chat
            return;
        }
        int eKey = args.GetKeyCode();

        if (eKey == game.GetKey(GlKeys.R))
        {
            Packet_Item item = game.d_Inventory.RightHand[game.ActiveMaterial];
            if (item != null && item.ItemClass == Packet_ItemClassEnum.Block &&
                game.blocktypes[item.BlockId].IsPistol &&
                game.reloadstartMilliseconds == 0)
            {
                int sound = game.rnd.Next() % game.blocktypes[item.BlockId].Sounds.ReloadCount;
                game.AudioPlay(StringTools.StringAppend(game.platform, game.blocktypes[item.BlockId].Sounds.Reload[sound], ".ogg"));
                game.reloadstartMilliseconds = game.platform.TimeMillisecondsFromStart();
                game.reloadblock             = item.BlockId;
                game.SendPacketClient(ClientPackets.Reload());
            }
        }
    }
    //TODO server side?
    internal void UpdateBlockDamageToPlayer(Game game, float dt)
    {
        float pX = game.player.position.x;
        float pY = game.player.position.y;
        float pZ = game.player.position.z;

        pY += game.entities[game.LocalPlayerId].drawModel.eyeHeight;
        int block1 = 0;
        int block2 = 0;

        if (game.map.IsValidPos(game.MathFloor(pX), game.MathFloor(pZ), game.MathFloor(pY)))
        {
            block1 = game.map.GetBlock(game.platform.FloatToInt(pX), game.platform.FloatToInt(pZ), game.platform.FloatToInt(pY));
        }
        if (game.map.IsValidPos(game.MathFloor(pX), game.MathFloor(pZ), game.MathFloor(pY) - 1))
        {
            block2 = game.map.GetBlock(game.platform.FloatToInt(pX), game.platform.FloatToInt(pZ), game.platform.FloatToInt(pY) - 1);
        }

        int damage = game.d_Data.DamageToPlayer()[block1] + game.d_Data.DamageToPlayer()[block2];

        if (damage > 0)
        {
            int hurtingBlock = block1;  //Use block at eyeheight as source block
            if (hurtingBlock == 0)
            {
                hurtingBlock = block2;
            }                                                   //Fallback to block at feet if eyeheight block is air
            int times = BlockDamageToPlayerTimer.Update(dt);
            for (int i = 0; i < times; i++)
            {
                game.ApplyDamageToPlayer(damage, Packet_DeathReasonEnum.BlockDamage, hurtingBlock);
            }
        }

        //Player drowning
        int deltaTime = game.platform.FloatToInt(one * (game.platform.TimeMillisecondsFromStart() - game.lastOxygenTickMilliseconds)); //Time in milliseconds

        if (deltaTime >= 1000)
        {
            if (game.WaterSwimmingEyes())
            {
                game.PlayerStats.CurrentOxygen -= 1;
                if (game.PlayerStats.CurrentOxygen <= 0)
                {
                    game.PlayerStats.CurrentOxygen = 0;
                    int dmg = game.platform.FloatToInt(one * game.PlayerStats.MaxHealth / 10);
                    if (dmg < 1)
                    {
                        dmg = 1;
                    }
                    game.ApplyDamageToPlayer(dmg, Packet_DeathReasonEnum.Drowning, block1);
                }
            }
            else
            {
                game.PlayerStats.CurrentOxygen = game.PlayerStats.MaxOxygen;
            }
            if (GameVersionHelper.ServerVersionAtLeast(game.platform, game.serverGameVersion, 2014, 3, 31))
            {
                game.SendPacketClient(ClientPackets.Oxygen(game.PlayerStats.CurrentOxygen));
            }
            game.lastOxygenTickMilliseconds = game.platform.TimeMillisecondsFromStart();
        }
    }
Esempio n. 20
0
        public void ChangePassword(ClientPackets.ChangePassword p, MirConnection c)
        {
            if (!Settings.AllowChangePassword)
            {
                c.Enqueue(new ServerPackets.ChangePassword {Result = 0});
                return;
            }

            if (!AccountIDReg.IsMatch(p.AccountID))
            {
                c.Enqueue(new ServerPackets.ChangePassword {Result = 1});
                return;
            }

            if (!PasswordReg.IsMatch(p.CurrentPassword))
            {
                c.Enqueue(new ServerPackets.ChangePassword {Result = 2});
                return;
            }

            if (!PasswordReg.IsMatch(p.NewPassword))
            {
                c.Enqueue(new ServerPackets.ChangePassword {Result = 3});
                return;
            }

            AccountInfo account = GetAccount(p.AccountID);

            if (account == null)
            {
                c.Enqueue(new ServerPackets.ChangePassword {Result = 4});
                return;
            }

            if (account.Banned)
            {
                if (account.ExpiryDate > Now)
                {
                    c.Enqueue(new ServerPackets.ChangePasswordBanned {Reason = account.BanReason, ExpiryDate = account.ExpiryDate});
                    return;
                }
                account.Banned = false;
            }
            account.BanReason = string.Empty;
            account.ExpiryDate = DateTime.MinValue;

            if (String.CompareOrdinal(account.Password, p.CurrentPassword) != 0)
            {
                c.Enqueue(new ServerPackets.ChangePassword {Result = 5});
                return;
            }

            account.Password = p.NewPassword;
            c.Enqueue(new ServerPackets.ChangePassword {Result = 6});
        }
Esempio n. 21
0
        public void NewAccount(ClientPackets.NewAccount p, MirConnection c)
        {
            if (!Settings.AllowNewAccount)
            {
                c.Enqueue(new ServerPackets.NewAccount {Result = 0});
                return;
            }

            if (!AccountIDReg.IsMatch(p.AccountID))
            {
                c.Enqueue(new ServerPackets.NewAccount {Result = 1});
                return;
            }

            if (!PasswordReg.IsMatch(p.Password))
            {
                c.Enqueue(new ServerPackets.NewAccount {Result = 2});
                return;
            }
            if (!string.IsNullOrWhiteSpace(p.EMailAddress) && !EMailReg.IsMatch(p.EMailAddress) ||
                p.EMailAddress.Length > 50)
            {
                c.Enqueue(new ServerPackets.NewAccount {Result = 3});
                return;
            }

            if (!string.IsNullOrWhiteSpace(p.UserName) && p.UserName.Length > 20)
            {
                c.Enqueue(new ServerPackets.NewAccount {Result = 4});
                return;
            }

            if (!string.IsNullOrWhiteSpace(p.SecretQuestion) && p.SecretQuestion.Length > 30)
            {
                c.Enqueue(new ServerPackets.NewAccount {Result = 5});
                return;
            }

            if (!string.IsNullOrWhiteSpace(p.SecretAnswer) && p.SecretAnswer.Length > 30)
            {
                c.Enqueue(new ServerPackets.NewAccount {Result = 6});
                return;
            }

            lock (AccountLock)
            {
                if (AccountExists(p.AccountID))
                {
                    c.Enqueue(new ServerPackets.NewAccount {Result = 7});
                    return;
                }

                AccountList.Add(new AccountInfo(p) {Index = ++NextAccountID, CreationIP = c.IPAddress});

                c.Enqueue(new ServerPackets.NewAccount {Result = 8});
            }
        }
Esempio n. 22
0
        private void NewCharacter(C.NewCharacter p)
        {
            if (Stage != GameStage.Select) return;

            SMain.Envir.NewCharacter(p, this);
        }
Esempio n. 23
0
        public void DeleteMail(C.DeleteMail p)
        {
            if (Stage != GameStage.Game) return;

            Player.DeleteMail(p.MailID);
        }
Esempio n. 24
0
        private void MarketSearch(C.MarketSearch p)
        {
            if (Stage != GameStage.Game) return;

            Player.MarketSearch(p.Match);
        }
 public void WriteClientPacket(ClientPackets clientPacket)
 {
     WriteInteger((int)clientPacket);
 }
Esempio n. 26
0
 private void GuildStorageGoldChange(C.GuildStorageGoldChange p)
 {
     if (Stage != GameStage.Game) return;
     Player.GuildStorageGoldChange(p.Type, p.Amount);
 }
Esempio n. 27
0
 private void GuildStorageItemChange(C.GuildStorageItemChange p)
 {
     if (Stage != GameStage.Game) return;
     Player.GuildStorageItemChange(p.Type, p.From, p.To);
 }
Esempio n. 28
0
        private void GuildInvite(C.GuildInvite p)
        {
            if (Stage != GameStage.Game) return;

            Player.GuildInvite(p.AcceptInvite);
        }
Esempio n. 29
0
        private void FishingChangeAutocast(C.FishingChangeAutocast p)
        {
            if (Stage != GameStage.Game) return;

            Player.FishingChangeAutocast(p.AutoCast);
        }
Esempio n. 30
0
        private void FishingCast(C.FishingCast p)
        {
            if (Stage != GameStage.Game) return;

            Player.FishingCast(p.CastOut, true);
        }
Esempio n. 31
0
        private void MarketGetBack(C.MarketGetBack p)
        {
            if (Stage != GameStage.Game) return;

            Player.MarketGetBack(p.AuctionID);
        }
Esempio n. 32
0
        private void MoveItem(C.MoveItem p)
        {
            if (Stage != GameStage.Game) return;

            Player.MoveItem(p.Grid, p.From, p.To);
        }
Esempio n. 33
0
        private void MarketPage(C.MarketPage p)
        {
            if (Stage != GameStage.Game) return;

            Player.MarketPage(p.Page);
        }
Esempio n. 34
0
    internal void NextBullet(Game game, int bulletsshot)
    {
        float one    = 1;
        bool  left   = game.mouseLeft;
        bool  middle = game.mouseMiddle;
        bool  right  = game.mouseRight;

        bool IsNextShot = bulletsshot != 0;

        if (!game.leftpressedpicking)
        {
            if (game.mouseleftclick)
            {
                game.leftpressedpicking = true;
            }
            else
            {
                left = false;
            }
        }
        else
        {
            if (game.mouseleftdeclick)
            {
                game.leftpressedpicking = false;
                left = false;
            }
        }
        if (!left)
        {
            game.currentAttackedBlock = null;
        }

        Packet_Item item          = game.d_Inventory.RightHand[game.ActiveMaterial];
        bool        ispistol      = (item != null && game.blocktypes[item.BlockId].IsPistol);
        bool        ispistolshoot = ispistol && left;
        bool        isgrenade     = ispistol && game.blocktypes[item.BlockId].PistolType == Packet_PistolTypeEnum.Grenade;

        if (ispistol && isgrenade)
        {
            ispistolshoot = game.mouseleftdeclick;
        }
        //grenade cooking - TODO: fix instant explosion when closing ESC menu
        if (game.mouseleftclick)
        {
            game.grenadecookingstartMilliseconds = game.platform.TimeMillisecondsFromStart();
            if (ispistol && isgrenade)
            {
                if (game.blocktypes[item.BlockId].Sounds.ShootCount > 0)
                {
                    game.AudioPlay(game.platform.StringFormat("{0}.ogg", game.blocktypes[item.BlockId].Sounds.Shoot[0]));
                }
            }
        }
        float wait = ((one * (game.platform.TimeMillisecondsFromStart() - game.grenadecookingstartMilliseconds)) / 1000);

        if (isgrenade && left)
        {
            if (wait >= game.grenadetime && isgrenade && game.grenadecookingstartMilliseconds != 0)
            {
                ispistolshoot         = true;
                game.mouseleftdeclick = true;
            }
            else
            {
                return;
            }
        }
        else
        {
            game.grenadecookingstartMilliseconds = 0;
        }

        if (ispistol && game.mouserightclick && (game.platform.TimeMillisecondsFromStart() - game.lastironsightschangeMilliseconds) >= 500)
        {
            game.IronSights = !game.IronSights;
            game.lastironsightschangeMilliseconds = game.platform.TimeMillisecondsFromStart();
        }

        IntRef pick2count = new IntRef();
        Line3D pick       = new Line3D();

        GetPickingLine(game, pick, ispistolshoot);
        BlockPosSide[] pick2 = game.Pick(game.s, pick, pick2count);

        if (left)
        {
            game.handSetAttackDestroy = true;
        }
        else if (right)
        {
            game.handSetAttackBuild = true;
        }

        if (game.overheadcamera && pick2count.value > 0 && left)
        {
            //if not picked any object, and mouse button is pressed, then walk to destination.
            if (game.Follow == null)
            {
                //Only walk to destination when not following someone
                game.playerdestination = Vector3Ref.Create(pick2[0].blockPos[0], pick2[0].blockPos[1] + 1, pick2[0].blockPos[2]);
            }
        }
        bool pickdistanceok = (pick2count.value > 0); //&& (!ispistol);

        if (pickdistanceok)
        {
            if (game.Dist(pick2[0].blockPos[0] + one / 2, pick2[0].blockPos[1] + one / 2, pick2[0].blockPos[2] + one / 2,
                          pick.Start[0], pick.Start[1], pick.Start[2]) > CurrentPickDistance(game))
            {
                pickdistanceok = false;
            }
        }
        bool playertileempty = game.IsTileEmptyForPhysics(
            game.platform.FloatToInt(game.player.position.x),
            game.platform.FloatToInt(game.player.position.z),
            game.platform.FloatToInt(game.player.position.y + (one / 2)));
        bool playertileemptyclose = game.IsTileEmptyForPhysicsClose(
            game.platform.FloatToInt(game.player.position.x),
            game.platform.FloatToInt(game.player.position.z),
            game.platform.FloatToInt(game.player.position.y + (one / 2)));
        BlockPosSide pick0 = new BlockPosSide();

        if (pick2count.value > 0 &&
            ((pickdistanceok && (playertileempty || (playertileemptyclose))) ||
             game.overheadcamera)
            )
        {
            game.SelectedBlockPositionX = game.platform.FloatToInt(pick2[0].Current()[0]);
            game.SelectedBlockPositionY = game.platform.FloatToInt(pick2[0].Current()[1]);
            game.SelectedBlockPositionZ = game.platform.FloatToInt(pick2[0].Current()[2]);
            pick0 = pick2[0];
        }
        else
        {
            game.SelectedBlockPositionX = -1;
            game.SelectedBlockPositionY = -1;
            game.SelectedBlockPositionZ = -1;
            pick0.blockPos    = new float[3];
            pick0.blockPos[0] = -1;
            pick0.blockPos[1] = -1;
            pick0.blockPos[2] = -1;
        }
        PickEntity(game, pick, pick2, pick2count);
        if (game.cameratype == CameraType.Fpp || game.cameratype == CameraType.Tpp)
        {
            int ntileX = game.platform.FloatToInt(pick0.Current()[0]);
            int ntileY = game.platform.FloatToInt(pick0.Current()[1]);
            int ntileZ = game.platform.FloatToInt(pick0.Current()[2]);
            if (game.IsUsableBlock(game.map.GetBlock(ntileX, ntileZ, ntileY)))
            {
                game.currentAttackedBlock = Vector3IntRef.Create(ntileX, ntileZ, ntileY);
            }
        }
        if (game.GetFreeMouse())
        {
            if (pick2count.value > 0)
            {
                OnPick_(pick0);
            }
            return;
        }

        if ((one * (game.platform.TimeMillisecondsFromStart() - lastbuildMilliseconds) / 1000) >= BuildDelay(game) ||
            IsNextShot)
        {
            if (left && game.d_Inventory.RightHand[game.ActiveMaterial] == null)
            {
                game.SendPacketClient(ClientPackets.MonsterHit(game.platform.FloatToInt(2 + game.rnd.NextFloat() * 4)));
            }
            if (left && !fastclicking)
            {
                //todo animation
                fastclicking = false;
            }
            if ((left || right || middle) && (!isgrenade))
            {
                lastbuildMilliseconds = game.platform.TimeMillisecondsFromStart();
            }
            if (isgrenade && game.mouseleftdeclick)
            {
                lastbuildMilliseconds = game.platform.TimeMillisecondsFromStart();
            }
            if (game.reloadstartMilliseconds != 0)
            {
                PickingEnd(left, right, middle, ispistol);
                return;
            }
            if (ispistolshoot)
            {
                if ((!(game.LoadedAmmo[item.BlockId] > 0)) ||
                    (!(game.TotalAmmo[item.BlockId] > 0)))
                {
                    game.AudioPlay("Dry Fire Gun-SoundBible.com-2053652037.ogg");
                    PickingEnd(left, right, middle, ispistol);
                    return;
                }
            }
            if (ispistolshoot)
            {
                float toX = pick.End[0];
                float toY = pick.End[1];
                float toZ = pick.End[2];
                if (pick2count.value > 0)
                {
                    toX = pick2[0].blockPos[0];
                    toY = pick2[0].blockPos[1];
                    toZ = pick2[0].blockPos[2];
                }

                Packet_ClientShot shot = new Packet_ClientShot();
                shot.FromX     = game.SerializeFloat(pick.Start[0]);
                shot.FromY     = game.SerializeFloat(pick.Start[1]);
                shot.FromZ     = game.SerializeFloat(pick.Start[2]);
                shot.ToX       = game.SerializeFloat(toX);
                shot.ToY       = game.SerializeFloat(toY);
                shot.ToZ       = game.SerializeFloat(toZ);
                shot.HitPlayer = -1;

                for (int i = 0; i < game.entitiesCount; i++)
                {
                    if (game.entities[i] == null)
                    {
                        continue;
                    }
                    if (game.entities[i].drawModel == null)
                    {
                        continue;
                    }
                    Entity p_ = game.entities[i];
                    if (p_.networkPosition == null)
                    {
                        continue;
                    }
                    if (!p_.networkPosition.PositionLoaded)
                    {
                        continue;
                    }
                    float feetposX = p_.position.x;
                    float feetposY = p_.position.y;
                    float feetposZ = p_.position.z;
                    //var p = PlayerPositionSpawn;
                    Box3D bodybox  = new Box3D();
                    float headsize = (p_.drawModel.ModelHeight - p_.drawModel.eyeHeight) * 2; //0.4f;
                    float h        = p_.drawModel.ModelHeight - headsize;
                    float r        = one * 35 / 100;

                    bodybox.AddPoint(feetposX - r, feetposY + 0, feetposZ - r);
                    bodybox.AddPoint(feetposX - r, feetposY + 0, feetposZ + r);
                    bodybox.AddPoint(feetposX + r, feetposY + 0, feetposZ - r);
                    bodybox.AddPoint(feetposX + r, feetposY + 0, feetposZ + r);

                    bodybox.AddPoint(feetposX - r, feetposY + h, feetposZ - r);
                    bodybox.AddPoint(feetposX - r, feetposY + h, feetposZ + r);
                    bodybox.AddPoint(feetposX + r, feetposY + h, feetposZ - r);
                    bodybox.AddPoint(feetposX + r, feetposY + h, feetposZ + r);

                    Box3D headbox = new Box3D();

                    headbox.AddPoint(feetposX - r, feetposY + h, feetposZ - r);
                    headbox.AddPoint(feetposX - r, feetposY + h, feetposZ + r);
                    headbox.AddPoint(feetposX + r, feetposY + h, feetposZ - r);
                    headbox.AddPoint(feetposX + r, feetposY + h, feetposZ + r);

                    headbox.AddPoint(feetposX - r, feetposY + h + headsize, feetposZ - r);
                    headbox.AddPoint(feetposX - r, feetposY + h + headsize, feetposZ + r);
                    headbox.AddPoint(feetposX + r, feetposY + h + headsize, feetposZ - r);
                    headbox.AddPoint(feetposX + r, feetposY + h + headsize, feetposZ + r);

                    float[] p;
                    float   localeyeposX = game.EyesPosX();
                    float   localeyeposY = game.EyesPosY();
                    float   localeyeposZ = game.EyesPosZ();
                    p = Intersection.CheckLineBoxExact(pick, headbox);
                    if (p != null)
                    {
                        //do not allow to shoot through terrain
                        if (pick2count.value == 0 || (game.Dist(pick2[0].blockPos[0], pick2[0].blockPos[1], pick2[0].blockPos[2], localeyeposX, localeyeposY, localeyeposZ)
                                                      > game.Dist(p[0], p[1], p[2], localeyeposX, localeyeposY, localeyeposZ)))
                        {
                            if (!isgrenade)
                            {
                                Entity entity = new Entity();
                                Sprite sprite = new Sprite();
                                sprite.positionX = p[0];
                                sprite.positionY = p[1];
                                sprite.positionZ = p[2];
                                sprite.image     = "blood.png";
                                entity.sprite    = sprite;
                                entity.expires   = Expires.Create(one * 2 / 10);
                                game.EntityAddLocal(entity);
                            }
                            shot.HitPlayer = i;
                            shot.IsHitHead = 1;
                        }
                    }
                    else
                    {
                        p = Intersection.CheckLineBoxExact(pick, bodybox);
                        if (p != null)
                        {
                            //do not allow to shoot through terrain
                            if (pick2count.value == 0 || (game.Dist(pick2[0].blockPos[0], pick2[0].blockPos[1], pick2[0].blockPos[2], localeyeposX, localeyeposY, localeyeposZ)
                                                          > game.Dist(p[0], p[1], p[2], localeyeposX, localeyeposY, localeyeposZ)))
                            {
                                if (!isgrenade)
                                {
                                    Entity entity = new Entity();
                                    Sprite sprite = new Sprite();
                                    sprite.positionX = p[0];
                                    sprite.positionY = p[1];
                                    sprite.positionZ = p[2];
                                    sprite.image     = "blood.png";
                                    entity.sprite    = sprite;
                                    entity.expires   = Expires.Create(one * 2 / 10);
                                    game.EntityAddLocal(entity);
                                }
                                shot.HitPlayer = i;
                                shot.IsHitHead = 0;
                            }
                        }
                    }
                }
                shot.WeaponBlock = item.BlockId;
                game.LoadedAmmo[item.BlockId] = game.LoadedAmmo[item.BlockId] - 1;
                game.TotalAmmo[item.BlockId]  = game.TotalAmmo[item.BlockId] - 1;
                float projectilespeed = game.DeserializeFloat(game.blocktypes[item.BlockId].ProjectileSpeedFloat);
                if (projectilespeed == 0)
                {
                    {
                        Entity entity = game.CreateBulletEntity(
                            pick.Start[0], pick.Start[1], pick.Start[2],
                            toX, toY, toZ, 150);
                        game.EntityAddLocal(entity);
                    }
                }
                else
                {
                    float vX      = toX - pick.Start[0];
                    float vY      = toY - pick.Start[1];
                    float vZ      = toZ - pick.Start[2];
                    float vLength = game.Length(vX, vY, vZ);
                    vX /= vLength;
                    vY /= vLength;
                    vZ /= vLength;
                    vX *= projectilespeed;
                    vY *= projectilespeed;
                    vZ *= projectilespeed;
                    shot.ExplodesAfter = game.SerializeFloat(game.grenadetime - wait);

                    {
                        Entity grenadeEntity = new Entity();

                        Sprite sprite = new Sprite();
                        sprite.image          = "ChemicalGreen.png";
                        sprite.size           = 14;
                        sprite.animationcount = 0;
                        sprite.positionX      = pick.Start[0];
                        sprite.positionY      = pick.Start[1];
                        sprite.positionZ      = pick.Start[2];
                        grenadeEntity.sprite  = sprite;

                        Grenade_ projectile = new Grenade_();
                        projectile.velocityX    = vX;
                        projectile.velocityY    = vY;
                        projectile.velocityZ    = vZ;
                        projectile.block        = item.BlockId;
                        projectile.sourcePlayer = game.LocalPlayerId;

                        grenadeEntity.expires = Expires.Create(game.grenadetime - wait);

                        grenadeEntity.grenade = projectile;
                        game.EntityAddLocal(grenadeEntity);
                    }
                }
                Packet_Client packet = new Packet_Client();
                packet.Id   = Packet_ClientIdEnum.Shot;
                packet.Shot = shot;
                game.SendPacketClient(packet);

                if (game.blocktypes[item.BlockId].Sounds.ShootEndCount > 0)
                {
                    game.pistolcycle = game.rnd.Next() % game.blocktypes[item.BlockId].Sounds.ShootEndCount;
                    game.AudioPlay(game.platform.StringFormat("{0}.ogg", game.blocktypes[item.BlockId].Sounds.ShootEnd[game.pistolcycle]));
                }

                bulletsshot++;
                if (bulletsshot < game.DeserializeFloat(game.blocktypes[item.BlockId].BulletsPerShotFloat))
                {
                    NextBullet(game, bulletsshot);
                }

                //recoil
                game.player.position.rotx -= game.rnd.NextFloat() * game.CurrentRecoil();
                game.player.position.roty += game.rnd.NextFloat() * game.CurrentRecoil() * 2 - game.CurrentRecoil();

                PickingEnd(left, right, middle, ispistol);
                return;
            }
            if (ispistol && right)
            {
                PickingEnd(left, right, middle, ispistol);
                return;
            }
            if (pick2count.value > 0)
            {
                if (middle)
                {
                    int newtileX = game.platform.FloatToInt(pick0.Current()[0]);
                    int newtileY = game.platform.FloatToInt(pick0.Current()[1]);
                    int newtileZ = game.platform.FloatToInt(pick0.Current()[2]);
                    if (game.map.IsValidPos(newtileX, newtileZ, newtileY))
                    {
                        int  clonesource  = game.map.GetBlock(newtileX, newtileZ, newtileY);
                        int  clonesource2 = game.d_Data.WhenPlayerPlacesGetsConvertedTo()[clonesource];
                        bool gotoDone     = false;
                        //find this block in another right hand.
                        for (int i = 0; i < 10; i++)
                        {
                            if (game.d_Inventory.RightHand[i] != null &&
                                game.d_Inventory.RightHand[i].ItemClass == Packet_ItemClassEnum.Block &&
                                game.d_Inventory.RightHand[i].BlockId == clonesource2)
                            {
                                game.ActiveMaterial = i;
                                gotoDone            = true;
                            }
                        }
                        if (!gotoDone)
                        {
                            IntRef freehand = game.d_InventoryUtil.FreeHand(game.ActiveMaterial);
                            //find this block in inventory.
                            for (int i = 0; i < game.d_Inventory.ItemsCount; i++)
                            {
                                Packet_PositionItem k = game.d_Inventory.Items[i];
                                if (k == null)
                                {
                                    continue;
                                }
                                if (k.Value_.ItemClass == Packet_ItemClassEnum.Block &&
                                    k.Value_.BlockId == clonesource2)
                                {
                                    //free hand
                                    if (freehand != null)
                                    {
                                        game.WearItem(
                                            game.InventoryPositionMainArea(k.X, k.Y),
                                            game.InventoryPositionMaterialSelector(freehand.value));
                                        break;
                                    }
                                    //try to replace current slot
                                    if (game.d_Inventory.RightHand[game.ActiveMaterial] != null &&
                                        game.d_Inventory.RightHand[game.ActiveMaterial].ItemClass == Packet_ItemClassEnum.Block)
                                    {
                                        game.MoveToInventory(
                                            game.InventoryPositionMaterialSelector(game.ActiveMaterial));
                                        game.WearItem(
                                            game.InventoryPositionMainArea(k.X, k.Y),
                                            game.InventoryPositionMaterialSelector(game.ActiveMaterial));
                                    }
                                }
                            }
                        }
                        string[] sound = game.d_Data.CloneSound()[clonesource];
                        if (sound != null)            // && sound.Length > 0)
                        {
                            game.AudioPlay(sound[0]); //todo sound cycle
                        }
                    }
                }
                if (left || right)
                {
                    BlockPosSide tile = pick0;
                    int          newtileX;
                    int          newtileY;
                    int          newtileZ;
                    if (right)
                    {
                        newtileX = game.platform.FloatToInt(tile.Translated()[0]);
                        newtileY = game.platform.FloatToInt(tile.Translated()[1]);
                        newtileZ = game.platform.FloatToInt(tile.Translated()[2]);
                    }
                    else
                    {
                        newtileX = game.platform.FloatToInt(tile.Current()[0]);
                        newtileY = game.platform.FloatToInt(tile.Current()[1]);
                        newtileZ = game.platform.FloatToInt(tile.Current()[2]);
                    }
                    if (game.map.IsValidPos(newtileX, newtileZ, newtileY))
                    {
                        //Console.WriteLine(". newtile:" + newtile + " type: " + d_Map.GetBlock(newtileX, newtileZ, newtileY));
                        if (!(pick0.blockPos[0] == -1 &&
                              pick0.blockPos[1] == -1 &&
                              pick0.blockPos[2] == -1))
                        {
                            int blocktype;
                            if (left)
                            {
                                blocktype = game.map.GetBlock(newtileX, newtileZ, newtileY);
                            }
                            else
                            {
                                blocktype = ((game.BlockInHand() == null) ? 1 : game.BlockInHand().value);
                            }
                            if (left && blocktype == game.d_Data.BlockIdAdminium())
                            {
                                PickingEnd(left, right, middle, ispistol);
                                return;
                            }
                            string[] sound = left ? game.d_Data.BreakSound()[blocktype] : game.d_Data.BuildSound()[blocktype];
                            if (sound != null)            // && sound.Length > 0)
                            {
                                game.AudioPlay(sound[0]); //todo sound cycle
                            }
                        }
                        //normal attack
                        if (!right)
                        {
                            //attack
                            int posx = newtileX;
                            int posy = newtileZ;
                            int posz = newtileY;
                            game.currentAttackedBlock = Vector3IntRef.Create(posx, posy, posz);
                            if (!game.blockHealth.ContainsKey(posx, posy, posz))
                            {
                                game.blockHealth.Set(posx, posy, posz, game.GetCurrentBlockHealth(posx, posy, posz));
                            }
                            game.blockHealth.Set(posx, posy, posz, game.blockHealth.Get(posx, posy, posz) - game.WeaponAttackStrength());
                            float health = game.GetCurrentBlockHealth(posx, posy, posz);
                            if (health <= 0)
                            {
                                if (game.currentAttackedBlock != null)
                                {
                                    game.blockHealth.Remove(posx, posy, posz);
                                }
                                game.currentAttackedBlock = null;
                                OnPick(game, game.platform.FloatToInt(newtileX), game.platform.FloatToInt(newtileZ), game.platform.FloatToInt(newtileY),
                                       game.platform.FloatToInt(tile.Current()[0]), game.platform.FloatToInt(tile.Current()[2]), game.platform.FloatToInt(tile.Current()[1]),
                                       tile.collisionPos,
                                       right);
                            }
                            PickingEnd(left, right, middle, ispistol);
                            return;
                        }
                        if (!right)
                        {
                            game.particleEffectBlockBreak.StartParticleEffect(newtileX, newtileY, newtileZ);//must be before deletion - gets ground type.
                        }
                        if (!game.map.IsValidPos(newtileX, newtileZ, newtileY))
                        {
                            game.platform.ThrowException("Error in picking - NextBullet()");
                        }
                        OnPick(game, game.platform.FloatToInt(newtileX), game.platform.FloatToInt(newtileZ), game.platform.FloatToInt(newtileY),
                               game.platform.FloatToInt(tile.Current()[0]), game.platform.FloatToInt(tile.Current()[2]), game.platform.FloatToInt(tile.Current()[1]),
                               tile.collisionPos,
                               right);
                        //network.SendSetBlock(new Vector3((int)newtile.X, (int)newtile.Z, (int)newtile.Y),
                        //    right ? BlockSetMode.Create : BlockSetMode.Destroy, (byte)MaterialSlots[activematerial]);
                    }
                }
            }
        }
        PickingEnd(left, right, middle, ispistol);
    }
Esempio n. 35
0
        private void MergeItem(C.MergeItem p)
        {
            if (Stage != GameStage.Game) return;

            Player.MergeItem(p.GridFrom, p.GridTo, p.IDFrom, p.IDTo);
        }
Esempio n. 36
0
        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
Esempio n. 37
0
        private void NewAccount(C.NewAccount p)
        {
            if (Stage != GameStage.Login) return;

            SMain.Envir.NewAccount(p, this);
        }
Esempio n. 38
0
        private void Inspect(C.Inspect p)
        {
            if (Stage != GameStage.Game) return;

            Player.Inspect(p.ObjectID);
        }
Esempio n. 39
0
        public void CollectParcel(C.CollectParcel p)
        {
            if (Stage != GameStage.Game) return;

            Player.CollectMail(p.MailID);
        }
Esempio n. 40
0
        //IntelligentCreature
        private void IntelligentCreaturePickup(C.IntelligentCreaturePickup p)
        {
            if (Stage != GameStage.Game) return;

            Player.IntelligentCreaturePickup(p.MouseMode, p.Location);
        }
Esempio n. 41
0
        public void NewCharacter(ClientPackets.NewCharacter p, MirConnection c)
        {
            if (!Settings.AllowNewCharacter)
            {
                c.Enqueue(new ServerPackets.NewCharacter {Result = 0});
                return;
            }

            if (!CharacterReg.IsMatch(p.Name))
            {
                c.Enqueue(new ServerPackets.NewCharacter {Result = 1});
                return;
            }

            if (p.Gender != MirGender.Male && p.Gender != MirGender.Female)
            {
                c.Enqueue(new ServerPackets.NewCharacter {Result = 2});
                return;
            }

            if (p.Class != MirClass.Warrior && p.Class != MirClass.Wizard && p.Class != MirClass.Taoist &&
                p.Class != MirClass.Assassin && p.Class != MirClass.Archer)
            {
                c.Enqueue(new ServerPackets.NewCharacter {Result = 3});
                return;
            }

            if((p.Class == MirClass.Assassin && !Settings.AllowCreateAssassin) ||
                (p.Class == MirClass.Archer && !Settings.AllowCreateArcher))
            {
                c.Enqueue(new ServerPackets.NewCharacter { Result = 3 });
                return;
            }

            int count = 0;

            for (int i = 0; i < c.Account.Characters.Count; i++)
            {
                if (c.Account.Characters[i].Deleted) continue;

                if (++count >= Globals.MaxCharacterCount)
                {
                    c.Enqueue(new ServerPackets.NewCharacter {Result = 4});
                    return;
                }
            }

            lock (AccountLock)
            {
                if (CharacterExists(p.Name))
                {
                    c.Enqueue(new ServerPackets.NewCharacter {Result = 5});
                    return;
                }

                CharacterInfo info = new CharacterInfo(p, c) { Index = ++NextCharacterID, AccountInfo = c.Account };

                c.Account.Characters.Add(info);
                CharacterList.Add(info);

                c.Enqueue(new ServerPackets.NewCharacterSuccess {CharInfo = info.ToSelectInfo()});
            }
        }
Esempio n. 42
0
        private void Login(C.Login p)
        {
            if (Stage != GameStage.Login) return;

            SMain.Envir.Login(p, this);
        }
Esempio n. 43
0
        public void Login(ClientPackets.Login p, MirConnection c)
        {
            if (!Settings.AllowLogin)
            {
                c.Enqueue(new ServerPackets.Login { Result = 0 });
                return;
            }

            if (!AccountIDReg.IsMatch(p.AccountID))
            {
                c.Enqueue(new ServerPackets.Login { Result = 1 });
                return;
            }

            if (!PasswordReg.IsMatch(p.Password))
            {
                c.Enqueue(new ServerPackets.Login { Result = 2 });
                return;
            }
            AccountInfo account = GetAccount(p.AccountID);

            if (account == null)
            {
                c.Enqueue(new ServerPackets.Login { Result = 3 });
                return;
            }

            if (account.Banned)
            {
                if (account.ExpiryDate > DateTime.Now)
                {
                    c.Enqueue(new ServerPackets.LoginBanned
                    {
                        Reason = account.BanReason,
                        ExpiryDate = account.ExpiryDate
                    });
                    return;
                }
                account.Banned = false;
            }
                account.BanReason = string.Empty;
                account.ExpiryDate = DateTime.MinValue;

            if (String.CompareOrdinal(account.Password, p.Password) != 0)
            {
                c.Enqueue(new ServerPackets.Login { Result = 4 });
                return;
            }

            lock (AccountLock)
            {
                if (account.Connection != null)
                    account.Connection.SendDisconnect(1);

                account.Connection = c;
            }

            c.Account = account;
            c.Stage = GameStage.Select;

            account.LastDate = Now;
            account.LastIP = c.IPAddress;

            c.Enqueue(new ServerPackets.LoginSuccess { Characters = account.GetSelectInfo() });
        }
Esempio n. 44
0
        private void Magic(C.Magic p)
        {
            if (Stage != GameStage.Game) return;

            if (!Player.Dead && (Player.ActionTime > SMain.Envir.Time || Player.SpellTime > SMain.Envir.Time))
                _retryList.Enqueue(p);
            else
                Player.Magic(p.Spell, p.Direction, p.TargetID, p.Location);
        }
Esempio n. 45
0
 /// <summary>Creates a new packet with a given ID. Used for sending.</summary>
 /// <param name="_id">The packet ID.</param>
 public Packet(ClientPackets _id) : this((int)_id)
 {
 }
Esempio n. 46
0
        private void MagicKey(C.MagicKey p)
        {
            if (Stage != GameStage.Game) return;

            for (int i = 0; i < Player.Info.Magics.Count; i++)
            {
                UserMagic magic = Player.Info.Magics[i];
                if (magic.Spell != p.Spell)
                {
                    if (magic.Key == p.Key)
                        magic.Key = 0;
                    continue;
                }

                magic.Key = p.Key;
            }
        }
Esempio n. 47
0
 private void GuildWarReturn(C.GuildWarReturn p)
 {
     if (Stage != GameStage.Game) return;
     Player.GuildWarReturn(p.Name);
 }
Esempio n. 48
0
        private void MarketBuy(C.MarketBuy p)
        {
            if (Stage != GameStage.Game) return;

            Player.MarketBuy(p.AuctionID);
        }
Esempio n. 49
0
 /// <summary>Creates a new packet with a given ID. Used for sending.</summary>
 /// <param name="id">The packet ID.</param>
 public Packet(ClientPackets id) : this((int)id)
 {
 }
Esempio n. 50
0
        private void Harvest(C.Harvest p)
        {
            if (Stage != GameStage.Game) return;

            if (!Player.Dead && Player.ActionTime > SMain.Envir.Time)
                _retryList.Enqueue(p);
            else
                Player.Harvest(p.Direction);
        }