public override Packet OnPacketReceive(Packet receivedPacket) { //get received packet ClientPacketDeletePet clientPacketDeletePet = receivedPacket as ClientPacketDeletePet; ConsoleHelper.Write("Receive - ClientPacketDeletePet"); //read packet infos int userID = clientPacketDeletePet.UserID; int petID = clientPacketDeletePet.PetID; //insert new profile into DB MySqlCommand deletePetCommand = new MySqlCommand(); deletePetCommand.Connection = Program.mySQLManager.MySQLConnection.MysqlConnection; deletePetCommand.CommandText = $"DELETE FROM T_Own WHERE T_Own.`fkPetID`='{petID}' AND T_Own.`fkUserID`='{userID}'; DELETE FROM `T_Share` WHERE `fkPetID`='{petID}'; DELETE FROM T_Pet WHERE `petID`= '{petID}'"; ServerPacketConfirmation serverPacketConfirmation; try { //Execute command deletePetCommand.ExecuteNonQuery(); serverPacketConfirmation = new ServerPacketConfirmation(true, NetworkError.NONE); } catch { serverPacketConfirmation = new ServerPacketConfirmation(false, NetworkError.GLOBAL_UNKNOWN); } ConsoleHelper.Write("Send - ServerPacketConfirmation"); return(serverPacketConfirmation); }
/// <summary> /// Deletes the pet. /// </summary> /// <returns>The pet.</returns> /// <param name="user">User.</param> /// <param name="pet">Pet.</param> public static ServerPacketConfirmation DeletePet(PLFUser user, PLFPet pet) { //get user and pet id int userID = user.ID; int petID = pet.PetID; //new client delete pet ClientPacketDeletePet clientPacketDeletePet = new ClientPacketDeletePet(userID, petID); //send delete packet to the server ServerPacketConfirmation serverPacketConfirmation = TCPClient.SendPacket(clientPacketDeletePet) as ServerPacketConfirmation; //if no answer if (serverPacketConfirmation == null) { return(new ServerPacketConfirmation(false, NetworkError.SERVER_UNAVAILABLE)); } return(serverPacketConfirmation); }