Exemple #1
0
        public override Packet OnPacketReceive(Packet receivedPacket)
        {
            //get received packet
            ClientPacketDownloadAttributs clientPacketDownloadAttributs = receivedPacket as ClientPacketDownloadAttributs;

            ConsoleHelper.Write("Receive - ClientPacketDownloadAttributs");

            //read packet infosk
            int petID = clientPacketDownloadAttributs.PetID;

            //download pets command
            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));
                }

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

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

            ConsoleHelper.Write("Send - ServerPacketDownloadAttributs");

            return(new ServerPacketDownloadAttributs(petAttributes));
        }
Exemple #2
0
        /// <summary>
        /// Downloads the attributs.
        /// </summary>
        /// <returns>The attributs.</returns>
        /// <param name="petID">Pet identifier.</param>
        public static ServerPacketDownloadAttributs DownloadAttributs(int petID)
        {
            //create new client packet download attributs
            ClientPacketDownloadAttributs clientPacketDownloadAttributs = new ClientPacketDownloadAttributs(petID);

            //Send packet to server
            ServerPacketDownloadAttributs serverPacketDownloadAttributs = TCPClient.SendPacket(clientPacketDownloadAttributs) as ServerPacketDownloadAttributs;

            //if no answer
            if (serverPacketDownloadAttributs == null)
            {
                return(new ServerPacketDownloadAttributs(new List <PetAttribute>()));
            }

            //return packet
            return(serverPacketDownloadAttributs);
        }