Ejemplo n.º 1
0
        /// <summary>
        /// Downloads the amount of attributs.
        /// </summary>
        /// <returns>The amount of attributs.</returns>
        /// <param name="petID">Pet identifier.</param>
        public static ServerPacketGetAmountOfAttributs DownloadAmountOfAttributs(int petID)
        {
            //create new client packet get amount of attributs
            ClientPacketGetAmountOfAttributs clientPacketGetAmountOfAttributs = new ClientPacketGetAmountOfAttributs(petID);

            //send packet to server
            ServerPacketGetAmountOfAttributs serverPacketGetAmountOfAttributs = TCPClient.SendPacket(clientPacketGetAmountOfAttributs) as ServerPacketGetAmountOfAttributs;

            //if no answer
            if (serverPacketGetAmountOfAttributs == null)
            {
                return(new ServerPacketGetAmountOfAttributs(0));
            }

            //return packet
            return(serverPacketGetAmountOfAttributs);
        }
Ejemplo n.º 2
0
        public override Packet OnPacketReceive(Packet receivedPacket)
        {
            ClientPacketGetAmountOfAttributs clientPacketGetAmountOfAttributs = receivedPacket as ClientPacketGetAmountOfAttributs;

            ConsoleHelper.Write("Receive - ClientPacketGetAmountOfAttributs");

            int petID = clientPacketGetAmountOfAttributs.PetID;

            //download pet
            MySqlCommand downloadPetsCommand = new MySqlCommand();

            downloadPetsCommand.Connection  = Program.mySQLManager.MySQLConnection.MysqlConnection;
            downloadPetsCommand.CommandText = $@"SELECT * FROM `T_Pet` WHERE `petID` IN ({petID})";


            MySqlDataReader mysqlDataReader = null;

            List <PetAttribute> petAttributes = new List <PetAttribute>();

            try
            {
                mysqlDataReader = downloadPetsCommand.ExecuteReader();

                //open reader
                while (mysqlDataReader.Read())
                {
                    petAttributes = JsonConvert.DeserializeObject <List <PetAttribute> >(mysqlDataReader.GetString(3));
                }

                mysqlDataReader.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            if (mysqlDataReader != null && !mysqlDataReader.IsClosed)
            {
                mysqlDataReader.Close();
            }

            ConsoleHelper.Write("Send - ServerPacketGetAmountOfAttributs");

            return(new ServerPacketGetAmountOfAttributs(petAttributes.Count));
        }